fix(T2049): in 2-pane mode, keyboard actions are applied to selection, not message you are viewing

Fixes T2049 and moves ownership of the reply/reply-all/forward actions to the MessageList, which Rob did for starring and actually makes more sense.
This commit is contained in:
Ben Gotow 2015-06-26 14:47:14 -07:00
parent 84295b05d0
commit 4b8dd87410
4 changed files with 37 additions and 38 deletions

View file

@ -66,7 +66,10 @@ class MessageList extends React.Component
@_unsubscribers.push MessageStore.listen @_onChange
commands = _.extend {},
'core:star-item': => @_onStarItem()
'core:star-item': => @_onStar()
'application:reply': => @_onReply()
'application:reply-all': => @_onReplyAll()
'application:forward': => @_onForward()
@command_unsubscriber = atom.commands.add('body', commands)
@ -113,13 +116,26 @@ class MessageList extends React.Component
_focusDraft: (draftElement) =>
draftElement.focus()
_onStarItem: =>
_onStar: =>
return unless @state.currentThread
if @state.currentThread.isStarred()
task = new AddRemoveTagsTask(@state.currentThread, [], ['starred'])
else
task = new AddRemoveTagsTask(@state.currentThread, ['starred'], [])
Actions.queueTask(task)
_onReply: =>
return unless @state.currentThread
Actions.composeReply(thread: @state.currentThread)
_onReplyAll: =>
return unless @state.currentThread
Actions.composeReplyAll(thread: @state.currentThread)
_onForward: =>
return unless @state.currentThread
Actions.composeForward(thread: @state.currentThread)
render: =>
if not @state.currentThread?
return <div className="message-list" id="message-list"></div>

View file

@ -217,9 +217,9 @@ describe "MessageList", ->
expect(items.length).toBe 1
it "toggles star on a thread if 's' is pressed", ->
spyOn(@messageList, "_onStarItem")
spyOn(@messageList, "_onStar")
NylasTestUtils.keyPress("s", document.body)
expect(@messageList._onStarItem).toHaveBeenCalled()
expect(@messageList._onStar).toHaveBeenCalled()
it "focuses new composers when a draft is added", ->
spyOn(@messageList, "_focusDraft")

View file

@ -125,11 +125,13 @@ ThreadListStore = Reflux.createStore
Actions.queueTask(task)
_onToggleStarFocused: ->
focusedThread = FocusedContentStore.focused('thread')
if focusedThread.isStarred()
task = new AddRemoveTagsTask(focusedThread, [], ['starred'])
focused = FocusedContentStore.focused('thread')
return unless focused
if focused.isStarred()
task = new AddRemoveTagsTask(focused, [], ['starred'])
else
task = new AddRemoveTagsTask(focusedThread, ['starred'], [])
task = new AddRemoveTagsTask(focused, ['starred'], [])
Actions.queueTask(task)
_onArchive: ->

View file

@ -133,9 +133,6 @@ class ThreadList extends React.Component
'core:star-item': @_onStarItem
'core:remove-and-previous': -> Actions.archiveAndPrevious()
'core:remove-and-next': -> Actions.archiveAndNext()
'application:reply': @_onReply
'application:reply-all': @_onReplyAll
'application:forward': @_onForward
@itemPropsProvider = (item) ->
className: classNames
@ -148,12 +145,6 @@ class ThreadList extends React.Component
componentWillUnmount: =>
window.removeEventListener('resize', @_onResize)
_onStarItem: =>
if @state.style is 'wide' or ThreadListStore.view().selection.count() > 0
Actions.toggleStarSelection()
else
Actions.toggleStarFocused()
render: =>
if @state.style is 'wide'
<MultiselectList
@ -188,31 +179,21 @@ class ThreadList extends React.Component
# Additional Commands
_onStarItem: =>
if WorkspaceStore.layoutMode() is "list" and WorkspaceStore.topSheet() is WorkspaceStore.Sheet.Thread
Actions.toggleStarFocused()
else if ThreadListStore.view().selection.count() > 0
Actions.toggleStarSelection()
else
Actions.toggleStarFocused()
_onArchive: =>
if ThreadListStore.view().selection.count() is 0
if WorkspaceStore.layoutMode() is "list" and WorkspaceStore.topSheet() is WorkspaceStore.Sheet.Thread
Actions.archive()
else
else if ThreadListStore.view().selection.count() > 0
Actions.archiveSelection()
_onReply: ({focusedId}) =>
return unless focusedId? and @_viewingFocusedThread()
Actions.composeReply(threadId: focusedId)
_onReplyAll: ({focusedId}) =>
return unless focusedId? and @_viewingFocusedThread()
Actions.composeReplyAll(threadId: focusedId)
_onForward: ({focusedId}) =>
return unless focusedId? and @_viewingFocusedThread()
Actions.composeForward(threadId: focusedId)
# Helpers
_viewingFocusedThread: =>
if WorkspaceStore.layoutMode() is "list"
WorkspaceStore.topSheet() is WorkspaceStore.Sheet.Thread
else
true
Actions.archive()
module.exports = ThreadList