Skip to content

Commit ae5e3a8

Browse files
committed
fix: Delete an indentation when pressing Backspace
This closes Megaxela#7.
1 parent fc44a0b commit ae5e3a8

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/internal/QCodeEditor.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,31 @@ void QCodeEditor::keyPressEvent(QKeyEvent *e)
656656
return;
657657
}
658658
}
659+
660+
if (textCursor().columnNumber() <= indentationSpaces.length() && textCursor().columnNumber() >= 1 &&
661+
!m_tabReplace.isEmpty())
662+
{
663+
auto cursor = textCursor();
664+
int realColumn = 0, newIndentLength = 0;
665+
for (int i = 0; i < cursor.columnNumber(); ++i)
666+
{
667+
if (indentationSpaces[i] != '\t')
668+
++realColumn;
669+
else
670+
{
671+
realColumn =
672+
(realColumn + m_tabReplace.length()) / m_tabReplace.length() * m_tabReplace.length();
673+
}
674+
if (realColumn % m_tabReplace.length() == 0 && i < cursor.columnNumber() - 1)
675+
{
676+
newIndentLength = i + 1;
677+
}
678+
}
679+
cursor.movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor,
680+
cursor.columnNumber() - newIndentLength);
681+
cursor.insertText("");
682+
return;
683+
}
659684
}
660685

661686
if (m_autoParentheses)

0 commit comments

Comments
 (0)