Skip to content

Need to be able to tell if the caret is displayed at the beginning or the end of the line #32

Open

Description

@BenjamP

If a caret is at the end of a line that wraps, it's hard to tell where it is on the screen (end of line or beginning of the next line). This is important for being able to control the selection (beforeSelectionChange).
-From MS Office Team

Activity

  1. johanneswilm commented on Jun 4, 2015

    @johanneswilm

    I agree. Very important for manual movement of the caret in block direction.

  2. rniwa commented on Jun 4, 2015

    @rniwa
    Contributor

    Should we add new property like readonly boolean attribute beforeLineWrap on Selection interface?

  3. johanneswilm commented on Jun 4, 2015

    @johanneswilm

    That should work to find out where the caret is yes. So that's a good idea.

    How about this part:

    This is important for being able to control the selection (beforeSelectionChange).

    As I understand it, we should also be able to set the selection at the start or end of the line, right? This would also be useful for manual movement of caret in block direction.

  4. rniwa commented on Jun 5, 2015

    @rniwa
    Contributor

    For that, we probably need to add a new event with a sequence of Range objects and a boolean indicating the caret is before or after the line wrap if the range is collapsed (i.e. selection is caret), and probably add a new method on Selection like setCaretPosition(Node node, unsigned long offset, bool beforeLineWrap) that specifies whether the caret should appear before the line wrap or not if the specified DOM position happens to be at a line wrap.

  5. johanneswilm commented on Jun 5, 2015

    @johanneswilm

    Sounds good!

  6. yosinch commented on Mar 16, 2016

    @yosinch

    Do we really need to expose beforeLineWrap to web author? It makes user script complicated.
    Once we can specify beforeLineWrap in Selection.modify(), e.g. move towards "inline-end" set internal state beforeLineWrap to true.

    Once the spec specifies firing selecitonChange event based on caret quad change instead of caret DOM position change, this issue can be resolved.

  7. rniwa commented on Mar 16, 2016

    @rniwa
    Contributor

    Well, the use case here is saving and restoring selection after mutating DOM so the author script must be able to tell whether beforeLineWrap is true or false.

  8. rubywwwilde commented on Sep 12, 2025

    @rubywwwilde

    Also, right now if you get bounding client rect of a range that is collapsed at a line break, it returns a dom rect, that is on the end of the previous line. That is completely misleading for the case when the caret stays on the start of the next line.
    Therefore getBoundingClientRect should return different rects based on beforeLineWrap.

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