UNPKG

substance

Version:

Substance is a JavaScript library for web-based content editing. It provides building blocks for realizing custom text editors and web-based publishing system. It is developed to power our online editing platform [Substance](http://substance.io).

48 lines (43 loc) 1.1 kB
import Command from './Command' export default class IndentListCommand extends Command { getCommandState (params) { const editorSession = params.editorSession const doc = editorSession.getDocument() const sel = editorSession.getSelection() if (sel && sel.isPropertySelection()) { const path = sel.path const node = doc.get(path[0]) if (node) { if (node.isListItem()) { return { disabled: false } } } } return { disabled: true } } execute (params) { const commandState = params.commandState const { disabled } = commandState if (disabled) return const editorSession = params.editorSession const action = this.config.spec.action switch (action) { case 'indent': { editorSession.transaction((tx) => { tx.indent() }, { action: 'indent' }) break } case 'dedent': { editorSession.transaction((tx) => { tx.dedent() }, { action: 'dedent' }) break } default: // } } }