Skip to content

[Feature request] Expose caret/cursor screen coordinatesΒ #469

Description

@ErionTp

Hi there! πŸ‘‹

First of all, great work on this library β€” we're really enjoying using it.

I wanted to ask if it would be possible to expose the caret's screen coordinates (x, y) via a callback, something like:

onCaretPositionChange?: (position: { x: number; y: number }) => void;

Why we need this:

We're implementing a mention popup (triggered by @ / # indicators) and we'd love to position it near the caret β€” similar to how desktop editors like VS Code, Slack, or Notion show autocomplete suggestions right at the cursor.

Currently, onChangeSelection provides character offsets (start, end, text), which is great for text manipulation, but doesn't give us the pixel coordinates needed to position a floating UI element near the caret.

Without screen coordinates, the best we can do is show the mention list relative to the editor container (e.g. pinned to the bottom), which works but isn't as polished as anchoring it to the cursor position.

Is this something that could be supported, or is there a workaround we might be missing? Would love to hear your thoughts.

Thanks!

Activity

  1. changed the title [-]Feature request: Expose caret/cursor screen coordinates[/-] [+][Feature request] Expose caret/cursor screen coordinates[/+] on Apr 28, 2026
  2. kacperzolkiewski commented on Jul 14, 2026

    @kacperzolkiewski
    Collaborator

    Hi @ErionTp,

    Thanks for the suggestion!
    At the moment, we don't plan to implement this feature because there hasn't been enough interest from the community. We'll keep this feature request open, though, so others can upvote or comment on it.
    If we see more demand for this feature in the future, we'll definitely reconsider implementing it.

  3. IslamRustamov commented on Jul 27, 2026

    @IslamRustamov
    Contributor

    I think this feature is quite simple to implement if I'm not mistaken.

    For iOS we can do in textViewDidChangeSelection the next thing:

      if (emitter != nullptr) {
        // iOS range works differently because it specifies location and length
        // here, start is the location, but end is the first index BEHIND the end.
        // So a 0 length range will have equal start and end
        CGPoint cursorPosition = [textView caretRectForPosition:textView.selectedTextRange.start].origin; // <--- this gets the position
    
        emitter->onChangeSelection(
            {.start = static_cast<int>(textView.selectedRange.location),
             .end = static_cast<int>(textView.selectedRange.location +
                                     textView.selectedRange.length),
              .x = cursorPosition.x,
              .y = cursorPosition.y,
             .text = [textAtSelection toCppString]});
      }
    

    And then we can store somewhere the layout position of text input (get it from onLayout) and add it to the selection position. This way we can do something like (red square is following the caret position):

    Image

    (but I guess the user of this will also need to cater for the max height of the input, the offsets and other stuff as we see in the end of the gif it just flies further, but it's only because I quickly "sketched" some code for its' positioning)

    If you guys are interested - I can also look at Android's implementation of this and create a PR.

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

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions