Skip to content

Commit

Permalink
Fix text selection when there's multiple viewports (#4760)
Browse files Browse the repository at this point in the history
* Closes #4758

Thanks to @lukexor for finding and diagnosing the problem!
  • Loading branch information
emilk authored Jul 3, 2024
1 parent fcb7764 commit 1b06c69
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 5 additions & 1 deletion crates/egui/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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)]
Expand Down
6 changes: 4 additions & 2 deletions crates/egui/src/text_selection/label_text_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,15 @@ impl LabelSelectionState {
}

pub fn load(ctx: &Context) -> Self {
ctx.data(|data| data.get_temp::<Self>(Id::NULL))
let id = Id::new(ctx.viewport_id());
ctx.data(|data| data.get_temp::<Self>(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);
});
}

Expand Down

0 comments on commit 1b06c69

Please sign in to comment.