fix(composer): keep the caret inside the normalized document

CodeMirror collapses a CRLF pair into one line break, so the document is
shorter than the string it was given. The composer derived the caret from
the JS string length, which put it past the end of the document and made
dispatch throw `RangeError: Selection points outside of document`.

Because the exception fires before the transaction applies, the document
never updates, the un-normalized text stays in React state, and the draft
persists as-is: every later visit to the session restores it and crashes
again, with no way out from the UI.

Derive the caret from the change set instead, in the controlled writeback
and in the imperative insert/replace handles.

fixes #3013

# Conflicts:
#	CHANGELOG.md
#	packages/vscode/CHANGELOG.md
This commit is contained in:
Iuliia Ivashko
2026-08-28 19:14:02 +03:00
parent 7b5b431d22
commit eca9353382
7 changed files with 117 additions and 17 deletions
+1
View File
@@ -4,6 +4,7 @@
- GitHub Copilot usage now shows a single AI Credits window, matching Copilot's token-based quota, in place of the old Chat Requests and Completions windows (thanks to @jakoss).
- The context usage readout now reports the session cost including everything its subagents spent, matching the work status panel instead of showing a lower figure.
- Updating OpenCode no longer fails with a bare "Bad Request": the extension names the release to install, which recent OpenCode versions require, and shows OpenCode's own reason when an update is refused.
- A saved draft or recalled message containing Windows line endings no longer replaces the chat with a "Selection points outside of document" error, and no longer brings the error back every time you reopen that session.
## [1.21.0] - 2026-08-26