forked from qt-creator/qt-creator
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: hjk <qthjk@ovi.com>
This commit is contained in:
@@ -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 "0 0 0 0 0");
|
||||||
KEYS("B9<c-x>", "x-x+x: -" X "9 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("<c-x>", "-- " X "0 --");
|
||||||
|
KEYS("u", "-" X "- 1 --");
|
||||||
|
KEYS("<c-r>", "-" X "- 0 --");
|
||||||
KEYS("<c-x><c-x>", "-- -" X "2 --");
|
KEYS("<c-x><c-x>", "-- -" X "2 --");
|
||||||
KEYS("2<c-a><c-a>", "-- " X "1 --");
|
KEYS("2<c-a><c-a>", "-- " X "1 --");
|
||||||
KEYS("<c-a>2<c-a>", "-- " X "4 --");
|
KEYS("<c-a>2<c-a>", "-- " X "4 --");
|
||||||
KEYS(".", "-- " X "6 --");
|
KEYS(".", "-- " X "6 --");
|
||||||
|
KEYS("u", "-- " X "4 --");
|
||||||
|
KEYS("<c-r>", "-- " X "6 --");
|
||||||
|
|
||||||
// hexadecimal and octal numbers
|
// hexadecimal and octal numbers
|
||||||
data.setText("0x0 0x1 -1 07 08");
|
data.setText("0x0 0x1 -1 07 08");
|
||||||
|
|||||||
@@ -1573,7 +1573,7 @@ public:
|
|||||||
void selectWORDTextObject(bool inner);
|
void selectWORDTextObject(bool inner);
|
||||||
void selectSentenceTextObject(bool inner);
|
void selectSentenceTextObject(bool inner);
|
||||||
void selectParagraphTextObject(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
|
// return true only if cursor is in a block delimited with correct characters
|
||||||
bool selectBlockTextObject(bool inner, char left, char right);
|
bool selectBlockTextObject(bool inner, char left, char right);
|
||||||
bool selectQuotedStringTextObject(bool inner, const QString "e);
|
bool selectQuotedStringTextObject(bool inner, const QString "e);
|
||||||
@@ -3414,7 +3414,7 @@ bool FakeVimHandler::Private::handleNoSubMode(const Input &input)
|
|||||||
enterInsertMode();
|
enterInsertMode();
|
||||||
setDotCommand("%1A", count());
|
setDotCommand("%1A", count());
|
||||||
} else if (input.isControl('a')) {
|
} else if (input.isControl('a')) {
|
||||||
changeNumberTextObject(count());
|
if (changeNumberTextObject(count()))
|
||||||
setDotCommand("%1<c-a>", count());
|
setDotCommand("%1<c-a>", count());
|
||||||
} else if ((input.is('c') || input.is('d')) && isNoVisualMode()) {
|
} else if ((input.is('c') || input.is('d')) && isNoVisualMode()) {
|
||||||
setAnchor();
|
setAnchor();
|
||||||
@@ -3663,7 +3663,7 @@ bool FakeVimHandler::Private::handleNoSubMode(const Input &input)
|
|||||||
setDotCommand("%1x", count());
|
setDotCommand("%1x", count());
|
||||||
finishMovement();
|
finishMovement();
|
||||||
} else if (input.isControl('x')) {
|
} else if (input.isControl('x')) {
|
||||||
changeNumberTextObject(-count());
|
if (changeNumberTextObject(-count()))
|
||||||
setDotCommand("%1<c-x>", count());
|
setDotCommand("%1<c-x>", count());
|
||||||
} else if (input.is('X')) {
|
} else if (input.is('X')) {
|
||||||
if (leftDist() > 0) {
|
if (leftDist() > 0) {
|
||||||
@@ -6877,7 +6877,7 @@ bool FakeVimHandler::Private::selectBlockTextObject(bool inner,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FakeVimHandler::Private::changeNumberTextObject(int count)
|
bool FakeVimHandler::Private::changeNumberTextObject(int count)
|
||||||
{
|
{
|
||||||
const QTextBlock block = this->block();
|
const QTextBlock block = this->block();
|
||||||
const QString lineText = block.text();
|
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)
|
while ((pos = re.indexIn(lineText, pos)) != -1 && pos + re.matchedLength() < posMin)
|
||||||
++pos;
|
++pos;
|
||||||
if (pos == -1)
|
if (pos == -1)
|
||||||
return;
|
return false;
|
||||||
int len = re.matchedLength();
|
int len = re.matchedLength();
|
||||||
QString prefix = re.cap(1) + re.cap(3);
|
QString prefix = re.cap(1) + re.cap(3);
|
||||||
bool hex = prefix.length() >= 2 && (prefix[1].toLower() == 'x');
|
bool hex = prefix.length() >= 2 && (prefix[1].toLower() == 'x');
|
||||||
@@ -6905,7 +6905,7 @@ void FakeVimHandler::Private::changeNumberTextObject(int count)
|
|||||||
uvalue = num.toULongLong(&ok, base);
|
uvalue = num.toULongLong(&ok, base);
|
||||||
else
|
else
|
||||||
value = num.toLongLong(&ok, base);
|
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
|
// negative decimal number
|
||||||
if (!octal && !hex && pos > 0 && lineText[pos - 1] == '-') {
|
if (!octal && !hex && pos > 0 && lineText[pos - 1] == '-') {
|
||||||
@@ -6935,9 +6935,12 @@ void FakeVimHandler::Private::changeNumberTextObject(int count)
|
|||||||
repl.prepend(prefix);
|
repl.prepend(prefix);
|
||||||
|
|
||||||
pos += block.position();
|
pos += block.position();
|
||||||
|
setUndoPosition();
|
||||||
setAnchorAndPosition(pos, pos + len);
|
setAnchorAndPosition(pos, pos + len);
|
||||||
replaceText(currentRange(), repl);
|
replaceText(currentRange(), repl);
|
||||||
setPosition(pos + repl.size() - 1);
|
setPosition(pos + repl.size() - 1);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FakeVimHandler::Private::selectQuotedStringTextObject(bool inner,
|
bool FakeVimHandler::Private::selectQuotedStringTextObject(bool inner,
|
||||||
|
|||||||
Reference in New Issue
Block a user