Skip to content

fix(muya): preserve cursor on IME composition backspace(#4956) - #4957

Merged
Jocs merged 1 commit into
marktext:developfrom
Zengzzhao:fix/ime-backspace
Sep 3, 2026
Merged

Jocs merged 1 commit into
marktext:developfrom
Zengzzhao:fix/ime-backspace

Conversation

@Zengzzhao

Copy link
Copy Markdown
Contributor

Closes #4956

Summary

Why: During IME composition, Backspace/Delete triggered the editor's backspaceHandler/deleteHandler instead of the IME. Since composition text isn't in this.text yet, the handler ran on a stale snapshot, dislocating the cursor.

Fix: Added if (!this.isComposed) guard in keydownHandler for Backspace/Delete, matching the existing guard for Enter/arrows/Tab.

Changes:
content.ts: guard the two keys during composition.
imeBackspaceComposition.spec.ts: new test (4 cases) covering composing vs. non-composing Backspace/Delete.

Type of change

  • Bug fix (non-breaking, fixes an issue)
  • New feature (non-breaking, adds functionality)
  • Breaking change (causes existing functionality to change)
  • Documentation update

Test plan

  • New tests added (or explain why not needed)
  • Manually tested on:

Notes for reviewers [optional]


By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

@Zengzzhao Zengzzhao changed the title fix(content): preserve cursor on IME composition backspace(#4956) fix(muya): preserve cursor on IME composition backspace(#4956) Jul 17, 2026
@Zengzzhao

Copy link
Copy Markdown
Contributor Author

@Jocs Hi, do you have time to take a look at the current bug fix? I'd really like to contribute.

niyo-oyin added a commit to niyo-oyin/marktext-ja that referenced this pull request Jul 29, 2026
Four fixes, all the same failure class — editor code acting on keys or
input events that belong to an open IME composition:

- content.ts keydownHandler: guard Backspace/Delete with !isComposed,
  matching the existing Enter/arrows/Tab guards. Mid-composition they ran
  backspaceHandler/deleteHandler against a stale text snapshot and
  dislocated the cursor (upstream marktext#4956; reimplements PR marktext#4957).
- codeBlockContent: apply upstream PR marktext#4876 (Jocs) verbatim — an IME
  commit no longer rebuilds domNode.innerHTML synchronously (which
  destroyed the text node the IME was anchored to, corrupting Japanese
  input from the 2nd character, marktext#4851); the syntax re-highlight runs
  behind a 300ms trailing debounce instead. State updates stay
  synchronous; structural edits still rebuild synchronously.
- langInputContent: the code-fence language input had no composition
  handling at all — every mid-composition input event rebuilt innerHTML.
  Ignore inputs while composing and commit IME text without re-rendering,
  same mechanism as marktext#4876.
- Float tools: handleContentKeydown, the BaseScrollFloat nav handler and
  the BaseFloat Escape handler now ignore keys pressed while a
  composition is open — Enter/Escape/Tab/arrows operate the IME's
  candidate list, not the float.

All fixes are unit-tested with synthetic composition events; each new
spec fails on the pre-fix code. Muya suite 1454/1454, lint/tsc/madge
clean.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ef4yFuXFbyKNTazkwUtygY
niyo-oyin added a commit to niyo-oyin/marktext-ja that referenced this pull request Jul 29, 2026
Four fixes, all the same failure class — editor code acting on keys or
input events that belong to an open IME composition:

- content.ts keydownHandler: guard Backspace/Delete with !isComposed,
  matching the existing Enter/arrows/Tab guards. Mid-composition they ran
  backspaceHandler/deleteHandler against a stale text snapshot and
  dislocated the cursor (upstream marktext#4956; reimplements PR marktext#4957).
- codeBlockContent: apply upstream PR marktext#4876 (Jocs) verbatim — an IME
  commit no longer rebuilds domNode.innerHTML synchronously (which
  destroyed the text node the IME was anchored to, corrupting Japanese
  input from the 2nd character, marktext#4851); the syntax re-highlight runs
  behind a 300ms trailing debounce instead. State updates stay
  synchronous; structural edits still rebuild synchronously.
- langInputContent: the code-fence language input had no composition
  handling at all — every mid-composition input event rebuilt innerHTML.
  Ignore inputs while composing and commit IME text without re-rendering,
  same mechanism as marktext#4876.
- Float tools: handleContentKeydown, the BaseScrollFloat nav handler and
  the BaseFloat Escape handler now ignore keys pressed while a
  composition is open — Enter/Escape/Tab/arrows operate the IME's
  candidate list, not the float.

All fixes are unit-tested with synthetic composition events; each new
spec fails on the pre-fix code. Muya suite 1454/1454, lint/tsc/madge
clean.
@Jocs

Jocs commented Sep 3, 2026

Copy link
Copy Markdown
Member

Apologies for the delayed review, I was away on summer vacation. Thanks for your contribution!

@Jocs
Jocs merged commit 3ee675b into marktext:develop Sep 3, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Cursor dislocates when pressing Backspace/Delete during IME composition

2 participants