Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix problem clicking the edge of a TextEdit #4272

Merged
merged 1 commit into from
Mar 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions crates/egui/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1113,8 +1113,6 @@ impl Context {
changed: false,
};

let clicked_elsewhere = res.clicked_elsewhere();
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bug was that this was called too early.


self.write(|ctx| {
let viewport = ctx.viewports.entry(ctx.viewport_id()).or_default();

Expand Down Expand Up @@ -1157,15 +1155,22 @@ impl Context {
}

let clicked = Some(id) == viewport.interact_widgets.clicked;
let mut any_press = false;

for pointer_event in &input.pointer.pointer_events {
if let PointerEvent::Released { click, .. } = pointer_event {
if enabled && sense.click && clicked && click.is_some() {
res.clicked = true;
match pointer_event {
PointerEvent::Moved(_) => {}
PointerEvent::Pressed { .. } => {
any_press = true;
}
PointerEvent::Released { click, .. } => {
if enabled && sense.click && clicked && click.is_some() {
res.clicked = true;
}

res.is_pointer_button_down_on = false;
res.dragged = false;
res.is_pointer_button_down_on = false;
res.dragged = false;
}
}
}

Expand All @@ -1188,14 +1193,10 @@ impl Context {
res.hovered = false;
}

if clicked_elsewhere && memory.has_focus(id) {
let pointer_pressed_elsewhere = any_press && !res.hovered;
if pointer_pressed_elsewhere && memory.has_focus(id) {
memory.surrender_focus(id);
}

if res.dragged() && !memory.has_focus(id) {
// e.g.: remove focus from a widget when you drag something else
memory.stop_text_input();
}
});

res
Expand Down
Loading