mirror of
https://github.com/penpot/penpot.git
synced 2026-07-31 02:16:13 +00:00
🐛 Fix undo crash after deleting a word (#10862)
This commit is contained in:
parent
056cd3d379
commit
3e7fb07931
@ -1311,7 +1311,14 @@
|
|||||||
{:new-shape? new-shape?
|
{:new-shape? new-shape?
|
||||||
:content-has-text? content-has-text?
|
:content-has-text? content-has-text?
|
||||||
:content content
|
: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?
|
:update-name? update-name?
|
||||||
:name name})))
|
:name name})))
|
||||||
(rx/empty))
|
(rx/empty))
|
||||||
|
|||||||
@ -436,7 +436,7 @@ impl TextEditorState {
|
|||||||
pub fn select_all(&mut self, text_content: &TextContent) -> bool {
|
pub fn select_all(&mut self, text_content: &TextContent) -> bool {
|
||||||
self.is_pointer_selection_active = false;
|
self.is_pointer_selection_active = false;
|
||||||
self.set_caret_from_position(&TextPositionWithAffinity::empty());
|
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 {
|
let Some(last_paragraph) = text_content.paragraphs().last() else {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -195,6 +195,10 @@ pub fn move_cursor_up(
|
|||||||
_text_content: &TextContent,
|
_text_content: &TextContent,
|
||||||
) -> TextPositionWithAffinity {
|
) -> TextPositionWithAffinity {
|
||||||
// TODO: Implement proper line-based navigation using line metrics
|
// TODO: Implement proper line-based navigation using line metrics
|
||||||
|
if paragraphs.is_empty() || cursor.paragraph >= paragraphs.len() {
|
||||||
|
return *cursor;
|
||||||
|
}
|
||||||
|
|
||||||
if cursor.paragraph > 0 {
|
if cursor.paragraph > 0 {
|
||||||
let prev_para = cursor.paragraph - 1;
|
let prev_para = cursor.paragraph - 1;
|
||||||
let char_count = paragraph_char_count(¶graphs[prev_para]);
|
let char_count = paragraph_char_count(¶graphs[prev_para]);
|
||||||
@ -212,6 +216,10 @@ pub fn move_cursor_down(
|
|||||||
_text_content: &TextContent,
|
_text_content: &TextContent,
|
||||||
) -> TextPositionWithAffinity {
|
) -> TextPositionWithAffinity {
|
||||||
// TODO: Implement proper line-based navigation using line metrics
|
// 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 {
|
if cursor.paragraph < paragraphs.len() - 1 {
|
||||||
let next_para = cursor.paragraph + 1;
|
let next_para = cursor.paragraph + 1;
|
||||||
let char_count = paragraph_char_count(¶graphs[next_para]);
|
let char_count = paragraph_char_count(¶graphs[next_para]);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user