mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-10 18:10:01 -06:00
Type tool: Alt-click on a closed path makes area type too; type along a closed path stays with Type on a Path
This commit is contained in:
+10
-13
@@ -6,9 +6,8 @@
|
||||
//! the Type tool […] and click anywhere on the object's path", [Create text](https://web.archive.org/web/20220127090642/https://helpx.adobe.com/illustrator/using/creating-text.html);
|
||||
//! "To create horizontal text along a path, select the Type tool or the Type On A Path tool […] If
|
||||
//! the path is closed, rather than open, you must use the Type On A Path tool", [Create type on a
|
||||
//! path](https://web.archive.org/web/20220127000000/https://helpx.adobe.com/illustrator/using/creating-type-path.html)).
|
||||
//! Alt (Option) held over a closed path sets type along it instead: our own shortcut, so the Type
|
||||
//! tool reaches both without switching tools.
|
||||
//! path](https://web.archive.org/web/20220127000000/https://helpx.adobe.com/illustrator/using/creating-type-path.html)),
|
||||
//! Alt or not: type along a closed path stays with Type on a Path.
|
||||
//! Area Type / Type on a Path: click a path to turn it into a text frame or a baseline
|
||||
//! (`text.createInPath`). While type is being edited, a click that lands on no type only
|
||||
//! ends the editing, and the next click makes new type. Point type placed by a click and left
|
||||
@@ -186,8 +185,6 @@ pub struct TypeTool {
|
||||
drag: Option<Point>,
|
||||
/// The Type tool the press acts as, with the keys held at the press ([`Self::acting`]).
|
||||
held: Option<(Mode, bool)>,
|
||||
/// Alt (Option) was held at the press: the Type tool sets type along a closed path, not in it.
|
||||
held_alt: bool,
|
||||
/// Smart Guides for where new type goes.
|
||||
snap: DrawSnap,
|
||||
/// The press landed in the edited text: dragging selects.
|
||||
@@ -619,9 +616,10 @@ impl TypeTool {
|
||||
self.caret = r.end;
|
||||
}
|
||||
|
||||
/// The path whose outline is under `p`, and whether it is closed.
|
||||
/// The path whose outline is under `p`, and whether it is closed: within the isolated group
|
||||
/// being edited, and no guide while guides are hidden or locked ([`ToolContext::hit_options`]).
|
||||
fn path_at(cx: &ToolContext, p: Point) -> Option<(NodeId, bool)> {
|
||||
let h = hit_test(cx.doc, p, vectorcraft_doc::hit::HitOptions { tol: cx.tol(4.0), outline: true, ..Default::default() })?;
|
||||
let h = hit_test(cx.doc, p, vectorcraft_doc::hit::HitOptions { tol: cx.tol(4.0), outline: true, ..cx.hit_options() })?;
|
||||
match &cx.doc.node(h.leaf)?.kind {
|
||||
NodeKind::Path { path, .. } => Some((h.leaf, path.is_closed())),
|
||||
_ => None,
|
||||
@@ -630,12 +628,12 @@ impl TypeTool {
|
||||
|
||||
/// What a click at `p` with the tool acting as `mode` makes of the path there: the path, and
|
||||
/// whether the type goes along it (else inside it); None when it makes no type in a path. The
|
||||
/// Type tools set type inside a closed path and along an open one, or along a closed one with
|
||||
/// `alt`; Area Type needs a closed path and Type on a Path takes either.
|
||||
fn in_path(cx: &ToolContext, p: Point, mode: Mode, alt: bool) -> Option<(NodeId, bool)> {
|
||||
/// Type tools set type inside a closed path and along an open one; Area Type needs a closed
|
||||
/// path and Type on a Path takes either.
|
||||
fn in_path(cx: &ToolContext, p: Point, mode: Mode) -> Option<(NodeId, bool)> {
|
||||
let (id, closed) = Self::path_at(cx, p)?;
|
||||
match mode {
|
||||
Mode::Type => Some((id, alt || !closed)),
|
||||
Mode::Type => Some((id, !closed)),
|
||||
Mode::Area => closed.then_some((id, false)),
|
||||
Mode::OnPath => Some((id, true)),
|
||||
}
|
||||
@@ -662,7 +660,6 @@ impl TypeTool {
|
||||
/// (#2871). A drag that draws an area-type frame makes it either way.
|
||||
fn on_up(&mut self, cx: &ToolContext, start: Point, at: Point) -> Vec<Action> {
|
||||
let (mode, vertical) = self.held.take().unwrap_or((self.mode, self.vertical));
|
||||
let alt = std::mem::take(&mut self.held_alt);
|
||||
// Click into existing text: place the caret.
|
||||
if let Some(out) = self.edit_at(cx, start) {
|
||||
return out;
|
||||
@@ -686,7 +683,7 @@ impl TypeTool {
|
||||
}
|
||||
// A click on a path: type in it or along it.
|
||||
if drag.is_none()
|
||||
&& let Some((pid, on_path)) = Self::in_path(cx, start, mode, alt)
|
||||
&& let Some((pid, on_path)) = Self::in_path(cx, start, mode)
|
||||
{
|
||||
let mode = if on_path { "onPath" } else { "area" };
|
||||
out.push(Action::Exec(
|
||||
|
||||
Reference in New Issue
Block a user