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:
Tom Praschan
2021-02-06 20:09:23 +01:00
parent b6f26ed67a
commit 509d5895f8
5 changed files with 34 additions and 0 deletions

View File

@@ -7615,6 +7615,13 @@ void FakeVimHandler::Private::joinLines(int count, bool preserveSpace)
{
int pos = position();
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) {
moveBehindEndOfLine();
pos = position();
@@ -7625,6 +7632,18 @@ void FakeVimHandler::Private::joinLines(int count, bool preserveSpace)
} else {
while (characterAtCursor() == ' ' || characterAtCursor() == '\t')
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(' '));
}
}