… I can say with quite a bit of confidence that setCursor works …
I know and understand.
It must be something particular to what I am doing. Please check if the following progress helps you to find out what is going on…
Why does it go through function setSelection
again?
Should I cancel mouse action e.g. event.stopPropagation()
?
Update: I tried it but didn’t make any difference.
// progress
cm.on('mousedown', (cm, e) => func(cm, node););
func(cm, node) {
console.log('func called'); // func called
cm.setCursor(1, 0);
}
// codemirror.js
setCursor: docMethodOp(function(line, ch, options) {console.log(line, ch, options);
// 1 0 undefined
function setSimpleSelection(doc, anchor, head, options) {console.log(doc, anchor, head, options);
// object object { line: 1, ch: 0, sticky: null } null undefiend
function setSelection(doc, sel, options) {console.log(doc, sel, options);
// object object undefiend
function setSelectionNoUndo(doc, sel, options) {console.log(doc, sel, options);
// object object undefiend
function addSelectionToHistory(doc, sel, opId, options) {console.log(doc, sel, opId, options);
// object object 4 undefiend
function setSelection(doc, sel, options) {console.log(doc, sel, options);
// object object Object { origin: "*mouse" }
function setSelectionNoUndo(doc, sel, options) {console.log(doc, sel, options);
// object object Object { origin: "*mouse" }
function addSelectionToHistory(doc, sel, opId, options) {console.log(doc, sel, opId, options);
// object object 4 Object { origin: "*mouse" }
// last one
Object {
cantEdit: false
children: Array [ {…} ]
cleanGeneration: 1
cm: Object { options: {…}, doc: {…}, display: {…}, … }
direction: "ltr"
extend: false
first: 0
height: 180
highlightFrontier: 12
history: Object { undoDepth: 200, lastSelTime: 1608567729426, lastModTime: 0, … }
id: 1
lineSep: null
mode: Object { blockCommentStart: "/*", blockCommentEnd: "*/", blockCommentContinue: " * ", … }
modeFrontier: 12
modeOption: "javascript"
parent: null
scrollLeft: 0
scrollTop: 0
sel: Object { ranges: (1) […], primIndex: 0 }
size: 12
}
Object {
primIndex: 0
ranges: [
anchor: Object { line: 4, ch: 39, sticky: "before", … }
head: Object { line: 4, ch: 39, sticky: "before", … }
length: 1
]
}