Commit 99d85671 authored by hluk's avatar hluk Committed by hjk

FakeVim: Use registers 0, 1 and -

Command "y" additionally yanks text to register 0 if the default
register " is used.

Delete and change command set register 1, if removed text contains
multiple lines, or to small delete register (-).

Register " is always set.

Change-Id: I9d357911cedaac97fb1a91698523c9b0f3de8621
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent 3fd6a52a
......@@ -2259,6 +2259,45 @@ void FakeVimPlugin::test_vim_ex_yank()
data.setText("abc" N "def");
KEYS("\"xy$", X "abc" N "def");
KEYS("\"xP", "ab" X "cabc" N "def");
data.setText(
"abc def" N
"ghi jkl" N
);
KEYS("yiwp",
"aab" X "cbc def" N
"ghi jkl" N
);
KEYS("u",
X "abc def" N
"ghi jkl" N
);
KEYS("\"0p",
"aab" X "cbc def" N
"ghi jkl" N
);
KEYS("\"xyiw",
X "aabcbc def" N
"ghi jkl" N
);
KEYS("\"0p",
"aab" X "cabcbc def" N
"ghi jkl" N
);
KEYS("\"xp",
"aabcaabcb" X "cabcbc def" N
"ghi jkl" N
);
// register " is last yank
data.setText(
"abc def" N
"ghi jkl" N
);
KEYS("yiwp\"xyiw\"\"p",
"aaabcb" X "cabcbc def" N
"ghi jkl" N
);
}
void FakeVimPlugin::test_vim_ex_delete()
......
......@@ -1896,7 +1896,7 @@ public:
void setCurrentRange(const Range &range);
Range currentRange() const { return Range(position(), anchor(), g.rangemode); }
void yankText(const Range &range, int toregister = '"');
void yankText(const Range &range, int toregister);
void pasteText(bool afterCursor);
......@@ -6806,7 +6806,26 @@ QString FakeVimHandler::Private::selectText(const Range &range) const
void FakeVimHandler::Private::yankText(const Range &range, int reg)
{
setRegister(reg, selectText(range), range.rangemode);
const QString text = selectText(range);
setRegister(reg, text, range.rangemode);
// If register is not specified or " ...
if (m_register == '"') {
// copy to yank register 0 too
setRegister('0', text, range.rangemode);
// with delete and change commands set register 1 (if text contains more lines) or
// small delete register -
if (g.submode == DeleteSubMode || g.submode == ChangeSubMode) {
if (text.contains(QLatin1Char('\n')))
setRegister('1', text, range.rangemode);
else
setRegister('-', text, range.rangemode);
}
} else {
// Always copy to " register too.
setRegister('"', text, range.rangemode);
}
const int lines = document()->findBlock(range.endPos).blockNumber()
- document()->findBlock(range.beginPos).blockNumber() + 1;
......
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