Commit 00a10fcf authored by Lukas Holecek's avatar Lukas Holecek Committed by hjk
Browse files

fakevim: Correct undo/redo position for changing numbers



Restore position on undo and redo after <C-A> and <C-X> commands.

Do not set dot command if no number was found.

Change-Id: Ia4e6d53ecfbd7f56e874d6a39c0939557f6cdc3d
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent fa986939
......@@ -571,12 +571,16 @@ void FakeVimPlugin::test_vim_transform_numbers()
KEYS("B9<c-x>", "x-x+x: " X "0 0 0 0 0");
KEYS("B9<c-x>", "x-x+x: -" X "9 0 0 0 0");
data.setText("-- 1 --");
data.setText("-" X "- 1 --");
KEYS("<c-x>", "-- " X "0 --");
KEYS("u", "-" X "- 1 --");
KEYS("<c-r>", "-" X "- 0 --");
KEYS("<c-x><c-x>", "-- -" X "2 --");
KEYS("2<c-a><c-a>", "-- " X "1 --");
KEYS("<c-a>2<c-a>", "-- " X "4 --");
KEYS(".", "-- " X "6 --");
KEYS("u", "-- " X "4 --");
KEYS("<c-r>", "-- " X "6 --");
// hexadecimal and octal numbers
data.setText("0x0 0x1 -1 07 08");
......
......@@ -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 &quote);
......@@ -3414,8 +3414,8 @@ bool FakeVimHandler::Private::handleNoSubMode(const Input &input)
enterInsertMode();
setDotCommand("%1A", count());
} else if (input.isControl('a')) {
changeNumberTextObject(count());
setDotCommand("%1<c-a>", count());
if (changeNumberTextObject(count()))
setDotCommand("%1<c-a>", 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<c-x>", count());
if (changeNumberTextObject(-count()))
setDotCommand("%1<c-x>", 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,
......
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