aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Gehrig <jgehrig@users.noreply.github.com>2021-06-27 15:30:09 -0400
committerGitHub <noreply@github.com>2021-06-27 15:30:09 -0400
commit5aaa1a1c0473d9e9ac824201f92ec65e190beeb7 (patch)
treec444f01a33a27801f73d4afebd19dc65ee36d068
parentbdf3df4027a5389a46b4c9a75b50aff5c0ecb351 (diff)
downloadrneovim-5aaa1a1c0473d9e9ac824201f92ec65e190beeb7.tar.gz
rneovim-5aaa1a1c0473d9e9ac824201f92ec65e190beeb7.tar.bz2
rneovim-5aaa1a1c0473d9e9ac824201f92ec65e190beeb7.zip
[RDY] Add buffer information to tabline_update (#12481)
* Add buffer information to tabline_update Most terminal implementations of the tabline display buffer and tab information. Many neovim-qt users disable GuiTabline because it lacks functionality provided in the terminal implementation. The tabline_update event should include buffer information too, so client GUIs can display rich useful tabs.
-rw-r--r--runtime/doc/ui.txt10
-rw-r--r--src/nvim/api/ui_events.in.h3
-rw-r--r--src/nvim/screen.c19
-rw-r--r--test/functional/ui/tabline_spec.lua43
4 files changed, 66 insertions, 9 deletions
diff --git a/runtime/doc/ui.txt b/runtime/doc/ui.txt
index b385cab36f..e7be14e732 100644
--- a/runtime/doc/ui.txt
+++ b/runtime/doc/ui.txt
@@ -631,11 +631,13 @@ Tabline Events *ui-tabline*
Activated by the `ext_tabline` |ui-option|.
-["tabline_update", curtab, tabs]
+["tabline_update", curtab, tabs, curbuf, buffers]
Tabline was updated. UIs should present this data in a custom tabline
- widget.
- curtab: Current Tabpage
- tabs: List of Dicts [{ "tab": Tabpage, "name": String }, ...]
+ widget. Note: options `curbuf` + `buffers` were added in API7.
+ curtab: Current Tabpage
+ tabs: List of Dicts [{ "tab": Tabpage, "name": String }, ...]
+ curbuf: Current buffer handle.
+ buffers: List of Dicts [{ "buffer": buffer handle, "name": String}, ...]
==============================================================================
Cmdline Events *ui-cmdline*
diff --git a/src/nvim/api/ui_events.in.h b/src/nvim/api/ui_events.in.h
index 11e21a88ea..35d39a34d7 100644
--- a/src/nvim/api/ui_events.in.h
+++ b/src/nvim/api/ui_events.in.h
@@ -130,7 +130,8 @@ void popupmenu_hide(void)
void popupmenu_select(Integer selected)
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
-void tabline_update(Tabpage current, Array tabs)
+void tabline_update(Tabpage current, Array tabs,
+ Buffer current_buffer, Array buffers)
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;
void cmdline_show(Array content, Integer pos, String firstc, String prompt,
diff --git a/src/nvim/screen.c b/src/nvim/screen.c
index 04157a0154..3446a944cd 100644
--- a/src/nvim/screen.c
+++ b/src/nvim/screen.c
@@ -7211,7 +7211,24 @@ void ui_ext_tabline_update(void)
ADD(tabs, DICTIONARY_OBJ(tab_info));
}
- ui_call_tabline_update(curtab->handle, tabs);
+
+ Array buffers = ARRAY_DICT_INIT;
+ FOR_ALL_BUFFERS(buf) {
+ // Do not include unlisted buffers
+ if (!buf->b_p_bl) {
+ continue;
+ }
+
+ Dictionary buffer_info = ARRAY_DICT_INIT;
+ PUT(buffer_info, "buffer", BUFFER_OBJ(buf->handle));
+
+ get_trans_bufname(buf);
+ PUT(buffer_info, "name", STRING_OBJ(cstr_to_string((char *)NameBuff)));
+
+ ADD(buffers, DICTIONARY_OBJ(buffer_info));
+ }
+
+ ui_call_tabline_update(curtab->handle, tabs, curbuf->handle, buffers);
}
/*
diff --git a/test/functional/ui/tabline_spec.lua b/test/functional/ui/tabline_spec.lua
index 23aae81745..ab8d63cda1 100644
--- a/test/functional/ui/tabline_spec.lua
+++ b/test/functional/ui/tabline_spec.lua
@@ -4,14 +4,17 @@ local clear, command, eq = helpers.clear, helpers.command, helpers.eq
describe('ui/ext_tabline', function()
local screen
- local event_tabs, event_curtab
+ local event_tabs, event_curtab, event_curbuf, event_buffers
before_each(function()
clear()
screen = Screen.new(25, 5)
screen:attach({rgb=true, ext_tabline=true})
- function screen:_handle_tabline_update(curtab, tabs)
- event_curtab, event_tabs = curtab, tabs
+ function screen:_handle_tabline_update(curtab, tabs, curbuf, buffers)
+ event_curtab = curtab
+ event_tabs = tabs
+ event_curbuf = curbuf
+ event_buffers = buffers
end
end)
@@ -45,4 +48,38 @@ describe('ui/ext_tabline', function()
eq(expected_tabs, event_tabs)
end}
end)
+
+ it('buffer UI events', function()
+ local expected_buffers_initial= {
+ {buffer = { id = 1 }, name = '[No Name]'},
+ }
+
+ screen:expect{grid=[[
+ ^ |
+ ~ |
+ ~ |
+ ~ |
+ |
+ ]], condition=function()
+ eq({ id = 1}, event_curbuf)
+ eq(expected_buffers_initial, event_buffers)
+ end}
+
+ command("badd another-buffer")
+ command("bnext")
+
+ local expected_buffers = {
+ {buffer = { id = 2 }, name = 'another-buffer'},
+ }
+ screen:expect{grid=[[
+ ^ |
+ ~ |
+ ~ |
+ ~ |
+ |
+ ]], condition=function()
+ eq({ id = 2 }, event_curbuf)
+ eq(expected_buffers, event_buffers)
+ end}
+ end)
end)