diff --git a/glfw/ibus_glfw.c b/glfw/ibus_glfw.c index 0d33970fd..4f2425d30 100644 --- a/glfw/ibus_glfw.c +++ b/glfw/ibus_glfw.c @@ -494,6 +494,15 @@ glfw_ibus_set_focused(_GLFWIBUSData *ibus, bool focused) { void glfw_ibus_set_cursor_geometry(_GLFWIBUSData *ibus, int x, int y, int w, int h) { + // Skip duplicate updates (e.g. pre-edit text changes while the anchor + // cell is unchanged) so the IME candidate window is not needlessly + // repositioned. Mirrors the dedup in wl_text_input.c. + static int last_x = INT_MIN, last_y = INT_MIN, last_w = INT_MIN, last_h = INT_MIN; + if (x == last_x && y == last_y && w == last_w && h == last_h) return; + last_x = x; + last_y = y; + last_w = w; + last_h = h; if (check_connection(ibus)) { glfw_dbus_call_method_no_reply( ibus->conn, diff --git a/kitty/keys.c b/kitty/keys.c index 8e7edf98e..14153968f 100644 --- a/kitty/keys.c +++ b/kitty/keys.c @@ -150,7 +150,9 @@ prepare_ime_position_update_event(OSWindow *osw, Window *w, Screen *screen, GLFW unsigned int cell_width = osw->fonts_data->fcm.cell_width, cell_height = osw->fonts_data->fcm.cell_height; unsigned int left = w->render_data.geometry.left, top = w->render_data.geometry.top; if (screen_is_overlay_active(screen)) { - left += screen->overlay_line.cursor_x * cell_width; + // Anchor to the start of the pre-edit text rather than its end, so the + // IME candidate window does not jump horizontally as the pre-edit grows. + left += screen->overlay_line.xstart * cell_width; top += MIN(screen->overlay_line.ynum + screen->scrolled_by, screen->lines - 1) * cell_height; } else { left += screen->cursor->x * cell_width; diff --git a/kitty/screen.c b/kitty/screen.c index 00a4f9431..b6639f691 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -5156,8 +5156,11 @@ render_overlay_line(Screen *self, Line *line, FONTS_DATA_HANDLE fonts_data) { line_reset_cells(line, 0, line->xnum, ol.original_line.gpu_cells, ol.original_line.cpu_cells); ol.is_dirty = false; const index_type y = MIN(ol.ynum + self->scrolled_by, self->lines - 1); - if (ol.last_ime_pos.x != ol.cursor_x || ol.last_ime_pos.y != y) { - ol.last_ime_pos.x = ol.cursor_x; + // Track the start of the pre-edit text, not its end, so IME position + // updates are not sent as the pre-edit grows, which would make the IME + // candidate window jump horizontally while typing. + if (ol.last_ime_pos.x != ol.xstart || ol.last_ime_pos.y != y) { + ol.last_ime_pos.x = ol.xstart; ol.last_ime_pos.y = y; update_ime_position_for_window(self->window_id, false, 0); }