How to use the prosemirror-commands.toggleMark function in prosemirror-commands

To help you get started, we’ve selected a few prosemirror-commands examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gamejolt / frontend-lib / components / content / content-editor / plugins / commands / keymap.ts View on Github external
export function getContentEditorKeymap(editor: AppContentEditor, schema: ContentEditorSchema) {
	const isMac = typeof navigator != 'undefined' ? /Mac/.test(navigator.platform) : false;

	const keymap = {
		'Mod-z': undo,
		'Shift-Mod-z': redo,
		'Mod-b': toggleMark(schema.marks.strong),
		'Mod-i': toggleMark(schema.marks.em),
		'Mod-`': toggleMark(schema.marks.code),
		'Shift-Enter': chainCommands(exitCodeStart(editor.capabilities), exitCode, insertHardBreak),
		// open emoji panel
		'Mod-e': () => {
			if (editor.capabilities.emoji) {
				editor.showEmojiPanel();
			}
			return true;
		},
		// Add/remove link
		'Mod-k': showLinkModal(editor.capabilities, schema),
	} as { [k: string]: any };

	const enterCommands = [] as PMKeymapCommand[];
github the-grid / ed / src / menu / menu-link.js View on Github external
run: function (state, dispatch, view, attrs) {
      // Toggle link off
      if (markActive(state, markType)) {
        toggleMark(markType)(state, dispatch)
        return true
      }

      // Toggle link on
      if (attrs) {
        toggleMark(markType, attrs)(state, dispatch)
        return true
      }

      // Prompt for link
      const {from, to} = state.selection
      const selectedText = state.doc.textBetween(from, to)
      const urlLike = isUrlLike(selectedText)
      const value = (urlLike ? selectedText : '')

      const {ed} = key.get(state).options.edStuff
github gamejolt / frontend-lib / components / content / content-editor / controls / text / controls.ts View on Github external
private dispatchMark(mark: MarkType, attrs?: { [key: string]: any }) {
		toggleMark(mark, attrs)(this.view.state, tr => {
			this.view.dispatch(tr);
		});
	}
github alidcastano / vue-prosemirror-editor / src / plugins / keys.js View on Github external
    'Mod-i': (em) => toggleMark(em),
    'Mod-u': (underline) => toggleMark(underline),
github pubpub / pubpub / src / components / AtomTypes / Document / proseEditor / keymap.js View on Github external
function buildKeymap(schema, mapKeys) {
  let keys = {}, type
  function bind(key, cmd) {
    if (mapKeys) {
      let mapped = mapKeys[key]
      if (mapped === false) return
      if (mapped) key = mapped
    }
    keys[key] = cmd
  }

  bind("Mod-Z", undo)
  bind("Mod-Y", redo)

  if (type = schema.marks.strong)
    bind("Mod-KeyB", toggleMark(type))
  if (type = schema.marks.em)
    bind("Mod-KeyI", toggleMark(type))
  if (type = schema.marks.code)
    bind("Mod-Backquote", toggleMark(type))

  if (type = schema.nodes.bullet_list)
    bind("Shift-Ctrl-Digit8", wrapInList(type))
  if (type = schema.nodes.ordered_list)
    bind("Shift-Ctrl-Digit9", wrapInList(type))
  if (type = schema.nodes.blockquote)
    bind("Shift-Ctrl-Period", wrapIn(type))
  if (type = schema.nodes.hard_break) {
    let br = type, cmd = chainCommands(newlineInCode, (state, onAction) => {
      onAction(state.tr.replaceSelection(br.create()).scrollAction())
      return true
    })
github cosmocode / dokuwiki-plugin-prosemirror / script / plugins / Menu / menu.js View on Github external
* @param {EditorState} state the editor's current state
     * @param {MarkType} type type of the mark based on the schema (e.g. schema.marks.strong )
     * @return {boolean} True if the mark is currently active
     */
    function markActive(state, type) {
        const {
            from, $from, to, empty,
        } = state.selection;
        if (empty) {
            return type.isInSet(state.storedMarks || $from.marks());
        }
        return state.doc.rangeHasMark(from, to, type);
    }

    return new MenuItem({
        command: toggleMark(markType),
        icon: svgIcon(iconName),
        label: title,
        isActive: editorState => markActive(editorState, markType),
    });
}
github pubpub / pubpub / src / components / AtomTypes / Document / proseEditor / menu.js View on Github external
callback(attrs) {
          toggleMark(markType, attrs)(view.state, view.props.onAction)
        }
      })
github pubpub / pubpub-editor / packages / pubpub-editor / src / prosemirror-setup / menu-config / menuItems.js View on Github external
run(state, dispatch, view, openPrompt) {

			if (markActive(state, markType)) {
				toggleMark(markType)(state, view.dispatch)
				return true
			}
			openPrompt({
				callback(attrs) {
					toggleMark(markType, attrs)(view.state, view.dispatch)
				}
			});

		}
	})
github pubpub / pubpub-editor / src / plugins / keymap.js View on Github external
bind('Backspace', undoInputRule);
	if (!mac) bind('Mod-y', redo);

	bind('Alt-ArrowUp', joinUp);
	bind('Alt-ArrowDown', joinDown);
	bind('Mod-BracketLeft', lift);
	bind('Escape', selectParentNode);

	if (schema.marks.strong) {
		bind('Mod-b', toggleMark(schema.marks.strong));
	}
	if (schema.marks.em) {
		bind('Mod-i', toggleMark(schema.marks.em));
	}
	if (schema.marks.sup) {
		bind('Mod-.', toggleMark(schema.marks.sup));
	}
	if (schema.marks.sub) {
		bind('Mod-,', toggleMark(schema.marks.sub));
	}
	if (schema.marks.strike) {
		bind('Mod-Shift-x', toggleMark(schema.marks.strike));
	}
	if (schema.marks.code) {
		bind('Mod-<', toggleMark(schema.marks.code));
	}
	if (schema.marks.link) {
		bind('Mod-k', toggleMark(schema.marks.link));
	}

	if (schema.nodes.bullet_list) {
		bind('Shift-Ctrl-8', wrapInList(schema.nodes.bullet_list));