forked from qt-creator/qt-creator
FakeVim: Merge comments when joining lines with 'J'
This is the default behavior in vim as well Change-Id: Ia4d56e3cfc7f91fc353078daefaabeada9a86bed Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -108,6 +108,8 @@
|
|||||||
\li \c :undo, \c :redo
|
\li \c :undo, \c :redo
|
||||||
\li \c :normal
|
\li \c :normal
|
||||||
\li \c :<, \c :>
|
\li \c :<, \c :>
|
||||||
|
\li \c{set formatoptions=}, see \c{:h fo-table} in the Vim documentation.
|
||||||
|
Currently supported letters: \c fo-j
|
||||||
\endlist
|
\endlist
|
||||||
|
|
||||||
\section2 Plugin Emulation
|
\section2 Plugin Emulation
|
||||||
|
@@ -4071,6 +4071,17 @@ void FakeVimPlugin::test_vim_command_J()
|
|||||||
KEYS("3J", lmid(0, 5) + " " + lmid(5, 1) + " " + lmid(6, 1).mid(4) + "| " + lmid(7));
|
KEYS("3J", lmid(0, 5) + " " + lmid(5, 1) + " " + lmid(6, 1).mid(4) + "| " + lmid(7));
|
||||||
KEYS("uu", lmid(0, 4) + "\nint |main(int argc, char *argv[])\n" + lmid(5));
|
KEYS("uu", lmid(0, 4) + "\nint |main(int argc, char *argv[])\n" + lmid(5));
|
||||||
COMMAND("redo", lmid(0, 4) + "\nint |main(int argc, char *argv[]) " + lmid(5));
|
COMMAND("redo", lmid(0, 4) + "\nint |main(int argc, char *argv[]) " + lmid(5));
|
||||||
|
|
||||||
|
// Joining comments
|
||||||
|
data.doCommand("set formatoptions=f");
|
||||||
|
data.setText("// abc" N "// def");
|
||||||
|
KEYS("J", "// abc def");
|
||||||
|
|
||||||
|
data.setText("/*" N X "* abc" N "* def" N "*/");
|
||||||
|
KEYS("J", "/*" N "* abc def" N "*/");
|
||||||
|
|
||||||
|
data.setText("# abc" N "# def");
|
||||||
|
KEYS("J", "# abc def");
|
||||||
}
|
}
|
||||||
|
|
||||||
void FakeVimPlugin::test_vim_command_put_at_eol()
|
void FakeVimPlugin::test_vim_command_put_at_eol()
|
||||||
|
@@ -113,6 +113,7 @@ FakeVimSettings::FakeVimSettings()
|
|||||||
createAction(ConfigBackspace, QString("indent,eol,start"), "ConfigBackspace", "bs");
|
createAction(ConfigBackspace, QString("indent,eol,start"), "ConfigBackspace", "bs");
|
||||||
createAction(ConfigIsKeyword, QString("@,48-57,_,192-255,a-z,A-Z"), "IsKeyword", "isk");
|
createAction(ConfigIsKeyword, QString("@,48-57,_,192-255,a-z,A-Z"), "IsKeyword", "isk");
|
||||||
createAction(ConfigClipboard, QString(), "Clipboard", "cb");
|
createAction(ConfigClipboard, QString(), "Clipboard", "cb");
|
||||||
|
createAction(ConfigFormatOptions, QString(), "formatoptions", "fo");
|
||||||
|
|
||||||
// Emulated plugins
|
// Emulated plugins
|
||||||
createAction(ConfigEmulateVimCommentary, false, "commentary");
|
createAction(ConfigEmulateVimCommentary, false, "commentary");
|
||||||
|
@@ -107,6 +107,7 @@ enum FakeVimSettingsCode
|
|||||||
ConfigShowCmd,
|
ConfigShowCmd,
|
||||||
ConfigScrollOff,
|
ConfigScrollOff,
|
||||||
ConfigRelativeNumber,
|
ConfigRelativeNumber,
|
||||||
|
ConfigFormatOptions,
|
||||||
|
|
||||||
// Plugin emulation
|
// Plugin emulation
|
||||||
ConfigEmulateVimCommentary,
|
ConfigEmulateVimCommentary,
|
||||||
|
@@ -7615,6 +7615,13 @@ void FakeVimHandler::Private::joinLines(int count, bool preserveSpace)
|
|||||||
{
|
{
|
||||||
int pos = position();
|
int pos = position();
|
||||||
const int blockNumber = m_cursor.blockNumber();
|
const int blockNumber = m_cursor.blockNumber();
|
||||||
|
|
||||||
|
const QString currentLine = lineContents(blockNumber + 1);
|
||||||
|
const bool startingLineIsComment
|
||||||
|
= currentLine.contains(QRegularExpression("^\\s*\\/\\/")) // Cpp-style
|
||||||
|
|| currentLine.contains(QRegularExpression("^\\s*\\/?\\*")) // C-style
|
||||||
|
|| currentLine.contains(QRegularExpression("^\\s*#")); // Python/Shell-style
|
||||||
|
|
||||||
for (int i = qMax(count - 2, 0); i >= 0 && blockNumber < document()->blockCount(); --i) {
|
for (int i = qMax(count - 2, 0); i >= 0 && blockNumber < document()->blockCount(); --i) {
|
||||||
moveBehindEndOfLine();
|
moveBehindEndOfLine();
|
||||||
pos = position();
|
pos = position();
|
||||||
@@ -7625,6 +7632,18 @@ void FakeVimHandler::Private::joinLines(int count, bool preserveSpace)
|
|||||||
} else {
|
} else {
|
||||||
while (characterAtCursor() == ' ' || characterAtCursor() == '\t')
|
while (characterAtCursor() == ' ' || characterAtCursor() == '\t')
|
||||||
moveRight();
|
moveRight();
|
||||||
|
|
||||||
|
// If the line we started from is a comment, remove the comment string from the next line
|
||||||
|
if (startingLineIsComment && config(ConfigFormatOptions).toString().contains('f')) {
|
||||||
|
if (characterAtCursor() == '/' && characterAt(position() + 1) == '/')
|
||||||
|
moveRight(2);
|
||||||
|
else if (characterAtCursor() == '*' || characterAtCursor() == '#')
|
||||||
|
moveRight(1);
|
||||||
|
|
||||||
|
if (characterAtCursor() == ' ')
|
||||||
|
moveRight();
|
||||||
|
}
|
||||||
|
|
||||||
m_cursor.insertText(QString(' '));
|
m_cursor.insertText(QString(' '));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user