Commit 2976345f authored by hluk's avatar hluk Committed by hjk

FakeVim: Fix mappings in insert mode

Mapped user input shouldn't break edit block in insert mode.

Change-Id: I47ad449d9f0a2623cfcbdfa6c66626aa876ed76b
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent 99d85671
......@@ -2603,6 +2603,7 @@ void FakeVimPlugin::test_map()
data.setText("abc" N "def");
data.doCommand(QString::fromUtf8("no \xc3\xb8 l|no l k|no k j|no j h"));
KEYS(QString::fromUtf8("\xc3\xb8"), "a" X "bc" N "def");
data.doCommand(QString::fromUtf8("unmap \xc3\xb8|unmap l|unmap k|unmap j"));
// Don't handle mapping in sub-modes that are not followed by movement command.
data.setText("abc" N "def");
......@@ -2627,6 +2628,16 @@ void FakeVimPlugin::test_map()
data.doCommand("onoremap iwwX 3iwX Y");
KEYS("ciwwX Z<esc>", "X Y " X "Z" N "ghi jkl");
data.doCommand("unmap <SPACE>X");
// use mapping for <ESC> in insert
data.setText("ab" X "c def" N "ghi jkl");
data.doCommand("inoremap jk <ESC>");
KEYS("<C-V>jll" "I__jk", "ab" X "__c def" N "gh__i jkl");
INTEGRITY(false);
data.doCommand("unmap jk"); // shouldn't unmap for insert mode
KEYS("ijk", "a" X "b__c def" N "gh__i jkl");
data.doCommand("iunmap jk");
KEYS("ijk<ESC>", "aj" X "kb__c def" N "gh__i jkl");
}
void FakeVimPlugin::test_vim_command_cc()
......
......@@ -1495,11 +1495,12 @@ private:
// state of current mapping
struct MappingState {
MappingState()
: noremap(false), silent(false) {}
MappingState(bool noremap, bool silent)
: noremap(noremap), silent(silent) {}
: noremap(false), silent(false), editBlock(false) {}
MappingState(bool noremap, bool silent, bool editBlock)
: noremap(noremap), silent(silent), editBlock(editBlock) {}
bool noremap;
bool silent;
bool editBlock;
};
class FakeVimHandler::Private : public QObject
......@@ -2683,9 +2684,13 @@ void FakeVimHandler::Private::prependMapping(const Inputs &inputs)
++g.mapDepth;
g.pendingInput.prepend(Input());
prependInputs(inputs);
g.mapStates << MappingState(inputs.noremap(), inputs.silent());
g.commandBuffer.setHistoryAutoSave(false);
beginLargeEditBlock();
// start new edit block (undo/redo) only if necessary
bool editBlock = m_editBlockLevel == 0 && !(isInsertMode() && isInsertStateValid());
if (editBlock)
beginLargeEditBlock();
g.mapStates << MappingState(inputs.noremap(), inputs.silent(), editBlock);
}
bool FakeVimHandler::Private::expandCompleteMapping()
......@@ -2715,8 +2720,9 @@ void FakeVimHandler::Private::endMapping()
--g.mapDepth;
if (g.mapStates.isEmpty())
return;
if (g.mapStates.last().editBlock)
endEditBlock();
g.mapStates.pop_back();
endEditBlock();
if (g.mapStates.isEmpty())
g.commandBuffer.setHistoryAutoSave(true);
updateMiniBuffer();
......
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