void GoIndenter::indentBlock(const QTextBlock &block, const QChar &typedChar, const TextEditor::TabSettings &tabSettings, int cursorPositionInEditor) { GoCodeFormatter codeFormatter(tabSettings); codeFormatter.updateStateUntil(block); int indentation; int padding; codeFormatter.calcIndentation(block, &indentation, &padding); if (isElectricCharacter(typedChar)) { int defaultIndentation; int defaultPadding; codeFormatter.calcIndentation(block, &defaultIndentation, &defaultPadding, true); } tabSettings.indentLine(block, indentation + padding, padding); }
virtual void indentSelection(const QTextCursor &selection, const QString &fileName, const TextEditor::TextDocument *textDocument) const { // ### shares code with QmlJSTextEditor::indent QTextDocument *doc = selection.document(); QTextBlock block = doc->findBlock(selection.selectionStart()); const QTextBlock end = doc->findBlock(selection.selectionEnd()).next(); const TextEditor::TabSettings &tabSettings = ProjectExplorer::actualTabSettings(fileName, textDocument); CreatorCodeFormatter codeFormatter(tabSettings); codeFormatter.updateStateUntil(block); do { const int depth = codeFormatter.indentFor(block); if (depth != -1) tabSettings.indentLine(block, depth); codeFormatter.updateLineStateChange(block); block = block.next(); } while (block.isValid() && block != end); }