diff options
author | Johannes Troscher <fritz_van_tom@hotmail.com> | 2011-08-21 18:15:06 +0200 |
---|---|---|
committer | Andrea Diamantini <adjam7@gmail.com> | 2011-08-21 18:15:06 +0200 |
commit | 4743583e3852d616daf7a7ade480ac5d04295474 (patch) | |
tree | 5092211901c066bc64d306a467facc9129b37ee0 | |
parent | Restore tab's history when restoring a tab/session (diff) | |
download | rekonq-4743583e3852d616daf7a7ade480ac5d04295474.tar.xz |
Fix vi-like navigation shortcuts
This patch introduces a check on input/textarea elements to be sure
we are NOT stealing focus there.. ;)
It also introduces a check to let the feature being optional (just to
be completely sure... )
CCBUG: 238761
REVIEW: 102255
REVIEWED-BY: adjam,elproxy
-rw-r--r-- | src/rekonq.kcfg | 3 | ||||
-rw-r--r-- | src/settings/settings_general.ui | 17 | ||||
-rw-r--r-- | src/webview.cpp | 29 |
3 files changed, 44 insertions, 5 deletions
diff --git a/src/rekonq.kcfg b/src/rekonq.kcfg index 4050c4a0..2d19b723 100644 --- a/src/rekonq.kcfg +++ b/src/rekonq.kcfg @@ -97,6 +97,9 @@ <entry name="clearHomePageThumbs" type="Bool"> <default>true</default> </entry> + <entry name="enableViShortcuts" type="Bool"> + <default>false</default> + </entry> </group> diff --git a/src/settings/settings_general.ui b/src/settings/settings_general.ui index d0c31655..3f7c0675 100644 --- a/src/settings/settings_general.ui +++ b/src/settings/settings_general.ui @@ -194,6 +194,13 @@ </property> </widget> </item> + <item> + <widget class="QCheckBox" name="kcfg_enableViShortcuts"> + <property name="text"> + <string>Enable Vi-like navigation shortcuts</string> + </property> + </widget> + </item> </layout> </widget> </item> @@ -214,15 +221,15 @@ </widget> <customwidgets> <customwidget> - <class>KLineEdit</class> - <extends>QLineEdit</extends> - <header>klineedit.h</header> - </customwidget> - <customwidget> <class>KComboBox</class> <extends>QComboBox</extends> <header>kcombobox.h</header> </customwidget> + <customwidget> + <class>KLineEdit</class> + <extends>QLineEdit</extends> + <header>klineedit.h</header> + </customwidget> </customwidgets> <resources/> <connections/> diff --git a/src/webview.cpp b/src/webview.cpp index d8325543..8dfcc051 100644 --- a/src/webview.cpp +++ b/src/webview.cpp @@ -643,6 +643,35 @@ void WebView::keyPressEvent(QKeyEvent *event) } } + // vi-like navigation + if (ReKonfig::enableViShortcuts()) + { + const QString tagName = page()->mainFrame()->evaluateJavaScript("document.activeElement.tagName").toString(); + if (tagName != QL1S("INPUT") && tagName != QL1S("TEXTAREA") && event->modifiers() == Qt::NoModifier) + { + switch (event->key()) + { + case Qt::Key_J: + event->accept(); + event = new QKeyEvent(QEvent::KeyPress, Qt::Key_Down, Qt::NoModifier); + break; + case Qt::Key_K: + event->accept(); + event = new QKeyEvent(QEvent::KeyPress, Qt::Key_Up, Qt::NoModifier); + break; + case Qt::Key_L: + event->accept(); + event = new QKeyEvent(QEvent::KeyPress, Qt::Key_Right, Qt::NoModifier); + break; + case Qt::Key_H: + event->accept(); + event = new QKeyEvent(QEvent::KeyPress, Qt::Key_Left, Qt::NoModifier); + break; + default: + break; + } + } + } KWebView::keyPressEvent(event); } |