Merge lp:~mhall119/webbrowser-app/alt-num-shortcut into lp:webbrowser-app

Proposed by Michael Hall
Status: Needs review
Proposed branch: lp:~mhall119/webbrowser-app/alt-num-shortcut
Merge into: lp:webbrowser-app
Diff against target: 113 lines (+82/-0)
3 files modified
src/app/webbrowser/Browser.qml (+62/-0)
tests/autopilot/webbrowser_app/tests/test_keyboard.py (+10/-0)
tests/unittests/qml/tst_TabsBar.qml (+10/-0)
To merge this branch: bzr merge lp:~mhall119/webbrowser-app/alt-num-shortcut
Reviewer Review Type Date Requested Status
Olivier Tilloy Needs Fixing
Riccardo Padovani (community) Needs Fixing
PS Jenkins bot continuous-integration Needs Fixing
Review via email: mp+272454@code.launchpad.net

Description of the change

Adds Alt+[0-9] KeyboartShortcut to switch between the first 10 tabs directly, similar to Chrome and Firefox.

Currently the tests fail, I'm not sure why, but the code works when I run it. The key press events seems to be falling through to the page in the tab though, which causes some pages like Facebook.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Riccardo Padovani (rpadovani) wrote :

Thanks, works quite well.

Just a note: it doesn't work when the address bar is focused.

E.g.:
0. Start the browser
1. Click CTRL+T
2. Click ALT+1

I expect to return to first tab, but instead it inserts 1 in the address bar.

BTW, I don't find any documentation about KeyboardShortcut, nor in developer.ubuntu.com (actually, a grep in ubuntu-ui-toolkit return nothing) nor in developer.qt.io (but I didn't check the source code here) - where did you find it?

review: Needs Fixing
Revision history for this message
Olivier Tilloy (osomon) wrote :

@Riccardo: KeyboardShortcut is a custom item in webbrowser-app’s source tree: http://bazaar.launchpad.net/~phablet-team/webbrowser-app/trunk/view/head:/src/app/webbrowser/KeyboardShortcut.qml.

See also the KeyboardShortcuts item that is meant to contain all keyboard shortcuts: http://bazaar.launchpad.net/~phablet-team/webbrowser-app/trunk/view/head:/src/app/webbrowser/KeyboardShortcuts.qml.

Revision history for this message
Olivier Tilloy (osomon) wrote :

QmlTests::TabsBar::test_goto_tab_keyboardshortcut consistently fails. This is because keyboard shortcuts are not handled at the TabsBar level, but in the top-level Browser component. So either that unit test needs to be removed, or the definition of these shortcuts need to be encapsulated at the TabsBar level (probably a better approach).

On a related note, given that the definition of this kind of shortcuts results in very repetitive (and thus error-prone) code, it would be good to consider instantiating them dynamically in a Component.onCompleted handler.

review: Needs Fixing

Unmerged revisions

1203. By Michael Hall

Add alt+# keyboard shortcuts to go directly to a tab

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/app/webbrowser/Browser.qml'
2--- src/app/webbrowser/Browser.qml 2015-09-22 01:27:19 +0000
3+++ src/app/webbrowser/Browser.qml 2015-09-25 17:45:14 +0000
4@@ -1728,5 +1728,67 @@
5 chrome.focus = true
6 }
7 }
8+
9+ // Alt + [0-9]: Go to tab
10+ KeyboardShortcut {
11+ modifiers: Qt.AltModifier
12+ key: Qt.Key_1
13+ enabled: tabsModel.count >= 1
14+ onTriggered: internal.switchToTab(0)
15+ }
16+ KeyboardShortcut {
17+ modifiers: Qt.AltModifier
18+ key: Qt.Key_2
19+ enabled: tabsModel.count >= 2
20+ onTriggered: internal.switchToTab(1)
21+ }
22+ KeyboardShortcut {
23+ modifiers: Qt.AltModifier
24+ key: Qt.Key_3
25+ enabled: tabsModel.count >= 3
26+ onTriggered: internal.switchToTab(2)
27+ }
28+ KeyboardShortcut {
29+ modifiers: Qt.AltModifier
30+ key: Qt.Key_4
31+ enabled: tabsModel.count >= 4
32+ onTriggered: internal.switchToTab(3)
33+ }
34+ KeyboardShortcut {
35+ modifiers: Qt.AltModifier
36+ key: Qt.Key_5
37+ enabled: tabsModel.count >= 5
38+ onTriggered: internal.switchToTab(4)
39+ }
40+ KeyboardShortcut {
41+ modifiers: Qt.AltModifier
42+ key: Qt.Key_6
43+ enabled: tabsModel.count >= 6
44+ onTriggered: internal.switchToTab(5)
45+ }
46+ KeyboardShortcut {
47+ modifiers: Qt.AltModifier
48+ key: Qt.Key_7
49+ enabled: tabsModel.count >= 7
50+ onTriggered: internal.switchToTab(6)
51+ }
52+ KeyboardShortcut {
53+ modifiers: Qt.AltModifier
54+ key: Qt.Key_8
55+ enabled: tabsModel.count >= 8
56+ onTriggered: internal.switchToTab(7)
57+ }
58+ KeyboardShortcut {
59+ modifiers: Qt.AltModifier
60+ key: Qt.Key_9
61+ enabled: tabsModel.count >= 9
62+ onTriggered: internal.switchToTab(8)
63+ }
64+ KeyboardShortcut {
65+ modifiers: Qt.AltModifier
66+ key: Qt.Key_0
67+ enabled: tabsModel.count >= 10
68+ onTriggered: internal.switchToTab(9)
69+ }
70 }
71 }
72
73=== modified file 'tests/autopilot/webbrowser_app/tests/test_keyboard.py'
74--- tests/autopilot/webbrowser_app/tests/test_keyboard.py 2015-08-14 09:25:38 +0000
75+++ tests/autopilot/webbrowser_app/tests/test_keyboard.py 2015-09-25 17:45:14 +0000
76@@ -103,6 +103,16 @@
77 self.main_window.press_key('Ctrl+Tab')
78 self.check_tab_number(2)
79
80+ def test_goto_tab(self):
81+ self.open_tabs(2)
82+ self.check_tab_number(2)
83+ self.main_window.press_key('Alt+1')
84+ self.check_tab_number(0)
85+ self.main_window.press_key('Alt+2')
86+ self.check_tab_number(1)
87+ self.main_window.press_key('Alt+3')
88+ self.check_tab_number(2)
89+
90 def test_can_switch_tabs_after_suggestions_escape(self):
91 self.open_tabs(1)
92 self.check_tab_number(1)
93
94=== modified file 'tests/unittests/qml/tst_TabsBar.qml'
95--- tests/unittests/qml/tst_TabsBar.qml 2015-08-10 15:22:00 +0000
96+++ tests/unittests/qml/tst_TabsBar.qml 2015-09-25 17:45:14 +0000
97@@ -103,6 +103,16 @@
98 compare(newTabRequestSpy.count, 3)
99 }
100
101+ function test_goto_tab_keyboardshortcut() {
102+ // Alt+[0-9] goes to the numbered tab
103+ populateTabs()
104+ var keys = [Qt.Key_1, Qt.Key_2, Qt.Key_3]
105+ for (var i = 2; i >= 0; --i) {
106+ keyClick(keys[i], Qt.AltModifier)
107+ compare(tabsModel.currentIndex, i)
108+ }
109+ }
110+
111 function test_mouse_left_click() {
112 // Left click makes the tab current
113 populateTabs()

Subscribers

People subscribed via source and target branches

to status/vote changes: