mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-21 12:26:11 +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);
|
actions.append(actionWrapLines);
|
||||||
|
|
||||||
// Completion
|
// Completion
|
||||||
|
completionActive = false;
|
||||||
completer = new QCompleter(&completionModel, this);
|
completer = new QCompleter(&completionModel, this);
|
||||||
completer->setMaxVisibleItems(20);
|
completer->setMaxVisibleItems(20);
|
||||||
completer->setCaseSensitivity(Qt::CaseInsensitive);
|
completer->setCaseSensitivity(Qt::CaseInsensitive);
|
||||||
@ -80,6 +81,11 @@ ConsoleWidget::ConsoleWidget(MainWindow *main, QAction *action) :
|
|||||||
connect(historyDownShortcut, SIGNAL(activated()), this, SLOT(historyNext()));
|
connect(historyDownShortcut, SIGNAL(activated()), this, SLOT(historyNext()));
|
||||||
historyDownShortcut->setContext(Qt::WidgetShortcut);
|
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()));
|
connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(setupFont()));
|
||||||
|
|
||||||
completer->popup()->installEventFilter(this);
|
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()
|
void ConsoleWidget::updateCompletion()
|
||||||
{
|
{
|
||||||
|
if (!completionActive) {
|
||||||
|
completionModel.setStringList({});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
auto current = ui->inputLineEdit->text();
|
auto current = ui->inputLineEdit->text();
|
||||||
auto completions = Core()->autocomplete(current, R_LINE_PROMPT_DEFAULT);
|
auto completions = Core()->autocomplete(current, R_LINE_PROMPT_DEFAULT);
|
||||||
int lastSpace = current.lastIndexOf(' ');
|
int lastSpace = current.lastIndexOf(' ');
|
||||||
@ -262,6 +293,7 @@ void ConsoleWidget::updateCompletion()
|
|||||||
|
|
||||||
void ConsoleWidget::clear()
|
void ConsoleWidget::clear()
|
||||||
{
|
{
|
||||||
|
disableCompletion();
|
||||||
ui->inputLineEdit->clear();
|
ui->inputLineEdit->clear();
|
||||||
|
|
||||||
invalidateHistoryPosition();
|
invalidateHistoryPosition();
|
||||||
|
@ -56,6 +56,8 @@ private slots:
|
|||||||
void historyNext();
|
void historyNext();
|
||||||
void historyPrev();
|
void historyPrev();
|
||||||
|
|
||||||
|
void triggerCompletion();
|
||||||
|
void disableCompletion();
|
||||||
void updateCompletion();
|
void updateCompletion();
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
@ -77,6 +79,7 @@ private:
|
|||||||
int maxHistoryEntries;
|
int maxHistoryEntries;
|
||||||
int lastHistoryPosition;
|
int lastHistoryPosition;
|
||||||
QStringList history;
|
QStringList history;
|
||||||
|
bool completionActive;
|
||||||
QStringListModel completionModel;
|
QStringListModel completionModel;
|
||||||
QCompleter *completer;
|
QCompleter *completer;
|
||||||
QShortcut *historyUpShortcut;
|
QShortcut *historyUpShortcut;
|
||||||
|
Loading…
Reference in New Issue
Block a user