all files / packages/list/ InsertListCommand.js

63.64% Statements 7/11
85.71% Branches 6/7
50% Functions 1/2
63.64% Lines 7/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24        1522× 1522× 1522× 1522× 1522× 546×   1522×                        
import { Command } from '../../ui'
 
class InsertListCommand extends Command {
  getCommandState (params) {
    let sel = this._getSelection(params)
    let selectionState = params.editorSession.getSelectionState()
    let commandState = {}
    let _disabledCollapsedCursor = this.config.disableCollapsedCursor && sel.isCollapsed()
    if (_disabledCollapsedCursor || !sel.isPropertySelection() || selectionState.isInlineNodeSelection()) {
      commandState.disabled = true
    }
    return commandState
  }
  execute (params) {
    let ordered = this.config.ordered
    let editorSession = params.editorSession
    editorSession.transaction((tx) => {
      tx.toggleList({ ordered: ordered })
    })
  }
}
 
export default InsertListCommand