Skip to content

Commit

Permalink
feat: keyboard paste at pointer position (#1311)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kneemund authored Dec 22, 2024
1 parent 0c0df2e commit 10e6d87
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
29 changes: 28 additions & 1 deletion crates/rnote-ui/src/appwindow/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use p2d::bounding_volume::BoundingVolume;
use rnote_compose::penevent::ShortcutKey;
use rnote_compose::SplitOrder;
use rnote_engine::engine::StrokeContent;
use rnote_engine::ext::GraphenePointExt;
use rnote_engine::pens::PenStyle;
use rnote_engine::strokes::resize::{ImageSizeOption, Resize};
use rnote_engine::{Camera, Engine};
Expand Down Expand Up @@ -1083,7 +1084,33 @@ impl RnAppWindow {
#[weak(rename_to=appwindow)]
self,
move |_, _| {
appwindow.clipboard_paste(None);
let Some(wrapper) = appwindow.active_tab_wrapper() else {
return;
};
let canvas = wrapper.canvas();

let pointer_pos = wrapper.pointer_pos().and_then(|wrapper_point| {
let canvas_point = wrapper
.compute_point(&canvas, &graphene::Point::from_na_vec(wrapper_point));

if let Some(point) = canvas_point {
let x = point.x() as f64;
let y = point.y() as f64;

if canvas.contains(x, y) {
let transformed_point =
(canvas.engine_ref().camera.transform().inverse()
* na::point![x, y])
.coords;

return Some(transformed_point);
}
}

return None;
});

appwindow.clipboard_paste(pointer_pos);
}
));

Expand Down
4 changes: 4 additions & 0 deletions crates/rnote-ui/src/canvaswrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,10 @@ impl RnCanvasWrapper {
self.set_property("inertial-scrolling", inertial_scrolling);
}

pub(crate) fn pointer_pos(&self) -> Option<na::Vector2<f64>> {
self.imp().pointer_pos.get()
}

pub(crate) fn last_contextmenu_pos(&self) -> Option<na::Vector2<f64>> {
self.imp().last_contextmenu_pos.get()
}
Expand Down

0 comments on commit 10e6d87

Please sign in to comment.