mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-10-14 19:27:04 -04:00
Select tool: a multi-click selects only on the frame egui reports it, so a cleared selection (or the highlighter's marked word) isn't selected again
The highlighter test now clicks at a human pace, with frames in between, which is what exposed it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
f46cf56be3
commit
be74e7b5b7
2 files changed
+14
-1
No files matched your search
@@ -2684,7 +2684,10 @@ pub fn document_area(app: &mut PdfCraftApp, index: usize, ui: &mut egui::Ui) {
|
||||
view.clicks = release_clicks;
|
||||
}
|
||||
let clicks = if view.clicks > 2 && tool != QuickTool::Select { 1 } else { view.clicks };
|
||||
if clicks >= 2 && over_text {
|
||||
// Only on the frame egui reports the multi-click: `view.clicks` outlives it, and
|
||||
// acting on every frame re-selected the word as soon as a selection was cleared
|
||||
// (a highlight made by the double-click left its word selected).
|
||||
if release_clicks > 0 && clicks >= 2 && over_text {
|
||||
if view.selection.is_none() {
|
||||
let span = text.nearest(vx, vy).and_then(|a| match clicks {
|
||||
2 => text.word_at(a),
|
||||
|
||||
@@ -77,6 +77,16 @@ fn quick_clicks_with_the_highlighter_mark_only_the_word() {
|
||||
let (mut h, at) = harness(|app| assert!(app.execute("comment.highlight")));
|
||||
for _ in 0..4 {
|
||||
click(&mut h, at);
|
||||
// The double-click's highlight re-renders the page; give its text layer up to 8 frames
|
||||
// to come back (still well inside egui's 0.3 s multi-click window at 1/60 s a frame), so
|
||||
// a loaded machine doesn't make the later clicks land on a page with no text yet.
|
||||
for _ in 0..8 {
|
||||
if !h.state().render_pending() {
|
||||
break;
|
||||
}
|
||||
std::thread::sleep(std::time::Duration::from_millis(20));
|
||||
h.run_steps(1);
|
||||
}
|
||||
}
|
||||
h.run_steps(3);
|
||||
// Under load the mark can land a few frames later; wait for it (egui's clock is fixed per
|
||||
|
||||
Reference in new issue
Block a user