Commit 530016aa authored by mae's avatar mae
Browse files

Fix cursor positioning for up/down after backspace

Reviewed-by: Roberto Raggi
parent 63ef0d36
...@@ -1171,7 +1171,6 @@ void BaseTextEditor::keyPressEvent(QKeyEvent *e) ...@@ -1171,7 +1171,6 @@ void BaseTextEditor::keyPressEvent(QKeyEvent *e)
break; break;
pos = cpos; pos = cpos;
} }
setTextCursor(textCursor()); // make cursor visible
return; return;
} else switch (e->key()) { } else switch (e->key()) {
...@@ -1215,7 +1214,6 @@ void BaseTextEditor::keyPressEvent(QKeyEvent *e) ...@@ -1215,7 +1214,6 @@ void BaseTextEditor::keyPressEvent(QKeyEvent *e)
| Qt::MetaModifier)) == Qt::NoModifier | Qt::MetaModifier)) == Qt::NoModifier
&& !textCursor().hasSelection()) { && !textCursor().hasSelection()) {
handleBackspaceKey(); handleBackspaceKey();
setTextCursor(textCursor()); // make cursor visible
e->accept(); e->accept();
return; return;
} }
...@@ -3723,6 +3721,8 @@ void BaseTextEditor::handleHomeKey(bool anchor) ...@@ -3723,6 +3721,8 @@ void BaseTextEditor::handleHomeKey(bool anchor)
setTextCursor(cursor); setTextCursor(cursor);
} }
#define SET_AND_RETURN(cursor) setTextCursor(cursor); return // make cursor visible and reset vertical x movement
void BaseTextEditor::handleBackspaceKey() void BaseTextEditor::handleBackspaceKey()
{ {
QTextCursor cursor = textCursor(); QTextCursor cursor = textCursor();
...@@ -3742,7 +3742,7 @@ void BaseTextEditor::handleBackspaceKey() ...@@ -3742,7 +3742,7 @@ void BaseTextEditor::handleBackspaceKey()
if (!tabSettings.m_smartBackspace) { if (!tabSettings.m_smartBackspace) {
cursor.deletePreviousChar(); cursor.deletePreviousChar();
return; SET_AND_RETURN(cursor);
} }
QTextBlock currentBlock = cursor.block(); QTextBlock currentBlock = cursor.block();
...@@ -3750,7 +3750,7 @@ void BaseTextEditor::handleBackspaceKey() ...@@ -3750,7 +3750,7 @@ void BaseTextEditor::handleBackspaceKey()
const QString blockText = currentBlock.text(); const QString blockText = currentBlock.text();
if (cursor.atBlockStart() || tabSettings.firstNonSpace(blockText) < positionInBlock) { if (cursor.atBlockStart() || tabSettings.firstNonSpace(blockText) < positionInBlock) {
cursor.deletePreviousChar(); cursor.deletePreviousChar();
return; SET_AND_RETURN(cursor);
} }
int previousIndent = 0; int previousIndent = 0;
...@@ -3769,10 +3769,11 @@ void BaseTextEditor::handleBackspaceKey() ...@@ -3769,10 +3769,11 @@ void BaseTextEditor::handleBackspaceKey()
cursor.setPosition(currentBlock.position(), QTextCursor::KeepAnchor); cursor.setPosition(currentBlock.position(), QTextCursor::KeepAnchor);
cursor.insertText(tabSettings.indentationString(previousNonEmptyBlockText)); cursor.insertText(tabSettings.indentationString(previousNonEmptyBlockText));
cursor.endEditBlock(); cursor.endEditBlock();
return; SET_AND_RETURN(cursor);
} }
} }
cursor.deletePreviousChar(); cursor.deletePreviousChar();
SET_AND_RETURN(cursor);
} }
void BaseTextEditor::wheelEvent(QWheelEvent *e) void BaseTextEditor::wheelEvent(QWheelEvent *e)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment