Skip to content

Commit 10c8ffa

Browse files
Fix to limit X position of text agent to client width (#870)
1 parent 83e490f commit 10c8ffa

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

egui_web/src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1217,13 +1217,13 @@ fn move_text_cursor(cursor: &Option<egui::Pos2>, canvas_id: &str) -> Option<()>
12171217
if is_mobile() == Some(false) {
12181218
cursor.as_ref().and_then(|&egui::Pos2 { x, y }| {
12191219
let canvas = canvas_element(canvas_id)?;
1220-
let y = (y + (canvas.scroll_top() + canvas.offset_top()) as f32).min(
1221-
canvas.client_height() as f32
1222-
- text_agent().get_bounding_client_rect().height() as f32,
1223-
);
1220+
let bounding_rect = text_agent().get_bounding_client_rect();
1221+
let y = (y + (canvas.scroll_top() + canvas.offset_top()) as f32)
1222+
.min(canvas.client_height() as f32 - bounding_rect.height() as f32);
12241223
let x = x + (canvas.scroll_left() + canvas.offset_left()) as f32;
12251224
// Canvas is translated 50% horizontally in html.
1226-
let x = x - canvas.offset_width() as f32 / 2.0;
1225+
let x = (x - canvas.offset_width() as f32 / 2.0)
1226+
.min(canvas.client_width() as f32 - bounding_rect.width() as f32);
12271227
style.set_property("position", "absolute").ok()?;
12281228
style.set_property("top", &(y.to_string() + "px")).ok()?;
12291229
style.set_property("left", &(x.to_string() + "px")).ok()

0 commit comments

Comments
 (0)