mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-30 18:25:34 +01:00
Merge main into feat/retype-installed-fonts
This commit is contained in:
commit
bf782369fc
568 files changed
+37351
-3478
No files matched your search
@@ -69,6 +69,9 @@ impl Session {
|
||||
selection_at_lend: None,
|
||||
lent_selection: None,
|
||||
last_selection_tool: None,
|
||||
last_part_selection_tool: None,
|
||||
press_lent: None,
|
||||
hover_lent: None,
|
||||
last_view: ViewInfo::default(),
|
||||
preview_memo: Default::default(),
|
||||
depth: 0,
|
||||
@@ -103,6 +106,8 @@ impl Session {
|
||||
profile_dir: None,
|
||||
color_settings_file: None,
|
||||
plugin_dir: None,
|
||||
plugin_loads: Default::default(),
|
||||
plugin_loads_in_background: false,
|
||||
scripts_dir: None,
|
||||
metadata_templates_dir: None,
|
||||
new_doc_profile_dir: None,
|
||||
@@ -139,6 +144,7 @@ impl Session {
|
||||
recovery: Default::default(),
|
||||
in_tool_actions: false,
|
||||
settled_warnings: None,
|
||||
held_interaction: None,
|
||||
previewing: false,
|
||||
decoded_images: Default::default(),
|
||||
envelope_defaults: None,
|
||||
@@ -212,6 +218,7 @@ impl Session {
|
||||
return;
|
||||
}
|
||||
self.press_type_selection = None;
|
||||
self.press_lent = None;
|
||||
let view = self.last_view;
|
||||
// The edit the tool computes on another thread and the input held for it belong to the
|
||||
// document being left. The switch goes on whatever they did, as for the deactivation.
|
||||
|
||||
@@ -287,6 +287,190 @@ impl Session {
|
||||
(r, settled)
|
||||
}
|
||||
|
||||
/// Run `f`, the top-level command `id` with `params` from outside the tool (a panel, a menu
|
||||
/// item, an automation client), with the active document's tool drag set aside: the command
|
||||
/// runs on the document the drag started from and records its own undo step and journal entry.
|
||||
/// The drag then starts from what the command left, and its preview is applied again, so the
|
||||
/// next preview, the commit and a cancel keep the command's edit, and Undo takes back the drag's
|
||||
/// step before the command's. While the command runs, [`Session::in_interaction`] is false, so
|
||||
/// it updates Recent Colors and converts or remaps the new-art paints at once, as it does with
|
||||
/// no drag in progress.
|
||||
///
|
||||
/// The interaction stays as it is, and the command runs inside it, for an interaction a dialog
|
||||
/// or a panel began (it builds its preview from commands), for typing in progress
|
||||
/// ([`Session::edit`] keeps it as a step of its own), for the Quick Pen (an edit made outside
|
||||
/// it ends the path it draws), and for a copy made with `object.transform` during a drag that
|
||||
/// copies (it copies the document as the drag's move left it). A command that settles,
|
||||
/// commits or cancels the interaction, or that hands the active tool actions to apply, gets it
|
||||
/// back first ([`Session::put_back_interaction`]), as it found it.
|
||||
pub(crate) fn outside_interaction(&mut self, id: &str, params: &Value, f: impl FnOnce(&mut Self) -> Result<Value>) -> Result<Value> {
|
||||
if cmd::typing_in_progress(self) || self.tool_id() == vectorcraft_tools::quickpen::ID {
|
||||
return f(self);
|
||||
}
|
||||
let Some(st) = self.active_mut() else { return f(self) };
|
||||
let Some(it) = st.interaction.as_ref().filter(|it| it.tool) else { return f(self) };
|
||||
// A drag that copies: its latest preview, applied or held back by Real-time Drawing off, copies.
|
||||
let copying = it.preview.as_ref().is_some_and(|(c, p)| c == "object.transform" && p.get("copy").and_then(Value::as_bool) == Some(true));
|
||||
if copying && id == "object.transform" && params.get("copy").and_then(Value::as_bool) == Some(true) {
|
||||
return f(self);
|
||||
}
|
||||
let Some(interaction) = st.interaction.take() else { return f(self) };
|
||||
// The document and selection on show, when a preview changed them.
|
||||
let previewed = !Arc::ptr_eq(&st.doc, &interaction.doc) || st.selection != *interaction.selection;
|
||||
let shown = previewed.then(|| (st.doc.clone(), st.selection.clone()));
|
||||
if previewed {
|
||||
st.doc = interaction.doc.clone();
|
||||
st.selection.clone_from(&interaction.selection);
|
||||
st.revision += 1;
|
||||
cmd::globaledit::follow_history(st);
|
||||
}
|
||||
let (uid, state) = (st.uid, crate::interaction::ViewState::of(st));
|
||||
let paint = self.paint.clone();
|
||||
self.held_interaction = Some(crate::HeldInteraction { uid, interaction, shown, state, paint });
|
||||
if previewed {
|
||||
self.sync_front_profiles();
|
||||
}
|
||||
let r = f(self);
|
||||
self.put_back_interaction();
|
||||
r
|
||||
}
|
||||
|
||||
/// Put back the interaction [`Session::outside_interaction`] set aside. When the command left
|
||||
/// the document and the selection as it found them, the preview on show before it is on show
|
||||
/// again. Otherwise the interaction starts from the document the command left and from its
|
||||
/// own selection, without the objects the command removed, hid or locked, and the preview that Real-time
|
||||
/// Drawing showed is applied to it again. The warning or the error of that preview goes to
|
||||
/// the command's result ([`Session::note_settled_warning`]); a preview that fails leaves the
|
||||
/// interaction with nothing to commit. An interaction whose document the command closed ends,
|
||||
/// and so does one with anchors or segments selected on a path the command changed in more
|
||||
/// than a move. A document
|
||||
/// the command left an interaction of its own on keeps that one.
|
||||
pub(crate) fn put_back_interaction(&mut self) {
|
||||
let Some(crate::HeldInteraction { uid, interaction: mut it, shown, state, paint }) = self.held_interaction.take() else { return };
|
||||
// A selection command loaded the paints of the selection it made into the fill and stroke
|
||||
// proxies. The drag goes on with its own selection, so they show its paints again.
|
||||
if self.paint != paint
|
||||
&& let Some(st) = self.active_mut().filter(|d| d.uid == uid && d.interaction.is_none())
|
||||
{
|
||||
let own = drag_selection(&it.selection, &st.doc);
|
||||
if st.selection != own {
|
||||
let made = std::mem::replace(&mut st.selection, own);
|
||||
self.inherit_new_art();
|
||||
self.load_selection_paints();
|
||||
if let Some(st) = self.active_mut() {
|
||||
st.selection = made;
|
||||
}
|
||||
}
|
||||
}
|
||||
// A change the command made to the new-art paints stays when the next preview or a cancel
|
||||
// puts back the paints the interaction began with (the Live Paint Bucket's colors); the
|
||||
// parts it left alone keep the interaction's. The pattern lists every field, so a field
|
||||
// added to `PaintDefaults` does not compile until it is handled here.
|
||||
let vectorcraft_tools::PaintDefaults { fill, stroke, stroke_width, appearance, opacity, blend, style, inherited } = &self.paint;
|
||||
let start = &mut it.paint;
|
||||
if *fill != paint.fill {
|
||||
start.fill.clone_from(fill);
|
||||
}
|
||||
if *stroke != paint.stroke {
|
||||
start.stroke.clone_from(stroke);
|
||||
}
|
||||
if *stroke_width != paint.stroke_width {
|
||||
start.stroke_width = *stroke_width;
|
||||
}
|
||||
if *appearance != paint.appearance {
|
||||
start.appearance.clone_from(appearance);
|
||||
}
|
||||
if *opacity != paint.opacity {
|
||||
start.opacity = *opacity;
|
||||
}
|
||||
if *blend != paint.blend {
|
||||
start.blend = *blend;
|
||||
}
|
||||
if *style != paint.style {
|
||||
start.style.clone_from(style);
|
||||
}
|
||||
if *inherited != paint.inherited {
|
||||
start.inherited = *inherited;
|
||||
}
|
||||
let active = self.active().is_some_and(|d| d.uid == uid);
|
||||
let Some(st) = self.docs.iter_mut().find(|d| d.uid == uid) else { return };
|
||||
if st.interaction.is_some() {
|
||||
return;
|
||||
}
|
||||
// A change the command made to the current layer, the highlighted rows or variable, or
|
||||
// isolation stays when the interaction is canceled.
|
||||
state.rebase(crate::interaction::ViewState::of(st), &mut it);
|
||||
let previewed = shown.is_some();
|
||||
if Arc::ptr_eq(&st.doc, &it.doc) && st.selection == *it.selection {
|
||||
if let Some((doc, selection)) = shown {
|
||||
st.doc = doc;
|
||||
st.selection = selection;
|
||||
st.revision += 1;
|
||||
cmd::globaledit::follow_history(st);
|
||||
}
|
||||
st.interaction = Some(it);
|
||||
if previewed {
|
||||
self.sync_front_profiles();
|
||||
}
|
||||
return;
|
||||
}
|
||||
// The drag's anchors and segments are numbered in the paths it began on. When the command
|
||||
// changed one of those paths in more than a move, the numbers can name other points, and
|
||||
// the drag ends without a step.
|
||||
if renumbered(&it.selection, &it.doc, &st.doc) {
|
||||
self.clear_deferred_overlay_cache();
|
||||
return;
|
||||
}
|
||||
let began = std::mem::replace(&mut it.doc, st.doc.clone());
|
||||
// The drag acts on the objects it began with: a selection the command made (a paste, a
|
||||
// duplicate, Select All) does not change what the drag moves.
|
||||
it.selection = Arc::new(drag_selection(&it.selection, &st.doc));
|
||||
// The journal holds the selection the command left. The drag's own selection is journaled
|
||||
// after it, so the drag and the commands after it replay on the objects they act on.
|
||||
let reselect = (active && st.selection != *it.selection)
|
||||
.then(|| selection_steps(&it.selection, &st.selection, &st.doc, st.active_layer, &st.highlighted_rows()));
|
||||
// The objects the drag's preview names leave out those the command removed, hid or locked.
|
||||
// A preview left naming none has nothing to apply, and the drag records no step.
|
||||
if it.preview.as_mut().is_some_and(|(_, p)| !drag_targets(p, &began, &st.doc)) {
|
||||
it.preview = None;
|
||||
}
|
||||
it.copies = None;
|
||||
it.move_box = std::sync::OnceLock::new();
|
||||
// With Real-time Drawing off the preview waits for the commit, as it did before the command.
|
||||
let again = it.preview.clone().filter(|_| previewed && active);
|
||||
// Without a preview to apply, the drag's own selection is on show, as a preview would leave
|
||||
// it before it acts.
|
||||
if again.is_none() && st.selection != *it.selection {
|
||||
st.selection.clone_from(&it.selection);
|
||||
st.revision += 1;
|
||||
}
|
||||
st.interaction = Some(it);
|
||||
if let Some(steps) = reselect {
|
||||
let (from, grouped) = (self.journal.len(), self.undo_group_docs());
|
||||
for step in steps {
|
||||
self.journal.push(step);
|
||||
}
|
||||
self.journal_in_undo_groups(Some(uid), &grouped, from);
|
||||
}
|
||||
self.clear_deferred_overlay_cache();
|
||||
if let Some((cmd, p)) = again {
|
||||
match self.preview(&cmd, &p) {
|
||||
Ok(v) => {
|
||||
if let Some(w) = v.get("warning").and_then(Value::as_str) {
|
||||
self.note_settled_warning(w);
|
||||
}
|
||||
}
|
||||
Err(e) => self.note_settled_warning(&e.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// While a command from outside the tool runs: the interaction it set aside
|
||||
/// ([`Session::outside_interaction`]).
|
||||
pub(crate) fn holds_interaction(&self) -> bool {
|
||||
self.held_interaction.is_some()
|
||||
}
|
||||
|
||||
/// [`Session::begin_interaction`] for a dialog or a panel that starts a preview → the warnings
|
||||
/// of the preview that keeping typing in progress applied, for its status bar.
|
||||
pub fn begin_interaction_warned(&mut self, label: &str) -> Result<Vec<String>> {
|
||||
@@ -311,6 +495,8 @@ impl Session {
|
||||
if label != "Typing" && cmd::typing_in_progress(self) {
|
||||
cmd::settle_interaction(self)?;
|
||||
}
|
||||
// A command from outside the tool that begins an interaction during a drag joins the drag's.
|
||||
self.put_back_interaction();
|
||||
// An edit the tool computes on another thread (a Shape Builder merge) is applied first too,
|
||||
// so the snapshot the interaction previews from and goes back to holds it.
|
||||
if !self.in_interaction() {
|
||||
@@ -327,6 +513,7 @@ impl Session {
|
||||
doc: st.doc.clone(),
|
||||
selection: Arc::new(st.selection.clone()),
|
||||
preview: None,
|
||||
tool: false,
|
||||
paint,
|
||||
used_defaults_only: false,
|
||||
preview_paint: None,
|
||||
@@ -347,6 +534,7 @@ impl Session {
|
||||
|
||||
/// Re-apply `cmd` on top of the interaction snapshot (replacing the previous preview).
|
||||
pub fn preview(&mut self, cmd: &str, params: &Value) -> Result<Value> {
|
||||
self.put_back_interaction();
|
||||
if self.script_running() {
|
||||
return Err(EngineError::Busy);
|
||||
}
|
||||
@@ -438,6 +626,7 @@ impl Session {
|
||||
fn commit_interaction_unwatched(&mut self) -> Result<()> {
|
||||
self.clear_deferred_overlay_cache();
|
||||
self.decoded_images.empty();
|
||||
self.put_back_interaction();
|
||||
if let Some(paint) = self.active().and_then(|st| st.interaction.as_ref()).and_then(|it| it.preview_paint.clone()) {
|
||||
self.paint = paint;
|
||||
}
|
||||
@@ -527,6 +716,7 @@ impl Session {
|
||||
}
|
||||
|
||||
pub fn cancel_interaction(&mut self) -> Result<()> {
|
||||
self.put_back_interaction();
|
||||
self.clear_deferred_overlay_cache();
|
||||
self.decoded_images.empty();
|
||||
self.pending_paint = None;
|
||||
@@ -567,3 +757,163 @@ impl Session {
|
||||
self.active().is_some_and(|d| d.interaction.is_some())
|
||||
}
|
||||
}
|
||||
|
||||
/// The selection a drag began with, without the objects that a command run during it removed,
|
||||
/// hid or locked in `doc`.
|
||||
fn drag_selection(began: &Selection, doc: &Document) -> Selection {
|
||||
let mut selection = began.clone();
|
||||
selection.prune(doc);
|
||||
let editable = doc.editable();
|
||||
let held: Vec<_> = selection.objects.iter().copied().filter(|&id| !editable(id)).collect();
|
||||
selection.remove_all(held);
|
||||
selection
|
||||
}
|
||||
|
||||
/// Take out of the `ids` of a drag's preview `params` the objects that a command run during the
|
||||
/// drag removed from `doc`, or hid or locked there while they were editable in `began` → false
|
||||
/// when the preview named objects and none of them is left.
|
||||
fn drag_targets(params: &mut Value, began: &Document, doc: &Document) -> bool {
|
||||
let Some(ids) = params.get_mut("ids").and_then(Value::as_array_mut) else { return true };
|
||||
if ids.is_empty() {
|
||||
return true;
|
||||
}
|
||||
let (was, now) = (began.editable(), doc.editable());
|
||||
ids.retain(|v| v.as_u64().map(vectorcraft_doc::NodeId).is_none_or(|id| doc.node(id).is_some() && (now(id) || !was(id))));
|
||||
!ids.is_empty()
|
||||
}
|
||||
|
||||
/// Whether a path with anchors or segments in `selection` is other in `doc` than in `began`, the
|
||||
/// document a drag began from, in more than a move: its anchors added, removed, put in another
|
||||
/// order (Reverse Path Direction) or reshaped, or a subpath opened or closed. A path the command
|
||||
/// moved as a whole keeps its numbers.
|
||||
fn renumbered(selection: &Selection, began: &Document, doc: &Document) -> bool {
|
||||
fn path(d: &Document, id: vectorcraft_doc::NodeId) -> Option<&[vectorcraft_geom::SubPath]> {
|
||||
d.node(id).and_then(|n| n.path_data()).map(|p| p.subpaths.as_slice())
|
||||
}
|
||||
selection.anchors.keys().chain(selection.segments.keys()).any(|&id| match (path(began, id), path(doc, id)) {
|
||||
(Some(was), Some(now)) => !moved_whole(was, now),
|
||||
(was, now) => was.is_some() != now.is_some(),
|
||||
})
|
||||
}
|
||||
|
||||
/// Whether the subpaths `now` are the subpaths `was` moved by one offset: the same number of each,
|
||||
/// each opened or closed as before, every anchor of the same kind, and every anchor and handle
|
||||
/// offset alike.
|
||||
fn moved_whole(was: &[vectorcraft_geom::SubPath], now: &[vectorcraft_geom::SubPath]) -> bool {
|
||||
if was.len() != now.len() || was.iter().zip(now).any(|(a, b)| a.closed != b.closed || a.anchors.len() != b.anchors.len()) {
|
||||
return false;
|
||||
}
|
||||
let mut pairs = was.iter().zip(now).flat_map(|(a, b)| a.anchors.iter().zip(b.anchors.iter()));
|
||||
let Some((a0, b0)) = pairs.next() else { return true };
|
||||
let (dx, dy) = (b0.p.x - a0.p.x, b0.p.y - a0.p.y);
|
||||
let alike = |a: vectorcraft_geom::Point, b: vectorcraft_geom::Point| {
|
||||
(b.x - a.x - dx).abs() <= vectorcraft_geom::EPS && (b.y - a.y - dy).abs() <= vectorcraft_geom::EPS
|
||||
};
|
||||
std::iter::once((a0, b0)).chain(pairs).all(|(a, b)| a.kind == b.kind && alike(a.p, b.p) && alike(a.h_in, b.h_in) && alike(a.h_out, b.h_out))
|
||||
}
|
||||
|
||||
/// The journal entries that select `selection` again in `doc` after `made`, the selection a
|
||||
/// command left with `layer` current and `rows` highlighted in the Layers panel ([`object_steps`]).
|
||||
/// When selecting the objects would make another layer current, `layer.setCurrent` makes `layer`
|
||||
/// current again, as the drag leaves it, and `layer.highlight` gives back the highlighted rows.
|
||||
fn selection_steps(
|
||||
selection: &Selection,
|
||||
made: &Selection,
|
||||
doc: &Document,
|
||||
layer: Option<vectorcraft_doc::NodeId>,
|
||||
rows: &[vectorcraft_doc::NodeId],
|
||||
) -> Vec<(String, Value)> {
|
||||
let mut steps = object_steps(selection, doc);
|
||||
// `layer.target` on a layer makes it current; any other change to the selected objects makes
|
||||
// the layer of the last selected object current.
|
||||
let targeted = steps.first().is_some_and(|(id, _)| id == "layer.target");
|
||||
let selects = match selection.target.filter(|t| targeted && doc.node(*t).is_some_and(|n| n.is_layer())) {
|
||||
Some(t) => Some(t),
|
||||
None if selection.objects != made.objects => {
|
||||
selection.objects.last().and_then(|id| doc.layer_containing(*id)).filter(|l| doc.is_editable(*l))
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
if let Some(layer) = layer.filter(|l| selects.is_some_and(|s| s != *l)) {
|
||||
steps.push(("layer.setCurrent".into(), serde_json::json!({ "id": layer.0 })));
|
||||
// `layer.setCurrent` highlights the layer's row. `layer.highlight` sets the rows the command
|
||||
// left instead; it keeps `layer` current while the last of them is on `layer`, or none is left.
|
||||
if rows != [layer] && rows.last().is_none_or(|r| doc.layer_containing(*r) == Some(layer)) {
|
||||
let ids: Vec<u64> = rows.iter().map(|r| r.0).collect();
|
||||
steps.push(("layer.highlight".into(), serde_json::json!({ "ids": ids, "mode": "set" })));
|
||||
}
|
||||
}
|
||||
steps
|
||||
}
|
||||
|
||||
/// The journal entries that select `selection` in `doc`: the selections made on their own (its
|
||||
/// slices with `object.slice.select`, its target with `layer.target`, its symbol part with
|
||||
/// `symbol.instance.selectPart`, its Objects on Path member with
|
||||
/// `object.objectsOnPath.selectMember`), or its objects in their order (`select.set`), the anchors
|
||||
/// left out on paths that are not selected whole (`select.anchorsMany`), the anchors of paths with
|
||||
/// every anchor selected (`select.anchors`) and its segments (`select.segments`); after its objects
|
||||
/// or its target, its ruler guides (`guide.select`) and its key object, key guide or key anchor
|
||||
/// (`select.key`).
|
||||
fn object_steps(selection: &Selection, doc: &Document) -> Vec<(String, Value)> {
|
||||
use serde_json::json;
|
||||
if !selection.slices.is_empty() {
|
||||
let slices: Vec<u64> = selection.slices.iter().map(|id| id.0).collect();
|
||||
return vec![("object.slice.select".into(), json!({ "slices": slices }))];
|
||||
}
|
||||
// A target is selected again only while targeting it selects the same objects: when a command
|
||||
// added art to a targeted layer, `select.set` selects the drag's objects.
|
||||
let targets = |t: vectorcraft_doc::NodeId| match doc.node(t) {
|
||||
Some(n) if n.is_layer() => n.layer_art(true) == selection.objects,
|
||||
_ => selection.objects == [t],
|
||||
};
|
||||
let json_refs = |refs: &mut dyn Iterator<Item = &(usize, usize)>| Value::Array(refs.map(|&(a, b)| json!([a, b])).collect());
|
||||
// A targeted object keeps the ruler guides and the key selected beside it.
|
||||
let mut steps = if let Some(t) = selection.target.filter(|&t| targets(t)) {
|
||||
vec![("layer.target".to_string(), json!({ "id": t.0 }))]
|
||||
} else if let Some(part) = &selection.symbol_part {
|
||||
return vec![("symbol.instance.selectPart".into(), json!({ "id": part.instance.0, "path": part.path }))];
|
||||
} else if let Some(member) = selection.on_path_member {
|
||||
return vec![("object.objectsOnPath.selectMember".into(), json!({ "member": member.0 }))];
|
||||
} else {
|
||||
let ids: Vec<u64> = selection.objects.iter().map(|id| id.0).collect();
|
||||
let mut steps = vec![("select.set".to_string(), json!({ "ids": ids }))];
|
||||
// `select.set` selects each path whole: subtracting the anchors that are not selected leaves
|
||||
// the ones that are, and keeps the order of the objects. A path with every anchor selected
|
||||
// as anchors gets them back with `select.anchors`, which keeps them all as anchors.
|
||||
let mut every = Vec::new();
|
||||
let partial: Vec<Value> = selection
|
||||
.objects
|
||||
.iter()
|
||||
.filter_map(|id| {
|
||||
let refs = selection.anchors.get(id)?;
|
||||
let path = doc.node(*id)?.path_data()?;
|
||||
let out: Vec<(usize, usize)> = path.anchors().map(|(s, i, _)| (s, i)).filter(|r| !refs.contains(r)).collect();
|
||||
if out.is_empty() {
|
||||
every.push(("select.anchors".to_string(), json!({ "id": id.0, "anchors": json_refs(&mut refs.iter()), "mode": "add" })));
|
||||
return None;
|
||||
}
|
||||
Some(json!({ "id": id.0, "anchors": json_refs(&mut out.iter()) }))
|
||||
})
|
||||
.collect();
|
||||
if !partial.is_empty() {
|
||||
steps.push(("select.anchorsMany".into(), json!({ "items": partial, "mode": "subtract" })));
|
||||
}
|
||||
steps.extend(every);
|
||||
for (id, refs) in &selection.segments {
|
||||
steps.push(("select.segments".into(), json!({ "id": id.0, "segments": json_refs(&mut refs.iter()), "mode": "add" })));
|
||||
}
|
||||
steps
|
||||
};
|
||||
if !selection.guides.is_empty() {
|
||||
let indexes = cmd::guide_indexes(doc, &selection.guides);
|
||||
steps.push(("guide.select".into(), json!({ "indexes": indexes, "toggle": true })));
|
||||
}
|
||||
if let Some((id, (s, i))) = selection.key_anchor {
|
||||
steps.push(("select.key".into(), json!({ "id": id.0, "anchor": [s, i] })));
|
||||
} else if let Some(g) = selection.key_guide.and_then(|g| cmd::guide_indexes(doc, &[g]).first().copied()) {
|
||||
steps.push(("select.key".into(), json!({ "guide": g })));
|
||||
} else if let Some(key) = selection.key {
|
||||
steps.push(("select.key".into(), json!({ "id": key.0 })));
|
||||
}
|
||||
steps
|
||||
}
|
||||
@@ -59,6 +59,13 @@ impl Session {
|
||||
|
||||
/// Execute a command by id. This is THE entry point for every frontend.
|
||||
pub fn execute(&mut self, id: &str, params: &Value) -> Result<Value> {
|
||||
// Plug-ins still loading on other threads ([`Session::load_plugins_in_background`]) are
|
||||
// installed before a plug-in command, its own commands included, and before a command that
|
||||
// may edit, as they would have been before the window showed; a step of a batch waits for
|
||||
// the plug-ins an earlier step started loading.
|
||||
if self.plugins_loading() && crate::waits_for_plugin_loads(id) {
|
||||
self.finish_plugin_loads();
|
||||
}
|
||||
self.revealing(|s| s.execute_unwatched(id, params))
|
||||
}
|
||||
|
||||
@@ -99,10 +106,17 @@ impl Session {
|
||||
self.finish_tool_edit_later()?;
|
||||
}
|
||||
let outer = std::mem::replace(&mut self.reading, !spec.journal || JOURNALED_READS.contains(&id));
|
||||
// A command from outside the tool, while the tool's drag is in progress, is a step of its
|
||||
// own before the drag's ([`Session::outside_interaction`]). Find Objects with `select` is
|
||||
// journaled (`Session::journal_query`), so it is one too.
|
||||
let find_selects = id == "document.find" && params.get("select").and_then(Value::as_bool) == Some(true);
|
||||
let outside = (spec.journal || find_selects) && !self.previewing && !self.in_tool_actions;
|
||||
// A preview that a top-level command applied first (a drag with Real-time Drawing off, kept
|
||||
// before Undo) reports its warning in the command's result.
|
||||
let r = if self.depth == 0 {
|
||||
let (r, settled) = self.collect_settled_warnings(|s| s.execute_spec(spec, id, params));
|
||||
let (r, settled) = self.collect_settled_warnings(|s| {
|
||||
if outside { s.outside_interaction(id, params, |s| s.execute_spec(spec, id, params)) } else { s.execute_spec(spec, id, params) }
|
||||
});
|
||||
r.map(|v| with_settled_warnings(v, &settled))
|
||||
} else {
|
||||
self.execute_spec(spec, id, params)
|
||||
|
||||
Reference in new issue
Block a user