Commit e4db1211 authored by Thorben Kroeger's avatar Thorben Kroeger Committed by hjk
Browse files

FakeVim: C-R {register, C-W} in command mode



Change-Id: I15dd0b88b2e908dde398df06bc03394a700839a7
Reviewed-by: default avatarLukas Holecek <hluk@email.cz>
Reviewed-by: default avatarhjk <hjk@theqtcompany.com>
parent a30e66f2
......@@ -2184,6 +2184,20 @@ void FakeVimPlugin::test_vim_search()
data.setText("abc" N "def" N "abc" N "ghi abc jkl" N "xyz");
KEYS("vj" "/abc<ESC>" "x", X "ef" N "abc" N "ghi abc jkl" N "xyz");
KEYS("vj" "/xxx<CR>" "x", X "bc" N "ghi abc jkl" N "xyz");
// insert word under cursor (C-R C-W)
data.setText("abc def ghi def.");
KEYS("fe/<C-R><C-W><CR>", "abc def ghi " X "def.");
// insert register (C-R{register})
data.setText("abc def ghi def.");
KEYS("feyiw/<C-R>0<CR>", "abc def ghi " X "def.");
// insert non-existing register
data.setText("abc def ghi def.");
KEYS("feyiw/<C-R>adef<CR>", "abc def ghi " X "def.");
// abort C-R via Esc
data.doCommand("set noincsearch");
data.setText("abc def ghi def.");
KEYS("fe/d<C-R><ESC>ef<CR>", "abc def ghi " X "def.");
}
void FakeVimPlugin::test_vim_indent()
......@@ -2999,6 +3013,15 @@ void FakeVimPlugin::test_vim_substitute()
COMMAND("undo | s/f\\|$/-/g", "abc de-");
}
void FakeVimPlugin::test_vim_ex_commandbuffer_paste()
{
TestData data;
setup(&data);
data.setText("abc def abc def xyz");
KEYS("fyyiw0:s/<C-R><C-W>/<C-R>0/g<CR>", "xyz def xyz def xyz");
}
void FakeVimPlugin::test_vim_ex_yank()
{
TestData data;
......
......@@ -1683,6 +1683,7 @@ public:
EventResult handleKey(const Input &input);
EventResult handleDefaultKey(const Input &input);
bool handleCommandBufferPaste(const Input &input);
EventResult handleCurrentMapAsDefault();
void prependInputs(const QVector<Input> &inputs); // Handle inputs.
void prependMapping(const Inputs &inputs); // Handle inputs as mapping.
......@@ -2246,6 +2247,7 @@ public:
SubSubMode subsubmode;
Input subsubdata;
VisualMode visualMode;
Input minibufferData;
// [count] for current command, 0 if no [count] available
int mvcount;
......@@ -2709,7 +2711,7 @@ void FakeVimHandler::Private::restoreWidget(int tabSize)
EventResult FakeVimHandler::Private::handleKey(const Input &input)
{
KEY_DEBUG("HANDLE INPUT: " << input << " MODE: " << mode);
KEY_DEBUG("HANDLE INPUT: " << input);
bool hasInput = input.isValid();
......@@ -2758,6 +2760,34 @@ EventResult FakeVimHandler::Private::handleKey(const Input &input)
return r;
}
bool FakeVimHandler::Private::handleCommandBufferPaste(const Input &input)
{
if (input.isControl('r')
&& (g.subsubmode == SearchSubSubMode || g.mode == ExMode)) {
g.minibufferData = input;
return true;
}
if (g.minibufferData.isControl('r')) {
g.minibufferData = Input();
if (input.isEscape())
return true;
CommandBuffer &buffer = (g.subsubmode == SearchSubSubMode)
? g.searchBuffer : g.commandBuffer;
if (input.isControl('w')) {
QTextCursor tc = m_cursor;
tc.select(QTextCursor::WordUnderCursor);
QString word = tc.selectedText();
buffer.insertText(word);
} else {
QString r = registerContents(input.asChar().unicode());
buffer.insertText(r);
}
updateMiniBuffer();
return true;
}
return false;
}
EventResult FakeVimHandler::Private::handleDefaultKey(const Input &input)
{
if (input == Nop)
......@@ -5147,6 +5177,10 @@ bool FakeVimHandler::Private::executeRegister(int reg)
EventResult FakeVimHandler::Private::handleExMode(const Input &input)
{
// handle C-R, C-R C-W, C-R {register}
if (handleCommandBufferPaste(input))
return EventHandled;
if (input.isEscape()) {
g.commandBuffer.clear();
leaveCurrentMode();
......@@ -5186,6 +5220,10 @@ EventResult FakeVimHandler::Private::handleSearchSubSubMode(const Input &input)
{
EventResult handled = EventHandled;
// handle C-R, C-R C-W, C-R {register}
if (handleCommandBufferPaste(input))
return handled;
if (input.isEscape()) {
g.currentMessage.clear();
setPosition(m_searchStartPosition);
......@@ -8562,7 +8600,8 @@ bool FakeVimHandler::eventFilter(QObject *ob, QEvent *ev)
return res == EventHandled || res == EventCancelled;
}
if (ev->type() == QEvent::ShortcutOverride && ob == d->editor()) {
if (ev->type() == QEvent::ShortcutOverride && (ob == d->editor()
|| (Private::g.mode == ExMode || Private::g.subsubmode == SearchSubSubMode))) {
QKeyEvent *kev = static_cast<QKeyEvent *>(ev);
if (d->wantsOverride(kev)) {
KEY_DEBUG("OVERRIDING SHORTCUT" << kev->key());
......
......@@ -105,6 +105,7 @@ private slots:
void test_vim_code_folding();
void test_vim_code_completion();
void test_vim_substitute();
void test_vim_ex_commandbuffer_paste();
void test_vim_ex_yank();
void test_vim_ex_delete();
void test_vim_ex_change();
......
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