Merge branch 'port/deckcraft/red/app-r6-1' into port/deckcraft/area/app

This commit is contained in:
Dylan M. Taylor committed 2026-11-27 23:01:31 +00:00
commit 0fff2426be
4 files changed
+94 -15

No files matched your search

+20 -12
View File
@@ -74,18 +74,11 @@ impl Session {
let r = match k {
"enter" | "return" => Some(self.execute("text.insert", &json!({"text": if mods.shift { "\u{b}" } else { "\n" }}))),
"escape" | "esc" => Some(self.execute("text.exit", &json!({}))),
"tab" => {
// Tab at the start of a paragraph changes the list level; elsewhere it types a tab.
let at_start = self.active().and_then(|d| d.selection.text.as_ref()).is_some_and(|t| t.ordered().0.1 == 0 || t.is_range());
let in_cell = self.active().and_then(|d| d.selection.text.as_ref()).is_some_and(|t| t.cell.is_some());
if in_cell {
Some(self.next_cell(mods.shift))
} else if at_start {
Some(self.execute(if mods.shift { "format.outdent" } else { "format.indent" }, &json!({})))
} else {
Some(self.execute("text.insert", &json!({"text": "\t"})))
}
}
"tab" => match self.text_tab(mods.shift) {
Ok(true) => Some(Ok(Value::Null)),
Ok(false) => Some(self.execute("text.insert", &json!({"text": "\t"}))),
Err(error) => Some(Err(error)),
},
_ => None,
};
if let Some(r) = r {
@@ -314,6 +307,21 @@ impl Session {
})
}
/// Tab (`back`: Shift+Tab) in edited text where it is not a tab character: in a table cell it goes to the next or
/// previous cell, at the start of a paragraph or over a range it changes the list level. `false` elsewhere, where
/// Tab types a tab.
pub fn text_tab(&mut self, back: bool) -> Result<bool> {
let Some(t) = self.active().and_then(|d| d.selection.text.clone()) else { return Ok(false) };
if t.cell.is_some() {
self.next_cell(back)?;
} else if t.ordered().0.1 == 0 || t.is_range() {
self.execute(if back { "format.outdent" } else { "format.indent" }, &json!({}))?;
} else {
return Ok(false);
}
Ok(true)
}
fn next_cell(&mut self, back: bool) -> Result<Value> {
let st = self.doc()?;
let Some(t) = st.selection.text.clone() else { return Ok(Value::Null) };
+7
View File
@@ -126,6 +126,10 @@ pub(crate) static DEFAULT_CHORDS: &[DefaultChord] = &[
DefaultChord { keys: &["Shift+F7"], id: "review.thesaurusPane", params: "", label: "Thesaurus" },
];
/// Chords that mean something else while slide text is edited, in the canvas editor's scope: Ctrl+] and Ctrl+[ grow
/// and shrink the font there, as Ctrl+Shift+> and < do, where they arrange the shape elsewhere.
const TEXT_EDITING_CHORDS: &[(&str, &str)] = &[("format.grow", "textEditor: Cmd+]"), ("format.shrink", "textEditor: Cmd+[")];
// The framework owns these ids; the engine keeps its command vocabulary.
const EDIT_IDS: &[(&str, &str)] = &[
("edit.cut", "edit.cut"),
@@ -189,6 +193,9 @@ pub(crate) fn build(session: &Session, generation: u64) -> Result<AppCatalog, St
def.defaults.push(binding);
}
}
for (_, key) in TEXT_EDITING_CHORDS.iter().filter(|(id, _)| *id == row.id) {
def.defaults.push(Binding::parse(key).map_err(|e| format!("{} binding: {e}", row.id))?);
}
if EDIT_IDS.iter().any(|(framework, _)| *framework == id) {
replacements.push((id.to_string(), def.defaults.clone()));
if id != row.id {
+62 -2
View File
@@ -2,7 +2,7 @@ use std::ops::Range;
use craft::behavior::{MotionMode, kurbo::Point};
use craft::text::ui::editor::{
CaretAffinity, CaretLine, ClickRuns, EditKind, EditorComposition, EditorEnd, HostLine, HostRun, TextEditor, TextEditorHost, TextEditorOutput,
CaretAffinity, CaretLine, CaretStop, ClickRuns, EditKind, EditorComposition, EditorEnd, HostLine, HostRun, TextEditor, TextEditorHost, TextEditorOutput,
TextReplacement, TextSelection,
};
use craft::ui::canvas::CanvasSpace;
@@ -13,7 +13,7 @@ use craft::ui::runtime::{
};
use deckcraft_engine::{Session, TextReplaceKind, TextSel, cmd::text};
use deckcraft_geom::Affine;
use deckcraft_model::text::TextBody;
use deckcraft_model::{edit, text::TextBody};
use deckcraft_text::{Affinity, Pos, TextLayout};
use egui::{Rect, Ui};
@@ -110,6 +110,13 @@ impl<'a> EngineTextHost<'a> {
}
}
/// Reads back the text and the selection a command left in the session.
fn adopt_selection(&mut self) -> Option<TextSelection> {
self.target = self.session.active()?.selection.text.clone()?;
self.refresh();
Some(self.offsets.selection(&self.target))
}
fn bounds(&self, space: &CanvasSpace) -> Option<Rect> {
let (layout, transform) = self.frame.as_ref()?;
// The inner box also gives empty paragraphs a hit surface, without inventing padding around glyphs.
@@ -285,6 +292,59 @@ impl TextEditorHost for EngineTextHost<'_> {
};
props.vert.unwrap_or(TextDir::Horizontal) != TextDir::Horizontal
}
/// Tab in a cell goes to the next cell, at a paragraph start or over a range it changes the list level; Shift+Tab
/// elsewhere types a tab as Tab does.
fn tab(&mut self, selection: TextSelection, back: bool) -> Option<TextSelection> {
self.select(selection);
match self.session.text_tab(back) {
Ok(true) => self.adopt_selection(),
Ok(false) if back => {
let replaced = self.replace(selection.range(), "\t", EditKind::Typed)?;
Some(replaced.selection)
}
Ok(false) => None,
Err(error) => {
self.error = Some(error.to_string());
Some(selection)
}
}
}
fn caret_stop(&mut self, offset: usize, stop: CaretStop, forward: bool) -> Option<usize> {
let body = text::body_of(self.session.active()?, &self.target)?;
let pos = self.offsets.pos(offset);
let pos = (pos.para, pos.ch);
let to = match (stop, forward) {
(CaretStop::Word, _) => edit::word_move(body, pos, forward),
(CaretStop::Paragraph, false) => edit::para_up(body, pos),
(CaretStop::Paragraph, true) => edit::para_down(body, pos),
_ => return None,
};
Some(self.offsets.offset(to))
}
/// PowerPoint's word delete: from the selection's start, leaving the rest of it, with its smart spacing.
fn delete_word(&mut self, selection: TextSelection, forward: bool) -> Option<TextSelection> {
self.select(selection);
let dir = if forward { "wordForward" } else { "wordBackward" };
if let Err(error) = self.session.execute("text.delete", &serde_json::json!({"dir": dir})) {
self.error = Some(error.to_string());
return Some(selection);
}
self.adopt_selection()
}
fn copy_html(&mut self, selection: TextSelection) -> Option<String> {
self.select(selection);
match self.session.execute("edit.copy", &serde_json::json!({})) {
Ok(reply) => reply.get("html").and_then(serde_json::Value::as_str).filter(|html| !html.is_empty()).map(str::to_owned),
Err(error) => {
self.error = Some(error.to_string());
None
}
}
}
}
fn layout_affinity(affinity: CaretAffinity) -> Affinity {
+5 -1
View File
@@ -929,7 +929,11 @@ fn editing_notes_in_the_pane_keeps_their_formatting() {
session.execute("slide.notes", &json!({"index": 0, "body": notes})).unwrap();
let mut harness = crate::test_harness::harness(session, Services::default());
harness.run_steps(2);
harness.get_by_role_and_label(egui::accesskit::Role::MultilineTextInput, "Notes").click();
// Five paragraphs run past the pane's visible height, so the click goes on the first line, not the node's centre.
let first_line = harness.get_by_role_and_label(egui::accesskit::Role::MultilineTextInput, "Notes").rect().left_top() + egui::vec2(40.0, 8.0);
harness.hover_at(first_line);
harness.drag_at(first_line);
harness.drop_at(first_line);
harness.run_steps(1);
harness.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::Home);
harness.key_press(egui::Key::End);