I implement a simple Script Editor with drag and drop (copy) from an list of keywords.
Its working very fine. Codemirror is super!!
Now my issue:
If i drop my text in editor, i could before setCursor with mouse click (manually)
But, i want drop my keyword text on current mouse position
What is the simplest solution?
The editor’s built-in drop handling should already insert the dropped content at the drop position. If you’re writing your own logic, look into coordsChar.
Wow super quickly.
Basically i use react-codemirror2 onDrop={(data, e)=>dropCodeLine(data, e)}
And i think i use it totally wrong.
let dropCodeLine=(editor:Editor, e:React.DragEvent<HTMLElement>)=>{
let newcodeline = e.dataTransfer.getData('codezeile')
let doc= editor.getDoc()
editor.focus()
//editor.setCursor(editor.coordsChar({left:10,top:20}))
let cursor = doc.getCursor()
let pos={line:cursor.line, ch:1}
doc.replaceRange(newcodeline, pos)
}
let dropCodeLine=(editor:Editor, e:React.DragEvent<HTMLElement>)=>{
let newline = e.dataTransfer.getData('codeline')
let doc= editor.getDoc()
editor.focus()
let x = e.pageX
let y = e.pageY
editor.setCursor(editor.coordsChar({left:x,top:y}))
let newpos = editor.getCursor()
console.log(newpos)
doc.replaceRange(newline, newpos)
}