Skip to content

fix jumping cursor bug#5937

Open
rafaroseira wants to merge 1 commit intoStirling-Tools:mainfrom
rafaroseira:fix/toc-cursor-jump
Open

fix jumping cursor bug#5937
rafaroseira wants to merge 1 commit intoStirling-Tools:mainfrom
rafaroseira:fix/toc-cursor-jump

Conversation

@rafaroseira
Copy link

@rafaroseira rafaroseira commented Mar 14, 2026

Description

Fixes #5870

Fixed an issue in the Table of Contents editor where the cursor would jump to the end of the input field on every keystroke. I modified the following file:

  • frontend/src/core/components/tools/editTableOfContents/BookmarkEditor.tsx

Changes

  1. Introduced a local state (currentTitleInput) and editingId to decouple text input from the tree re-renders;

  2. Implemented a getLatestTree method to synchronize the current title input with the tree state before any changes on the tree (adding/removing/expanding/collapsing nodes or changing target page number);

  3. Changed onClick button events to onMouseDown events with preventDefault() to ensure that tree updates trigger before the input focus is lost.

The change (1) was already enough to fix the main bug, but I realized it introduced another bug while I was testing: if the user typed the title input (without clicking outside the text input box) and immediately after clicked on the up and down arrows to change the target page number or clicked on a button (add child/sibling, delete, expand/collapse), then the title input would be restored to its previous state. Hence why I did changes (2) and (3) aswell.

Checklist

General

Documentation

Translations (if applicable)

UI Changes (if applicable)

  • Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR)

Testing (if applicable)

  • I have tested my changes locally. Refer to the Testing Guide for more details.

@dosubot dosubot bot added size:M This PR changes 30-99 lines ignoring generated files. Bugfix Pull requests that fix bugs labels Mar 14, 2026
@stirlingbot stirlingbot bot added Front End Issues or pull requests related to front-end development and removed Bugfix Pull requests that fix bugs labels Mar 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Front End Issues or pull requests related to front-end development size:M This PR changes 30-99 lines ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Edit table of contents - Cursor jumps to end of line after character input.

1 participant