Status bar: Copy, Cut and Image Trace notes follow status changes, not only the text

Copy and Cut record how many times the status has been set when they
run. Their clipboard formats' notes now stay out when anything set the
status in between, including a message with the same text, such as
File > New clearing an empty status bar.

An Image Trace without notes clears the counted message and hover notes
that an earlier trace left, while nothing has set the status since. Any
other message stays.

File > New, choosing a data set and `ui.set`'s `status` set the status
through `VectorcraftApp::status`, so these changes are counted.
This commit is contained in:
dotCooCoo
2026-11-14 08:18:57 -08:00
parent b12c2c482c
commit 8047847792
6 changed files with 83 additions and 17 deletions
+20 -8
View File
@@ -263,7 +263,7 @@ impl VectorcraftApp {
self.show_trace_notes(v);
}
if id == "file.new" {
self.ui.status.clear();
self.status("");
// New Document's Pixel preview mode (Overprint Preview is the engine's).
if v["previewMode"] == "pixel" {
self.ui.view.pixel_preview = true;
@@ -272,7 +272,7 @@ impl VectorcraftApp {
// Choosing a data set, or stepping to one, clears the status bar. The reply's `warning`
// below then shows when no object is bound to a variable the data set has a value for.
if matches!(id, "dataset.select" | "dataset.next" | "dataset.prev") {
self.ui.status.clear();
self.status("");
}
// A font applied with Character's font menu or Find Font's Change becomes the newest recent font.
// Find Font's Change records the family the text now carries (any name of it is stored as its
@@ -306,7 +306,7 @@ impl VectorcraftApp {
}
// The message the Copy or Cut leaves is the one its clipboard formats' notes may replace.
if copied {
self.clipboard_publishing.ran_with_status(&self.ui.status);
self.clipboard_publishing.ran_with_status(&self.ui);
}
r
}
@@ -322,13 +322,25 @@ impl VectorcraftApp {
}
/// Image Trace's notes in `reply` (a large image traces more slowly, or was scaled down): the
/// first of them and how many there are, with the rest for the message's hover. Without notes
/// the status bar keeps its message.
/// first of them and how many there are, with the rest for the message's hover. Without notes,
/// the message an earlier trace's notes left is cleared while nothing has set the status since,
/// and any other message stays.
fn show_trace_notes(&mut self, reply: &Value) {
let notes = io::notes_of(reply);
if let Some(first) = notes.first() {
let status = crate::trace_runs::traced_with_notes(notes.len(), first);
io::show_with_notes(self, status, notes);
match notes.first() {
Some(first) => {
let status = crate::trace_runs::traced_with_notes(notes.len(), first);
io::show_with_notes(self, status, notes);
self.trace_runs.notes_status = Some((self.ui.status.clone(), self.ui.status_sets));
}
None => {
// Only while nothing has set the status since.
let left = self.trace_runs.notes_status.take();
if left.is_some_and(|(status, sets)| status == self.ui.status && sets == self.ui.status_sets) {
self.status("");
self.ui.status_notes = None;
}
}
}
}
+1 -1
View File
@@ -2079,7 +2079,7 @@ fn set_ui(app: &mut VectorcraftApp, req: &ControlRequest) -> Outcome {
r = app.run("window.panel", json!({"panel": pn}));
}
if let Some(st) = s("status") {
app.ui.status = st.to_string();
app.status(st);
}
for (k, flag) in [
("rulers", "view.rulers"),
+16 -8
View File
@@ -103,9 +103,10 @@ pub(crate) struct Publishing {
/// The latest one's formats could not be written: what the system clipboard held when the
/// write failed, and the text of those formats.
unwritten: Option<(Held, String)>,
/// The status bar's message when the latest one ran. Its formats' notes replace the message
/// only while the status bar still shows it.
status: String,
/// The status bar's message when the latest one ran, with [`crate::state::UiState::status_sets`]
/// then. Its formats' notes replace the message only while the status bar still shows it and
/// nothing has set the status since.
status: (String, u64),
}
impl Publishing {
@@ -120,10 +121,17 @@ impl Publishing {
self.latest.load(Ordering::SeqCst)
}
/// `status` is the status bar's message the latest Copy or Cut left, which its formats' notes
/// `ui`'s status bar message is the one the latest Copy or Cut left, which its formats' notes
/// may replace.
pub(crate) fn ran_with_status(&mut self, status: &str) {
status.clone_into(&mut self.status);
pub(crate) fn ran_with_status(&mut self, ui: &crate::state::UiState) {
ui.status.clone_into(&mut self.status.0);
self.status.1 = ui.status_sets;
}
/// Does `ui`'s status bar still show the message the latest Copy or Cut left, with nothing
/// setting the status since?
fn shows_status(&self, ui: &crate::state::UiState) -> bool {
ui.status == self.status.0 && ui.status_sets == self.status.1
}
}
@@ -225,7 +233,7 @@ impl VectorcraftApp {
let n = latest.fetch_add(1, Ordering::SeqCst).wrapping_add(1);
self.clipboard_publishing.pending = true;
self.clipboard_publishing.unwritten = None;
self.clipboard_publishing.ran_with_status(&self.ui.status);
self.clipboard_publishing.ran_with_status(&self.ui);
// What the clipboard holds at the Copy or Cut: a copy made elsewhere before the write is newer.
let before = self.services.system_clipboard.as_deref_mut().map(Held::now);
let (tx, made) = channel();
@@ -277,7 +285,7 @@ impl VectorcraftApp {
// The PNG's and PDF's notes (an image that couldn't be decoded, type in the
// fallback font), unless another message has replaced the Copy or Cut's since.
Ok(warnings) => {
if app.ui.status == app.clipboard_publishing.status {
if app.clipboard_publishing.shows_status(&app.ui) {
show_copy_notes(app, cut, warnings);
}
}
+21
View File
@@ -449,6 +449,27 @@ fn a_copy_note_does_not_replace_a_newer_message() {
assert_eq!((app.ui.status.as_str(), &app.ui.status_notes), ("Saved /out/a.vectorcraft", &None));
}
/// A message set while a Copy's formats are made on the worker stays even when its text is the
/// Copy's: an empty status bar set again, or File › New clearing it.
#[test]
fn a_copy_note_does_not_replace_a_message_with_the_same_text() {
for then in ["status", "file.new"] {
let (mut app, board, hold) = app_with_busy_worker("");
vectorcraft_testkit::fixtures::place_cut_png(&mut app.session, &cut_short_png(), json!({}));
app.status("");
run(&mut app, "edit.copy", json!({}));
if then == "status" {
app.status("");
} else {
run(&mut app, "file.new", json!({}));
}
drop(hold);
background::wait_all(&mut app);
assert_eq!(written(&board), [TEXT, SVG, PNG], "{then}");
assert_eq!((app.ui.status.as_str(), &app.ui.status_notes), ("", &None), "{then}");
}
}
/// Text copied in a field or with the Type tool after Copy, before the formats are written: they
/// are not written, the system clipboard keeps the text, and Paste takes it.
#[test]
+22
View File
@@ -148,6 +148,28 @@ fn a_trace_shows_how_many_notes_it_has() {
}
}
/// A trace without notes clears the message an earlier trace's notes left, with its hover notes,
/// and leaves any other message, one with the same text set since included.
#[test]
fn a_trace_without_notes_clears_an_earlier_traces_notes() {
let mut app = app();
let earlier = "Traced with 2 notes: a note";
for (then, kept) in [(None, ""), (Some("Ready"), "Ready"), (Some(earlier), earlier)] {
app.status(earlier);
app.trace_runs.notes_status = Some((earlier.to_string(), app.ui.status_sets));
if let Some(then) = then {
app.status(then);
}
app.ui.status_notes = Some((app.ui.status.clone(), vec!["a note".to_string(), "another".to_string()]));
let v = app.run("imageTrace.make", json!({"preset": "Default"})).unwrap();
assert_eq!(v["warnings"], json!([]), "{then:?}");
assert_eq!(app.ui.status, kept, "{then:?}");
assert_eq!(app.ui.status_notes.is_none(), kept.is_empty(), "{then:?}");
assert_eq!(app.trace_runs.notes_status, None, "{then:?}");
app.run("edit.undo", json!({})).unwrap();
}
}
/// Nothing to trace fails at once, before anything runs.
#[test]
fn nothing_to_trace_fails_at_once() {
+3
View File
@@ -75,6 +75,9 @@ pub struct TraceRuns {
next_id: u64,
/// Set by unit tests whose app traces off the UI thread.
pub(crate) off_the_ui_thread: bool,
/// The status bar's message the latest Image Trace with notes left, with
/// [`crate::state::UiState::status_sets`] then.
pub(crate) notes_status: Option<(String, u64)>,
}
/// The status bar's line after an Image Trace with `n` notes, the first of them `first`.