mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-02-25 00:25:03 +08:00
fix(thread-list): Use interaction handlers, don’t update selection directly
This commit is contained in:
parent
3298f6a36b
commit
109fb21dc7
6 changed files with 34 additions and 20 deletions
|
@ -127,10 +127,6 @@ export default class PreferencesSignatures extends React.Component {
|
|||
return numSelected.toString() + (numSelected === 1 ? " Account" : " Accounts")
|
||||
}
|
||||
|
||||
_getEmail = (accountOrAlias) => {
|
||||
return accountOrAlias.email
|
||||
}
|
||||
|
||||
_renderAccountPicker() {
|
||||
const buttonText = this._labelForAccountPicker()
|
||||
|
||||
|
@ -143,7 +139,7 @@ export default class PreferencesSignatures extends React.Component {
|
|||
itemKey={this._selectItemKey}
|
||||
current={this.selectedSignature}
|
||||
buttonText={buttonText}
|
||||
itemContent={this._getEmail}
|
||||
itemContent={(accountOrAlias) => accountOrAlias.email}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
|
|
@ -302,21 +302,21 @@ class ThreadList extends React.Component
|
|||
_onSelectRead: =>
|
||||
dataSource = ThreadListStore.dataSource()
|
||||
items = dataSource.itemsCurrentlyInViewMatching (item) -> not item.unread
|
||||
dataSource.selection.set(items)
|
||||
@refs.list.handler().onSelect(items)
|
||||
|
||||
_onSelectUnread: =>
|
||||
dataSource = ThreadListStore.dataSource()
|
||||
items = dataSource.itemsCurrentlyInViewMatching (item) -> item.unread
|
||||
dataSource.selection.set(items)
|
||||
@refs.list.handler().onSelect(items)
|
||||
|
||||
_onSelectStarred: =>
|
||||
dataSource = ThreadListStore.dataSource()
|
||||
items = dataSource.itemsCurrentlyInViewMatching (item) -> item.starred
|
||||
dataSource.selection.set(items)
|
||||
@refs.list.handler().onSelect(items)
|
||||
|
||||
_onSelectUnstarred: =>
|
||||
dataSource = ThreadListStore.dataSource()
|
||||
items = dataSource.itemsCurrentlyInViewMatching (item) -> not item.starred
|
||||
dataSource.selection.set(items)
|
||||
@refs.list.handler().onSelect(items)
|
||||
|
||||
module.exports = ThreadList
|
||||
|
|
|
@ -80,17 +80,17 @@ describe "MultiselectListInteractionHandler", ->
|
|||
@handler.onEnter()
|
||||
expect(@onFocusItem).toHaveBeenCalledWith(@itemKeyboardFocus)
|
||||
|
||||
describe "onSelect (x key on keyboard)", ->
|
||||
describe "onSelectKeyboardItem (x key on keyboard)", ->
|
||||
describe "on the root view", ->
|
||||
it "should toggle the selection of the keyboard item", ->
|
||||
@isRootSheet = true
|
||||
@handler.onSelect()
|
||||
@handler.onSelectKeyboardItem()
|
||||
expect(@dataSource.selection.toggle).toHaveBeenCalledWith(@itemKeyboardFocus)
|
||||
|
||||
describe "on the thread view", ->
|
||||
it "should toggle the selection of the focused item", ->
|
||||
@isRootSheet = false
|
||||
@handler.onSelect()
|
||||
@handler.onSelectKeyboardItem()
|
||||
expect(@dataSource.selection.toggle).toHaveBeenCalledWith(@itemFocus)
|
||||
|
||||
describe "onShift", ->
|
||||
|
|
|
@ -36,7 +36,13 @@ class MultiselectListInteractionHandler
|
|||
item = @props.dataSource.getById(keyboardCursorId)
|
||||
@onFocusItem(item)
|
||||
|
||||
onSelect: =>
|
||||
onDeselect: =>
|
||||
@props.dataSource.selection.clear()
|
||||
|
||||
onSelect: (items) =>
|
||||
@props.dataSource.selection.set(items)
|
||||
|
||||
onSelectKeyboardItem: =>
|
||||
{id} = @_keyboardContext()
|
||||
return unless id
|
||||
@props.dataSource.selection.toggle(@props.dataSource.getById(id))
|
||||
|
|
|
@ -70,7 +70,7 @@ class MultiselectList extends React.Component
|
|||
_globalKeymapHandlers: ->
|
||||
_.extend({}, @props.keymapHandlers, {
|
||||
'core:focus-item': => @_onEnter()
|
||||
'core:select-item': => @_onSelect()
|
||||
'core:select-item': => @_onSelectKeyboardItem()
|
||||
'core:next-item': => @_onShift(1)
|
||||
'core:previous-item': => @_onShift(-1)
|
||||
'core:select-down': => @_onShift(1, {select: true})
|
||||
|
@ -140,18 +140,18 @@ class MultiselectList extends React.Component
|
|||
return unless @state.handler
|
||||
@state.handler.onEnter()
|
||||
|
||||
_onSelect: =>
|
||||
_onSelectKeyboardItem: =>
|
||||
return unless @state.handler
|
||||
@state.handler.onSelect()
|
||||
@state.handler.onSelectKeyboardItem()
|
||||
|
||||
_onSelectAll: =>
|
||||
return unless @state.handler
|
||||
items = @props.dataSource.itemsCurrentlyInViewMatching -> true
|
||||
@props.dataSource.selection.set(items)
|
||||
@state.handler.onSelect(items)
|
||||
|
||||
_onDeselect: =>
|
||||
return unless @_visible() and @props.dataSource
|
||||
@props.dataSource.selection.clear()
|
||||
return unless @_visible() and @state.handler
|
||||
@state.handler.onDeselect()
|
||||
|
||||
_onShift: (delta, options = {}) =>
|
||||
return unless @state.handler
|
||||
|
@ -209,6 +209,9 @@ class MultiselectList extends React.Component
|
|||
|
||||
# Public Methods
|
||||
|
||||
handler: ->
|
||||
return @state.handler
|
||||
|
||||
itemIdAtPoint: (x, y) ->
|
||||
item = document.elementFromPoint(x, y).closest('[data-item-id]')
|
||||
return null unless item
|
||||
|
|
|
@ -35,8 +35,17 @@ class MultiselectSplitInteractionHandler
|
|||
@_checkSelectionAndFocusConsistency()
|
||||
|
||||
onEnter: =>
|
||||
# This concept does not exist in split mode
|
||||
|
||||
onSelect: =>
|
||||
onDeselect: =>
|
||||
@props.dataSource.selection.clear()
|
||||
@_checkSelectionAndFocusConsistency()
|
||||
|
||||
onSelect: (items) =>
|
||||
@props.dataSource.selection.set(items)
|
||||
@_checkSelectionAndFocusConsistency()
|
||||
|
||||
onSelectKeyboardItem: =>
|
||||
@_checkSelectionAndFocusConsistency()
|
||||
|
||||
onShift: (delta, options) =>
|
||||
|
|
Loading…
Reference in a new issue