aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-12-10 14:53:02 +0800
committerGitHub <noreply@github.com>2024-12-10 14:53:02 +0800
commitd1fd674df3eb07049c780d6b7821e17d471fdc4c (patch)
tree61c4eea43636e9979310746e8896b27ed0c93770
parent98694c36756f747e7929033343e8479f39094461 (diff)
downloadrneovim-d1fd674df3eb07049c780d6b7821e17d471fdc4c.tar.gz
rneovim-d1fd674df3eb07049c780d6b7821e17d471fdc4c.tar.bz2
rneovim-d1fd674df3eb07049c780d6b7821e17d471fdc4c.zip
fix(ui): update title in more cases (#31508)
-rw-r--r--src/nvim/drawscreen.c26
-rw-r--r--src/nvim/ex_getln.c5
-rw-r--r--src/nvim/normal.c4
-rw-r--r--src/nvim/terminal.c1
-rw-r--r--test/functional/ui/title_spec.lua57
5 files changed, 85 insertions, 8 deletions
diff --git a/src/nvim/drawscreen.c b/src/nvim/drawscreen.c
index a939038603..0961aabf21 100644
--- a/src/nvim/drawscreen.c
+++ b/src/nvim/drawscreen.c
@@ -679,6 +679,10 @@ int update_screen(void)
updating_screen = false;
+ if (need_maketitle) {
+ maketitle();
+ }
+
// Clear or redraw the command line. Done last, because scrolling may
// mess up the command line.
if (clear_cmdline || redraw_cmdline || redraw_mode) {
@@ -856,6 +860,19 @@ void setcursor_mayforce(win_T *wp, bool force)
}
}
+/// Mark the title and icon for redraw if either of them uses statusline format.
+///
+/// @return whether either title or icon uses statusline format.
+bool redraw_custom_title_later(void)
+{
+ if ((p_icon && (stl_syntax & STL_IN_ICON))
+ || (p_title && (stl_syntax & STL_IN_TITLE))) {
+ need_maketitle = true;
+ return true;
+ }
+ return false;
+}
+
/// Show current cursor info in ruler and various other places
///
/// @param always if false, only show ruler if position has changed.
@@ -889,10 +906,7 @@ void show_cursor_info_later(bool force)
curwin->w_redr_status = true;
}
- if ((p_icon && (stl_syntax & STL_IN_ICON))
- || (p_title && (stl_syntax & STL_IN_TITLE))) {
- need_maketitle = true;
- }
+ redraw_custom_title_later();
}
curwin->w_stl_cursor = curwin->w_cursor;
@@ -2773,6 +2787,10 @@ void redraw_statuslines(void)
if (redraw_tabline) {
draw_tabline();
}
+
+ if (need_maketitle) {
+ maketitle();
+ }
}
/// Redraw all status lines at the bottom of frame "frp".
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index 2d9d4417dd..85fbdbd20a 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -847,6 +847,10 @@ static uint8_t *command_line_enter(int firstc, int count, int indent, bool clear
found_one = true;
}
+ if (redraw_custom_title_later()) {
+ found_one = true;
+ }
+
if (found_one) {
redraw_statuslines();
}
@@ -959,6 +963,7 @@ theend:
msg_ext_clear_later();
}
if (!cmd_silent) {
+ redraw_custom_title_later();
status_redraw_all(); // redraw to show mode change
}
diff --git a/src/nvim/normal.c b/src/nvim/normal.c
index 92a6068c5a..4d2abf1c8c 100644
--- a/src/nvim/normal.c
+++ b/src/nvim/normal.c
@@ -1372,10 +1372,6 @@ static void normal_redraw(NormalState *s)
}
}
- if (need_maketitle) {
- maketitle();
- }
-
curbuf->b_last_used = time(NULL);
// Display message after redraw. If an external message is still visible,
diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c
index b4496d6758..6d4af0fc57 100644
--- a/src/nvim/terminal.c
+++ b/src/nvim/terminal.c
@@ -619,6 +619,7 @@ bool terminal_enter(void)
invalidate_terminal(s->term, s->term->cursor.row, s->term->cursor.row + 1);
showmode();
curwin->w_redr_status = true; // For mode() in statusline. #8323
+ redraw_custom_title_later();
ui_busy_start();
apply_autocmds(EVENT_TERMENTER, NULL, NULL, false, curbuf);
may_trigger_modechanged();
diff --git a/test/functional/ui/title_spec.lua b/test/functional/ui/title_spec.lua
index 66eb15478b..aa9ac3f5b5 100644
--- a/test/functional/ui/title_spec.lua
+++ b/test/functional/ui/title_spec.lua
@@ -37,6 +37,63 @@ describe('title', function()
end)
end)
+ it('is updated in Insert mode', function()
+ api.nvim_set_option_value('title', true, {})
+ screen:expect(function()
+ eq('[No Name] - Nvim', screen.title)
+ end)
+ feed('ifoo')
+ screen:expect(function()
+ eq('[No Name] + - Nvim', screen.title)
+ end)
+ feed('<Esc>')
+ api.nvim_set_option_value('titlestring', '%m %f (%{mode(1)}) | nvim', {})
+ screen:expect(function()
+ eq('[+] [No Name] (n) | nvim', screen.title)
+ end)
+ feed('i')
+ screen:expect(function()
+ eq('[+] [No Name] (i) | nvim', screen.title)
+ end)
+ feed('<Esc>')
+ screen:expect(function()
+ eq('[+] [No Name] (n) | nvim', screen.title)
+ end)
+ end)
+
+ it('is updated in Cmdline mode', function()
+ api.nvim_set_option_value('title', true, {})
+ api.nvim_set_option_value('titlestring', '%f (%{mode(1)}) | nvim', {})
+ screen:expect(function()
+ eq('[No Name] (n) | nvim', screen.title)
+ end)
+ feed(':')
+ screen:expect(function()
+ eq('[No Name] (c) | nvim', screen.title)
+ end)
+ feed('<Esc>')
+ screen:expect(function()
+ eq('[No Name] (n) | nvim', screen.title)
+ end)
+ end)
+
+ it('is updated in Terminal mode', function()
+ api.nvim_set_option_value('title', true, {})
+ api.nvim_set_option_value('titlestring', '(%{mode(1)}) | nvim', {})
+ fn.termopen({ n.testprg('shell-test'), 'INTERACT' })
+ screen:expect(function()
+ eq('(nt) | nvim', screen.title)
+ end)
+ feed('i')
+ screen:expect(function()
+ eq('(t) | nvim', screen.title)
+ end)
+ feed([[<C-\><C-N>]])
+ screen:expect(function()
+ eq('(nt) | nvim', screen.title)
+ end)
+ end)
+
describe('is not changed by', function()
local file1 = is_os('win') and 'C:\\mydir\\myfile1' or '/mydir/myfile1'
local file2 = is_os('win') and 'C:\\mydir\\myfile2' or '/mydir/myfile2'