forked from qt-creator/qt-creator
FakeVim: C-R {register, C-W} in command mode
Change-Id: I15dd0b88b2e908dde398df06bc03394a700839a7 Reviewed-by: Lukas Holecek <hluk@email.cz> Reviewed-by: hjk <hjk@theqtcompany.com>
This commit is contained in:
@@ -2184,6 +2184,20 @@ void FakeVimPlugin::test_vim_search()
|
|||||||
data.setText("abc" N "def" N "abc" N "ghi abc jkl" N "xyz");
|
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" "/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");
|
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()
|
void FakeVimPlugin::test_vim_indent()
|
||||||
@@ -2999,6 +3013,15 @@ void FakeVimPlugin::test_vim_substitute()
|
|||||||
COMMAND("undo | s/f\\|$/-/g", "abc de-");
|
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()
|
void FakeVimPlugin::test_vim_ex_yank()
|
||||||
{
|
{
|
||||||
TestData data;
|
TestData data;
|
||||||
|
@@ -1683,6 +1683,7 @@ public:
|
|||||||
|
|
||||||
EventResult handleKey(const Input &input);
|
EventResult handleKey(const Input &input);
|
||||||
EventResult handleDefaultKey(const Input &input);
|
EventResult handleDefaultKey(const Input &input);
|
||||||
|
bool handleCommandBufferPaste(const Input &input);
|
||||||
EventResult handleCurrentMapAsDefault();
|
EventResult handleCurrentMapAsDefault();
|
||||||
void prependInputs(const QVector<Input> &inputs); // Handle inputs.
|
void prependInputs(const QVector<Input> &inputs); // Handle inputs.
|
||||||
void prependMapping(const Inputs &inputs); // Handle inputs as mapping.
|
void prependMapping(const Inputs &inputs); // Handle inputs as mapping.
|
||||||
@@ -2246,6 +2247,7 @@ public:
|
|||||||
SubSubMode subsubmode;
|
SubSubMode subsubmode;
|
||||||
Input subsubdata;
|
Input subsubdata;
|
||||||
VisualMode visualMode;
|
VisualMode visualMode;
|
||||||
|
Input minibufferData;
|
||||||
|
|
||||||
// [count] for current command, 0 if no [count] available
|
// [count] for current command, 0 if no [count] available
|
||||||
int mvcount;
|
int mvcount;
|
||||||
@@ -2709,7 +2711,7 @@ void FakeVimHandler::Private::restoreWidget(int tabSize)
|
|||||||
|
|
||||||
EventResult FakeVimHandler::Private::handleKey(const Input &input)
|
EventResult FakeVimHandler::Private::handleKey(const Input &input)
|
||||||
{
|
{
|
||||||
KEY_DEBUG("HANDLE INPUT: " << input << " MODE: " << mode);
|
KEY_DEBUG("HANDLE INPUT: " << input);
|
||||||
|
|
||||||
bool hasInput = input.isValid();
|
bool hasInput = input.isValid();
|
||||||
|
|
||||||
@@ -2758,6 +2760,34 @@ EventResult FakeVimHandler::Private::handleKey(const Input &input)
|
|||||||
return r;
|
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)
|
EventResult FakeVimHandler::Private::handleDefaultKey(const Input &input)
|
||||||
{
|
{
|
||||||
if (input == Nop)
|
if (input == Nop)
|
||||||
@@ -5147,6 +5177,10 @@ bool FakeVimHandler::Private::executeRegister(int reg)
|
|||||||
|
|
||||||
EventResult FakeVimHandler::Private::handleExMode(const Input &input)
|
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()) {
|
if (input.isEscape()) {
|
||||||
g.commandBuffer.clear();
|
g.commandBuffer.clear();
|
||||||
leaveCurrentMode();
|
leaveCurrentMode();
|
||||||
@@ -5186,6 +5220,10 @@ EventResult FakeVimHandler::Private::handleSearchSubSubMode(const Input &input)
|
|||||||
{
|
{
|
||||||
EventResult handled = EventHandled;
|
EventResult handled = EventHandled;
|
||||||
|
|
||||||
|
// handle C-R, C-R C-W, C-R {register}
|
||||||
|
if (handleCommandBufferPaste(input))
|
||||||
|
return handled;
|
||||||
|
|
||||||
if (input.isEscape()) {
|
if (input.isEscape()) {
|
||||||
g.currentMessage.clear();
|
g.currentMessage.clear();
|
||||||
setPosition(m_searchStartPosition);
|
setPosition(m_searchStartPosition);
|
||||||
@@ -8562,7 +8600,8 @@ bool FakeVimHandler::eventFilter(QObject *ob, QEvent *ev)
|
|||||||
return res == EventHandled || res == EventCancelled;
|
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);
|
QKeyEvent *kev = static_cast<QKeyEvent *>(ev);
|
||||||
if (d->wantsOverride(kev)) {
|
if (d->wantsOverride(kev)) {
|
||||||
KEY_DEBUG("OVERRIDING SHORTCUT" << kev->key());
|
KEY_DEBUG("OVERRIDING SHORTCUT" << kev->key());
|
||||||
|
@@ -105,6 +105,7 @@ private slots:
|
|||||||
void test_vim_code_folding();
|
void test_vim_code_folding();
|
||||||
void test_vim_code_completion();
|
void test_vim_code_completion();
|
||||||
void test_vim_substitute();
|
void test_vim_substitute();
|
||||||
|
void test_vim_ex_commandbuffer_paste();
|
||||||
void test_vim_ex_yank();
|
void test_vim_ex_yank();
|
||||||
void test_vim_ex_delete();
|
void test_vim_ex_delete();
|
||||||
void test_vim_ex_change();
|
void test_vim_ex_change();
|
||||||
|
Reference in New Issue
Block a user