Merge pull request #8648 from dotCooCoo/fix/issue-8582

Fix #8582: inactive document tabs show the name alone, so more tabs fit
This commit is contained in:
BFlat
2026-11-19 15:08:53 +07:00
committed by GitHub
8 changed files with 106 additions and 30 deletions
+5 -1
View File
@@ -691,12 +691,16 @@ fn art_carried_through_a_tab_drops_into_a_third_documents_pane() {
app.run("window.arrange.tile", json!({})).unwrap();
let source = app.session.documents()[0].doc.clone();
let third = app.session.documents()[2].doc.clone();
// A tab's title starts with its document's name (an inactive tab shows the name alone).
let names: Vec<String> = app.session.documents().iter().map(|d| d.title()).collect();
let titles = |out: egui::FullOutput| -> Vec<egui::Rect> {
let mut t: Vec<_> = out
.shapes
.iter()
.filter_map(|s| match &s.shape {
Shape::Text(t) if t.galley.text().contains(" @ ") => Some(egui::Rect::from_min_size(t.pos, t.galley.size())),
Shape::Text(t) if names.iter().any(|n| t.galley.text().starts_with(n.as_str())) => {
Some(egui::Rect::from_min_size(t.pos, t.galley.size()))
}
_ => None,
})
.collect();
+30 -17
View File
@@ -16,8 +16,14 @@ fn view_tab_title(d: &vectorcraft_engine::DocState, number: Option<u32>, zoom: f
let color = if d.doc.color_mode == vectorcraft_doc::ColorMode::Cmyk { "CMYK" } else { "RGB" };
format!("{color}/{}", if outline { tl!("Outline") } else { tl!("Preview") })
};
format!("{} @ {} ({mode})", view_tab_name(d, number), zoom_label(zoom, display_print_size).replace('%', " %"))
}
/// The start of [`view_tab_title`], which an inactive document tab shows alone (#8582): "Name*",
/// or for a view of a document with more than one view, "Name:2*".
fn view_tab_name(d: &vectorcraft_engine::DocState, number: Option<u32>) -> String {
let number = number.map(|n| format!(":{n}")).unwrap_or_default();
format!("{}{number}{} @ {} ({mode})", d.title(), if d.is_dirty() { "*" } else { "" }, zoom_label(zoom, display_print_size).replace('%', " %"))
format!("{}{number}{}", d.title(), if d.is_dirty() { "*" } else { "" })
}
/// The title of window `w`, a view of document `d`: with the view's zoom and Outline or Preview,
@@ -177,13 +183,14 @@ fn tab_close_box(ui: &Ui, t: &Tokens, xr: egui::Rect, w: f32, id: egui::Id) -> O
Some(xresp)
}
/// Document tab strip: "Name* @ 66.67% (RGB/Preview)". User Interface › Large Tabs makes the tabs
/// taller, with larger titles. Tabs that don't fit are reached from a » button at the strip's
/// right end, which lists every open document, and the active tab is always in view (#746). The
/// first tab that doesn't fit whole fills the room left before the » button with its title
/// shortened, when that room holds some of the title (#8584). When the active tab is among the last
/// ones and the tabs from it to the end leave room, the tab before them fills that room instead. An
/// active tab wider than the whole strip is shortened to it.
/// Document tab strip: the active tab's title is "Name* @ 66.67 % (RGB/Preview)", and each other
/// tab shows "Name*" alone, with the whole title in its tooltip (#8582). User Interface › Large
/// Tabs makes the tabs taller, with larger titles. Tabs that don't fit are reached from a » button
/// at the strip's right end, which lists every open document, and the active tab is always in view
/// (#746). The first tab that doesn't fit whole fills the room left before the » button with its
/// title shortened, when that room holds some of the title (#8584). When the active tab is among
/// the last ones and the tabs from it to the end leave room, the tab before them fills that room
/// instead. An active tab wider than the whole strip is shortened to it.
/// Each view Window › New Window opened has a tab of its own. Windows floating have no tab
/// ([`crate::doc_windows`]); while the current window is a floating one, the tab of the window the
/// strip shows is the highlighted one. A tab dragged more than [`crate::doc_windows::TEAR_OFF`]
@@ -205,18 +212,24 @@ pub fn doc_tabs(app: &mut VectorcraftApp, ui: &mut Ui) {
ui.painter().line_segment([strip.left_bottom(), strip.right_bottom()], Stroke::new(1.0, t.border));
// On the Home screen no tab is the current one.
let shown = crate::doc_windows::tab_window(app).filter(|_| app.ui.home.is_none());
// The windows under the tabs, with their titles; `active` is the position of the highlighted one.
let tabs: Vec<(crate::doc_windows::Win, String, std::sync::Arc<egui::Galley>)> = crate::doc_windows::docked_windows(app)
// The windows under the tabs, with the text each tab shows, its whole title and the text laid
// out; `active` is the position of the highlighted one. An inactive tab shows the name alone,
// without the zoom and the mode in parentheses (color mode and view, or the opacity mask being
// edited) (#8582), and its tooltip shows the whole title.
type Tab = (crate::doc_windows::Win, String, String, std::sync::Arc<egui::Galley>);
let tabs: Vec<Tab> = crate::doc_windows::docked_windows(app)
.into_iter()
.filter_map(|w| Some((w, app.session.documents().get(w.0)?)))
.map(|(w, d)| {
let title = window_tab_title(app, w, d);
let color = if Some(w) == shown { t.text_strong } else { t.text_dim };
(w, title.clone(), ui.painter().layout_no_wrap(title, theme::semibold(title_size), color))
let (text, color) =
if Some(w) == shown { (title.clone(), t.text_strong) } else { (view_tab_name(d, crate::doc_windows::label(app, w)), t.text_dim) };
let galley = ui.painter().layout_no_wrap(text.clone(), theme::semibold(title_size), color);
(w, text, title, galley)
})
.collect();
let active = tabs.iter().position(|(w, _, _)| Some(*w) == shown);
let widths: Vec<f32> = tabs.iter().map(|(_, _, g)| g.size().x + TAB_PADDING).collect();
let active = tabs.iter().position(|(w, ..)| Some(*w) == shown);
let widths: Vec<f32> = tabs.iter().map(|(.., g)| g.size().x + TAB_PADDING).collect();
let overflow = widths.iter().sum::<f32>() > strip.width();
let room = strip.width() - if overflow { MORE } else { 0.0 };
let first = if overflow { first_tab_shown(&widths, active, room) } else { 0 };
@@ -230,7 +243,7 @@ pub fn doc_tabs(app: &mut VectorcraftApp, ui: &mut Ui) {
// the drag just ended), for moving it along the strip.
let mut slots: Vec<(usize, egui::Rect)> = vec![];
let mut dragged = None;
for (k, ((win, title, galley), w)) in tabs.iter().zip(&widths).enumerate().skip(first) {
for (k, ((win, text, title, galley), w)) in tabs.iter().zip(&widths).enumerate().skip(first) {
// A tab that doesn't fit whole takes the rest of the strip with its title shortened, as
// long as some of the title fits (#8584); its tooltip shows the whole title. The active
// tab always shows, shortened to the strip when it is wider than the whole strip. The
@@ -245,7 +258,7 @@ pub fn doc_tabs(app: &mut VectorcraftApp, ui: &mut Ui) {
break;
}
let color = if Some(*win) == shown { t.text_strong } else { t.text_dim };
let (galley, fits) = shortened_title(ui.ctx(), title, theme::semibold(title_size), color, left - TAB_PADDING);
let (galley, fits) = shortened_title(ui.ctx(), text, theme::semibold(title_size), color, left - TAB_PADDING);
(galley, left.max(0.0), true, fits)
} else {
(galley.clone(), *w, false, true)
@@ -254,7 +267,7 @@ pub fn doc_tabs(app: &mut VectorcraftApp, ui: &mut Ui) {
let i = win.0;
let r = egui::Rect::from_min_size(egui::pos2(x, strip.top()), vec2(w, strip.height() - 1.0));
let resp = ui.interact(r, ui.scope_id().with(("tab", i, win.1)), Sense::click_and_drag());
let resp = if shortened { super::status_bar::full_text_tooltip(resp, title.as_str()) } else { resp };
let resp = if shortened || text != title { super::status_bar::full_text_tooltip(resp, title.as_str()) } else { resp };
slots.push((i, r));
if resp.dragged() || resp.drag_stopped() {
dragged = Some((i, resp.drag_stopped()));
+3 -1
View File
@@ -2510,11 +2510,13 @@ fn artboard_document_tabs_frame(app: &mut crate::VectorcraftApp, ctx: &egui::Con
let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1200.0, 700.0));
let mut out = ctx.run_ui(egui::RawInput { screen_rect: Some(screen), events, ..Default::default() }, |ui| super::doc_tabs(app, ui));
out.textures_delta.clear();
// A tab's title starts with its document's name (an inactive tab shows the name alone).
let names: Vec<String> = app.session.documents().iter().map(|d| d.title()).collect();
let mut titles: Vec<_> = out
.shapes
.iter()
.filter_map(|shape| match &shape.shape {
egui::Shape::Text(t) if t.galley.text().contains(" @ ") => Some(t.visual_bounding_rect()),
egui::Shape::Text(t) if names.iter().any(|n| t.galley.text().starts_with(n.as_str())) => Some(t.visual_bounding_rect()),
_ => None,
})
.collect();
+3 -2
View File
@@ -514,9 +514,10 @@ fn dragging_a_tab_off_the_strip_floats_its_document_at_the_pointer() {
let shapes = frame(&mut app, &ctx, vec![]);
let title = app.session.documents()[0].title();
let tab = tab_at(&shapes, &title);
// A short drag, and a drag along the strip, leave the tabs as they are.
// A short drag, and a drag along the strip short of the next tab's middle, leave the tabs as
// they are.
drag(&mut app, &ctx, tab, tab + vec2(0.0, 35.0 + TEAR_OFF - 10.0 - tab.y));
drag(&mut app, &ctx, tab, tab + vec2(300.0, 0.0));
drag(&mut app, &ctx, tab, tab + vec2(40.0, 0.0));
assert!(app.ui.floating.is_empty(), "the document stays under its tab");
assert_eq!(app.session.active_index(), Some(2), "a drag is not a click");
// Dragged well below the strip, it floats in a window under the pointer and becomes current.
+25 -6
View File
@@ -36,11 +36,15 @@ fn frame(app: &mut VectorcraftApp, ctx: &egui::Context, time: f64, events: Vec<E
},
);
out.textures_delta.clear();
// A tab's title starts with its document's name (an inactive tab shows the name alone).
let names: Vec<String> = app.session.documents().iter().map(|d| d.title()).collect();
let mut titles: Vec<_> = out
.shapes
.iter()
.filter_map(|s| match &s.shape {
egui::Shape::Text(t) if t.galley.text().contains(" @ ") => Some(egui::Rect::from_min_size(t.pos, t.galley.size())),
egui::Shape::Text(t) if names.iter().any(|n| t.galley.text().starts_with(n.as_str())) => {
Some(egui::Rect::from_min_size(t.pos, t.galley.size()))
}
_ => None,
})
.collect();
@@ -275,15 +279,26 @@ fn hovering_back_to_source_resumes_move_instead_of_copying() {
let (mut app, ctx, _, tabs) = drag_fixture();
let id = app.session.active().unwrap().selection.objects[0];
let undo = app.session.active().unwrap().history.undo.len();
frame(&mut app, &ctx, 0.2, vec![Event::PointerMoved(tabs[1].center())]);
let over = tabs[1].center();
frame(&mut app, &ctx, 0.2, vec![Event::PointerMoved(over)]);
frame(&mut app, &ctx, 0.25, vec![]);
frame(&mut app, &ctx, 0.8, vec![]);
frame(&mut app, &ctx, 0.9, vec![Event::PointerMoved(tabs[0].center())]);
frame(&mut app, &ctx, 1.4, vec![]);
assert_eq!(app.session.active_index(), Some(1));
// The current document's tab shows its whole title, so the tabs move as Target becomes current,
// and the pointer stays over Target's tab: a small movement there switches to no other tab.
let tabs = frame(&mut app, &ctx, 0.85, vec![]);
assert!(tabs[1].contains(over), "the pointer stays over Target's tab: {:?} {over:?}", tabs[1]);
frame(&mut app, &ctx, 0.86, vec![Event::PointerMoved(over + egui::vec2(1.0, 0.0))]);
frame(&mut app, &ctx, 0.9, vec![]);
frame(&mut app, &ctx, 1.3, vec![]);
assert_eq!(app.session.active_index(), Some(1), "no other document becomes current");
let tabs = frame(&mut app, &ctx, 1.31, vec![]);
frame(&mut app, &ctx, 1.35, vec![Event::PointerMoved(tabs[0].center())]);
frame(&mut app, &ctx, 1.85, vec![]);
assert_eq!(app.session.active_index(), Some(0));
let drop = canvas::Xf::new(app.canvas_rect.unwrap(), app.view().unwrap()).to_screen(Point::new(175.0, 180.0));
frame(&mut app, &ctx, 1.5, vec![Event::PointerMoved(drop)]);
frame(&mut app, &ctx, 1.6, vec![button(drop, false)]);
frame(&mut app, &ctx, 1.9, vec![Event::PointerMoved(drop)]);
frame(&mut app, &ctx, 2.0, vec![button(drop, false)]);
let st = app.session.active().unwrap();
assert_eq!(st.selection.objects, vec![id]);
assert_eq!(st.history.undo.len(), undo + 1);
@@ -299,6 +314,8 @@ fn a_drop_back_in_the_source_uses_the_release_position_and_alt() {
frame(&mut app, &ctx, 0.2, vec![Event::PointerMoved(tabs[1].center())]);
frame(&mut app, &ctx, 0.25, vec![]);
frame(&mut app, &ctx, 0.8, vec![]);
// The current document's tab shows its whole title, so the tabs move as Target becomes current.
let tabs = frame(&mut app, &ctx, 0.85, vec![]);
frame(&mut app, &ctx, 0.9, vec![Event::PointerMoved(tabs[0].center())]);
frame(&mut app, &ctx, 1.4, vec![]);
assert_eq!(app.session.active_index(), Some(0));
@@ -369,6 +386,8 @@ fn hovering_back_to_a_source_whose_type_is_measured_again_resumes_move() {
frame(&mut app, &ctx, 0.25, vec![]);
frame(&mut app, &ctx, 0.8, vec![]);
assert_eq!(app.session.active_index(), Some(1));
// The current document's tab shows its whole title, so the tabs move as Target becomes current.
let tabs = frame(&mut app, &ctx, 0.85, vec![]);
let left = app.session.documents()[0].doc.clone();
frame(&mut app, &ctx, 0.9, vec![Event::PointerMoved(tabs[0].center())]);
frame(&mut app, &ctx, 1.4, vec![]);
+38 -3
View File
@@ -53,9 +53,9 @@ fn click(at: Pos2, pressed: bool) -> Event {
#[test]
fn the_tab_that_does_not_fit_whole_fills_the_rest_of_the_strip() {
let mut app = VectorcraftApp::new(Session::new(), Default::default());
// Three tabs about 240 pt wide fit whole; the fourth, with a longer name, doesn't.
// The active tab and two inactive ones fit whole; the fourth, with a much longer name, doesn't.
for i in 0..8 {
let name = if i == 3 { format!("Tab test {i} with a much longer name") } else { format!("Tab test {i}") };
let name = if i == 3 { format!("Tab test {i} {}", "with a much longer name ".repeat(4)) } else { format!("Tab test {i}") };
app.run("file.new", json!({"width": 100, "height": 100, "name": name})).unwrap();
}
app.session.set_active(0);
@@ -85,14 +85,49 @@ fn the_tab_that_does_not_fit_whole_fills_the_rest_of_the_strip() {
);
}
/// An inactive tab shows the document's name alone, without the zoom and the color mode and view,
/// so more tabs fit in the strip (#8582): in a 1000 pt window, 7 tabs fit whole where 3 did with
/// whole titles. The active tab keeps its whole title, and an inactive tab's tooltip shows it.
#[test]
fn inactive_tabs_show_the_name_alone_so_more_tabs_fit() {
let mut app = VectorcraftApp::new(Session::new(), Default::default());
for i in 0..12 {
app.run("file.new", json!({"width": 100, "height": 100, "name": format!("Tab test {i}")})).unwrap();
}
// The second document has unsaved changes, which its tab still marks.
app.session.set_active(1);
app.run("shape.rectangle", json!({"x": 0, "y": 0, "width": 10, "height": 10})).unwrap();
app.session.set_active(0);
app.sync_views();
let ctx = egui::Context::default();
crate::theme::install_fonts(&ctx);
let texts = frame(&mut app, &ctx, 0.0, vec![]);
let mut tabs: Vec<(String, egui::Rect)> = texts.into_iter().filter(|(t, _)| t.starts_with("Tab test")).collect();
tabs.sort_by(|a, b| a.1.left().total_cmp(&b.1.left()));
let whole = tabs.iter().filter(|(t, _)| !t.ends_with('…')).count();
assert_eq!(whole, 7, "7 tabs fit whole: {tabs:?}");
assert!(tabs.first().is_some_and(|(t, _)| t == "Tab test 0 @ 100 % (RGB/Preview)"), "the active tab keeps its whole title: {tabs:?}");
assert!(tabs.get(1).is_some_and(|(t, _)| t == "Tab test 1*"), "an inactive tab shows the name and the unsaved mark: {tabs:?}");
assert!(tabs.iter().skip(2).all(|(t, _)| !t.contains('@') && !t.contains("RGB")), "inactive tabs show no zoom or mode: {tabs:?}");
// The whole title shows in an inactive tab's tooltip.
let r = tabs.get(2).map(|(_, r)| *r).unwrap_or_else(|| panic!("{tabs:?}"));
let mut texts = frame(&mut app, &ctx, 1.0, vec![Event::PointerMoved(r.center())]);
for i in 1..20 {
texts = frame(&mut app, &ctx, 1.0 + f64::from(i) * 0.1, vec![]);
}
assert!(texts.iter().any(|(t, _)| t == "Tab test 2 @ 100 % (RGB/Preview)"), "the tooltip shows the whole title: {texts:?}");
}
/// With the last document active, the tabs from it to the end leave room before the » button, and
/// the tab before them fills that room with its title shortened instead of the strip ending short
/// of the » button (#8584).
#[test]
fn with_the_last_document_active_the_tab_before_the_shown_ones_fills_the_room() {
let mut app = VectorcraftApp::new(Session::new(), Default::default());
// The last three tabs fit whole; the one before them, with a much longer name, doesn't.
for i in 0..8 {
app.run("file.new", json!({"width": 100, "height": 100, "name": format!("Tab test {i}")})).unwrap();
let name = if i <= 4 { format!("Tab test {i} {}", "with a much longer name ".repeat(4)) } else { format!("Tab test {i}") };
app.run("file.new", json!({"width": 100, "height": 100, "name": name})).unwrap();
}
app.session.set_active(7);
app.sync_views();
+1
View File
@@ -90,6 +90,7 @@ fn a_tab_dragged_along_the_strip_moves_its_document_and_the_current_one_stays()
assert_eq!(during.platform_output.cursor_icon, egui::CursorIcon::Grabbing, "the tab is held while it moves");
assert_eq!(order(&app), ["Bravo", "Charlie", "Delta", "Alpha"]);
assert_eq!(current(&app), "Delta", "a move is not a switch");
assert!(app.ui.floating.is_empty(), "a move along the strip floats no document");
// The tabs are drawn in the new order.
let xs: Vec<f32> = NAMES.iter().map(|n| tab(&mut app, &ctx, 1.0, n).x).collect();
assert!(xs[1] < xs[2] && xs[2] < xs[3] && xs[3] < xs[0], "Bravo, Charlie, Delta, Alpha: {xs:?}");
+1
View File
@@ -424,6 +424,7 @@ next unit in the order a right-click on a ruler lists them, from Feet back to Po
| A document tab dragged along the tab strip moves its document; a line marks where it goes, the current document and every document's view stay as they were, and a drag off the strip still floats it | done | #5663, [public source](https://helpx.adobe.com/illustrator/using/customizing-workspace.html); `document.move`; `tests::tab_reorder`, `chrome::tests` (drop index with floating and view tabs), `engine` `tests::document_move` |
| A middle-click on a document tab or its × closes it as the × does; closing a modified document's last view asks to save first (VectorCraft addition, as in PhotoCraft) | done | #6506; `chrome::tests::a_middle_click_on_a_tab_closes_it_as_the_close_box_does`; not scored |
| When the document tabs don't all fit, the first tab that doesn't fit whole fills the room before the » button with its title shortened and ending in "…", once that room leaves at least 40 pt for the title; with the active tab among the last ones, the tab before the ones shown fills the room left at the start instead; an active tab wider than the strip is shortened to it, and a tab narrower than 25 pt shows no ×; the tooltip of a shortened tab shows the whole title, wrapped to the window (VectorCraft's own rule) | done | #8584; `tests::tab_overflow`; not scored |
| An inactive document tab shows the document's name, the view number and the unsaved-changes mark, without the zoom and the mode in parentheses (the color mode and view, or the opacity mask being edited); the active tab keeps its whole title, and an inactive tab's tooltip shows the whole title (VectorCraft's own rule) | done | #8582; `tests::tab_overflow::inactive_tabs_show_the_name_alone_so_more_tabs_fit`; not scored |
| Panels hidden by Tab or Shift+Tab show for a while when the pointer rests on the left or right edge of the window, over the canvas, and hide again when it moves away; Tab shows them for good | done | Part of #5661; `window.panels.peek` ([Workspace basics](https://web.archive.org/web/2014/https://helpx.adobe.com/illustrator/using/workspace-basics.html), "Hide or show all panels"); VectorCraft's own choices: the 6 pt band and the 0.3 s delays, only the docked panels on that side show (floating panels, Tools and the Control bar stay hidden), and nothing shows in Presentation Mode; `panel_docking::tests::resting_on_the_right_edge_shows_the_hidden_panels_over_the_canvas_until_the_pointer_leaves` and the tests after it |
| Behaviour | Status | Notes |