Tabs: a stop moved past another stays selected

A tab stop moved past another stop in the Tabs panel, by a drag on the
ruler or by a value typed in X, lost the selection. The panel sorts the
stops by position after the move but kept the selected index, so the
ruler highlighted another stop and the X, Leader and Align On fields
showed and changed that stop. With stops at 30 and 50 pt and the 50 pt
stop dragged to 10 pt, the panel selected the stop at 30 pt.

After a drag or an X value re-sorts the stops, the panel now selects
the moved stop at its new place, found by its position as a click that
adds a stop does. When text.tabs.set refuses the new position (an X
past 100,000 pt), the stops and the selection stay as they were.

Docs: docs/target-app-parity.md.
This commit is contained in:
dotCooCoo
2026-10-21 15:42:37 +07:00
committed by bflatastic
parent 5660a15b75
commit a810044e5a
2 changed files with 101 additions and 8 deletions
+100 -8
View File
@@ -92,15 +92,28 @@ fn stops_json(stops: &[TabStop]) -> Value {
)
}
fn apply(app: &mut VectorcraftApp, stops: &[TabStop]) {
/// Run `text.tabs.set` with `stops` on the text the panel acts on. Returns false when it fails.
fn apply(app: &mut VectorcraftApp, stops: &[TabStop]) -> bool {
if let Some((id, a, b)) = super::character::text_editing(app) {
super::character::end_typing(app);
app.run("text.tabs.set", json!({"stops": stops_json(stops), "ids": [id.0], "start": a, "end": b})).ok();
app.run("text.tabs.set", json!({"stops": stops_json(stops), "ids": [id.0], "start": a, "end": b})).is_ok()
} else {
app.run("text.tabs.set", json!({"stops": stops_json(stops)})).ok();
app.run("text.tabs.set", json!({"stops": stops_json(stops)})).is_ok()
}
}
/// Sort `stops` by position and set them, then select the first stop within 1e-6 pt of `position`
/// on the ruler, the stop `text.tabs.set` keeps of those it merges. Returns its index, or `None`
/// when the stops are not set and the selection stays as it was.
fn apply_moved(app: &mut VectorcraftApp, ctx: &egui::Context, stops: &mut [TabStop], position: f64) -> Option<usize> {
stops.sort_by(|a, b| a.position.total_cmp(&b.position));
let i = stops.iter().position(|s| (s.position - position).abs() < 1e-6).unwrap_or(0);
apply(app, stops).then(|| {
set_pstate(ctx, "tabs-sel", i);
i
})
}
pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
let t = Tokens::get(ui.ctx());
let Some((node, mut stops, span)) = current(app) else {
@@ -143,8 +156,10 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
&& let Some(s) = stops.get_mut(sel)
{
s.position = v.max(0.0);
stops.sort_by(|a, b| a.position.total_cmp(&b.position));
apply(app, &stops);
let position = s.position;
if let Some(i) = apply_moved(app, ui.ctx(), &mut stops, position) {
sel = i;
}
}
ui.end_row();
ui.label(egui::RichText::new(tl!("Leader:")).color(t.text));
@@ -242,11 +257,12 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
if pos.y > rect.bottom() + 20.0 {
// Dragged off the ruler: delete.
stops.remove(i);
apply(app, &stops);
} else {
stops[i].position = place(pos.x);
stops.sort_by(|a, b| a.position.total_cmp(&b.position));
let position = place(pos.x);
stops[i].position = position;
apply_moved(app, ui.ctx(), &mut stops, position);
}
apply(app, &stops);
}
} else if resp.clicked()
&& let Some(pos) = resp.interact_pointer_pos()
@@ -600,6 +616,82 @@ mod tests {
assert_eq!((position(&app) / 72.0 * 8.0).round(), position(&app) / 72.0 * 8.0, "a binary fraction of an inch");
}
/// One frame of the panel with `events` → the texts painted and where.
fn panel_frame(ctx: &egui::Context, app: &mut VectorcraftApp, events: Vec<egui::Event>) -> Vec<(String, egui::Rect)> {
let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, vec2(400.0, 400.0));
let mut out = ctx.run_ui(egui::RawInput { screen_rect: Some(screen), events, ..Default::default() }, |ui| show(app, ui));
out.textures_delta.clear();
out.shapes
.iter()
.filter_map(|c| match &c.shape {
egui::Shape::Text(t) => Some((t.galley.text().to_string(), t.visual_bounding_rect())),
_ => None,
})
.collect()
}
/// A stop dragged past another stays selected once the stops are sorted, so the X field shows
/// where it was dropped.
#[test]
fn a_stop_dragged_past_another_stays_selected() {
let mut app = VectorcraftApp::new(Session::new(), Default::default());
app.session.execute("file.new", &json!({})).unwrap();
app.session.execute("text.create", &json!({"x": 10, "y": 20, "text": "a b", "area": {"width": 300, "height": 100}})).unwrap();
app.session.execute("text.tabs.set", &json!({"stops": [{"position": 30}, {"position": 50}]})).unwrap();
let ctx = egui::Context::default();
drag_on_ruler(&ctx, &mut app, 50.0, 10.0, false);
let stops = current(&app).unwrap().1;
assert_eq!(stops.len(), 2);
assert!((stops[0].position - 10.0).abs() < 1.0 && stops[1].position == 30.0, "{stops:?}");
assert_eq!(pstate::<usize>(&ctx, "tabs-sel"), 0);
let shown = app.session.general_unit().format(stops[0].position);
let texts = panel_frame(&ctx, &mut app, vec![]);
assert!(texts.iter().any(|(t, _)| *t == shown), "{shown} in {texts:?}");
}
/// An X typed past the next stop keeps the stop selected once the stops are sorted. An X the
/// stops cannot take (past 100,000 pt) leaves the stops and the selection as they were.
#[test]
fn an_x_typed_past_the_next_stop_keeps_the_stop_selected() {
let mut app = VectorcraftApp::new(Session::new(), Default::default());
app.session.execute("file.new", &json!({})).unwrap();
app.session.execute("text.create", &json!({"x": 10, "y": 20, "text": "a b", "area": {"width": 300, "height": 100}})).unwrap();
app.session.execute("text.tabs.set", &json!({"stops": [{"position": 30}, {"position": 50}]})).unwrap();
let ctx = egui::Context::default();
let key = |key, modifiers| egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers };
// Click the X field showing `shown`, type `typed` over it and press Enter → the texts painted next.
let type_x = |app: &mut VectorcraftApp, shown: &str, typed: &str| {
let texts = panel_frame(&ctx, app, vec![]);
let at = texts.iter().find(|(t, _)| t == shown).unwrap_or_else(|| panic!("{shown} in {texts:?}")).1.center();
let button =
|pressed| egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() };
panel_frame(&ctx, app, vec![egui::Event::PointerMoved(at), button(true)]);
panel_frame(&ctx, app, vec![button(false)]);
panel_frame(&ctx, app, vec![key(egui::Key::A, egui::Modifiers::COMMAND)]);
panel_frame(&ctx, app, vec![egui::Event::Text(typed.into())]);
panel_frame(&ctx, app, vec![key(egui::Key::Enter, egui::Modifiers::NONE)]);
panel_frame(&ctx, app, vec![])
};
let positions = |app: &VectorcraftApp| current(app).unwrap().1.iter().map(|s| s.position).collect::<Vec<_>>();
set_pstate(&ctx, "tabs-sel", 0usize);
let texts = type_x(&mut app, "30 pt", "70");
assert_eq!(positions(&app), [50.0, 70.0]);
assert_eq!(pstate::<usize>(&ctx, "tabs-sel"), 1);
assert!(texts.iter().any(|(t, _)| t == "70 pt"), "70 pt in {texts:?}");
set_pstate(&ctx, "tabs-sel", 0usize);
let texts = type_x(&mut app, "50 pt", "200000");
assert_eq!(positions(&app), [50.0, 70.0]);
assert_eq!(pstate::<usize>(&ctx, "tabs-sel"), 0);
assert!(texts.iter().any(|(t, _)| t == "50 pt"), "50 pt in {texts:?}");
// An X less than 1e-6 pt above another stop merges the two into the stop already there,
// which is selected.
app.session.execute("text.tabs.set", &json!({"stops": [{"position": 30}, {"position": 50}, {"position": 70}]})).unwrap();
set_pstate(&ctx, "tabs-sel", 0usize);
type_x(&mut app, "30 pt", "50.0000001");
assert_eq!(positions(&app), [50.0, 70.0]);
assert_eq!(pstate::<usize>(&ctx, "tabs-sel"), 0);
}
/// One frame of the panel menu with `events` → the rows' texts and where they are painted.
fn menu_frame(ctx: &egui::Context, app: &mut VectorcraftApp, events: Vec<egui::Event>) -> Vec<(String, egui::Rect)> {
let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, vec2(320.0, 400.0));
+1
View File
@@ -654,6 +654,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
Type › Optical Margin Alignment (`type.opticalMarginAlignment`) hangs the punctuation and letter edges at the ends of a type object's lines outside its margins: at the left of left-aligned lines, at the right of right-aligned lines, and at both ends of centered and justified lines, in point and area type of left-to-right paragraphs. Quotation marks, hyphens, full stops and commas hang wholly; asterisks, tildes, ellipses, en and em dashes, colons and semicolons hang by half; and A, V, W, Y, v, w and y hang by a tenth of their width. It is off by default and saved with the type object.
The Paragraph panel menu's Hyphenation… (`ui.hyphenation`, `text.setFormat {wordsLongerThan, afterFirst, beforeLast, hyphenLimit, hyphenationZone, hyphenateCapitalized}`) sets each paragraph's hyphenation limits: the shortest word that breaks, the fewest letters on each side of the hyphen, the most hyphenated lines in a row, a zone at the right edge where the Single-line Composer breaks before a word instead of hyphenating it, and whether capitalized words break. The defaults are words longer than 5 letters, 3 letters on each side, no limit or zone, and capitalized words hyphenated; paragraph styles and the native file keep the options.
The Tabs panel's ruler is numbered in the General unit with the canvas rulers' label steps and a tick every tenth of a step. With the panel menu's Snap to Unit on, or Shift held, a tab stop placed by a click on the ruler or dragged on it lands on the nearest tick (`text.tabs.set`).
When a drag on the Tabs panel's ruler or a value typed in its X field moves a tab stop past another stop, the moved stop stays selected.
The Tabs panel menu's Clear All Tabs (`text.tabs.clear`), Delete Tab and Repeat Tab (`text.tabs.set`) can be chosen while the panel's ruler shows tab stops. Delete Tab removes the stop selected on the ruler. Repeat Tab replaces the stops after the selected stop with up to 20 copies of it. The copies are spaced by the selected stop's distance from the stop before it, or from the paragraph's left indent when it is the first stop, and no copy is placed at 2,000 pt or beyond. Clear All Tabs removes every stop, so the default stops every ½ inch apply again.
- **Interface languages, vertical type:** Preferences ▸ User Interface (or VectorCraft ▸ Language on macOS) picks Automatic (the system locale) or a registered language, persisted as `interfaceLanguage`. Translations come from per-language catalogs (`i18n/*.tsv`): Traditional and Simplified Chinese, Japanese, German (every `de-*` locale), Spanish (neutral international Spanish, for every `es-*` locale), French (every `fr-*` locale), Italian (every `it-*` locale) Russian (every `ru-*` locale) and Ukrainian (every `uk-*` locale) cover the whole interface, Czech every menu label; Czech, German, Greek, Spanish, French, Hungarian, Italian, Japanese, Korean, Vietnamese, Polish, Brazilian Portuguese, Russian, Simplified Chinese, Traditional Chinese, Swedish, Ukrainian and Finnish also translate status-bar and error messages as they are shown (`@msg` templates, every message literal tested; the messages themselves stay English for agents); untranslated text stays English. Japanese and Chinese glyphs come from the craft-fonts build input (release builds) or the installed fonts, Czech, German, Spanish, French, Italian, Russian and Ukrainian ones from the bundled UI fonts. The web app follows the browser's languages (or `?lang=`). The Basic toolbar's Type button holds Vertical Type in its flyout. Vertical Type, Vertical Area Type and Vertical Type on a Path create vertical text (columns right to left, upright CJK glyphs and marks with `vert` alternates, Latin and longer numbers on their side, two- and three-digit numbers set as tate-chu-yoko in one em of the column (kept whole when justified), upright glyphs centred on the column (tracked or justified too), point type's anchor on the first column's centre line); kinsoku applies to horizontal and vertical Japanese (Paragraph panel › Kinsoku Set, `text.setFormat {kinsoku}`: Hard, the default, keeps closing marks, iteration marks, the prolonged sound mark and small kana off the line start and opening brackets off its end; Soft lets 々, ー and small kana start a line as JLREQ's level 3 rules do; None turns it off), and justified Japanese lines spread their room between characters (not inside Latin words); Paragraph panel › Mojikumi Set (shown with Preferences › Type › Show East Asian Options, `text.setFormat {mojikumi}`): None or Line-end Punctuation Half Width (new type's default, as in Illustrator; older documents and imported text keep None) shares one half-em space between consecutive punctuation, sets a closing mark ending a line half width and an opening bracket starting a line flush with its start (a paragraph's first line at its first-line indent, JIS X 4051's principle in JLREQ 3.1.5), and puts a quarter em between Japanese and Latin letters or digits; Paragraph panel menu › Top-to-Top / Bottom-to-Bottom Leading measures leading from em box top to top (area type's first line touches the frame) or from baseline to baseline (new type in a Japanese interface starts top to top, with em box centre character alignment, #432); Paragraph panel menu › Burasagari None / Regular / Force (`text.setFormat {burasagari: "none"|"standard"|"forced"}`) hangs an East Asian comma or full stop (、。,.、。) ending an area type line outside it, Regular (new type's default) when it doesn't fit and Force always (the rest of the line then fills the measure; closing brackets and Latin punctuation don't hang); Character panel menu › Character Alignment (with the East Asian options; `text.setFormat` or `text.setRangeStyle {charAlign}`) lines characters smaller than the largest on their line up on the Roman baseline, the em box top/right, centre or bottom/left, or the ICF (ideographic character face) top/right or bottom/left, from the font's BASE table or, without one, the average ink box of some ideographs and kana; Proportional Metrics (the same menu; `{proportionalMetrics}`) sets full-width glyphs on the font's proportional widths (OpenType `palt`) in horizontal type and upright glyphs on its proportional heights (`vpal`, shaped top to bottom; fonts without vertical metrics keep their cells) in vertical type, and Line-end Punctuation Half Width takes nothing more off the punctuation they re-spaced; Type ▸ Type Orientation switches existing text; caret, selection, hit testing and arrow keys follow the writing direction. Vertical text exports to PDF as real text and to SVG as outlines. The interface is available in Polish (`pl`): menus, panels, dialogs and messages, with one/few/many plurals; AI-drafted, native review pending (#1498).
- **Transparency:** opacity masks (clip/invert/disable/link), exported as SVG `<mask>` and PDF soft masks. The constant alpha soft mask that PDF and `.ai` export draw a CMYK page with transparency through is white, so applications that read every soft mask by its luminosity show the page too (#1359, part of #1286).