Keyboard’s Backspace and Left Arrow neither work while caret after Decoration.widget which’s “side” is sets to -1.
example:
1(Decoration.widget is here)(caret is here, both Backspace and Left Arrow doesn’t work)2
Keyboard’s Backspace and Left Arrow neither work while caret after Decoration.widget which’s “side” is sets to -1.
example:
1(Decoration.widget is here)(caret is here, both Backspace and Left Arrow doesn’t work)2
Can you try to set up a minimal example script for this? If I just use a simple widget I don’t see it happening.
Thanks for your reply, this is my minimal example script.
System: windows10
Browser: chrome
Expection: Pressing Backspace or Left Arrow while caret directly occur after widget should deletes prev letter before widget or moves caret before prev letter
What the widget plugin do is adding a space between English and Chinese(I have remove that logic to make this example minimal)
import { Decoration, DecorationSet } from 'prosemirror-view'
import { EditorView } from 'prosemirror-view'
import { EditorState, Plugin } from 'prosemirror-state'
import { Schema } from 'prosemirror-model'
import crelt from 'crelt'
export function init(elm: HTMLElement) {
return new EditorView(elm, {
state: EditorState.create({
schema: new Schema({
nodes: {
doc: {
content: '(paragraph | block)+',
},
paragraph: {
content: 'inline*',
group: 'block liContent',
toDOM(node) {
return ['p', node.attrs, 0]
},
},
text: {
group: 'inline',
},
},
}),
plugins: [
new Plugin({
props: {
decorations(state) {
const posArr: number[] = []
state.doc.descendants((node, pos) => {
if (!node.isTextblock) return
const text = node.textContent
for (let i = 0; i < text.length - 1; i++) {
posArr.push(pos + i + 2)
}
})
return DecorationSet.create(
state.doc,
posArr.map((pos) => {
return Decoration.widget(
pos,
() => {
return crelt('i', ' ')
},
{ side: -1 }
)
})
)
},
},
}),
],
}),
})
}
I tried in both Firefox and Chrome (Linux), and both left arrow and backspace seem to work in that example.
System Information:
22.04.1-Ubuntu
5.19.0-45-generic
Browser: Chrome, Left Arrow and Backspace neither work
Browser: Firefox, Left Arrow works but Backspace doesn’t