Skip to content

setPosition/collapse should taken an optional argument for whether the caret is before or after a line break #51

Open

Description

@rniwa

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.

Activity

  1. marijnh commented on Jan 23, 2020

    @marijnh

    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.

  2. rubywwwilde commented on Sep 12, 2025

    @rubywwwilde

    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.

  3. marijnh commented on Sep 12, 2025

    @marijnh

    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.

  4. rubywwwilde commented on Sep 13, 2025

    @rubywwwilde

    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?

  5. marijnh commented on Sep 13, 2025

    @marijnh

    Just that it's ugly and it would help a lot to have a proper API for this.

  6. rubywwwilde commented on Sep 18, 2025

    @rubywwwilde

    @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 :)

  7. marijnh commented on Sep 18, 2025

    @marijnh

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions