feat(mtext): editable preview with caret, blink, and new-line support
Type directly into the rendered MText preview: click to position the caret, insert/delete, Enter for a new line, Space for a literal space, and arrow keys to move. The caret blinks when idle. Keep the trailing empty paragraph in the editor so the caret appears on a fresh line immediately after Enter, before any typing. parse_mtext_paragraphs split into a _ex variant; layout_mtext skips the blank-edge trim when emitting glyph boxes. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
9fa33ec7a0
commit
ac9022676f
8 changed files with 162 additions and 26 deletions
|
|
@ -1211,6 +1211,15 @@ impl OpenCADStudio {
|
|||
Task::none()
|
||||
}
|
||||
|
||||
Message::CommandSpace => {
|
||||
// Space is a literal space inside the MText preview; otherwise
|
||||
// it finalises the active command like Enter.
|
||||
if self.mtext_editor.as_ref().is_some_and(|e| e.show_preview) {
|
||||
self.mtext_type(" ");
|
||||
return Task::none();
|
||||
}
|
||||
return self.update(Message::CommandFinalize);
|
||||
}
|
||||
Message::CommandFinalize => {
|
||||
// In the MText preview, Enter inserts a line break.
|
||||
if self.mtext_editor.as_ref().is_some_and(|e| e.show_preview) {
|
||||
|
|
@ -3580,6 +3589,7 @@ impl OpenCADStudio {
|
|||
ed.sel_anchor = off;
|
||||
ed.sel = Some((off, off));
|
||||
ed.caret = off;
|
||||
ed.caret_blink_on = true;
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
|
|
@ -3588,6 +3598,7 @@ impl OpenCADStudio {
|
|||
let a = ed.sel_anchor;
|
||||
ed.sel = Some((a.min(off), a.max(off)));
|
||||
ed.caret = off;
|
||||
ed.caret_blink_on = true;
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
|
|
@ -3595,6 +3606,12 @@ impl OpenCADStudio {
|
|||
self.mtext_caret_move(d);
|
||||
Task::none()
|
||||
}
|
||||
Message::MTextCaretBlink => {
|
||||
if let Some(ed) = self.mtext_editor.as_mut() {
|
||||
ed.caret_blink_on = !ed.caret_blink_on;
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
Message::MTextOk => {
|
||||
self.mtext_commit();
|
||||
Task::none()
|
||||
|
|
|
|||
Loading…
Reference in a new issue