Commit 8d932e2a authored by hjk's avatar hjk
Browse files

Fixes: fakevim: improve handling of 'p' and 'Y'

    Details:  tank count() into account, fix cursor positioning after undo
parent 42a70000
...@@ -286,11 +286,11 @@ public: ...@@ -286,11 +286,11 @@ public:
void recordInsert(int position, const QString &data); void recordInsert(int position, const QString &data);
void recordRemove(int position, const QString &data); void recordRemove(int position, const QString &data);
void recordRemove(int position, int length); void recordRemove(int position, int length);
void recordMove(int position, int nestedCount);
void recordRemoveNextChar(); void recordRemoveNextChar();
void recordInsertText(const QString &data); void recordInsertText(const QString &data);
QString recordRemoveSelectedText(); QString recordRemoveSelectedText();
void recordMove();
void recordBeginGroup(); void recordBeginGroup();
void recordEndGroup(); void recordEndGroup();
int anchor() const { return m_anchor; } int anchor() const { return m_anchor; }
...@@ -928,19 +928,27 @@ bool FakeVimHandler::Private::handleCommandMode(int key, int unmodified, ...@@ -928,19 +928,27 @@ bool FakeVimHandler::Private::handleCommandMode(int key, int unmodified,
//qDebug() << "REGISTERS: " << m_registers << "MOVE: " << m_moveType; //qDebug() << "REGISTERS: " << m_registers << "MOVE: " << m_moveType;
//qDebug() << "LINES: " << n << text << m_register; //qDebug() << "LINES: " << n << text << m_register;
if (n > 0) { if (n > 0) {
recordMove();
moveToStartOfLine(); moveToStartOfLine();
if (key == 'p') m_desiredColumn = 0;
moveDown(); for (int i = count(); --i >= 0; ) {
recordInsertText(text); if (key == 'p')
moveUp(n); moveDown();
recordInsertText(text);
moveUp(n);
}
} else { } else {
if (key == 'p') m_desiredColumn = 0;
moveRight(); for (int i = count(); --i >= 0; ) {
recordInsertText(text); if (key == 'p')
moveLeft(); moveRight();
recordInsertText(text);
moveLeft();
}
} }
recordEndGroup(); recordEndGroup();
m_dotCommand = "p"; m_dotCommand = QString("%1p").arg(count());
finishMovement();
} else if (key == 'r') { } else if (key == 'r') {
m_submode = ReplaceSubMode; m_submode = ReplaceSubMode;
m_dotCommand = "r"; m_dotCommand = "r";
...@@ -1868,8 +1876,19 @@ void FakeVimHandler::Private::recordInsertText(const QString &data) ...@@ -1868,8 +1876,19 @@ void FakeVimHandler::Private::recordInsertText(const QString &data)
m_tc.insertText(data); m_tc.insertText(data);
} }
void FakeVimHandler::Private::recordMove()
{
EditOperation op;
op.position = m_tc.position();
m_undoStack.push(op);
m_redoStack.clear();
//qDebug() << "MOVE: " << op;
//qDebug() << "\nSTACK: " << m_undoStack;
}
void FakeVimHandler::Private::recordOperation(const EditOperation &op) void FakeVimHandler::Private::recordOperation(const EditOperation &op)
{ {
//qDebug() << "OP: " << op;
// No need to record operations that actually do not change anything. // No need to record operations that actually do not change anything.
if (op.from.isEmpty() && op.to.isEmpty() && op.itemCount == 0) if (op.from.isEmpty() && op.to.isEmpty() && op.itemCount == 0)
return; return;
...@@ -1878,14 +1897,7 @@ void FakeVimHandler::Private::recordOperation(const EditOperation &op) ...@@ -1878,14 +1897,7 @@ void FakeVimHandler::Private::recordOperation(const EditOperation &op)
return; return;
m_undoStack.push(op); m_undoStack.push(op);
m_redoStack.clear(); m_redoStack.clear();
} //qDebug() << "\nSTACK: " << m_undoStack;
void FakeVimHandler::Private::recordMove(int position, int nestedCount)
{
EditOperation op;
op.position = position;
op.itemCount = nestedCount;
recordOperation(op);
} }
void FakeVimHandler::Private::recordInsert(int position, const QString &data) void FakeVimHandler::Private::recordInsert(int position, const QString &data)
......
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