Repository: neovim/neovim
File: src/nvim/ui.c (C)

Code before:
  win_ui_flush(false);
  // Avoid flushing callbacks expected to change text during textlock.
  if (textlock == 0 && expr_map_lock == 0) {
    cmdline_ui_flush();
    msg_ext_ui_flush();
  }
  msg_scroll_flush();

  if (pending_cursor_update) {
    ui_call_grid_cursor_goto(cursor_grid_handle, cursor_row, cursor_col);
    pending_cursor_update = false;
    // The cursor move might change the composition order,
    // so flush again to update the windows that changed
    // TODO(bfredl): refactor the flow of information so that win_ui_flush()
    // only is called once. (as order state is exposed, it should be owned
    // by nvim core, not the compositor)
    win_ui_flush(false);
  }

  if (ui_comp_should_draw() && !(State & MODE_CMDLINE)) {
    int crow = curwin->w_winrow + curwin->w_winrow_off + curwin->w_wrow;
    int ccol = curwin->w_wincol + curwin->w_wincol_off +
               (curwin->w_p_rl ? curwin->w_view_width - curwin->w_wcol - 1 : curwin->w_wcol);
    if (curwin->w_cursor.coladd > 0) {
      ccol += curwin->w_cursor.coladd;
    }
    ScreenGrid *top_grid = ui_comp_get_grid_at_coord(crow, ccol);
    win_T *wp = (top_grid && top_grid != &curwin->w_grid_alloc
                 && top_grid != &default_grid) ? get_win_by_grid_handle(top_grid->handle) : NULL;
    int cur_z = curwin->w_floating ? curwin->w_config.zindex : 0;
    bool cursor_obscured = wp && wp->w_floating && wp->w_config.zindex > cur_z;

    int new_idx = cursor_obscured ? SHAPE_IDX_R : cursor_get_mode_idx();
    if (ui_mode_idx != new_idx) {
      ui_mode_idx = new_idx;
      pending_mode_update = true;
    }
  }

  if (pending_mode_info_update) {
    Arena arena = ARENA_EMPTY;
    Array style = mode_style_array(&arena);
    bool enabled = (*p_guicursor != NUL);
    ui_call_mode_info_set(enabled, style);
    arena_mem_free(arena_finish(&arena));
    pending_mode_info_update = false;
  }
  if (pending_mode_update && !starting) {
    char *full_name = shape_table[ui_mode_idx].full_name;
    ui_call_mode_change(cstr_as_string(full_name), ui_mode_idx);
    pending_mode_update = false;

Review comment (bug):
```suggestion
```

Why was this added? This fails [my prior example](https://github.com/neovim/neovim/pull/37624#discussion_r2758457545) and should have failed CI if it's including it.

Code after:
  win_ui_flush(false);
  // Avoid flushing callbacks expected to change text during textlock.
  if (textlock == 0 && expr_map_lock == 0) {
    cmdline_ui_flush();
    msg_ext_ui_flush();
  }
  msg_scroll_flush();

  if (pending_cursor_update) {
    ui_call_grid_cursor_goto(cursor_grid_handle, cursor_row, cursor_col);
    pending_cursor_update = false;
    // The cursor move might change the composition order,
    // so flush again to update the windows that changed
    // TODO(bfredl): refactor the flow of information so that win_ui_flush()
    // only is called once. (as order state is exposed, it should be owned
    // by nvim core, not the compositor)
    win_ui_flush(false);
  }

  // Show "empty box" (underline style) cursor if behind a floatwin.
  if (!(State & MODE_CMDLINE)) {
    bool cursor_obscured = ui_cursor_is_behind_floatwin();
    int new_idx = cursor_obscured ? SHAPE_IDX_R : cursor_get_mode_idx();
    if (ui_mode_idx != new_idx) {
      ui_mode_idx = new_idx;
      pending_mode_update = true;
    }
  }

  if (pending_mode_info_update) {
    Arena arena = ARENA_EMPTY;
    Array style = mode_style_array(&arena);
    bool enabled = (*p_guicursor != NUL);
    ui_call_mode_info_set(enabled, style);
    arena_mem_free(arena_finish(&arena));
    pending_mode_info_update = false;
  }
  if (pending_mode_update && !starting) {
    char *full_name = shape_table[ui_mode_idx].full_name;
    ui_call_mode_change(cstr_as_string(full_name), ui_mode_idx);
    pending_mode_update = false;
  }
  if (pending_has_mouse != has_mouse) {
    (has_mouse ? ui_call_mouse_on : ui_call_mouse_off)();
    pending_has_mouse = has_mouse;
  }
  ui_call_flush();

  if (p_wd && (rdb_flags & kOptRdbFlagFlush)) {
    os_sleep((uint64_t)llabs(p_wd));
  }