Open dmtrrk opened 2 years ago
@dmtrrk Here are some examples: https://github.com/uiwjs/react-markdown-editor/blob/eced98752edced4de4b17d70a0e0e7a94c6237a8/src/commands/image.tsx#L17-L28
const main = view.state.selection.main;
const txt = view.state.sliceDoc(view.state.selection.main.from, view.state.selection.main.to);
view.dispatch({
changes: {
from: main.from,
to: main.to,
insert: `![](${txt})`,
},
selection: EditorSelection.range(main.from + 4, main.to + 4),
// selection: { anchor: main.from + 4 },
});
@dmtrrk
cm.getCursor() → cm.state.selection.main.head
The selection, like in the previous version, consists of a number of selection ranges, one of which is considered the main selection.
cm.getCursor() → cm.state.selection.main.head
cm.listSelections() → cm.state.selection.ranges
cm.getSelection() → cm.state.sliceDoc(
cm.state.selection.main.from,
cm.state.selection.main.to)
cm.getSelections() → cm.state.selection.ranges.map(
r => cm.state.sliceDoc(r.from, r.to))
cm.somethingSelected() → cm.state.selection.ranges.some(r => !r.empty)
@dmtrrk You may need to find your answer here (https://discuss.codemirror.net/)
I'm using the Code Mirror to visualize and lint a list of words for the user. My expectation is to auto-format the inserted text e.g. convert
a, b, c
to 3 lines ofa
,b
andc
.I tried to use:
onPaste
event andclipboard.setData('text/plain', myData)
0, 0
, there is nogetCursor()
interface, so I did not find how to do soIs there a correct approach to do that?