🐛 Fix undo crash after deleting a word (#10862)

This commit is contained in:
Belén Albeza 2026-07-29 15:53:41 +02:00 committed by GitHub
parent 056cd3d379
commit 3e7fb07931
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 2 deletions

View File

@ -1311,7 +1311,14 @@
{:new-shape? new-shape?
:content-has-text? content-has-text?
:content content
:original-content original-content
;; Undo baseline for the finalize commit: restore the
;; content as it was right before this commit. For existing
;; shapes that's `prev-content`; using the (unset, nil)
;; `original-content` here wiped `:content` to nil on undo,
;; which emptied the shape and crashed the WASM editor's
;; select-all on 0 paragraphs. New shapes keep the previous
;; behavior (their create is bundled in the undo group).
:original-content (if new-shape? original-content prev-content)
:update-name? update-name?
:name name})))
(rx/empty))

View File

@ -436,7 +436,7 @@ impl TextEditorState {
pub fn select_all(&mut self, text_content: &TextContent) -> bool {
self.is_pointer_selection_active = false;
self.set_caret_from_position(&TextPositionWithAffinity::empty());
let num_paragraphs = text_content.paragraphs().len() - 1;
let num_paragraphs = text_content.paragraphs().len().saturating_sub(1);
let Some(last_paragraph) = text_content.paragraphs().last() else {
return false;
};

View File

@ -195,6 +195,10 @@ pub fn move_cursor_up(
_text_content: &TextContent,
) -> TextPositionWithAffinity {
// TODO: Implement proper line-based navigation using line metrics
if paragraphs.is_empty() || cursor.paragraph >= paragraphs.len() {
return *cursor;
}
if cursor.paragraph > 0 {
let prev_para = cursor.paragraph - 1;
let char_count = paragraph_char_count(&paragraphs[prev_para]);
@ -212,6 +216,10 @@ pub fn move_cursor_down(
_text_content: &TextContent,
) -> TextPositionWithAffinity {
// TODO: Implement proper line-based navigation using line metrics
if paragraphs.is_empty() || cursor.paragraph >= paragraphs.len() {
return *cursor;
}
if cursor.paragraph < paragraphs.len() - 1 {
let next_para = cursor.paragraph + 1;
let char_count = paragraph_char_count(&paragraphs[next_para]);