mirror of
https://github.com/storytold/designcraft.git
synced 2026-11-19 08:51:57 +01:00
fix(canvas): restart the text caret blink on typing, caret moves and clicks (#1953)
* fix(canvas): restart the text caret blink on typing, caret moves and clicks * fix(canvas): stop caret blink repaints in an unfocused window * Update crates/ui-egui/src/canvas/tests.rs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Apply review fixes - crates/ui-egui/src/canvas/input.rs - crates/ui-egui/src/canvas/text_overlay.rs * Apply review fixes - crates/ui-egui/src/canvas/input.rs - crates/ui-egui/src/canvas/text_overlay.rs * Fix failing CI check - crates/ui-egui/src/canvas/input.rs * remove focus guard and respective test --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: aiongg <67543387+aiongg@users.noreply.github.com>
This commit is contained in:
7 files changed
+91
-6
No files matched your search
@@ -452,6 +452,7 @@ Newest first.
|
||||
- **2026-10-28** · Discretionary hyphens (U+00AD) break in the single-line composer with automatic hyphenation on or off, matching the paragraph composer. Unbroken soft hyphens remain invisible and zero-width, and words containing them keep only their discretionary break points (#1955). No readiness percentage change.
|
||||
- **2026-10-28** · Autoflow no longer sizes the rest of a story by a frame that a Start Paragraph option (next column, frame, page, or odd or even page) ends early (#1209). With a title before a chapter that starts on the next odd page, it estimated a page per few characters, added up to 2000 pages (the autoflow limit) and removed them again: placing 2000 words took 36 s in the app, now 0.4 s, with the same pages. It looks past tracked-deleted paragraphs for the option, as composing does, and asks for every frame that start options and breaks force in one round: 200 one-line chapters on their own pages take 9 ms (58 ms before). A break and the start option it meets count once, and breaks that tracked changes delete or a hidden condition hides don't count. No readiness percentage change.
|
||||
- **2026-10-28** · IDML export writes the document's default `StoryPreference` in `Resources/Preferences.xml`, as InDesign does. Only each story carried one, and IDML readers that take the spread reading order from the document's (Okapi's IDML filter) failed on DesignCraft's files. No readiness percentage change.
|
||||
- **2026-10-28** · The text caret's blink restarts on typing, caret keys and canvas clicks, for story text and table cell or footnote text alike, so it never disappears under the user's hand; it repaints at each phase boundary instead of every 330 ms. No readiness percentage change.
|
||||
- **2026-10-27** · An iconic panel's flyout stays open while you work in the canvas or a text field: Auto-Collapse Iconic Panels is off by default, and preferences saved with it on start with it off. Preferences › Interface › Panels holds the setting next to the column bar's menu item. No readiness percentage change.
|
||||
- **2026-10-26** · Inner Shadow, Inner Glow (from the edges) and Bevel and Emboss on a frame holding an image follow what the image paints: a transparent part is outside the object, so the effect lines the image's opaque edge, not the frame (#1622). Satin and a centred Inner Glow still follow the frame. No readiness percentage change.
|
||||
- **2026-10-25** · Duplicate Layer (`layer.duplicate`; the layer's context menu in the Layers panel, or a layer dropped on Create New Layer) adds a copy named after the layer with " copy" added ("Art copy" for Art) above the layer, with its settings, a copy of every object on it and copies of its ruler guides, on document and parent pages, in one undo step. Copied frames stay threaded to the copies of frames on the same layer and are not threaded to frames on other layers. A copied override of a parent item overrides that item's copy, and pages hide the copy where they hide the parent item. Hyperlinks on copied objects and text get copies that go to the same destinations. No readiness percentage change.
|
||||
|
||||
@@ -92,5 +92,8 @@ display_name = "Jonathan Cardoso"
|
||||
real_name = "Adithya Shankaran"
|
||||
sync_github_name = true
|
||||
|
||||
[people.alejo-c]
|
||||
sync_github_name = true
|
||||
|
||||
[people.gmrmad1]
|
||||
real_name = "Madhav Agarwal"
|
||||
@@ -14,6 +14,7 @@ use serde_json::{Value, json};
|
||||
|
||||
use crate::{DesignApp, ScreenMode, View, theme::Tokens};
|
||||
|
||||
mod caret;
|
||||
mod column_guides;
|
||||
mod frames;
|
||||
mod guides;
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
//! One blink phase for the text caret: the story, table cell and footnote carets share it.
|
||||
|
||||
use designcraft_doc::TextSel;
|
||||
|
||||
const BLINK_HZ: f64 = 1.6;
|
||||
|
||||
fn start_id() -> egui::Id {
|
||||
egui::Id::unique("canvas_caret_blink_start")
|
||||
}
|
||||
|
||||
fn caret_id() -> egui::Id {
|
||||
egui::Id::unique("canvas_caret_blink_caret")
|
||||
}
|
||||
|
||||
pub(super) fn reset(ctx: &egui::Context) {
|
||||
let now = ctx.input(|i| i.time);
|
||||
ctx.data_mut(|d| d.insert_temp(start_id(), now));
|
||||
}
|
||||
|
||||
pub(super) fn visible(ctx: &egui::Context, caret: TextSel) -> bool {
|
||||
let now = ctx.input(|i| i.time);
|
||||
let start = ctx.data_mut(|d| match (d.get_temp::<f64>(start_id()), d.get_temp::<TextSel>(caret_id())) {
|
||||
(Some(start), Some(last)) if last == caret => start,
|
||||
_ => {
|
||||
d.insert_temp(start_id(), now);
|
||||
d.insert_temp(caret_id(), caret);
|
||||
now
|
||||
}
|
||||
});
|
||||
|
||||
let phase = (now - start) * BLINK_HZ;
|
||||
let wait = until_flip(phase);
|
||||
|
||||
if wait.is_finite() {
|
||||
ctx.request_repaint_after(std::time::Duration::from_secs_f64(wait));
|
||||
}
|
||||
phase as i64 % 2 == 0
|
||||
}
|
||||
|
||||
pub(super) fn until_flip(phase: f64) -> f64 {
|
||||
(1.0 - phase.rem_euclid(1.0)) / BLINK_HZ
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
use super::caret;
|
||||
use super::column_guides::{COLUMN_DRAG, ColumnDrag, column_guide_drag};
|
||||
use super::guides::guide_drag;
|
||||
use super::ime::{finish_pending_ime_delete, ime_event};
|
||||
@@ -298,6 +299,13 @@ fn note_release(ui: &egui::Ui, clicks_id: egui::Id, latest: Option<Pos2>, now: f
|
||||
}
|
||||
}
|
||||
|
||||
/// Typing, IME input, a paste or a key press restarts the caret's blink.
|
||||
fn restart_caret_blink(ctx: &egui::Context, e: &egui::Event) {
|
||||
if matches!(e, egui::Event::Text(_) | egui::Event::Ime(_) | egui::Event::Paste(_) | egui::Event::Key { pressed: true, .. }) {
|
||||
caret::reset(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
/// Give an open menu priority, then handle wheel/zoom/pan, spring Zoom, guide drags and primary pointer routing.
|
||||
pub(super) fn handle_input(app: &mut DesignApp, ui: &mut egui::Ui, resp: &egui::Response, rect: Rect) {
|
||||
// While a context menu is open (in either pane), the click that closes it and the keys go to the menu.
|
||||
@@ -348,6 +356,7 @@ pub(super) fn handle_input(app: &mut DesignApp, ui: &mut egui::Ui, resp: &egui::
|
||||
let (delay, dist) = ui.ctx().options(|o| (o.input_options.max_double_click_delay, o.input_options.max_click_dist));
|
||||
let n = press_count(ui.data(|d| d.get_temp(clicks_id)), o, now, delay, dist);
|
||||
ui.data_mut(|d| d.insert_temp(clicks_id, Clicks { at: f64::NEG_INFINITY, pos: o, n }));
|
||||
caret::reset(ui.ctx());
|
||||
events.push(PointerEvent { kind: PointerKind::Down, pos: pos(o), mods: m, clicks: n });
|
||||
down = true;
|
||||
}
|
||||
@@ -420,6 +429,7 @@ pub(super) fn handle_input(app: &mut DesignApp, ui: &mut egui::Ui, resp: &egui::
|
||||
let mut held =
|
||||
ui.data(|d| d.get_temp::<(egui::Modifiers, egui::Modifiers)>(modifiers_id())).map_or_else(|| ui.input(|i| i.modifiers), |(start, _)| start);
|
||||
for e in evs {
|
||||
restart_caret_blink(ui.ctx(), &e);
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
let chord = {
|
||||
if let egui::Event::ModifiersChanged(m) = &e {
|
||||
|
||||
@@ -3441,6 +3441,37 @@ fn table_cells_show_their_hidden_characters() {
|
||||
assert_eq!((last.0, last.1), (designcraft_geom::Point::new(frag.rect.x1 + 1.0, frag.rect.y1), "¶"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_caret_blink_restarts_on_input_and_caret_changes() {
|
||||
let ctx = egui::Context::default();
|
||||
let caret = designcraft_doc::TextSel::caret(designcraft_doc::StoryId(1), 7);
|
||||
|
||||
let shown = |t: f64, caret: designcraft_doc::TextSel, reset: bool| {
|
||||
let mut visible = false;
|
||||
|
||||
let mut out = ctx.run_ui(egui::RawInput { time: Some(t), ..Default::default() }, |ui| {
|
||||
if reset {
|
||||
caret::reset(ui.ctx());
|
||||
}
|
||||
visible = caret::visible(ui.ctx(), caret);
|
||||
});
|
||||
out.textures_delta.clear();
|
||||
visible
|
||||
};
|
||||
assert!(shown(10.0, caret, true), "a reset shows the caret");
|
||||
assert!(shown(10.5, caret, false), "the first half is on");
|
||||
assert!(!shown(10.7, caret, false), "the second half is off");
|
||||
assert!(shown(11.3, caret, false), "the next cycle is on");
|
||||
assert!(shown(10.7, caret, true), "typing shows it again");
|
||||
assert!(!shown(11.4, caret, false), "and its phase follows the reset");
|
||||
|
||||
let moved = designcraft_doc::TextSel::caret(designcraft_doc::StoryId(1), 8);
|
||||
assert!(shown(11.4, moved, false), "a caret that moved shows at once");
|
||||
assert!((caret::until_flip(0.0) - 0.625).abs() < 1e-9);
|
||||
assert!((caret::until_flip(0.96) - 0.025).abs() < 1e-9);
|
||||
assert!((caret::until_flip(1.0) - 0.625).abs() < 1e-9);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn leaving_parent_editing_for_the_left_page_of_a_spread_keeps_that_page_selected() {
|
||||
let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use super::caret;
|
||||
use super::frames::{item_canvas_xf, layer_color, path_screen};
|
||||
use super::{Affine, CanvasLayout, Color32, DesignApp, Document, Point, Pos2, Rect, Stroke, Xf, compose, pos2};
|
||||
|
||||
@@ -113,11 +114,9 @@ pub(super) fn draw_text_selection(
|
||||
let on = |p: Point| compose::PathTextMap::new(it, ft).map_or(p, |map| map.to_path(p));
|
||||
let p0 = xf.to_screen(m * on(Point::new(x, bl - asc)));
|
||||
let p1 = xf.to_screen(m * on(Point::new(x, bl + desc)));
|
||||
let blink = (painter.ctx().input(|i| i.time) * 1.6) as i64 % 2 == 0;
|
||||
if blink {
|
||||
if caret::visible(painter.ctx(), ts) {
|
||||
painter.line_segment([p0, p1], Stroke::new(1.0, Color32::BLACK));
|
||||
}
|
||||
painter.ctx().request_repaint_after(std::time::Duration::from_millis(330));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,11 +166,9 @@ fn draw_cell_selection(
|
||||
{
|
||||
let m = a * doc.text_xf(it);
|
||||
let (p0, p1) = (xf.to_screen(m * Point::new(x, bl - asc)), xf.to_screen(m * Point::new(x, bl + desc)));
|
||||
let blink = (painter.ctx().input(|i| i.time) * 1.6) as i64 % 2 == 0;
|
||||
if blink {
|
||||
if caret::visible(painter.ctx(), ts) {
|
||||
painter.line_segment([p0, p1], Stroke::new(1.0, Color32::BLACK));
|
||||
}
|
||||
painter.ctx().request_repaint_after(std::time::Duration::from_millis(330));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user