diff --git a/src/plugins/fakevim/fakevim_test.cpp b/src/plugins/fakevim/fakevim_test.cpp index 4bf1738312d..891ea33dd7f 100644 --- a/src/plugins/fakevim/fakevim_test.cpp +++ b/src/plugins/fakevim/fakevim_test.cpp @@ -571,12 +571,16 @@ void FakeVimPlugin::test_vim_transform_numbers() KEYS("B9", "x-x+x: " X "0 0 0 0 0"); KEYS("B9", "x-x+x: -" X "9 0 0 0 0"); - data.setText("-- 1 --"); + data.setText("-" X "- 1 --"); KEYS("", "-- " X "0 --"); + KEYS("u", "-" X "- 1 --"); + KEYS("", "-" X "- 0 --"); KEYS("", "-- -" X "2 --"); KEYS("2", "-- " X "1 --"); KEYS("2", "-- " X "4 --"); KEYS(".", "-- " X "6 --"); + KEYS("u", "-- " X "4 --"); + KEYS("", "-- " X "6 --"); // hexadecimal and octal numbers data.setText("0x0 0x1 -1 07 08"); diff --git a/src/plugins/fakevim/fakevimhandler.cpp b/src/plugins/fakevim/fakevimhandler.cpp index 20e00e72519..65599b98565 100644 --- a/src/plugins/fakevim/fakevimhandler.cpp +++ b/src/plugins/fakevim/fakevimhandler.cpp @@ -1573,7 +1573,7 @@ public: void selectWORDTextObject(bool inner); void selectSentenceTextObject(bool inner); void selectParagraphTextObject(bool inner); - void changeNumberTextObject(int count); + bool changeNumberTextObject(int count); // return true only if cursor is in a block delimited with correct characters bool selectBlockTextObject(bool inner, char left, char right); bool selectQuotedStringTextObject(bool inner, const QString "e); @@ -3414,8 +3414,8 @@ bool FakeVimHandler::Private::handleNoSubMode(const Input &input) enterInsertMode(); setDotCommand("%1A", count()); } else if (input.isControl('a')) { - changeNumberTextObject(count()); - setDotCommand("%1", count()); + if (changeNumberTextObject(count())) + setDotCommand("%1", count()); } else if ((input.is('c') || input.is('d')) && isNoVisualMode()) { setAnchor(); m_opcount = m_mvcount; @@ -3663,8 +3663,8 @@ bool FakeVimHandler::Private::handleNoSubMode(const Input &input) setDotCommand("%1x", count()); finishMovement(); } else if (input.isControl('x')) { - changeNumberTextObject(-count()); - setDotCommand("%1", count()); + if (changeNumberTextObject(-count())) + setDotCommand("%1", count()); } else if (input.is('X')) { if (leftDist() > 0) { setAnchor(); @@ -6877,7 +6877,7 @@ bool FakeVimHandler::Private::selectBlockTextObject(bool inner, return true; } -void FakeVimHandler::Private::changeNumberTextObject(int count) +bool FakeVimHandler::Private::changeNumberTextObject(int count) { const QTextBlock block = this->block(); const QString lineText = block.text(); @@ -6889,7 +6889,7 @@ void FakeVimHandler::Private::changeNumberTextObject(int count) while ((pos = re.indexIn(lineText, pos)) != -1 && pos + re.matchedLength() < posMin) ++pos; if (pos == -1) - return; + return false; int len = re.matchedLength(); QString prefix = re.cap(1) + re.cap(3); bool hex = prefix.length() >= 2 && (prefix[1].toLower() == 'x'); @@ -6905,7 +6905,7 @@ void FakeVimHandler::Private::changeNumberTextObject(int count) uvalue = num.toULongLong(&ok, base); else value = num.toLongLong(&ok, base); - QTC_ASSERT(ok, qDebug() << "Cannot parse number:" << num << "base:" << base; return); + QTC_ASSERT(ok, qDebug() << "Cannot parse number:" << num << "base:" << base; return false); // negative decimal number if (!octal && !hex && pos > 0 && lineText[pos - 1] == '-') { @@ -6935,9 +6935,12 @@ void FakeVimHandler::Private::changeNumberTextObject(int count) repl.prepend(prefix); pos += block.position(); + setUndoPosition(); setAnchorAndPosition(pos, pos + len); replaceText(currentRange(), repl); setPosition(pos + repl.size() - 1); + + return true; } bool FakeVimHandler::Private::selectQuotedStringTextObject(bool inner,