Hi! I need to show some tools in position: absolute window by entering /, how can I do it?
I had such thoughts:
I thought that I had to watch on transactions and when transaction would have added text content ‘/’, I’ll show my tools, it works, but looks bad because transactions not always have this structure:
transaction.steps[transaction.steps.length - 1]?.slice.content.content[0]?.text === '/'
// I think it's a bad and incorrect decision.
I thought maybe I need to use prosemirror-inputrules module but I’m not sure :.
Or I need to write a plugin, or to describe handleTextInput event for my view.
create an input rule plugin, trigger display action.
use EditorView.posAtCoords | EditorView.domAtPos | EditorView.nodeDOM to calculate the display position
close tools
Sample code
new InputRule(/^\/(\w+)?$/, (state, match) = >{
if (match) {
// show tools and calculate the position
}
return null;
}),
new Plugin({
props: {
handleClick: () = >{
// close tools or other action
},
handleKeyDown: () = >{
// close tools or other action
}
}
})