Merge pull request #9339 from dotCooCoo/fix/canvas-marks-reset-without-document

Type: closing the last document releases the hidden-character and spelling marks
This commit is contained in:
BFlat
2026-11-26 21:58:04 +07:00
committed by GitHub
3 changed files with 38 additions and 3 deletions
+4
View File
@@ -109,6 +109,10 @@ pub(crate) fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
if app.ui.home.is_some_and(|k| k != crate::menus::home_key(app)) {
app.ui.home = None;
}
// The Home screen and the empty window show no marks: a closed document's text nodes are not kept.
if app.session.active().is_none() {
marks::release_text_marks(app);
}
let full = ui.available_rect_before_wrap();
if crate::menus::home_showing(app) {
// No type editor shows to lose the keys: the marked text stays as typed.
+8 -3
View File
@@ -160,6 +160,13 @@ pub(crate) struct Marks {
artboard_marks: Vec<BezPath>,
}
/// Drops the hidden-character and spelling memos and the text nodes they hold.
pub(crate) fn release_text_marks(app: &mut VectorcraftApp) {
app.canvas.hidden_chars.marks.clear();
app.canvas.spelling = SpellingMarks::default();
app.canvas.text_nodes = TextNodes::default();
}
/// The marks of one canvas pass over `view`. The memos of [`crate::CanvasCache`] are kept while their
/// gate is on and dropped, with the text nodes they hold, when it is off.
pub(crate) fn marks_of(app: &mut VectorcraftApp, view: &CanvasView) -> Marks {
@@ -183,9 +190,7 @@ pub(crate) fn marks_of(app: &mut VectorcraftApp, view: &CanvasView) -> Marks {
let fades = artboards::fades_outside_artboards(app);
let shows_artboards = artboards::shows_artboards(app);
let Some(st) = app.session.active() else {
app.canvas.hidden_chars.marks.clear();
app.canvas.spelling = SpellingMarks::default();
app.canvas.text_nodes = TextNodes::default();
release_text_marks(app);
return m;
};
let key = (st.uid, st.revision);
+26
View File
@@ -122,6 +122,32 @@ fn hidden_characters_off_and_a_closed_document_release_the_text_nodes() {
assert!(app.canvas.text_nodes.list.is_none(), "no list of the closed document's text objects is kept");
}
/// Closing the last document drops the memos' text nodes on the canvas's next frame, whether it
/// shows the Home screen or, with Show The Home Screen When No Documents Are Open off, an empty window.
#[test]
fn a_canvas_frame_without_a_document_releases_the_text_nodes() {
let ctx = crate::testing::ui_context();
let frame = |app: &mut VectorcraftApp| {
let raw = egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(Pos2::ZERO, Vec2::new(800.0, 600.0))), ..Default::default() };
crate::testing::part_frame(app, &ctx, raw, crate::canvas::show);
};
for home in [true, false] {
let mut app = app();
app.session.execute("prefs.set", &json!({"key": "showHomeScreen", "value": home})).unwrap();
text(&mut app, 20, 60, "one\ttwo qzxv\nthree");
app.ui.view.hidden_chars = true;
app.ui.view.auto_spell_check = true;
frame(&mut app);
assert!(app.canvas.text_nodes.list.is_some() && !app.canvas.hidden_chars.marks.is_empty(), "home {home}: the canvas keeps the memos");
app.session.execute("file.close", &json!({})).unwrap();
assert_eq!(crate::menus::home_showing(&app), home);
frame(&mut app);
assert!(app.canvas.text_nodes.list.is_none(), "home {home}: no list of the closed document's text objects is kept");
assert!(app.canvas.hidden_chars.marks.is_empty(), "home {home}: no hidden-character marks of the closed document are kept");
assert!(app.canvas.spelling.lines.is_empty(), "home {home}: no spelling marks of the closed document are kept");
}
}
/// `paths` small rectangles and three point type objects with hidden characters and words no
/// dictionary knows: the first on the first layer, the second in a group on that layer and the
/// third on a second layer. Show Hidden Characters and Auto Spell Check are on. Returns the type