Commit 519b2d21 authored by Kornelia Poenitz's avatar Kornelia Poenitz Committed by Oswald Buddenhagen
Browse files

FakeVim: Correct cursor moving in InsertMode



Text was selected after horizontal cursor moving / insert / enter followed by
vertical cursor movement. Also, target column was sometimes wrong.

Reviewed-By: hjk

Merge-request: 1050
Reviewed-by: default avatarOswald Buddenhagen <oswald.buddenhagen@nokia.com>
parent 1e7b4063
...@@ -1564,30 +1564,34 @@ EventResult FakeVimHandler::Private::handleInsertMode(int key, int, ...@@ -1564,30 +1564,34 @@ EventResult FakeVimHandler::Private::handleInsertMode(int key, int,
} }
} else if (key == Key_Left) { } else if (key == Key_Left) {
moveLeft(count()); moveLeft(count());
setTargetColumn();
m_lastInsertion.clear(); m_lastInsertion.clear();
} else if (key == Key_Down) { } else if (key == Key_Down) {
removeAutomaticIndentation(); //removeAutomaticIndentation();
m_submode = NoSubMode; m_submode = NoSubMode;
moveDown(count()); moveDown(count());
m_lastInsertion.clear(); m_lastInsertion.clear();
} else if (key == Key_Up) { } else if (key == Key_Up) {
removeAutomaticIndentation(); //removeAutomaticIndentation();
m_submode = NoSubMode; m_submode = NoSubMode;
moveUp(count()); moveUp(count());
m_lastInsertion.clear(); m_lastInsertion.clear();
} else if (key == Key_Right) { } else if (key == Key_Right) {
moveRight(count()); moveRight(count());
setTargetColumn();
m_lastInsertion.clear(); m_lastInsertion.clear();
} else if (key == Key_Return) { } else if (key == Key_Return) {
m_submode = NoSubMode; m_submode = NoSubMode;
m_tc.insertBlock(); m_tc.insertBlock();
m_lastInsertion += "\n"; m_lastInsertion += "\n";
insertAutomaticIndentation(true); insertAutomaticIndentation(true);
setTargetColumn();
} else if (key == Key_Backspace || key == control('h')) { } else if (key == Key_Backspace || key == control('h')) {
if (!removeAutomaticIndentation()) if (!removeAutomaticIndentation())
if (!m_lastInsertion.isEmpty() || hasConfig(ConfigBackspace, "start")) { if (!m_lastInsertion.isEmpty() || hasConfig(ConfigBackspace, "start")) {
m_tc.deletePreviousChar(); m_tc.deletePreviousChar();
m_lastInsertion.chop(1); m_lastInsertion.chop(1);
setTargetColumn();
} }
} else if (key == Key_Delete) { } else if (key == Key_Delete) {
m_tc.deleteChar(); m_tc.deleteChar();
...@@ -1604,6 +1608,7 @@ EventResult FakeVimHandler::Private::handleInsertMode(int key, int, ...@@ -1604,6 +1608,7 @@ EventResult FakeVimHandler::Private::handleInsertMode(int key, int,
QString str = QString(theFakeVimSetting(ConfigTabStop)->value().toInt(), ' '); QString str = QString(theFakeVimSetting(ConfigTabStop)->value().toInt(), ' ');
m_lastInsertion.append(str); m_lastInsertion.append(str);
m_tc.insertText(str); m_tc.insertText(str);
setTargetColumn();
} else if (key >= control('a') && key <= control('z')) { } else if (key >= control('a') && key <= control('z')) {
// ignore these // ignore these
} else if (!text.isEmpty()) { } else if (!text.isEmpty()) {
...@@ -1625,6 +1630,7 @@ EventResult FakeVimHandler::Private::handleInsertMode(int key, int, ...@@ -1625,6 +1630,7 @@ EventResult FakeVimHandler::Private::handleInsertMode(int key, int,
if (!m_inReplay) if (!m_inReplay)
emit q->completionRequested(); emit q->completionRequested();
setTargetColumn();
} else { } else {
return EventUnhandled; return EventUnhandled;
} }
...@@ -2200,14 +2206,14 @@ void FakeVimHandler::Private::shiftRegionLeft(int repeat) ...@@ -2200,14 +2206,14 @@ void FakeVimHandler::Private::shiftRegionLeft(int repeat)
void FakeVimHandler::Private::moveToTargetColumn() void FakeVimHandler::Private::moveToTargetColumn()
{ {
const QTextBlock &block = m_tc.block(); const QTextBlock &block = m_tc.block();
int col = m_tc.position() - m_tc.block().position(); int col = m_tc.position() - block.position();
if (col == m_targetColumn) if (col == m_targetColumn)
return; return;
//qDebug() << "CORRECTING COLUMN FROM: " << col << "TO" << m_targetColumn; //qDebug() << "CORRECTING COLUMN FROM: " << col << "TO" << m_targetColumn;
if (m_targetColumn == -1 || m_tc.block().length() <= m_targetColumn) if (m_targetColumn == -1 || block.length() <= m_targetColumn)
m_tc.setPosition(block.position() + block.length() - 1, KeepAnchor); m_tc.setPosition(block.position() + block.length() - 1, MoveAnchor);
else else
m_tc.setPosition(m_tc.block().position() + m_targetColumn, KeepAnchor); m_tc.setPosition(block.position() + m_targetColumn, MoveAnchor);
} }
/* if simple is given: /* if simple is given:
......
Supports Markdown
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