This repository has been archived by the owner on Jan 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 71
Keyboard shortcuts #755
Open
treppo
wants to merge
12
commits into
pixelated:master
Choose a base branch
from
treppo:keyboard-shortcuts
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Keyboard shortcuts #755
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8dbebaa
Open compose box on keyboard shortcut 'c'
treppo 39733bd
Close compose box on keyboard shortcut <ESC>
treppo a85cdc7
WIP feature test
treppo 7c83aef
Send mail with shortcut
treppo ec073fa
Add "wip" tag to feature test
treppo 6a5d108
Focus search input field when pressing <s> or </>
treppo f15bc41
Differenciate between shortcuts on mail composition and others
treppo d60e09e
Test all code paths
treppo eb9ce7e
Use underscore binding and iterators
treppo 58c86bf
Attach ComposeBox shortcuts to the right element
treppo a6381dc
Attach generic mail view shortcuts to the right elements
treppo 6b8d6ef
Attach mail composition shortcuts to draft mails
treppo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
service/test/functional/features/keyboard_shortcuts_to_compose.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# | ||
# Copyright (c) 2014 ThoughtWorks, Inc. | ||
# | ||
# Pixelated is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# Pixelated is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
@wip | ||
Feature: Using keyboard shortcuts to compose and send a mail | ||
As a user of pixelated | ||
I want to use keyboard shortcuts | ||
So I can compose mails | ||
|
||
Scenario: User composes a mail and sends it using shortcuts | ||
When I use a shortcut to compose a message with | ||
| subject | body | | ||
| Pixelated rocks! | You should definitely use it. Cheers, User. | | ||
And for the 'To' field I enter 'pixelated@friends.org' | ||
And I use a shortcut to send it | ||
When I select the tag 'sent' | ||
And I open the first mail in the mail list | ||
Then I see that the subject reads 'Pixelated rocks!' | ||
Then I see that the body reads 'You should definitely use it. Cheers, User.' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright (c) 2014 ThoughtWorks, Inc. | ||
* | ||
* Pixelated is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Pixelated is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Pixelated. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
define([ | ||
'flight/lib/component', | ||
'page/events' | ||
], | ||
function (defineComponent, events) { | ||
'use strict'; | ||
|
||
return defineComponent(mailViewShortcuts); | ||
|
||
function mailViewShortcuts() { | ||
var keyCodes = { | ||
ENTER: 13 | ||
}; | ||
var modifierKeys = { | ||
META: "META", | ||
CTRL: "CTRL" | ||
}; | ||
|
||
// make constants public | ||
this.keyCodes = keyCodes; | ||
|
||
this.after('initialize', function () { | ||
this.on('keydown', _.partial(tryKeyEvents, _.bind(this.trigger, this, document))); | ||
}); | ||
|
||
function tryKeyEvents(triggerFunc, event) { | ||
var keyEvents = {}; | ||
keyEvents[modifierKeys.CTRL + keyCodes.ENTER] = events.ui.mail.send; | ||
keyEvents[modifierKeys.META + keyCodes.ENTER] = events.ui.mail.send; | ||
|
||
if (!keyEvents.hasOwnProperty(modifierKey(event) + event.which)) { | ||
return; | ||
} | ||
|
||
event.preventDefault(); | ||
return triggerFunc(keyEvents[modifierKey(event) + event.which]); | ||
} | ||
|
||
function modifierKey(event) { | ||
var modifierKey = ""; | ||
if (event.ctrlKey === true) { | ||
modifierKey = modifierKeys.CTRL; | ||
} | ||
if (event.metaKey === true) { | ||
modifierKey = modifierKeys.META; | ||
} | ||
return modifierKey; | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright (c) 2014 ThoughtWorks, Inc. | ||
* | ||
* Pixelated is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Pixelated is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Pixelated. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
define([ | ||
'flight/lib/component', | ||
'page/events' | ||
], | ||
function (defineComponent, events) { | ||
'use strict'; | ||
|
||
return defineComponent(mailViewShortcuts); | ||
|
||
function mailViewShortcuts() { | ||
var keyCodes = { | ||
ESC: 27 | ||
}; | ||
|
||
// make constants public | ||
this.keyCodes = keyCodes; | ||
|
||
this.after('initialize', function () { | ||
this.on(document, 'keydown', _.partial(tryKeyEvents, _.bind(this.trigger, this, document))); | ||
}); | ||
|
||
function tryKeyEvents(triggerFunc, event) { | ||
var keyEvents = {}; | ||
keyEvents[keyCodes.ESC] = events.dispatchers.rightPane.openNoMessageSelected; | ||
|
||
if (!keyEvents.hasOwnProperty(event.which)) { | ||
return; | ||
} | ||
|
||
event.preventDefault(); | ||
return triggerFunc(keyEvents[event.which]); | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright (c) 2014 ThoughtWorks, Inc. | ||
* | ||
* Pixelated is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Pixelated is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Pixelated. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
define([ | ||
'flight/lib/component', | ||
'page/events' | ||
], | ||
function (defineComponent, events) { | ||
'use strict'; | ||
|
||
return defineComponent(shortcuts); | ||
|
||
function shortcuts() { | ||
var composeBoxId = 'compose-box'; | ||
var keyCodes = { | ||
C: 67, | ||
FORWARD_SLASH: 191, | ||
S: 83 | ||
}; | ||
|
||
// make constants public | ||
this.keyCodes = keyCodes; | ||
this.composeBoxId = composeBoxId; | ||
|
||
this.after('initialize', function () { | ||
this.on('keydown', _.partial(tryMailHandlingKeyEvents, _.bind(this.trigger, this, document))); | ||
}); | ||
|
||
function tryMailHandlingKeyEvents(triggerFunc, event) { | ||
if (isTriggeredOnInputField(event.target) || composeBoxIsShown()) { | ||
return; | ||
} | ||
|
||
var mailHandlingKeyEvents = {}; | ||
mailHandlingKeyEvents[keyCodes.S] = events.search.focus; | ||
mailHandlingKeyEvents[keyCodes.FORWARD_SLASH] = events.search.focus; | ||
mailHandlingKeyEvents[keyCodes.C] = events.dispatchers.rightPane.openComposeBox; | ||
|
||
if (!mailHandlingKeyEvents.hasOwnProperty(event.which)) { | ||
return; | ||
} | ||
|
||
event.preventDefault(); | ||
return triggerFunc(mailHandlingKeyEvents[event.which]); | ||
} | ||
|
||
function isTriggeredOnInputField(element) { | ||
return $(element).is('input') || $(element).is('textarea'); | ||
} | ||
|
||
function composeBoxIsShown() { | ||
return $('#' + composeBoxId).length; | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not very happy with this. Is there any way to get that state of the application other than by accessing the DOM?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@treppo Not really, we just try to minimize the impact of messing with the dom by only changing things rendered inside the specific component. In this case, I would use the key combos to trigger events to specific components, that can deal with the dom manipulation it needs to do the action
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bwagnerr i do trigger events on the specific components. only these events here have to be triggered on
document
. and therefore i have to check whether the compose box is open by accessing the dom…