Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prosemirror-suggest example out of day, using keyBindings, etc. #2187

Open
Palmik opened this issue Oct 31, 2023 · 1 comment
Open

prosemirror-suggest example out of day, using keyBindings, etc. #2187

Palmik opened this issue Oct 31, 2023 · 1 comment
Labels
type: bug 🪲 Something isn't working

Comments

@Palmik
Copy link

Palmik commented Oct 31, 2023

Summary

The prosemirror-suggest example / readme is out of date, as it references interfaces have have since changed, like keyBindings. It would be great to have an up-to-date example for newcomers.

@Palmik Palmik added the type: bug 🪲 Something isn't working label Oct 31, 2023
@manakuro
Copy link

It's because the prosemirror-suggest API has been refactored here.

#623

The keyBindings, createCommand , and onExit has been removed. When it comes to the keyBindings, you can define them through the prosemirror-keymap like so:

import { keymap } from 'prosemirror-keymap';
import { undo, redo } from 'prosemirror-history';
import { schema } from 'prosemirror-schema-basic';
import { EditorState } from 'prosemirror-state';
import { EditorView } from 'prosemirror-view';
import { baseKeymap, toggleMark } from 'prosemirror-commands';

// First, define the commands you want to bind to
const myKeymap = {
  "Mod-z": undo,
  "Mod-y": redo,
  "Mod-b": toggleMark(schema.marks.strong), // Toggle bold mark
  "Mod-i": toggleMark(schema.marks.em) // Toggle italic mark
  "ArrowUp": () => console.log("Your ArrowUp here"),
  "ArrowDown": () => console.log("Your ArrowDown here"),
  "Enter": () => console.log("Your Enter here"),
  "Esc": () => console.log("Your Esc here")
}

// You might have multiple keymaps, and just in case they conflict, you'll want to decide what priority they have:
const keymapPlugin = keymap(myKeymap)
const defaultKeymapPlugin = keymap(baseKeymap)

// Now add the created plugins to your PM instance
let state = EditorState.create({
  schema,
  plugins: [keymapPlugin, defaultKeymapPlugin, /* other plugins */]
})

const view = new EditorView(document.body, { state })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug 🪲 Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants