Skip to content

[72837] Click position is lost when activating an inline edit field#23449

Merged
HDinger merged 2 commits into
release/17.5from
bug/72837-click-position-is-lost-when-activating-an-inline-edit-field-2
Jun 2, 2026
Merged

[72837] Click position is lost when activating an inline edit field#23449
HDinger merged 2 commits into
release/17.5from
bug/72837-click-position-is-lost-when-activating-an-inline-edit-field-2

Conversation

@HDinger
Copy link
Copy Markdown
Contributor

@HDinger HDinger commented May 29, 2026

Ticket

https://community.openproject.org/wp/72837

What are you trying to accomplish?

Remember click position when switching from display to edit field. Due to the limit of of the setSelectionRange method this only works for inputs of type text.

What approach did you choose and why?

On click, the char offset is determined and stored in a module-level Map, keyed by the field's data-inplace-edit-stable-key. When the edit field controller connects to the rendered input, it reads the stored offset and applies it via setSelectionRange.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses ticket #72837 by preserving the user’s click/cursor position when switching an inplace-edit field from display mode to an inline text input, even though the DOM gets replaced via Turbo Streams.

Changes:

  • Introduces a module-level Map keyed by data-inplace-edit-stable-key to persist cursor offsets across Turbo Stream replacements.
  • Captures the character offset on click before requesting the edit field, and restores the selection on controller connect via setSelectionRange.
  • Adds helpers to compute a click-based character offset by walking text nodes.

Comment thread frontend/src/stimulus/controllers/dynamic/inplace-edit.controller.ts Outdated
@HDinger HDinger force-pushed the bug/72837-click-position-is-lost-when-activating-an-inline-edit-field-2 branch from 311cd5a to 9f4d28a Compare June 1, 2026 07:58
@HDinger HDinger requested a review from myabc June 1, 2026 07:59
Copy link
Copy Markdown
Contributor

@myabc myabc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻 code looks much better.

One thing that is still not ideal, but doesn't need to block merging: although the caret is placed in the right place when using a standard text input, it may not be visible when there is a long piece of text. I don't know if there is a reliable/cross-browser way to scroll the caret into view?

Screen.Recording.2026-06-01.at.12.24.12.mov

my workaround: use keyboard left/right keys to bring caret into view.

@HDinger HDinger merged commit 9d07295 into release/17.5 Jun 2, 2026
19 checks passed
@HDinger HDinger deleted the bug/72837-click-position-is-lost-when-activating-an-inline-edit-field-2 branch June 2, 2026 07:23
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 2, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Development

Successfully merging this pull request may close these issues.

3 participants