mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-18 07:49:26 +00:00
Type: stop a text edit when typing in progress can't be kept
When the typing Real-time Drawing off leaves unapplied can't be kept, the Character, Paragraph and Tabs panel edits, Kerning, the Variable Font sliders, Justification, Bullets and Numbering, Tate-chu-yoko, Warichu and Underline now stop with the error instead of acting on a selection read in the text without the typing. Underline reports a failed format instead of the new state.
This commit is contained in:
@@ -85,7 +85,7 @@ pub fn open(app: &mut VectorcraftApp, p: &Value) -> Result<Value, String> {
|
||||
crate::panels::character::text_style(app).ok_or("select some type first")?;
|
||||
// While typing, the dialog acts on the paragraphs of the text being edited.
|
||||
let mut targets = json!({});
|
||||
if let Some((id, a, b)) = crate::panels::character::text_editing_kept(app) {
|
||||
if let Some((id, a, b)) = crate::panels::character::text_editing_kept(app)? {
|
||||
targets = json!({"ids": [id.0], "start": a, "end": b});
|
||||
}
|
||||
let mut values = Map::new();
|
||||
|
||||
@@ -92,7 +92,7 @@ pub fn open(app: &mut VectorcraftApp) -> Result<Value, String> {
|
||||
// While typing, the dialog acts on the paragraphs of the text being edited.
|
||||
let mut targets = json!({});
|
||||
let mut story = None;
|
||||
if let Some((id, a, b)) = crate::panels::character::text_editing_kept(app) {
|
||||
if let Some((id, a, b)) = crate::panels::character::text_editing_kept(app)? {
|
||||
targets = json!({"ids": [id.0], "start": a, "end": b});
|
||||
// After Select All in threaded text: every paragraph of every frame ([`params`]).
|
||||
story = crate::panels::character::text_story(app).map(|_| id.0);
|
||||
|
||||
@@ -263,7 +263,7 @@ pub(crate) fn format(app: &mut VectorcraftApp, p: Value) {
|
||||
/// has selected (the whole text when nothing is selected) while it edits text, else
|
||||
/// `text.setFormat` on the selected stories ([`selected_stories`]).
|
||||
pub(crate) fn run_format(app: &mut VectorcraftApp, mut p: Value) -> Result<Value, String> {
|
||||
let Some((id, a, b)) = text_editing_kept(app) else {
|
||||
let Some((id, a, b)) = text_editing_kept(app)? else {
|
||||
target_selected_stories(app, &mut p);
|
||||
return app.run("text.setFormat", p);
|
||||
};
|
||||
@@ -320,7 +320,8 @@ fn char_cmd(app: &mut VectorcraftApp, cmd: &str, mut p: Value) {
|
||||
/// and Optical set no space (#5111); nowhere to set at an empty line's start. Else it is a
|
||||
/// character attribute like the others: the selected range, or all the text.
|
||||
fn set_kerning(app: &mut VectorcraftApp, value: Value) {
|
||||
let Some((id, a, b)) = text_editing_kept(app) else {
|
||||
let Ok(editing) = text_editing_kept(app) else { return };
|
||||
let Some((id, a, b)) = editing else {
|
||||
format(app, json!({"kerning": value}));
|
||||
return;
|
||||
};
|
||||
@@ -517,14 +518,14 @@ pub(crate) fn highlight(app: &mut VectorcraftApp, field: Field) -> Result<Value,
|
||||
pub(crate) fn toggle_underline(app: &mut VectorcraftApp) -> Result<Value, String> {
|
||||
text_style(app).ok_or("select some type first")?;
|
||||
let on = shared(app, |s| s.underline) != Some(true);
|
||||
format(app, json!({"underline": on}));
|
||||
run_format(app, json!({"underline": on}))?;
|
||||
Ok(json!(on))
|
||||
}
|
||||
|
||||
/// `text.setRangeStyle` with `p` on the range the Type tool has selected (the whole text when
|
||||
/// nothing is selected). Does nothing unless the Type tool edits text.
|
||||
pub(crate) fn range_style(app: &mut VectorcraftApp, p: Value) {
|
||||
let Some((id, a, b)) = text_editing_kept(app) else { return };
|
||||
let Ok(Some((id, a, b))) = text_editing_kept(app) else { return };
|
||||
if let Some(first) = text_story(app).and_then(|story| story.first().copied()) {
|
||||
story_style(app, first, p).ok();
|
||||
return;
|
||||
@@ -553,10 +554,12 @@ pub(crate) fn text_editing(app: &VectorcraftApp) -> Option<(NodeId, usize, usize
|
||||
}
|
||||
|
||||
/// [`text_editing`] after [`end_typing`], for an edit of the text: the selection is read in the
|
||||
/// text with the typing applied, which Real-time Drawing off leaves unapplied until then.
|
||||
pub(crate) fn text_editing_kept(app: &mut VectorcraftApp) -> Option<(NodeId, usize, usize)> {
|
||||
end_typing(app);
|
||||
text_editing(app)
|
||||
/// text with the typing applied, which Real-time Drawing off leaves unapplied until then. When the
|
||||
/// typing can't be kept, the error (also shown in the status bar), so the edit stops instead of
|
||||
/// acting on a selection in the text without the typing.
|
||||
pub(crate) fn text_editing_kept(app: &mut VectorcraftApp) -> Result<Option<(NodeId, usize, usize)>, String> {
|
||||
try_end_typing(app)?;
|
||||
Ok(text_editing(app))
|
||||
}
|
||||
|
||||
/// The frames of the threaded story whose whole text the Type tool has selected after Select All,
|
||||
@@ -635,15 +638,21 @@ fn story_style(app: &mut VectorcraftApp, first: NodeId, mut p: Value) -> Result<
|
||||
/// typing Real-time Drawing off left unapplied is applied first; when it can't be kept, the error
|
||||
/// shows and the session goes on.
|
||||
pub(crate) fn end_typing(app: &mut VectorcraftApp) {
|
||||
try_end_typing(app).ok();
|
||||
}
|
||||
|
||||
/// [`end_typing`] that also returns the error when the typing can't be kept.
|
||||
fn try_end_typing(app: &mut VectorcraftApp) -> Result<(), String> {
|
||||
if app.session.tool_options().get("typing").and_then(Value::as_bool) == Some(true) {
|
||||
if let Err(e) = app.keep_typing() {
|
||||
app.status(e);
|
||||
return;
|
||||
app.status(e.clone());
|
||||
return Err(e);
|
||||
}
|
||||
app.session.set_tool_option("commitTyping", &json!(true));
|
||||
app.session.commit_interaction().ok();
|
||||
app.sync_views();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
static CTX: OnceLock<egui::Context> = OnceLock::new();
|
||||
@@ -1236,7 +1245,9 @@ pub(crate) fn axis_sliders(app: &mut VectorcraftApp, ui: &mut Ui, face: &vectorc
|
||||
/// Set Variable Font settings `axes` on the text the panel acts on, live while a slider drags.
|
||||
fn axes_cmd(app: &mut VectorcraftApp, axes: Value, phase: widgets::Live) {
|
||||
match text_editing_kept(app) {
|
||||
Some((id, a, b)) => {
|
||||
// The typing can't be kept (the error shows): nothing is set.
|
||||
Err(_) => {}
|
||||
Ok(Some((id, a, b))) => {
|
||||
let mut q = json!({"id": id.0, "fontAxes": axes});
|
||||
// After Select All in threaded text: every frame of the story.
|
||||
if let Some(first) = text_story(app).and_then(|story| story.first().copied()) {
|
||||
@@ -1248,7 +1259,7 @@ fn axes_cmd(app: &mut VectorcraftApp, axes: Value, phase: widgets::Live) {
|
||||
}
|
||||
super::live_run(app, "Character", "text.setRangeStyle", q, phase);
|
||||
}
|
||||
None => {
|
||||
Ok(None) => {
|
||||
let mut p = json!({ "fontAxes": axes });
|
||||
target_selected_stories(app, &mut p);
|
||||
super::live_run(app, "Character", "text.setFormat", p, phase);
|
||||
|
||||
@@ -80,7 +80,7 @@ fn para_cmd(app: &mut VectorcraftApp, cmd: &str, p: Value) {
|
||||
/// the Selection tool these are the paragraphs of every frame of the selected stories
|
||||
/// ([`super::character::selected_stories`]).
|
||||
pub(crate) fn run_on_paragraphs(app: &mut VectorcraftApp, cmd: &str, mut p: Value) -> Result<Value, String> {
|
||||
if let Some((id, a, b)) = super::character::text_editing_kept(app) {
|
||||
if let Some((id, a, b)) = super::character::text_editing_kept(app)? {
|
||||
match super::character::text_story(app) {
|
||||
// After Select All in threaded text: every paragraph of every frame.
|
||||
Some(story) => p["ids"] = json!(story.iter().map(|f| f.0).collect::<Vec<_>>()),
|
||||
|
||||
@@ -423,7 +423,8 @@ fn stops_json(stops: &[TabStop]) -> Value {
|
||||
/// frame of the selected stories ([`super::character::selected_stories`]). Returns false when it
|
||||
/// fails.
|
||||
fn apply(app: &mut VectorcraftApp, stops: &[TabStop]) -> bool {
|
||||
if let Some((id, a, b)) = super::character::text_editing_kept(app) {
|
||||
let Ok(editing) = super::character::text_editing_kept(app) else { return false };
|
||||
if let Some((id, a, b)) = editing {
|
||||
let p = match super::character::text_story(app) {
|
||||
// After Select All in threaded text: every paragraph of every frame.
|
||||
Some(story) => json!({"stops": stops_json(stops), "ids": story.iter().map(|f| f.0).collect::<Vec<_>>()}),
|
||||
|
||||
Reference in New Issue
Block a user