How to detect the boundary of the current “line” (with cursor) in a long line that is soft wrapped multiple times?
(To modify the addon “selection/active-line” to highlight only that line fragment).
Edit (after Google research): Or rather, does CM have anything that would help with that detection?
Oh, right, no, I don’t think 5.x provides something like that directly, but I think calling coordsChar with position with the line’s vertical position and horizontal positions to the left/right of the editor should work.
I made some progress (I was able to detect the first “line” of wrapped line).
But how do I style that line fragment? Classes for spans from markText are overridden by other span (or line) classes inserted later by the mode, so simple cm.doc.markText(range.from,range.to, {className:WRAP_CLASS+" "+BACK_CLASS})
doesn’t color the fragment (code placed in the addon active-line function updateActiveLines).
They are, but if a later class (on the same span) have the same attribute, it will overwrite the previous setting (unless it had !important).
I tried it again and the active classes are working on non-tokenized line, but if the line is a token that sets background-color (to rgba(34,17,153,0.04), if it have any meaning), then it disables the background-color of the added .CodeMirror-activeline-background (I assume the token classes are added after setting the “active” classes - token classes are listed as the first ones in the span class list in F12 Inspector).
Other questions:
Can something else be used to mark (color) the fragment beside the region mark (I clear all marks to “unfold all”, so it probably will conflict)?
Is there a relatively simple way (without changing the CM code) to mark the entire “line” (to the right border of the editor window)? I can mark only text in line, so there will be gaps on the right - especially at the end of the line, where there could be only one word.
I think that addLineWidget could be the answer, depending on how it works (didn’t tested it yet).
Oh, by the way: how to mark the range marks, to filter them out from the getAllMarks list (add custom property, change type or something else)?
Hmm… This could be a CM or custom implementation of CM (5.58.3) fault, because it handles Home/End on wrapped lines in a weird way (End [goLineRight] places cursor before the first char in next “line” [position gets sticky=before]).