[COMMS-806] Documents: impossible to delete characters with backspace after adding a wp link#169
Conversation
wrong cursor placement when inserting in the middle of a text
There was a problem hiding this comment.
Pull request overview
This PR is a proof-of-concept mitigation for a regression where Backspace stops deleting text after inserting an inline work package link (“WP chip”), by forcing an additional cursor placement step to trigger ProseMirror/Yjs re-sync.
Changes:
- Adds an extra cursor placement (
setTextCursorPosition(..., 'end')) after inline WP insertion in the SlashMenu and HashMenu flows. - Refactors formatting for
placeCursorAfterInlineNodeusage/signature. - Touches the cursor-position integration test file (currently only via imports).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| test/lib/components/integration/editor.cursorPosition.browser.test.tsx | Adds editor helper imports (currently unused). |
| lib/utils/cursor.ts | Reformats placeCursorAfterInlineNode signature for readability. |
| lib/components/SlashMenu.tsx | After inline WP insertion, forces an additional cursor placement to try to restore Backspace behavior. |
| lib/components/HashMenu/editorUtils.ts | After hash-menu chip insertion, adds a BlockNote cursor placement attempt intended to land after trailing space / trigger re-sync. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| import { | ||
| insertInlineWorkPackageViaHash, | ||
| insertInlineWorkPackageViaSlashMenu, | ||
| } from '../../../helpers/editorHelpers'; |
| // | ||
| // A re-sync event (timeout, click, or next edit) restores normal behavior. | ||
| // We're setting the cursor position to trigger this re-sync event. | ||
| editor.setTextCursorPosition(current.blockId, 'end'); |
| // Additionally place the cursor via the BlockNote API. When the chip (plus its trailing | ||
| // space) is the last content of the block, setTextCursorPosition('end') lands the cursor | ||
| // after the trailing space; it runs after placeCursorAfterInlineNode so it wins. Mid-block | ||
| // we keep placeCursorAfterInlineNode's position, since BlockNote has no inline-offset API. | ||
| const blockId = editor.getTextCursorPosition()?.block?.id; | ||
| editor.setTextCursorPosition(blockId, 'end'); | ||
| }); |
| // Mitigate bug where backspace would not work on text typed directly after adding | ||
| // a new inline work package link. | ||
| // Tiptap's built-in Backspace handler only covers special cases - undoing input |
|
The ideal fix would be to place the cursor right after the chip (not at end-of-line) so the user can immediately type at the correct position. All attempts to do this while keeping Backspace functional failed: Attempt 1 - placeCursorAfterInlineNode at range.to (between chip and trailing space) Attempt 2 - placeCursorAfterInlineNode at range.to + 1 (after the trailing space, same absolute position as setTextCursorPosition('end') for end-of-block chips) Attempt 3 - setTextCursorPosition('end') first, then placeCursorAfterInlineNode Attempt 4 - synthetic arrow key events |
Ticket
https://community.openproject.org/wp/COMMS-806
SO FAR THIS IS JUST A PROOF OF CONCEPT - the cursor placement needs to be refined, but overall it's having the expected effect to make backspace work again.
What are you trying to accomplish?
Screenshots
What approach did you choose and why?
Merge checklist