AcadeDoc/apps/client
Olivier Lambert f6a8247c48
fix: cursor jumps to end of text when editing a comment (#1924)
* fix: cursor jumps to end of text when editing a comment

When editing a comment mid-text, the cursor would jump to the end after
every keystroke, making it impossible to insert text at any position
other than the end.

Root cause: on each keystroke, the comment editor's onUpdate callback
updated parent state (setContent), which changed the defaultContent prop
passed back to CommentEditor. A useEffect watching defaultContent then
called commentEditor.commands.setContent(), which reset the entire
editor content and moved the cursor to the end.

Fix:
- Store in-progress edits in a ref instead of state to avoid triggering
  React re-renders and the prop->effect->setContent cascade
- Read from the ref when saving the comment
- Sync the ref back into state after a successful save so the read-only
  view updates immediately
- Guard the setContent useEffect to only run for read-only editors, so
  websocket-driven updates from other browsers still work

Fixes #1791

Functionally tested on Firefox and Chrome: mid-text editing, saving,
cross-browser live updates via websocket.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix stale content on edit cancel

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Philipinho <16838612+Philipinho@users.noreply.github.com>
2026-02-09 15:16:40 -08:00
..
public New translations translation.json (German) (#1915) 2026-02-06 11:37:33 -08:00
src fix: cursor jumps to end of text when editing a comment (#1924) 2026-02-09 15:16:40 -08:00
.dockerignore fixes 2024-06-07 17:29:34 +01:00
.gitignore switch to nx monorepo 2024-01-09 18:58:26 +01:00
eslint.config.mjs chore: fix linting (#544) 2024-12-09 14:51:31 +00:00
index.html feat: progressive web app (#614) 2025-09-04 01:33:52 +01:00
package.json v0.25.2 2026-02-06 11:32:00 -08:00
postcss.config.js switch to nx monorepo 2024-01-09 18:58:26 +01:00
README.md switch to nx monorepo 2024-01-09 18:58:26 +01:00
tsconfig.json switch to nx monorepo 2024-01-09 18:58:26 +01:00
tsconfig.node.json switch to nx monorepo 2024-01-09 18:58:26 +01:00
vite.config.ts posthog integration (cloud) (#1304) 2025-06-27 10:58:36 +01:00

React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:

  • Configure the top-level parserOptions property like this:
   parserOptions: {
    ecmaVersion: 'latest',
    sourceType: 'module',
    project: ['./tsconfig.json', './tsconfig.node.json'],
    tsconfigRootDir: __dirname,
   },
  • Replace plugin:@typescript-eslint/recommended to plugin:@typescript-eslint/recommended-type-checked or plugin:@typescript-eslint/strict-type-checked
  • Optionally add plugin:@typescript-eslint/stylistic-type-checked
  • Install eslint-plugin-react and add plugin:react/recommended & plugin:react/jsx-runtime to the extends list