* claim: #5855 * Ignore middle-click clipboard paste during navigation (#5855) Firefox on Linux sends a primary-selection paste event when the middle button orbits or pans. Paste events on frames where the middle button is pressed, held, or released no longer reach the design; Ctrl/Cmd+V still pastes.
This commit is contained in:
@@ -203,11 +203,16 @@ pub fn handle(app: &mut SolveApp, ctx: &egui::Context) {
|
||||
let mut copies = 0;
|
||||
let mut cuts = 0;
|
||||
let mut pastes = 0;
|
||||
// Firefox on Linux sends primary-selection Paste events during middle-click navigation.
|
||||
// Include release frames and clicks completed within one frame; explicit Ctrl/Cmd+V still works.
|
||||
let middle_navigation = i.pointer.button_down(egui::PointerButton::Middle)
|
||||
|| i.pointer.button_pressed(egui::PointerButton::Middle)
|
||||
|| i.pointer.button_released(egui::PointerButton::Middle);
|
||||
for e in &i.events {
|
||||
match e {
|
||||
egui::Event::Copy => copies += 1,
|
||||
egui::Event::Cut => cuts += 1,
|
||||
egui::Event::Paste(_) => pastes += 1,
|
||||
egui::Event::Paste(_) if !middle_navigation => pastes += 1,
|
||||
egui::Event::Key { key: egui::Key::C, pressed: true, modifiers, .. } if modifiers.command && !modifiers.shift && !modifiers.alt => {
|
||||
copies += 1
|
||||
}
|
||||
|
||||
@@ -48,6 +48,66 @@ fn start(h: &Harness, id: &str) -> Vec2 {
|
||||
sk.point(c.kind.point_ids()[0]).unwrap()
|
||||
}
|
||||
|
||||
fn clipboard_frame(h: &mut Harness, ctx: &egui::Context, events: Vec<egui::Event>) {
|
||||
let _ = ctx.run_ui(egui::RawInput { events, ..Default::default() }, |ui| super::handle(&mut h.app, ui.ctx()));
|
||||
}
|
||||
|
||||
fn middle_button(pressed: bool) -> egui::Event {
|
||||
egui::Event::PointerButton { pos: egui::pos2(500.0, 500.0), button: egui::PointerButton::Middle, pressed, modifiers: egui::Modifiers::NONE }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn middle_button_press_and_hold_do_not_paste() {
|
||||
let (mut h, _) = rectangle();
|
||||
assert!(super::copy(&mut h.app));
|
||||
let before = curves(&h);
|
||||
let undo = h.app.session.undo.len();
|
||||
let ctx = egui::Context::default();
|
||||
clipboard_frame(&mut h, &ctx, vec![middle_button(true), egui::Event::Paste("primary selection".into())]);
|
||||
assert_eq!(curves(&h), before, "middle-button press must only navigate");
|
||||
clipboard_frame(&mut h, &ctx, vec![egui::Event::Paste("primary selection".into())]);
|
||||
assert_eq!(curves(&h), before, "holding the middle button must only navigate");
|
||||
assert_eq!(h.app.session.undo.len(), undo);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn middle_button_release_and_single_frame_click_do_not_paste() {
|
||||
for single_frame in [false, true] {
|
||||
let (mut h, _) = rectangle();
|
||||
assert!(super::copy(&mut h.app));
|
||||
let before = curves(&h);
|
||||
let undo = h.app.session.undo.len();
|
||||
let ctx = egui::Context::default();
|
||||
let mut events = vec![middle_button(true)];
|
||||
if !single_frame {
|
||||
clipboard_frame(&mut h, &ctx, std::mem::take(&mut events));
|
||||
}
|
||||
events.extend([middle_button(false), egui::Event::Paste("primary selection".into())]);
|
||||
clipboard_frame(&mut h, &ctx, events);
|
||||
assert_eq!(curves(&h), before, "middle-button release must not paste (single frame: {single_frame})");
|
||||
assert_eq!(h.app.session.undo.len(), undo);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn keyboard_paste_still_works_with_and_without_middle_button() {
|
||||
for modifiers in [egui::Modifiers::CTRL | egui::Modifiers::COMMAND, egui::Modifiers::MAC_CMD | egui::Modifiers::COMMAND] {
|
||||
let (mut h, _) = rectangle();
|
||||
assert!(super::copy(&mut h.app));
|
||||
let before = curves(&h).len();
|
||||
let ctx = egui::Context::default();
|
||||
clipboard_frame(
|
||||
&mut h,
|
||||
&ctx,
|
||||
vec![middle_button(true), egui::Event::Key { key: egui::Key::V, physical_key: None, pressed: true, repeat: false, modifiers }],
|
||||
);
|
||||
assert_eq!(curves(&h).len(), before + 4, "explicit keyboard paste works while navigating");
|
||||
clipboard_frame(&mut h, &ctx, vec![middle_button(false)]);
|
||||
clipboard_frame(&mut h, &ctx, vec![egui::Event::Paste("keyboard clipboard".into())]);
|
||||
assert_eq!(curves(&h).len(), before + 8, "keyboard paste events work after navigation ends");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ctrl_c_ctrl_v_pastes_the_sketch_selection_at_the_cursor_selected_in_one_undo_step() {
|
||||
let (mut h, rect) = rectangle();
|
||||
|
||||
Reference in New Issue
Block a user