Jump to content

Topic on Extension talk:CodeMirror

Collapsed range (markText) hides cursor just before the range

4
Summary by Thiemo Kreuz (WMDE)
MarMi wiki (talkcontribs)

If you do markText with option collapsed=true (with replacedWith), and place the cursor just before the arrows marking collapsed range, the cursor won't be showing.

Example code (part above the empty line run once, markText to test range, clear to remove mark):

var text = document.createTextNode('\u2194');
widget = document.createElement("span");
widget.appendChild(text);
widget.className = "CodeMirror-foldmarker";
var editor = $(".CodeMirror")

editor[0].CodeMirror.doc.markText({line:0,ch:1},{line:1,ch:10},{collapsed:true,replacedWith:widget})
editor[0].CodeMirror.getAllMarks()[0].clear()

pl.wikipedia.org

Thiemo Kreuz (WMDE) (talkcontribs)
MarMi wiki (talkcontribs)

I don't think it's entirely the CM fault, it could be something either in the changed CM library code, mediawiki mode, or in mediawiki css (or it's just a matter of config option?).

Because if you load mode manually, the cursor in front of the range is shown.

This works (in code editor without CodeMirror present - disable highlighting and refresh the editor by F5; use editor. in place of editor[0].CodeMirror. with markText line above):

mw.loader.load("ext.CodeMirror")
mw.loader.load("ext.CodeMirror.lib.mode.htmlmixed")
var editor = CodeMirror.fromTextArea(document.getElementById("wpTextbox1"),{mode:"htmlmixed"})

mw.loader.load("ext.CodeMirror")
mw.loader.load("ext.CodeMirror.mode.mediawiki")
var editor = CodeMirror.fromTextArea(document.getElementById("wpTextbox1"),{mode:"mediawiki",mwConfig:mw.config.get( 'extCodeMirrorConfig' )})

But if you switch normally to CM editor by the button, the cursor in front of the range won't be shown (move cursor by cursor keys, mouse isn't very reliable).

MarMi wiki (talkcontribs)