mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-25 20:01:07 +01:00
Merge pull request #8860 from dotCooCoo/feat/tabs-x-field-adds-stop
Tabs: a position typed in X or Y adds a stop when the paragraph has none
This commit is contained in:
3 files changed
+88
-4
No files matched your search
@@ -1,4 +1,5 @@
|
||||
//! Tabs panel: tab-stop alignment, X position (Y in vertical type), leader and "align on", and the
|
||||
//! Tabs panel: tab-stop alignment, X position (Y in vertical type; a position typed there for a
|
||||
//! paragraph with no stops adds a stop at it), leader and "align on", and the
|
||||
//! framework's text ruler numbered in the General unit, on which a click adds a stop, dragging moves
|
||||
//! one and dragging it off the ruler deletes it. Ctrl-dragging a stop (Command on macOS) moves all the
|
||||
//! stops by the same distance. A stop lands on the ruler's step, or free with Alt held. While a stop is
|
||||
@@ -677,8 +678,10 @@ pub(crate) fn apply_ruler_edit(app: &mut VectorcraftApp, node: &Node, para: &Par
|
||||
}
|
||||
|
||||
/// The X (Y in vertical type) field's `value`: a picked marker moves to it, else the picked stop
|
||||
/// does and stays picked after the stops are sorted. A position past [`MAX_STOP`] is refused by
|
||||
/// `text.tabs.set` and nothing changes. `picked`: the stop and the marker of [`TabsPanel`].
|
||||
/// does and stays picked after the stops are sorted. A paragraph with no stops and no picked marker
|
||||
/// gets a stop there with the panel's alignment, which is then picked, as a click on the ruler adds
|
||||
/// one. A position past [`MAX_STOP`] is refused by `text.tabs.set` and nothing changes. `picked`:
|
||||
/// the stop and the marker of [`TabsPanel`].
|
||||
pub(crate) fn set_position(app: &mut VectorcraftApp, node: &Node, para: &ParaStyle, span: f64, picked: (usize, Option<RulerItem>), value: f64) {
|
||||
let (stop, marker) = picked;
|
||||
match marker {
|
||||
@@ -692,6 +695,13 @@ pub(crate) fn set_position(app: &mut VectorcraftApp, node: &Node, para: &ParaSty
|
||||
set_marker(app, marker, value, para, span, &targets, false);
|
||||
}
|
||||
}
|
||||
None if para.tabs.is_empty() => {
|
||||
let align = app.ui.tabs_panel.align;
|
||||
let added = TabStop { position: value.max(0.0), align, leader: String::new(), align_on: '.' };
|
||||
if apply(app, std::slice::from_ref(&added)) {
|
||||
app.ui.tabs_panel.stop = 0;
|
||||
}
|
||||
}
|
||||
None => {
|
||||
let mut stops = para.tabs.clone();
|
||||
if let Some(i) = apply_moved(app, &mut stops, stop, value.max(0.0)) {
|
||||
|
||||
@@ -759,6 +759,80 @@ fn an_x_typed_past_the_next_stop_keeps_the_stop_selected() {
|
||||
assert_eq!(app.ui.tabs_panel.stop, 0);
|
||||
}
|
||||
|
||||
/// The undo steps of the active document.
|
||||
fn undo_steps(app: &VectorcraftApp) -> usize {
|
||||
app.session.active().unwrap().history.undo.len()
|
||||
}
|
||||
|
||||
/// A position typed in the X field of a paragraph with no stops adds a stop there with the chosen
|
||||
/// alignment, keeps its hundredths of a point, picks it, and is one undo step.
|
||||
#[test]
|
||||
fn typing_x_into_a_paragraph_without_stops_adds_and_selects_a_stop() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.run("file.new", json!({})).unwrap();
|
||||
app.run("text.create", json!({"x": 10, "y": 20, "text": "a\tb", "area": {"width": 300, "height": 100}})).unwrap();
|
||||
assert!(current(&app).unwrap().1.is_empty());
|
||||
app.ui.tabs_panel.align = TabAlign::Right;
|
||||
app.ui.tabs_panel.stop = 3;
|
||||
let before = undo_steps(&app);
|
||||
type_position(&mut app, 36.47);
|
||||
let stops = current(&app).unwrap().1;
|
||||
assert_eq!(stops.iter().map(|s| (s.position, s.align)).collect::<Vec<_>>(), [(36.47, TabAlign::Right)]);
|
||||
assert_eq!(app.ui.tabs_panel.stop, 0);
|
||||
assert_eq!(undo_steps(&app), before + 1);
|
||||
app.run("edit.undo", json!({})).unwrap();
|
||||
assert!(current(&app).unwrap().1.is_empty());
|
||||
}
|
||||
|
||||
/// In vertical type the position field is Y, and a position typed there for a paragraph with no
|
||||
/// stops adds a stop.
|
||||
#[test]
|
||||
fn typing_y_into_vertical_type_without_stops_adds_a_stop() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.run("file.new", json!({})).unwrap();
|
||||
app.run("text.create", json!({"x": 10, "y": 20, "text": "a\tb", "vertical": true})).unwrap();
|
||||
type_position(&mut app, 48.0);
|
||||
let stops = current(&app).unwrap().1;
|
||||
assert_eq!(stops.iter().map(|s| (s.position, s.align)).collect::<Vec<_>>(), [(48.0, TabAlign::Left)]);
|
||||
}
|
||||
|
||||
/// A first stop past 100,000 pt adds no stop and records no undo step. A negative position adds
|
||||
/// the stop at 0 pt.
|
||||
#[test]
|
||||
fn a_refused_first_stop_adds_nothing_and_records_no_undo() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.run("file.new", json!({})).unwrap();
|
||||
app.run("text.create", json!({"x": 10, "y": 20, "text": "a\tb", "area": {"width": 300, "height": 100}})).unwrap();
|
||||
let before = undo_steps(&app);
|
||||
type_position(&mut app, 200000.0);
|
||||
assert!(current(&app).unwrap().1.is_empty());
|
||||
assert_eq!(undo_steps(&app), before);
|
||||
type_position(&mut app, -5.0);
|
||||
assert_eq!(stop_positions(&app), [0.0]);
|
||||
assert_eq!(undo_steps(&app), before + 1);
|
||||
}
|
||||
|
||||
/// With the Selection tool on two texts, a first stop typed for the shown text, which has no
|
||||
/// stops, becomes every selected text's stops in one undo step, replacing the other text's stop.
|
||||
#[test]
|
||||
fn typing_the_first_stop_over_mixed_paragraphs_uses_the_displayed_list() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.run("file.new", json!({})).unwrap();
|
||||
let id = |v: serde_json::Value| v["id"].as_u64().unwrap();
|
||||
let a = id(app.run("text.create", json!({"x": 10, "y": 20, "text": "a\tb", "area": {"width": 300, "height": 60}})).unwrap());
|
||||
let b = id(app.run("text.create", json!({"x": 10, "y": 100, "text": "c\td", "area": {"width": 250, "height": 60}})).unwrap());
|
||||
app.run("select.set", json!({"ids": [b]})).unwrap();
|
||||
app.run("text.tabs.set", json!({"stops": [{"position": 90}]})).unwrap();
|
||||
app.run("select.set", json!({"ids": [a, b]})).unwrap();
|
||||
assert_eq!(current(&app).unwrap().0.id.0, a);
|
||||
let before = undo_steps(&app);
|
||||
type_position(&mut app, 25.0);
|
||||
for text in [a, b] {
|
||||
assert_eq!(text_of(&app, text).para_at(0).tabs.iter().map(|s| s.position).collect::<Vec<_>>(), [25.0], "text {text}");
|
||||
}
|
||||
assert_eq!(undo_steps(&app), before + 1);
|
||||
}
|
||||
|
||||
/// The panel menu's Repeat Tab, Delete Tab and Clear All Tabs can be chosen while the text has
|
||||
/// tab stops and show no check mark. Repeat Tab and Delete Tab act on the stop selected on the
|
||||
/// ruler, and Clear All Tabs removes every stop.
|
||||
|
||||
@@ -1861,7 +1861,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
The Character panel menu's Character Direction (with the Indic options; `text.setFormat {charDirection}`, `text.setRangeStyle {charDirection}`) sets the selected characters left to right or right to left inside their paragraph, as a Unicode bidi embedding: a date set Left to Right keeps its order in right-to-left text, and a word set Right to Left keeps the punctuation after it on its left. Default (the default) leaves the characters to the bidi algorithm; character styles and the native file keep the setting.
|
||||
In vertical type, the Tabs panel names its alignment buttons Top-Justified Tab, Center-Justified Tab, Bottom-Justified Tab and Decimal-Justified Tab, in their tool tips and for screen readers, and labels the position field Y. In horizontal type the buttons keep the names Left-Justified Tab and Right-Justified Tab, and the field keeps the label X.
|
||||
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`).
|
||||
With Snap to Unit off and Shift not held, a tab stop placed by a click on the Tabs panel's ruler or dragged on it lands on the nearest whole point. A position typed in the X or Y field keeps its hundredths of a point.
|
||||
With Snap to Unit off and Shift not held, a tab stop placed by a click on the Tabs panel's ruler or dragged on it lands on the nearest whole point. A position typed in the X or Y field keeps its hundredths of a point. When the shown paragraph has no tab stops and no indent marker is selected, a position typed in the X or Y field and committed adds a stop there with the chosen alignment and selects it, in one undo step, as a click on the ruler does; the [archived user guide](https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf#page=521) gives typing a position as another way to set a new stop. The field holds a typed position to 0 to 100,000 pt (VectorCraft's own limits). Tests `panels::tabs::tests::typing_x_into_a_paragraph_without_stops_adds_and_selects_a_stop`, `typing_y_into_vertical_type_without_stops_adds_a_stop`, `a_refused_first_stop_adds_nothing_and_records_no_undo` and `typing_the_first_stop_over_mixed_paragraphs_uses_the_displayed_list`.
|
||||
The Tabs ruler's upper first-line marker and lower left-indent marker show absolute positions and set paragraph indents (`text.setFormat`). Dragging the lower marker keeps the upper position, while Ctrl-dragging it (Command on macOS) moves both; marker drags snap like tab stops, and each release is one undo step. With differing left indents, only the upper marker is shown and its absolute target applies to every touched paragraph.
|
||||
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.
|
||||
With the Selection tool, the Tabs panel shows the ruler and stops of the first paragraph of the first selected text object, also when the text is inside a selected group or a shape is selected before it; a selection without text shows "No text selected". A stop set on that ruler is set on every selected text object and the text in selected groups, and other objects are left as they were. This is VectorCraft's own rule. Tests `panels::tabs::tests::the_ruler_shows_text_selected_after_an_object_that_is_not_text`, `the_ruler_shows_text_inside_a_selected_group`, `a_stop_added_on_a_mixed_selection_sets_every_selected_text` and `a_selection_without_text_shows_no_ruler`.
|
||||
|
||||
Reference in new issue
Block a user