diff options
-rw-r--r-- | src/plugins/fakevim/fakevim_test.cpp | 44 | ||||
-rw-r--r-- | src/plugins/fakevim/fakevimhandler.cpp | 11 |
2 files changed, 54 insertions, 1 deletions
diff --git a/src/plugins/fakevim/fakevim_test.cpp b/src/plugins/fakevim/fakevim_test.cpp index f8b37bd814..07ab92c191 100644 --- a/src/plugins/fakevim/fakevim_test.cpp +++ b/src/plugins/fakevim/fakevim_test.cpp @@ -3029,6 +3029,50 @@ void FakeVimPlugin::test_vim_substitute() COMMAND("undo | s/\\(b...E\\)/\\U\\1/g", "aBC DEfGh"); COMMAND("undo | s/\\(C..E\\)/\\l\\1/g", "abc dEfGh"); COMMAND("undo | s/\\(b...E\\)/\\L\\1/g", "abc defGh"); + + // replace 1 backslash with 1 forward slash (separator: /) + data.setText(R"(abc\def)"); + COMMAND(R"(s/\\/\/)", X "abc/def"); + + // replace 1 backslash with X normal on line (separator: /) + data.setText(R"(abc\def\ghi)"); + COMMAND(R"(s/\\/X/g)", X "abcXdefXghi"); + + // replace 1 backslash with 1 forward slash on line (separator: /) + data.setText(R"(abc\def\ghi)"); + COMMAND(R"(s/\\/\//g)", X "abc/def/ghi"); + + // replace 1 backslash with 1 forward slash + data.setText(R"(abc\def)"); + COMMAND(R"(s#\\#/)", X "abc/def"); + + // replace 1 backslash with 1 forward slash on line + data.setText(R"(abc\def\ghi)"); + COMMAND(R"(s#\\#/#g)", X "abc/def/ghi"); + + // replace 2 backslash with 2 forward slash + data.setText(R"(abc\\def)"); + COMMAND(R"(s#\\\\#//)", X "abc//def"); + + // replace 2 backslash with 2 forward slash on line + data.setText(R"(abc\\def\\ghi)"); + COMMAND(R"(s#\\\\#//#g)", X "abc//def//ghi"); + + // replace 1 backslash with 1 forward slash last char + data.setText(R"(abc\)"); + COMMAND(R"(s#\\#/)", X "abc/"); + + // replace 1 backslash with 1 forward slash first char + data.setText(R"(\abc)"); + COMMAND(R"(s#\\#/)", X "/abc"); + + // replace 1 # with 2 # on line + data.setText(R"(abc#def#ghi)"); + COMMAND(R"(s#\##\#\##g)", X "abc##def##ghi"); + + // replace 2 # with 4 # on line + data.setText(R"(abc##def##ghi)"); + COMMAND(R"(s#\#\##\#\#\#\##g)", X "abc####def####ghi"); } void FakeVimPlugin::test_vim_ex_commandbuffer_paste() diff --git a/src/plugins/fakevim/fakevimhandler.cpp b/src/plugins/fakevim/fakevimhandler.cpp index aa8b74a00e..79e8153c01 100644 --- a/src/plugins/fakevim/fakevimhandler.cpp +++ b/src/plugins/fakevim/fakevimhandler.cpp @@ -816,9 +816,18 @@ static bool substituteText(QString *text, static int findUnescaped(QChar c, const QString &line, int from) { + bool singleBackSlashBefore = false; for (int i = from; i < line.size(); ++i) { - if (line.at(i) == c && (i == 0 || line.at(i - 1) != '\\')) + const QChar currentChar = line.at(i); + if (currentChar == '\\') { + singleBackSlashBefore = !singleBackSlashBefore; + continue; + } + + if (currentChar == c && !singleBackSlashBefore) return i; + + singleBackSlashBefore = false; } return -1; } |