mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-18 19:06:10 +00:00
Enable Console Completion only on Tab (#1558)
This commit is contained in:
parent
7e8eb9c393
commit
d32e3fa20f
@ -52,6 +52,7 @@ ConsoleWidget::ConsoleWidget(MainWindow *main, QAction *action) :
|
||||
actions.append(actionWrapLines);
|
||||
|
||||
// Completion
|
||||
completionActive = false;
|
||||
completer = new QCompleter(&completionModel, this);
|
||||
completer->setMaxVisibleItems(20);
|
||||
completer->setCaseSensitivity(Qt::CaseInsensitive);
|
||||
@ -80,6 +81,11 @@ ConsoleWidget::ConsoleWidget(MainWindow *main, QAction *action) :
|
||||
connect(historyDownShortcut, SIGNAL(activated()), this, SLOT(historyNext()));
|
||||
historyDownShortcut->setContext(Qt::WidgetShortcut);
|
||||
|
||||
QShortcut *completionShortcut = new QShortcut(QKeySequence(Qt::Key_Tab), ui->inputLineEdit);
|
||||
connect(completionShortcut, &QShortcut::activated, this, &ConsoleWidget::triggerCompletion);
|
||||
|
||||
connect(ui->inputLineEdit, &QLineEdit::editingFinished, this, &ConsoleWidget::disableCompletion);
|
||||
|
||||
connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(setupFont()));
|
||||
|
||||
completer->popup()->installEventFilter(this);
|
||||
@ -246,8 +252,33 @@ void ConsoleWidget::historyPrev()
|
||||
}
|
||||
}
|
||||
|
||||
void ConsoleWidget::triggerCompletion()
|
||||
{
|
||||
if (completionActive) {
|
||||
return;
|
||||
}
|
||||
completionActive = true;
|
||||
updateCompletion();
|
||||
completer->complete();
|
||||
}
|
||||
|
||||
void ConsoleWidget::disableCompletion()
|
||||
{
|
||||
if (!completionActive) {
|
||||
return;
|
||||
}
|
||||
completionActive = false;
|
||||
updateCompletion();
|
||||
completer->popup()->hide();
|
||||
}
|
||||
|
||||
void ConsoleWidget::updateCompletion()
|
||||
{
|
||||
if (!completionActive) {
|
||||
completionModel.setStringList({});
|
||||
return;
|
||||
}
|
||||
|
||||
auto current = ui->inputLineEdit->text();
|
||||
auto completions = Core()->autocomplete(current, R_LINE_PROMPT_DEFAULT);
|
||||
int lastSpace = current.lastIndexOf(' ');
|
||||
@ -262,6 +293,7 @@ void ConsoleWidget::updateCompletion()
|
||||
|
||||
void ConsoleWidget::clear()
|
||||
{
|
||||
disableCompletion();
|
||||
ui->inputLineEdit->clear();
|
||||
|
||||
invalidateHistoryPosition();
|
||||
|
@ -56,6 +56,8 @@ private slots:
|
||||
void historyNext();
|
||||
void historyPrev();
|
||||
|
||||
void triggerCompletion();
|
||||
void disableCompletion();
|
||||
void updateCompletion();
|
||||
|
||||
void clear();
|
||||
@ -77,6 +79,7 @@ private:
|
||||
int maxHistoryEntries;
|
||||
int lastHistoryPosition;
|
||||
QStringList history;
|
||||
bool completionActive;
|
||||
QStringListModel completionModel;
|
||||
QCompleter *completer;
|
||||
QShortcut *historyUpShortcut;
|
||||
|
Loading…
Reference in New Issue
Block a user