mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge pull request #26381 from bfredl/delaycolors
fix(startup): only send one default_colors_set event during startup
This commit is contained in:
commit
8bb5089974
@ -63,6 +63,7 @@ bool ui_cb_ext[kUIExtCount]; ///< Internalized UI capabilities.
|
||||
|
||||
static bool has_mouse = false;
|
||||
static int pending_has_mouse = -1;
|
||||
static bool pending_default_colors = false;
|
||||
|
||||
static Array call_buf = ARRAY_DICT_INIT;
|
||||
|
||||
@ -283,8 +284,21 @@ void ui_schedule_refresh(void)
|
||||
|
||||
void ui_default_colors_set(void)
|
||||
{
|
||||
ui_call_default_colors_set(normal_fg, normal_bg, normal_sp,
|
||||
cterm_normal_fg_color, cterm_normal_bg_color);
|
||||
// Throttle setting of default colors at startup, so it only happens once
|
||||
// if the user sets the colorscheme in startup.
|
||||
pending_default_colors = true;
|
||||
if (starting == 0) {
|
||||
ui_may_set_default_colors();
|
||||
}
|
||||
}
|
||||
|
||||
static void ui_may_set_default_colors(void)
|
||||
{
|
||||
if (pending_default_colors) {
|
||||
pending_default_colors = false;
|
||||
ui_call_default_colors_set(normal_fg, normal_bg, normal_sp,
|
||||
cterm_normal_fg_color, cterm_normal_bg_color);
|
||||
}
|
||||
}
|
||||
|
||||
void ui_busy_start(void)
|
||||
@ -442,6 +456,9 @@ void ui_line(ScreenGrid *grid, int row, int startcol, int endcol, int clearcol,
|
||||
flags |= kLineFlagInvalid;
|
||||
}
|
||||
|
||||
// set default colors now so that that text won't have to be repainted later
|
||||
ui_may_set_default_colors();
|
||||
|
||||
size_t off = grid->line_offset[row] + (size_t)startcol;
|
||||
|
||||
ui_call_raw_line(grid->handle, row, startcol, endcol, clearcol, clearattr,
|
||||
|
@ -143,6 +143,39 @@ describe('--embed UI', function()
|
||||
{2:-- INSERT --} |
|
||||
]]}
|
||||
end)
|
||||
|
||||
it("only sets background colors once even if overridden", function()
|
||||
local screen, current, seen
|
||||
local function handle_default_colors_set(_, _, rgb_bg, _, _, _)
|
||||
seen[rgb_bg] = true
|
||||
current = rgb_bg
|
||||
end
|
||||
local function startup(...)
|
||||
seen = {}
|
||||
current = nil
|
||||
clear {args_rm={'--headless'}, args={...}}
|
||||
|
||||
-- attach immediately after startup, for early UI
|
||||
screen = Screen.new(40, 8)
|
||||
screen._handle_default_colors_set = handle_default_colors_set
|
||||
screen:attach()
|
||||
end
|
||||
|
||||
startup()
|
||||
screen:expect{condition=function()
|
||||
eq(16777215, current)
|
||||
end}
|
||||
eq({[16777215]=true}, seen)
|
||||
|
||||
-- NB: by accident how functional/helpers.lua currently handles the default color scheme, the
|
||||
-- above is sufficient to test the behavior. But in case that workaround is removed, we need
|
||||
-- a test with an explicit override like below, so do it to remain safe.
|
||||
startup('--cmd', 'hi NORMAL guibg=#FF00FF')
|
||||
screen:expect{condition=function()
|
||||
eq(16711935, current)
|
||||
end}
|
||||
eq({[16711935]=true}, seen) -- we only saw the last one, despite 16777215 was set internally earlier
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('--embed --listen UI', function()
|
||||
|
Loading…
Reference in New Issue
Block a user