We have methods on the surface for converting between source and nwe offsets so should be a case of re-implementing the method form jquery.textSelection.
- Mentioned In
- T152760: jquery.textSelection does not scroll textbox in Chromium, works in Firefox
T198010: jquery.textSelection methods work incorrectly with 2017 wikitext editor
T187454: "encapsulateSelection" broken with the proofread-page content model
- Mentioned Here
- T187454: "encapsulateSelection" broken with the proofread-page content model
I've started working on this, and then realized that we should be able to implement $.textSelection's encapsulateSelection in terms of the other $.textSelection functions. This way we won't have to duplicate this 100-line monster in every custom wikitext editor.
On second thought, I'm not sure if that was the best idea… This now essentially works by replacing the entire contents of the editor, which a) sometimes causes the scroll position to jump and b) generates inefficient transactions. I might have to come back to this, and do it the boring way.
(NB there is another textSelection implementation in CodeMirror that is 90% encapsulateSelection that could be replaced with a single line codeMirror.doc.replaceSelection( insertText );)