diff --git a/crates/ui-egui/src/panels/script_console.rs b/crates/ui-egui/src/panels/script_console.rs index 27925a9ed0..e1adf9473f 100644 --- a/crates/ui-egui/src/panels/script_console.rs +++ b/crates/ui-egui/src/panels/script_console.rs @@ -14,15 +14,15 @@ use serde_json::{Value, json}; use vectorcraft_engine::script::console::{Console, ConsoleLine, Ending, Entry}; // PLAN: assumed paths of the framework items below, re-exported by craft-ui (behavior, theme and keymap types) -use craft::behavior::{DisplayOrder, IconId, ItemSource}; +use craft::behavior::{DisplayOrder, IconId, ItemSource, Selection}; use craft::keymap::CommandRef; use craft::theme::variant::Tone; use craft::ui::buttons::Button; -use craft::ui::contract::{Bind, LeastWidth, Props as _, ScrollAnchor, Show, ShowCollection, ShowContainer, Sizing, clicked}; +use craft::ui::contract::{Bind, CollectionEvent, LeastWidth, Props as _, ScrollAnchor, Show, ShowCollection, ShowContainer, Sizing, clicked}; use craft::ui::layout::RowAlign; use craft::ui::layout_components::{Row, Stack}; use craft::ui::list::{List, ListRow, RowInk}; -use craft::ui::menu::PanelRow; +use craft::ui::menu::{Menu, MenuItem, PanelRow}; use craft::ui::notices::Notice; use craft::ui::primitives::IconSpec; use craft::ui::runtime::commands::{CommandState, CommandStates}; @@ -209,11 +209,14 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { selection.anchor = selection.anchor.take().filter(held); let buttons = buttons(count > 0, !selection.items.is_empty()); let mut picked = None; + let mut menu_command = None; Stack::new().fill().footer(|ui, _| picked = footer(ui, buttons).or(picked)).show(ui, |ui, _| { if let Some(n) = notice(c) { Notice::new(Tone::Info, n).show(ui); } - List::::new(tl!("Script Console")) + let out = List::::new(tl!("Script Console")) + .id(ui.scope_id().with("console-lines")) + .row_menu() .sizing(Sizing::Fill) .scroll_anchor(ScrollAnchor::End) .selection(Bind::bound(&mut *selection)) @@ -227,9 +230,23 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { Entry::Output(_) | Entry::Log(_) => row, } }); + if let Some(line) = out.menu.map(|request| request.key).filter(held) { + // The row's More button can open the menu without a selection gesture. + if out.events.iter().any(|event| matches!(event, CollectionEvent::ContextMenu(_))) && !selection.items.contains(&line) { + *selection = Selection::single(line); + } + Menu::context(tl!("Script Console"), &out.response).show(ui, |ui, _| { + if MenuItem::new(tl!("Copy Line")).show(ui).ran { + menu_command = Some((COMMANDS[2], json!({"first": line, "last": line}))); + } + if MenuItem::new(tl!("Copy Selected")).enabled(!selection.items.is_empty()).show(ui).ran { + menu_command = Some((COMMANDS[1], json!({}))); + } + }); + } }); - if let Some(id) = picked { - run_ui(app, id, json!({})); + if let Some((id, params)) = menu_command.or_else(|| picked.map(|id| (id, json!({})))) { + run_ui(app, id, params); } } diff --git a/crates/ui-egui/src/panels/tests_script_console.rs b/crates/ui-egui/src/panels/tests_script_console.rs index 71766dce0a..706b2b965a 100644 --- a/crates/ui-egui/src/panels/tests_script_console.rs +++ b/crates/ui-egui/src/panels/tests_script_console.rs @@ -77,6 +77,70 @@ fn the_console_footer_buttons_run_their_commands_at_minimum_width() { assert!(!panel.enabled("Copy All")); } +#[test] +fn the_row_menu_copies_its_line_or_the_selected_range_while_output_arrives() { + let mut app = app(); + run(&mut app, "$.writeln('one'); $.writeln('two'); $.writeln('three')"); + let mut panel = Panel::new(app, show); + panel.click("#1 c.js: one"); + panel.click_with("#1 c.js: three", egui::Modifiers::SHIFT); + panel.secondary_click("#1 c.js: two"); + run(&mut panel.app(), "$.writeln('later')"); + panel.frame(); + panel.click_menu_item("Copy Line"); + assert_eq!(panel.app().clipboard_out.take().as_deref(), Some("#1 c.js: two")); + + panel.secondary_click("#1 c.js: two"); + panel.click_menu_item("Copy Selected"); + assert_eq!(panel.app().clipboard_out.take().as_deref(), Some("#1 c.js: one\n#1 c.js: two\n#1 c.js: three")); + + panel.secondary_click("#2 c.js: later"); + panel.click_menu_item("Copy Selected"); + assert_eq!(panel.app().clipboard_out.take().as_deref(), Some("#2 c.js: later")); + + panel.secondary_click("#1 c.js: two"); + panel.app().run("script.console.clear", json!({})).unwrap(); + run(&mut panel.app(), "$.writeln('replacement')"); + panel.frame(); + assert!(!panel.shows("Copy Line"), "a replacement at the same row cannot inherit the menu"); +} + +#[test] +fn copy_line_follows_its_number_when_older_output_is_dropped() { + let mut app = app(); + run(&mut app, "$.writeln('first'); $.writeln('target'); $.writeln('next')"); + let mut panel = Panel::new(app, show); + panel.secondary_click("#1 c.js: target"); + + // Fill the console and evict its first line while the menu is open. + let free = vectorcraft_engine::script::console::MAX_CONSOLE_LINES - panel.app().session.script_console().lines().len(); + // Each run also writes a start, an end and a report. + run(&mut panel.app(), &format!("for (var i = 0; i < {}; i++) $.writeln(i)", free - 2)); + assert_eq!(panel.app().session.script_console().first_number(), 1); + panel.frame(); + panel.click_menu_item("Copy Line"); + assert_eq!(panel.app().clipboard_out.take().as_deref(), Some("#1 c.js: target")); +} + +#[test] +fn the_focused_console_row_opens_its_menu_from_the_keyboard() { + use craft::ui::contract::Role; + use egui::{Key, Modifiers}; + + let mut app = app(); + run(&mut app, "$.writeln('one')"); + let mut panel = Panel::new(app, show); + panel.click("#1 c.js: one"); + let list_focus = panel.ctx().memory(|memory| memory.focused()).expect("the console list has focus"); + + panel.key(Key::F10, Modifiers::SHIFT); + assert!(panel.menu_item_enabled("Copy Line")); + assert!(panel.menu_item_enabled("Copy Selected")); + panel.key(Key::Escape, Modifiers::NONE); + assert!(!panel.shows_role("Copy Line", Role::MENU_ITEM)); + assert_eq!(panel.ctx().memory(|memory| memory.focused()), Some(list_focus)); +} + #[test] fn clear_works_during_a_run_and_the_run_goes_on_writing() { let mut app = app(); diff --git a/docs/mcp.md b/docs/mcp.md index 9a6f721b93..71424b1638 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -4315,7 +4315,9 @@ carriage returns and the two together break lines, and other control characters Pictures. The console keeps at most 2,048 lines and 1 MiB of text and drops the oldest lines past that. A line longer than 4,096 bytes, and a script's name longer than 256 bytes, is cut with `…`. When the console has dropped or cut any lines, a note at the top counts them. The panel lays out only the rows in view. Click a line to select it and Shift-click to extend the selection. Clear, Copy Selected and Copy All are -at the bottom of the panel and in its menu. Output goes on while the panel is closed. +at the bottom of the panel and in its menu. Right-click a selected line to keep the range. Choose Copy Line +to copy just that line, or Copy Selected to copy from the first selected line through the last. Right-clicking +an unselected line selects it. Output goes on while the panel is closed. - `script.console {}` returns `{lines: [{run, name, kind, text}], droppedLines, truncatedLines}`. `run` is the run's number in the session, and `kind` is `start`, `output`, `log`, `error`, `end` or `report`. An end line's text diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index aa49d934ac..6999765821 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1130,7 +1130,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - Scripts: a document's variables and data sets, the variables its page items are bound to, Lock Variables, and importing and exporting a variable library through a `File`, as the help pages https://ai-scripting.docsforadobe.dev/jsobjref/Variables/, https://ai-scripting.docsforadobe.dev/jsobjref/Variable/, https://ai-scripting.docsforadobe.dev/jsobjref/Datasets/ and https://ai-scripting.docsforadobe.dev/jsobjref/Dataset/ describe them; `variable.setBinding` binds one object for one slot, and `dataset.update {name}` updates a data set that is not the active one (`docs/mcp.md`). `crates/engine/src/tests/script_variables.rs`. - Scripts: `app.selectTool(name)` makes the named tool the current tool when the run ends without an error (https://community.adobe.com/questions-652/what-s-new-in-illustrator-scripting-cc2020-769942). `crates/engine/src/tests/script_dom.rs`. - Scripts: `app.doScript(action, set, dialogs?)` plays an action of the Actions panel inside the run, as the `DoScript` method of the scripting reference https://web.archive.org/web/20170621180804/https://wwwimages.adobe.com/content/dam/Adobe/en/devnet/illustrator/sdk/CC2015_3/Illustrator%20VBScript%20Reference.pdf describes it: its steps join the run's one undo step and keep the script's file limits, and a stop or a step a script may not run, or that plays an action or runs a script, is refused before any step runs (`docs/mcp.md`). `app.loadAction` and `app.unloadAction` are not there yet. `crates/engine/src/tests/script_actions.rs`. - - Scripts: Window › Script Console shows each run's `$.write` and `$.writeln` output, `vc.log` entries, uncaught error with the script's name, line and column, and a report of its time, host calls and slowest commands, keeping at most 2,048 lines and counting the lines it dropped. `script.run`'s report carries the same data, and `script.console`, `script.console.clear` and `ui.copyScriptConsole` read, clear and copy it. `crates/engine/src/tests/script_console.rs`. + - Scripts: Window › Script Console shows each run's `$.write` and `$.writeln` output, `vc.log` entries, uncaught error with the script's name, line and column, and a report of its time, host calls and slowest commands, keeping at most 2,048 lines and counting the lines it dropped. `script.run`'s report carries the same data, and `script.console`, `script.console.clear` and `ui.copyScriptConsole` read, clear and copy it. A line's menu copies that line or the selected range. `crates/engine/src/tests/script_console.rs`. - Scripts: the status bar translates its own words around a failed run's error and the app's own error messages, and shows text the script threw itself (a value, an error it made, or an error whose name or message it changed) as it is, even when that text reads like one of the app's messages. `script.run`'s report gives `messageOrigin` (`script` or `built-in`), and the advice about objects other applications give their scripts follows only the app's own reference errors. VectorCraft's own rule. `crates/js/src/interp_tests.rs`, `crates/engine/src/tests/script_run.rs`, `crates/ui-egui/src/chrome/tests.rs`. - Scripts: the warning before File › Scripts › Other Script… runs a script lists what `script.check` finds the script reaches outside the document (files it writes, moves or deletes, other apps, the network, native code, environment variables, preferences, code the checker can't read), the files and dialogs it needs, features only the reference app has and its included files, read without running it. It says when the script is too large to check, compiled, not a script or not read, and when a list was cut short. VectorCraft's own rule. `crates/ui-egui/src/tests/script_run.rs`. - Scripts: the `$` object has the other members the Dollar object page lists (https://extendscript.docsforadobe.dev/extendscript-tools-features/dollar-object/), from `$.about()` to `$.version`, and scripts have the global `localize(object, ...values)` (https://extendscript.docsforadobe.dev/extendscript-tools-features/localizing-extendscript-strings/), `toSource(value)` and `Object.prototype.toSource()`. Each run starts with the interface's locale, and what a script changes in `$` lasts only for that run. `crates/engine/src/tests/script_dollar.rs`, `crates/js/src/extension_tests.rs`.