MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / changeBlockIndent

Method changeBlockIndent

lib/QCodeEditor/src/internal/QCodeEditor.cpp:857–904  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

855}
856
857void QCodeEditor::changeBlockIndent(bool increase)
858{
859 auto cursor = textCursor();
860 const int startPos = qMin(cursor.anchor(), cursor.position());
861 const int endPos = qMax(cursor.anchor(), cursor.position());
862
863 auto probe = QTextCursor(document());
864 probe.setPosition(startPos);
865 const int firstBlock = probe.blockNumber();
866 probe.setPosition(endPos);
867 int lastBlock = probe.blockNumber();
868
869 // A selection ending at column 0 does not include that line
870 if (lastBlock > firstBlock && cursor.hasSelection()
871 && probe.positionInBlock() == 0)
872 --lastBlock;
873
874 probe.beginEditBlock();
875 for (int i = firstBlock; i <= lastBlock; ++i)
876 {
877 const auto block = document()->findBlockByNumber(i);
878 auto line = QTextCursor(block);
879
880 if (increase)
881 {
882 if (!block.text().isEmpty())
883 line.insertText(m_tabReplace);
884 continue;
885 }
886
887 const auto text = block.text();
888 int remove = 0;
889 while (remove < m_tabReplace.size() && remove < text.size()
890 && text[remove] == ' ')
891 ++remove;
892
893 if (remove == 0 && !text.isEmpty() && text[0] == '\t')
894 remove = 1;
895
896 if (remove > 0)
897 {
898 line.movePosition(QTextCursor::MoveOperation::Right,
899 QTextCursor::MoveMode::KeepAnchor, remove);
900 line.removeSelectedText();
901 }
902 }
903 probe.endEditBlock();
904}
905
906void QCodeEditor::toggleLineComment()
907{

Callers

nothing calls this directly

Calls 3

isEmptyMethod · 0.80
textMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected