mirror of
https://github.com/rizinorg/cutter.git
synced 2025-01-31 08:37:26 +00:00
Disable Up/Down in Console during Completion (#1554)
This commit is contained in:
parent
c0f4f458ed
commit
7e8eb9c393
@ -23,7 +23,10 @@ ConsoleWidget::ConsoleWidget(MainWindow *main, QAction *action) :
|
||||
ui(new Ui::ConsoleWidget),
|
||||
debugOutputEnabled(true),
|
||||
maxHistoryEntries(100),
|
||||
lastHistoryPosition(invalidHistoryPos)
|
||||
lastHistoryPosition(invalidHistoryPos),
|
||||
completer(nullptr),
|
||||
historyUpShortcut(nullptr),
|
||||
historyDownShortcut(nullptr)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
@ -55,7 +58,7 @@ ConsoleWidget::ConsoleWidget(MainWindow *main, QAction *action) :
|
||||
completer->setFilterMode(Qt::MatchStartsWith);
|
||||
ui->inputLineEdit->setCompleter(completer);
|
||||
|
||||
connect(ui->inputLineEdit, &QLineEdit::textChanged, this, &ConsoleWidget::updateCompletion);
|
||||
connect(ui->inputLineEdit, &QLineEdit::textEdited, this, &ConsoleWidget::updateCompletion);
|
||||
updateCompletion();
|
||||
|
||||
// Set console output context menu
|
||||
@ -69,15 +72,17 @@ ConsoleWidget::ConsoleWidget(MainWindow *main, QAction *action) :
|
||||
clear_shortcut->setContext(Qt::WidgetShortcut);
|
||||
|
||||
// Up and down arrows show history
|
||||
QShortcut *historyOnUp = new QShortcut(QKeySequence(Qt::Key_Up), ui->inputLineEdit);
|
||||
connect(historyOnUp, SIGNAL(activated()), this, SLOT(historyPrev()));
|
||||
historyOnUp->setContext(Qt::WidgetShortcut);
|
||||
historyUpShortcut = new QShortcut(QKeySequence(Qt::Key_Up), ui->inputLineEdit);
|
||||
connect(historyUpShortcut, SIGNAL(activated()), this, SLOT(historyPrev()));
|
||||
historyUpShortcut->setContext(Qt::WidgetShortcut);
|
||||
|
||||
QShortcut *historyOnDown = new QShortcut(QKeySequence(Qt::Key_Down), ui->inputLineEdit);
|
||||
connect(historyOnDown, SIGNAL(activated()), this, SLOT(historyNext()));
|
||||
historyOnDown->setContext(Qt::WidgetShortcut);
|
||||
historyDownShortcut = new QShortcut(QKeySequence(Qt::Key_Down), ui->inputLineEdit);
|
||||
connect(historyDownShortcut, SIGNAL(activated()), this, SLOT(historyNext()));
|
||||
historyDownShortcut->setContext(Qt::WidgetShortcut);
|
||||
|
||||
connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(setupFont()));
|
||||
|
||||
completer->popup()->installEventFilter(this);
|
||||
}
|
||||
|
||||
ConsoleWidget::~ConsoleWidget()
|
||||
@ -85,6 +90,22 @@ ConsoleWidget::~ConsoleWidget()
|
||||
delete completer;
|
||||
}
|
||||
|
||||
bool ConsoleWidget::eventFilter(QObject *obj, QEvent *event)
|
||||
{
|
||||
if(completer && obj == completer->popup() &&
|
||||
// disable up/down shortcuts if completer is shown
|
||||
(event->type() == QEvent::Type::Show || event->type() == QEvent::Type::Hide)) {
|
||||
bool enabled = !completer->popup()->isVisible();
|
||||
if (historyUpShortcut) {
|
||||
historyUpShortcut->setEnabled(enabled);
|
||||
}
|
||||
if (historyDownShortcut) {
|
||||
historyDownShortcut->setEnabled(enabled);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ConsoleWidget::setupFont()
|
||||
{
|
||||
ui->outputTextEdit->setFont(Config()->getFont());
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <memory>
|
||||
|
||||
class QCompleter;
|
||||
class QShortcut;
|
||||
|
||||
namespace Ui {
|
||||
class ConsoleWidget;
|
||||
@ -34,6 +35,9 @@ public:
|
||||
maxHistoryEntries = max;
|
||||
}
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *obj, QEvent *event);
|
||||
|
||||
public slots:
|
||||
void focusInputLineEdit();
|
||||
|
||||
@ -75,6 +79,8 @@ private:
|
||||
QStringList history;
|
||||
QStringListModel completionModel;
|
||||
QCompleter *completer;
|
||||
QShortcut *historyUpShortcut;
|
||||
QShortcut *historyDownShortcut;
|
||||
};
|
||||
|
||||
#endif // CONSOLEWIDGET_H
|
||||
|
Loading…
Reference in New Issue
Block a user