Topic on Extension talk:CodeMirror/5

Wrapped lines: spaces on wraps and End

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

If wrapped lines ends by spaces (so nearly always), End puts the cursor at the beginning of the next wrapped line - so it basically behaves like Home (except it puts the cursor in the wrapped line below).

You can't put the cursor behind the last space (in the same horizontal line), you can either put cursor before the last space, or "after" it (which puts cursor at the beginning of the wrapped line below).

Can it be set so it would behave like thread editor here: End puts the cursor after last space (in the same horizontal line). Cursor right places cursor at the beginning of wrapped line below)?


Example of a long wrapped line:

Góry Zielone (ang. Green Mountains, fr. Montagnes Vertes) – pasmo górskie w stanach Vermont i Massachusetts (Stany Zjednoczone) oraz prowincji Quebec (Kanada), wchodzące w skład Appalachów. Góry Zielone (ang. Green Mountains, fr. Montagnes Vertes) – pasmo górskie w stanach Vermont i Massachusetts (Stany Zjednoczone) oraz prowincji Quebec (Kanada), wchodzące w skład Appalachów.

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

TL: read the summary in my next post.


Not quite, because current version of CM wraps lines similar to what I proposed - except cursor right at the end of wrap (End) places the cursor after first char of the wrapped line below.

So this is either the question of CM implementation used by the extension (ie. this could be introduced in later version than 5.53.x), or some settings (or maybe mode/style influence the cursor?).

Edit: 5.53.3 can set the cursor at the end of line wrap, because it does so if the mode is loaded manually:

editor.setOption("lineWrapping",true);
var ek=editor.getOption("extraKeys");
if (!ek) ek={}
ek.End='goLineRight'
editor.setOption("extraKeys",ek);

So it's a matter of extension changes in implementation, its settings or mode (including styles).

I think that placing the cursor at the end of line by End is more natural than its current behavior in mediawiki mode.

(Does mediawiki mode is also covered by Extension:CodeMirror?).

Even later edit: I've pinpointed the setting that influences cursor behavior: it's inputStyle: 'contenteditable' (in ex.CodeMirror.js)

Full test code for clarity:

mw.loader.load("ext.CodeMirror")    //execute separately

mw.loader.load("ext.CodeMirror.mode.mediawiki") //execute separately

var cmOptions={mode:"text/mediawiki",mwConfig:mw.config.get('extCodeMirrorConfig'),lineWrapping: true,inputStyle: 'contenteditable'}
var editor = CodeMirror.fromTextArea(document.getElementById("wpTextbox1"),cmOptions)
var ek=editor.getOption("extraKeys");
if (!ek) ek={}
ek.End='goLineRight'
editor.setOption("extraKeys",ek);
MarMi wiki (talkcontribs)

Summary of the above (sorry for multiple edits):

I guess it's a CM thing after all.

Since you can't change inputStyle at runtime (yet, according to comment in CM code), maybe there is a way to change it on Wikipedia on the browser client side (without the need of changing code in the extension)?

Edit: Also, on contenteditable in 2020: What are the pitfalls of using inputStyle ‘contenteditable’ in 2020?.

And in 2021: CM5: No cursor before bookmark.

As to the cursor at the end of wrapped lines (in contenteditable): it's probably possible, but would require implementing a custom cursor (CM5: inputStyle contenteditable, cursor display after goLineRight (wrapped line)).