Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

Merge upstream main into docking-trial

aiongg02cb2876d295
diff --cc crates/pdf/src/export.rs
index 00248bbab,1dfb7f44c..0099e9b36
--- a/crates/pdf/src/export.rs
+++ b/crates/pdf/src/export.rs
@@@ -457,6 -450,22 +450,23 @@@ fn now_unix() -> Option<i64>
None
}
+ /// The document information from File Info (title, author, description, keywords). `title` and
+ /// `author` from the export options replace File Info's.
+ fn file_info_metadata(doc: &Document, title: Option<&str>, author: Option<&str>) -> Metadata {
+ let info = &doc.file_info;
+ let description = info.description.trim();
+ Metadata {
+ creator: "DesignCraft".into(),
+ producer: "DesignCraft".into(),
+ title: Some(title.unwrap_or_else(|| doc.metadata_title()).to_string()),
+ authors: author.or_else(|| doc.metadata_author()).map(str::to_string).into_iter().collect(),
+ description: (!description.is_empty()).then(|| description.to_string()),
+ keywords: info.keywords.clone(),
+ created: None,
++ modified: None,
+ }
+ }
+
fn date_time(t: i64) -> krilla::metadata::DateTime {
let c = civil(t);
krilla::metadata::DateTime::new(c.0.clamp(0, 9999) as u16)
diff --cc crates/ui-egui/src/panels/notes.rs
index da250bff5,bcee4776f..ee6cc17a5
--- a/crates/ui-egui/src/panels/notes.rs
+++ b/crates/ui-egui/src/panels/notes.rs
@@@ -46,7 -46,10 +46,10 @@@ pub fn show(app: &mut DesignApp, ui: &m
if !author.is_empty() {
ui.label(egui::RichText::new(author).size(10.5).color(t.text_dim));
}
- ui.label(n["text"].as_str().unwrap_or(""));
+ let mut text = n["text"].as_str().unwrap_or("");
- let text_id = egui::Id::new(("note_text", story.as_u64(), nid.as_u64()));
++ let text_id = egui::Id::unique(("note_text", story.as_u64(), nid.as_u64()));
+ ui.add(egui::TextEdit::multiline(&mut text).id(text_id).frame(egui::Frame::NONE).desired_rows(1).desired_width(f32::INFINITY));
+ let split_at = split_point(ui.ctx(), text_id, text);
ui.horizontal(|ui| {
if ui.small_button(crate::rtl::widget(ui, crate::i18n::tr(&app.ui.language, "Go To"))).clicked() {
let _ = app.run("text.select", json!({"story": story, "anchor": at, "focus": at + 3}));
@@@ -61,3 -71,60 +71,60 @@@
});
}
}
+
+ /// The byte offset of the insertion point in a note's text field, when it lies strictly inside
+ /// the text and selects nothing.
+ fn split_point(ctx: &egui::Context, id: egui::Id, text: &str) -> Option<usize> {
+ let r = egui::TextEdit::load_state(ctx, id)?.cursor.char_range()?;
+ let k: usize = r.primary.index.into();
+ if r.primary.index != r.secondary.index || k == 0 {
+ return None;
+ }
+ text.char_indices().nth(k).map(|(i, _)| i)
+ }
+
+ #[cfg(test)]
+ mod tests {
+ use egui_kittest::Harness;
+ use egui_kittest::kittest::{NodeT, Queryable};
+
+ use super::*;
+
+ #[test]
+ fn split_note_splits_the_note_at_the_insertion_point_in_its_text() {
+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
+ app.run("file.new", json!({})).unwrap();
+ let r = app.run("frame.create", json!({"rect": [72, 72, 400, 300], "content": "text", "text": "Draft copy."})).unwrap();
+ app.run("text.select", json!({"story": r["story"], "anchor": 5, "focus": 5})).unwrap();
+ app.run("note.new", json!({"text": "check this", "author": "Ed"})).unwrap();
+ let mut h = Harness::builder().with_size(egui::vec2(320.0, 400.0)).build_ui_state(
+ |ui, app: &mut DesignApp| {
- let id = egui::Id::new("test_fonts");
++ let id = egui::Id::unique("test_fonts");
+ if ui.data(|d| d.get_temp::<bool>(id)).is_none() {
+ crate::theme::install_fonts(ui.ctx(), "");
+ ui.data_mut(|d| d.insert_temp(id, true));
+ return;
+ }
+ show(app, ui);
+ },
+ app,
+ );
+ h.run_steps(3);
+ assert!(h.get_by_label("Split Note").accesskit_node().is_disabled(), "no insertion point in the note yet");
+ let field = h.get_by(|n| n.role() == egui::accesskit::Role::MultilineTextInput && n.value().as_deref() == Some("check this")).rect();
+ h.hover_at(field.center());
+ h.drag_at(field.center());
+ h.drop_at(field.center());
+ h.run_steps(2);
+ h.key_press(egui::Key::Home);
+ for _ in 0..6 {
+ h.key_press(egui::Key::ArrowRight);
+ }
+ h.run_steps(2);
+ h.get_by_label("Split Note").click();
+ h.run_steps(3);
+ let list = h.state_mut().session.execute("note.list", &json!({})).unwrap();
+ let texts: Vec<_> = list.as_array().unwrap().iter().map(|n| (n["text"].clone(), n["author"].clone())).collect();
+ assert_eq!(texts, [(json!("check "), json!("Ed")), (json!("this"), json!("Ed"))]);
+ }
+ }