move processing of completion to separate function
This commit is contained in:
@ -309,28 +309,7 @@ void CodeEditor::keyPressEvent(QKeyEvent *event)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (event->key() == Qt::Key_Backtab) {
|
if (event->key() == Qt::Key_Backtab) {
|
||||||
if (command_completer) {
|
runCompletion();
|
||||||
auto cursor = textCursor();
|
|
||||||
auto line = cursor.block().text().trimmed();
|
|
||||||
if (line.isEmpty()) return;
|
|
||||||
|
|
||||||
auto words = split_line(line.toStdString());
|
|
||||||
cursor.select(QTextCursor::WordUnderCursor);
|
|
||||||
|
|
||||||
// if on first word, try to complete command
|
|
||||||
if ((words.size() > 0) && (words[0] == cursor.selectedText().toStdString())) {
|
|
||||||
// no completion on comment lines
|
|
||||||
if (words[0][0] == '#') return;
|
|
||||||
command_completer->setCompletionPrefix(words[0].c_str());
|
|
||||||
auto popup = command_completer->popup();
|
|
||||||
QRect cr = cursorRect();
|
|
||||||
cr.setWidth(popup->sizeHintForColumn(0) +
|
|
||||||
popup->verticalScrollBar()->sizeHint().width());
|
|
||||||
popup->setAlternatingRowColors(true);
|
|
||||||
command_completer->setCurrentRow(0);
|
|
||||||
command_completer->complete(cr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QPlainTextEdit::keyPressEvent(event);
|
QPlainTextEdit::keyPressEvent(event);
|
||||||
@ -479,6 +458,32 @@ void CodeEditor::reformatCurrentLine()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CodeEditor::runCompletion()
|
||||||
|
{
|
||||||
|
if (command_completer) {
|
||||||
|
auto cursor = textCursor();
|
||||||
|
auto line = cursor.block().text().trimmed();
|
||||||
|
if (line.isEmpty()) return;
|
||||||
|
|
||||||
|
auto words = split_line(line.toStdString());
|
||||||
|
cursor.select(QTextCursor::WordUnderCursor);
|
||||||
|
|
||||||
|
// if on first word, try to complete command
|
||||||
|
if ((words.size() > 0) && (words[0] == cursor.selectedText().toStdString())) {
|
||||||
|
// no completion on comment lines
|
||||||
|
if (words[0][0] == '#') return;
|
||||||
|
|
||||||
|
command_completer->setCompletionPrefix(words[0].c_str());
|
||||||
|
auto popup = command_completer->popup();
|
||||||
|
QRect cr = cursorRect();
|
||||||
|
cr.setWidth(popup->sizeHintForColumn(0) +
|
||||||
|
popup->verticalScrollBar()->sizeHint().width());
|
||||||
|
popup->setAlternatingRowColors(true);
|
||||||
|
command_completer->complete(cr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CodeEditor::insertCompletedCommand(const QString &completion)
|
void CodeEditor::insertCompletedCommand(const QString &completion)
|
||||||
{
|
{
|
||||||
if (command_completer->widget() != this) return;
|
if (command_completer->widget() != this) return;
|
||||||
|
|||||||
@ -53,6 +53,7 @@ private slots:
|
|||||||
void find_help(QString &page, QString &help);
|
void find_help(QString &page, QString &help);
|
||||||
void open_help();
|
void open_help();
|
||||||
void reformatCurrentLine();
|
void reformatCurrentLine();
|
||||||
|
void runCompletion();
|
||||||
void insertCompletedCommand(const QString &completion);
|
void insertCompletedCommand(const QString &completion);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user