diff options
author | glepnir <glephunter@gmail.com> | 2024-12-12 18:45:57 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-12 02:45:57 -0800 |
commit | 17383870dd3b7f04eddd48ed929cc25c7e102277 (patch) | |
tree | c23df9162c2e9ab174ad628c4a475f788555bc44 /src | |
parent | de794f2d24099b73419ce2cd98424f702908040f (diff) | |
download | rneovim-17383870dd3b7f04eddd48ed929cc25c7e102277.tar.gz rneovim-17383870dd3b7f04eddd48ed929cc25c7e102277.tar.bz2 rneovim-17383870dd3b7f04eddd48ed929cc25c7e102277.zip |
fix(float): re-sort layers when grid zindex changed #30259
Problem: when zindex is changed in vim.schedule the zindex sort in
layers not changed.
Solution: resort layers when zindex changed.
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/ui_compositor.c | 29 | ||||
-rw-r--r-- | src/nvim/window.c | 6 |
2 files changed, 35 insertions, 0 deletions
diff --git a/src/nvim/ui_compositor.c b/src/nvim/ui_compositor.c index 4cddc3dc82..38d882462d 100644 --- a/src/nvim/ui_compositor.c +++ b/src/nvim/ui_compositor.c @@ -101,6 +101,35 @@ bool ui_comp_should_draw(void) return composed_uis != 0 && valid_screen; } +/// Raises or lowers the layer, syncing comp_index with zindex. +/// +/// This function adjusts the position of a layer in the layers array +/// based on its zindex, either raising or lowering it. +/// +/// @param[in] layer_idx Index of the layer to be raised or lowered. +/// @param[in] raise Raise the layer if true, else lower it. +void ui_comp_layers_adjust(size_t layer_idx, bool raise) +{ + size_t size = layers.size; + ScreenGrid *layer = layers.items[layer_idx]; + + if (raise) { + while (layer_idx < size - 1 && layer->zindex > layers.items[layer_idx + 1]->zindex) { + layers.items[layer_idx] = layers.items[layer_idx + 1]; + layers.items[layer_idx]->comp_index = layer_idx; + layer_idx++; + } + } else { + while (layer_idx > 0 && layer->zindex < layers.items[layer_idx - 1]->zindex) { + layers.items[layer_idx] = layers.items[layer_idx - 1]; + layers.items[layer_idx]->comp_index = layer_idx; + layer_idx--; + } + } + layers.items[layer_idx] = layer; + layer->comp_index = layer_idx; +} + /// Places `grid` at (col,row) position with (width * height) size. /// Adds `grid` as the top layer if it is a new layer. /// diff --git a/src/nvim/window.c b/src/nvim/window.c index 79c3ce9304..938d9d7618 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -852,7 +852,13 @@ void ui_ext_win_position(win_T *wp, bool validate) } } + bool resort = wp->w_grid_alloc.comp_index != 0 + && wp->w_grid_alloc.zindex != wp->w_config.zindex; + bool raise = resort && wp->w_grid_alloc.zindex < wp->w_config.zindex; wp->w_grid_alloc.zindex = wp->w_config.zindex; + if (resort) { + ui_comp_layers_adjust(wp->w_grid_alloc.comp_index, raise); + } if (ui_has(kUIMultigrid)) { String anchor = cstr_as_string(float_anchor_str[c.anchor]); if (!c.hide) { |