change insertion function to always replace partial word with completion

Also change popup mode to always display all possible completions
and only highlight the current selection. This seems more beginner friendly.
This commit is contained in:
Axel Kohlmeyer
2023-09-18 18:03:27 -04:00
parent 70a8aff561
commit 934055601b

View File

@ -138,7 +138,7 @@ CodeEditor::CodeEditor(QWidget *parent) :
// set up completer class (without a model currently)
#define COMPLETER_SETUP(completer) \
completer->setCompletionMode(QCompleter::PopupCompletion); \
completer->setCompletionMode(QCompleter::UnfilteredPopupCompletion); \
completer->setModelSorting(QCompleter::CaseInsensitivelySortedModel); \
completer->setWidget(this); \
completer->setMaxVisibleItems(16); \
@ -940,10 +940,8 @@ void CodeEditor::insertCompletedCommand(const QString &completion)
auto *completer = qobject_cast<QCompleter *>(sender());
if (completer->widget() != this) return;
auto cursor = textCursor();
int extra = completion.length() - completer->completionPrefix().length();
cursor.movePosition(QTextCursor::Left);
cursor.movePosition(QTextCursor::EndOfWord);
cursor.insertText(completion.right(extra));
cursor.movePosition(QTextCursor::StartOfWord, QTextCursor::KeepAnchor);
cursor.insertText(completion);
setTextCursor(cursor);
}