fakevim: Improved jump list

Record jump before changing text cursor position.

Implemented "latest jump" mark (single quote).

Change-Id: Ia3392761f80c185b06ad326718ad9db0d3108d45
Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
Lukas Holecek
2012-08-11 14:31:42 +02:00
committed by hjk
parent 2481e58da8
commit a57b4cf93e

View File

@@ -1197,8 +1197,9 @@ public:
void getRegisterType(int reg, bool *isClipboard, bool *isSelection) const; void getRegisterType(int reg, bool *isClipboard, bool *isSelection) const;
void recordJump(); void recordJump();
QVector<CursorPosition> m_jumpListUndo; void jump(int distance);
QVector<CursorPosition> m_jumpListRedo; QStack<CursorPosition> m_jumpListUndo;
QStack<CursorPosition> m_jumpListRedo;
int m_lastChangePosition; int m_lastChangePosition;
QList<QTextEdit::ExtraSelection> m_searchSelections; QList<QTextEdit::ExtraSelection> m_searchSelections;
@@ -1412,12 +1413,11 @@ EventResult FakeVimHandler::Private::handleEvent(QKeyEvent *ev)
QTextCursor tc = cursor(); QTextCursor tc = cursor();
tc.setVisualNavigation(true); tc.setVisualNavigation(true);
setCursor(tc);
if (m_firstKeyPending) { if (m_firstKeyPending) {
m_firstKeyPending = false; m_firstKeyPending = false;
recordJump(); recordJump();
} }
setCursor(tc);
if (m_fakeEnd) if (m_fakeEnd)
moveRight(); moveRight();
@@ -1896,18 +1896,18 @@ void FakeVimHandler::Private::finishMovement(const QString &dotCommand)
handleStartOfLine(); handleStartOfLine();
endEditBlock(); endEditBlock();
} else if (m_submode == IndentSubMode) { } else if (m_submode == IndentSubMode) {
setUndoPosition();
recordJump(); recordJump();
setUndoPosition();
indentSelectedText(); indentSelectedText();
m_submode = NoSubMode; m_submode = NoSubMode;
} else if (m_submode == ShiftRightSubMode) { } else if (m_submode == ShiftRightSubMode) {
setUndoPosition();
recordJump(); recordJump();
setUndoPosition();
shiftRegionRight(1); shiftRegionRight(1);
m_submode = NoSubMode; m_submode = NoSubMode;
} else if (m_submode == ShiftLeftSubMode) { } else if (m_submode == ShiftLeftSubMode) {
setUndoPosition();
recordJump(); recordJump();
setUndoPosition();
shiftRegionLeft(1); shiftRegionLeft(1);
m_submode = NoSubMode; m_submode = NoSubMode;
} }
@@ -2095,8 +2095,12 @@ EventResult FakeVimHandler::Private::handleCommandSubSubMode(const Input &input)
m_subsubmode = NoSubSubMode; m_subsubmode = NoSubSubMode;
} else if (m_subsubmode == BackTickSubSubMode } else if (m_subsubmode == BackTickSubSubMode
|| m_subsubmode == TickSubSubMode) { || m_subsubmode == TickSubSubMode) {
int m = mark(input.asChar().unicode()); ushort markChar = input.asChar().unicode();
int m = mark(markChar);
if (m != -1) { if (m != -1) {
if (markChar == '\'' && !m_jumpListUndo.isEmpty())
m_jumpListUndo.pop();
recordJump();
setPosition(m); setPosition(m);
if (m_subsubmode == TickSubSubMode) if (m_subsubmode == TickSubSubMode)
moveToFirstNonBlankOnLine(); moveToFirstNonBlankOnLine();
@@ -2700,11 +2704,7 @@ EventResult FakeVimHandler::Private::handleCommandMode2(const Input &input)
breakEditBlock(); breakEditBlock();
enterInsertMode(); enterInsertMode();
} else if (input.isControl('i')) { } else if (input.isControl('i')) {
if (!m_jumpListRedo.isEmpty()) { jump(count());
m_jumpListUndo.append(cursorPosition());
setCursorPosition(m_jumpListRedo.last());
m_jumpListRedo.pop_back();
}
} else if (input.is('j') || input.isKey(Key_Down) } else if (input.is('j') || input.isKey(Key_Down)
|| input.isControl('j') || input.isControl('n')) { || input.isControl('j') || input.isControl('n')) {
m_movetype = MoveLineWise; m_movetype = MoveLineWise;
@@ -2817,11 +2817,7 @@ EventResult FakeVimHandler::Private::handleCommandMode2(const Input &input)
insertAutomaticIndentation(false); insertAutomaticIndentation(false);
endEditBlock(); endEditBlock();
} else if (input.isControl('o')) { } else if (input.isControl('o')) {
if (!m_jumpListUndo.isEmpty()) { jump(-count());
m_jumpListRedo.append(cursorPosition());
setCursorPosition(m_jumpListUndo.last());
m_jumpListUndo.pop_back();
}
} else if (input.is('p') || input.is('P')) { } else if (input.is('p') || input.is('P')) {
pasteText(input.is('p')); pasteText(input.is('p'));
setTargetColumn(); setTargetColumn();
@@ -4192,10 +4188,10 @@ void FakeVimHandler::Private::searchBalanced(bool forward, QChar needle, QChar o
// Making this unconditional feels better, but is not "vim like". // Making this unconditional feels better, but is not "vim like".
if (oldLine != cursorLine() - cursorLineOnScreen()) if (oldLine != cursorLine() - cursorLineOnScreen())
scrollToLine(cursorLine() - linesOnScreen() / 2); scrollToLine(cursorLine() - linesOnScreen() / 2);
recordJump();
setPosition(pos); setPosition(pos);
setTargetColumn(); setTargetColumn();
updateSelection(); updateSelection();
recordJump();
return; return;
} }
} }
@@ -4241,6 +4237,8 @@ void FakeVimHandler::Private::search(const SearchData &sd)
} }
} }
recordJump();
// Set Cursor. In contrast to the main editor we have the cursor // Set Cursor. In contrast to the main editor we have the cursor
// position before the anchor position. // position before the anchor position.
setAnchorAndPosition(tc.position(), tc.anchor()); setAnchorAndPosition(tc.position(), tc.anchor());
@@ -4257,7 +4255,6 @@ void FakeVimHandler::Private::search(const SearchData &sd)
if (sd.highlightMatches) if (sd.highlightMatches)
highlightMatches(sd.needle); highlightMatches(sd.needle);
updateSelection(); updateSelection();
recordJump();
} }
void FakeVimHandler::Private::highlightMatches(const QString &needle) void FakeVimHandler::Private::highlightMatches(const QString &needle)
@@ -5299,11 +5296,27 @@ void FakeVimHandler::Private::enterExMode()
void FakeVimHandler::Private::recordJump() void FakeVimHandler::Private::recordJump()
{ {
m_jumpListUndo.append(cursorPosition()); CursorPosition pos = cursorPosition();
setMark('\'', pos.position);
if (m_jumpListUndo.isEmpty() || m_jumpListUndo.top().position != pos.position)
m_jumpListUndo.push(pos);
m_jumpListRedo.clear(); m_jumpListRedo.clear();
UNDO_DEBUG("jumps: " << m_jumpListUndo); UNDO_DEBUG("jumps: " << m_jumpListUndo);
} }
void FakeVimHandler::Private::jump(int distance)
{
QStack<CursorPosition> &from = (distance > 0) ? m_jumpListRedo : m_jumpListUndo;
QStack<CursorPosition> &to = (distance > 0) ? m_jumpListUndo : m_jumpListRedo;
int len = qMin(qAbs(distance), from.size());
setMark('\'', position());
for (int i = 0; i < len; ++i) {
to.push(cursorPosition());
setCursorPosition(from.top());
from.pop();
}
}
Column FakeVimHandler::Private::indentation(const QString &line) const Column FakeVimHandler::Private::indentation(const QString &line) const
{ {
int ts = config(ConfigTabStop).toInt(); int ts = config(ConfigTabStop).toInt();