From 69503b5acdb21ecf1920edbe2b39f283a693e112 Mon Sep 17 00:00:00 2001 From: Yufan You Date: Sat, 9 May 2020 15:48:49 +0800 Subject: [PATCH] fix: Process Shift+Enter as pure Enter (#16) Before this commit, Shift+Enter adds a new line in the same block, and result in a wrong line number. It is somehow fine if only the line number is wrong, but with the language server, the squiggles are also in the wrong place, thus it's necessary to fix this. --- src/internal/QCodeEditor.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/internal/QCodeEditor.cpp b/src/internal/QCodeEditor.cpp index 5fb0796..74dd0f1 100644 --- a/src/internal/QCodeEditor.cpp +++ b/src/internal/QCodeEditor.cpp @@ -610,7 +610,7 @@ void QCodeEditor::keyPressEvent(QKeyEvent *e) if (!completerSkip) { - if ((e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter)) + if ((e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) && e->modifiers() != Qt::NoModifier) { QKeyEvent pureEnter(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier); if (e->modifiers() == Qt::ControlModifier) @@ -636,6 +636,11 @@ void QCodeEditor::keyPressEvent(QKeyEvent *e) } return; } + else if (e->modifiers() == Qt::ShiftModifier) + { + keyPressEvent(&pureEnter); + return; + } } if (e->key() == Qt::Key_Tab && e->modifiers() == Qt::NoModifier)