forked from qt-creator/qt-creator
QmlDesigner: Override shortcuts in text editor
There are a couple of known shortcuts that we have to override in the text editor. We install an event filter and handle the shortcut override event for the keys in question. Change-Id: Icb5483b19e2202d85e99d24c20d05097aaa33da6 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -34,8 +34,12 @@
|
||||
|
||||
#include <utils/fileutils.h>
|
||||
|
||||
#include <QEvent>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
TextEditorWidget::TextEditorWidget(TextEditorView *textEditorView) : QWidget()
|
||||
@@ -64,6 +68,7 @@ void TextEditorWidget::setTextEditor(TextEditor::BaseTextEditor *textEditor) {
|
||||
|
||||
connect(textEditor->editorWidget(), &QPlainTextEdit::cursorPositionChanged,
|
||||
&m_updateSelectionTimer, static_cast<void (QTimer::*)()>(&QTimer::start));
|
||||
textEditor->editorWidget()->installEventFilter(this);
|
||||
}
|
||||
|
||||
QString TextEditorWidget::contextHelpId() const
|
||||
@@ -136,4 +141,18 @@ int TextEditorWidget::currentLine() const
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool TextEditorWidget::eventFilter( QObject *, QEvent *event)
|
||||
{
|
||||
static std::vector<int> overrideKeys = { Qt::Key_Delete, Qt::Key_Backspace, Qt::Key_Left, Qt::Key_Right, Qt::Key_Up, Qt::Key_Down };
|
||||
if (event->type() == QEvent::ShortcutOverride) {
|
||||
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
|
||||
if (std::find(overrideKeys.begin(), overrideKeys.end(), keyEvent->key()) != overrideKeys.end()) {
|
||||
keyEvent->accept();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
} // namespace QmlDesigner
|
||||
|
||||
@@ -58,6 +58,9 @@ public:
|
||||
void clearStatusBar();
|
||||
|
||||
int currentLine() const;
|
||||
protected:
|
||||
bool eventFilter(QObject *object, QEvent *event) override;
|
||||
|
||||
private:
|
||||
void updateSelectionByCursorPosition();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user