From 94a4aefa96a530b4779a7003bf876b7316be2f98 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Wed, 3 Jul 2024 10:19:03 +0200 Subject: [PATCH] Fix text selection when there's multiple viewports (#4760) * Closes https://github.com/emilk/egui/issues/4758 Thanks to @lukexor for finding and diagnosing the problem! --- crates/egui/src/context.rs | 6 +++++- crates/egui/src/text_selection/label_text_selection.rs | 6 ++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/crates/egui/src/context.rs b/crates/egui/src/context.rs index 4643b17d9315..8c08df68e91d 100644 --- a/crates/egui/src/context.rs +++ b/crates/egui/src/context.rs @@ -774,8 +774,11 @@ impl Context { /// ``` pub fn begin_frame(&self, new_input: RawInput) { crate::profile_function!(); - self.read(|ctx| ctx.plugins.clone()).on_begin_frame(self); + self.write(|ctx| ctx.begin_frame_mut(new_input)); + + // Plugs run just after the frame has started: + self.read(|ctx| ctx.plugins.clone()).on_begin_frame(self); } } @@ -1807,6 +1810,7 @@ impl Context { crate::gui_zoom::zoom_with_keyboard(self); } + // Plugins run just before the frame ends. self.read(|ctx| ctx.plugins.clone()).on_end_frame(self); #[cfg(debug_assertions)] diff --git a/crates/egui/src/text_selection/label_text_selection.rs b/crates/egui/src/text_selection/label_text_selection.rs index ec5a4729eeeb..7988820d6af5 100644 --- a/crates/egui/src/text_selection/label_text_selection.rs +++ b/crates/egui/src/text_selection/label_text_selection.rs @@ -154,13 +154,15 @@ impl LabelSelectionState { } pub fn load(ctx: &Context) -> Self { - ctx.data(|data| data.get_temp::(Id::NULL)) + let id = Id::new(ctx.viewport_id()); + ctx.data(|data| data.get_temp::(id)) .unwrap_or_default() } pub fn store(self, ctx: &Context) { + let id = Id::new(ctx.viewport_id()); ctx.data_mut(|data| { - data.insert_temp(Id::NULL, self); + data.insert_temp(id, self); }); }