You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
setPosition/collapse should taken an optional argument for whether the caret is before or after a line break #51
Like the issue #32, we need a mechanism by which to specify whether the caret appears before or after a link break. Alternatively, we could make the attribute we're adding in the issue #32 writable but having to call setPosition / collapse and set a property separately in order to place a caret isn't great.
I think a solution for this should definitely take #57 into account. It may be worthwhile to systematically look at all pieces of (currently) hidden state that exist in a selection, and define some kind of options object that allows user code to set them. Or go with writable attributes—that's crude, but seems to work for caretBidiLevel in Gecko.
Is there a way to currently set position to the end of a line? Right now collapsing selection either to start or to end both produce text caret displayed on the start of the next line.
You can put the cursor one past the position you want, and then move it back to the proper position with Selection.modify—if you move backwards, it'll associate with the text after it, if you move forward with the text before it. But that is a really terrible hack.
@marijnh But is there a way to know if caret in the browser is before or after line break?
Now I know how to set it properly, but how do I know where was it set to?
I cannot trust "onselectionchange", it does not give me any useful information for such identification. Therefore it seems like I need to keep track of this parameter separately and do all the selection changes in browser myself. That works well when user changes selection with keyboard, but not when they change it with mouse.
Does it mean that I need to keep track of pointer events to figure out if user clicked on the place that is at the new line or at the start of the previous line? That sounds incredibly ugly :)
But is there a way to know if caret in the browser is before or after line break?
I don't think there is, unfortunately. CodeMirror captures all user interaction that updates the selection model, so it only needs to set the selection, not read it.
Activity
marijnh commentedon Jan 23, 2020
I think a solution for this should definitely take #57 into account. It may be worthwhile to systematically look at all pieces of (currently) hidden state that exist in a selection, and define some kind of options object that allows user code to set them. Or go with writable attributes—that's crude, but seems to work for
caretBidiLevelin Gecko.rubywwwilde commentedon Sep 12, 2025
Is there a way to currently set position to the end of a line? Right now collapsing selection either to start or to end both produce text caret displayed on the start of the next line.
marijnh commentedon Sep 12, 2025
You can put the cursor one past the position you want, and then move it back to the proper position with
Selection.modify—if you move backwards, it'll associate with the text after it, if you move forward with the text before it. But that is a really terrible hack.rubywwwilde commentedon Sep 13, 2025
Thank you! Yes, I went to code mirror and saw your solution there. You mean that this hack is terrible because it has side effects to it?
marijnh commentedon Sep 13, 2025
Just that it's ugly and it would help a lot to have a proper API for this.
rubywwwilde commentedon Sep 18, 2025
@marijnh But is there a way to know if caret in the browser is before or after line break?
Now I know how to set it properly, but how do I know where was it set to?
I cannot trust "onselectionchange", it does not give me any useful information for such identification. Therefore it seems like I need to keep track of this parameter separately and do all the selection changes in browser myself. That works well when user changes selection with keyboard, but not when they change it with mouse.
Does it mean that I need to keep track of pointer events to figure out if user clicked on the place that is at the new line or at the start of the previous line? That sounds incredibly ugly :)
marijnh commentedon Sep 18, 2025
I don't think there is, unfortunately. CodeMirror captures all user interaction that updates the selection model, so it only needs to set the selection, not read it.