Commit: patch 9.2.0978: terminal: empty lines don't use the background color of hl-terminal

Christian Brabandt <[email protected]>
Newsgroups gmane.editors.vim.devel
Message-ID <[email protected]>
patch 9.2.0978: terminal: empty lines don't use the background color of hl-terminal

Commit: https://github.com/vim/vim/commit/5ae1ad12985399c57e53f6abccce25a6f616a5a4
Author: Hirohito Higashi <[email protected]>
Date:   Wed Aug 19 18:58:40 2026 +0000

    patch 9.2.0978: terminal: empty lines don't use the background color of hl-terminal
    
    Problem:  In a terminal window the empty lines are drawn without the
              background color that was set with hl-terminal, while the lines
              with text do use it (bfrg).
    Solution: Stop clearing the window attribute on an empty line.  The Visual
              selection is already combined into the first cell of such a line,
              so the background color can be kept (Hirohito Higashi).
    
    fixes:   #21087
    related: #17559
    related: #20547
    closes:  #21093
    
    Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
    Signed-off-by: Hirohito Higashi <[email protected]>
    Signed-off-by: Christian Brabandt <[email protected]>

diff --git a/src/drawline.c b/src/drawline.c
index edd5ef6ea..00afb6409 100644
--- a/src/drawline.c
+++ b/src/drawline.c
@@ -2872,16 +2872,6 @@ win_line(
 #endif
 		// no more cells to skip
 		skip_cells = 0;
-#ifdef FEAT_TERMINAL
-		if (term_show_buffer(wp->w_buffer)
-		    && wlv.vcol == 0
-		    && wlv.win_attr == term_get_attr(wp, lnum, -1)
-		    && wlv.win_attr == term_get_default_attr(wp))
-		    // Reset the attribute for an empty line with the
-		    // default background, so a Visual selection shows;
-		    // keep an explicitly set background color.
-		    wlv.win_attr = 0;
-#endif
 	    }
 
 	    if (has_mbyte)
diff --git a/src/proto/terminal.pro b/src/proto/terminal.pro
index cc859dd6c..6429ffadd 100644
--- a/src/proto/terminal.pro
+++ b/src/proto/terminal.pro
@@ -36,7 +36,6 @@ int term_is_finished(buf_T *buf);
 int term_show_buffer(buf_T *buf);
 void term_change_in_curbuf(void);
 int term_get_attr(win_T *wp, linenr_T lnum, int col);
-int term_get_default_attr(win_T *wp);
 void term_reset_hlfwin(win_T *wp);
 void term_update_hlfwin(win_T *wp);
 void term_update_hlfwin_all(void);
diff --git a/src/terminal.c b/src/terminal.c
index f136e1efb..8bdaa1b4c 100644
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -4457,19 +4457,6 @@ term_get_attr(win_T *wp, linenr_T lnum, int col)
     return cell2attr(term, wp, &cellattr->attrs, &cellattr->fg, &cellattr->bg);
 }
 
-/*
- * Return the screen attribute for the terminal's default color.  Used to tell
- * whether a line's fill (background) is the default or was set explicitly.
- */
-    int
-term_get_default_attr(win_T *wp)
-{
-    term_T	*term = wp->w_buffer->b_term;
-    cellattr_T	*cellattr = &term->tl_default_color;
-
-    return cell2attr(term, wp, &cellattr->attrs, &cellattr->fg, &cellattr->bg);
-}
-
 /*
  * Convert a cterm color number 0 - 255 to RGB.
  * This is compatible with xterm.
diff --git a/src/testdir/dumps/Test_terminal_hl_empty_1.dump b/src/testdir/dumps/Test_terminal_hl_empty_1.dump
new file mode 100644
index 000000000..460f1fb94
--- /dev/null
+++ b/src/testdir/dumps/Test_terminal_hl_empty_1.dump
@@ -0,0 +1,10 @@
+|o+0&#e000002|n|e| @71
+@75
+|t|w|o| @71
+> @74
+|!+2#ffffff16#00e0003|s|h| |-|c| |"|p|r|i|n|t|f| |'|o|n|e|\@1|n|\@1|n|t|w|o|\@1|n|\@1|n|'|"| |[|f|i|n|i|s|h|e|d|]| @9|4|,|0|-|1| @9|A|l@1
+| +0#0000000#ffffff0@74
+|~+0#4040ff13&| @73
+|~| @73
+|[+1#0000000&|N|o| |N|a|m|e|]| @47|0|,|0|-|1| @9|A|l@1
+| +0&&@74
diff --git a/src/testdir/dumps/Test_terminal_hl_empty_2.dump b/src/testdir/dumps/Test_terminal_hl_empty_2.dump
new file mode 100644
index 000000000..460f1fb94
--- /dev/null
+++ b/src/testdir/dumps/Test_terminal_hl_empty_2.dump
@@ -0,0 +1,10 @@
+|o+0&#e000002|n|e| @71
+@75
+|t|w|o| @71
+> @74
+|!+2#ffffff16#00e0003|s|h| |-|c| |"|p|r|i|n|t|f| |'|o|n|e|\@1|n|\@1|n|t|w|o|\@1|n|\@1|n|'|"| |[|f|i|n|i|s|h|e|d|]| @9|4|,|0|-|1| @9|A|l@1
+| +0#0000000#ffffff0@74
+|~+0#4040ff13&| @73
+|~| @73
+|[+1#0000000&|N|o| |N|a|m|e|]| @47|0|,|0|-|1| @9|A|l@1
+| +0&&@74
diff --git a/src/testdir/dumps/Test_terminal_hl_empty_3.dump b/src/testdir/dumps/Test_terminal_hl_empty_3.dump
new file mode 100644
index 000000000..4f146cc19
--- /dev/null
+++ b/src/testdir/dumps/Test_terminal_hl_empty_3.dump
@@ -0,0 +1,10 @@
+|o+0#0000001#a8a8a8255|n|e| +0#0000000#e000002@71
+| +0#0000001#a8a8a8255| +0#0000000#e000002@73
+|t+0#0000001#a8a8a8255|w|o| +0#0000000#e000002@71
+> @74
+|!+2#ffffff16#00e0003|s|h| |-|c| |"|p|r|i|n|t|f| |'|o|n|e|\@1|n|\@1|n|t|w|o|\@1|n|\@1|n|'|"| |[|f|i|n|i|s|h|e|d|]| @9|4|,|0|-|1| @9|A|l@1
+| +0#0000000#ffffff0@74
+|~+0#4040ff13&| @73
+|~| @73
+|[+1#0000000&|N|o| |N|a|m|e|]| @47|0|,|0|-|1| @9|A|l@1
+|-+2&&@1| |V|I|S|U|A|L| |L|I|N|E| |-@1| +0&&@46|4| @9
diff --git a/src/testdir/test_terminal3.vim b/src/testdir/test_terminal3.vim
index 67952bfb6..ae773279e 100644
--- a/src/testdir/test_terminal3.vim
+++ b/src/testdir/test_terminal3.vim
@@ -1088,6 +1088,35 @@ func Test_terminal_visual_colored_empty_line()
   call StopVimInTerminal(buf)
 endfunc
 
+func Test_terminal_hl_terminal_empty_line()
+  CheckScreendump
+  CheckRunVimInTerminal
+  CheckUnix
+
+  " When a background color is set with hl-terminal the empty lines must use
+  " it as well, both while the job runs and in Terminal-Normal mode.
+  let lines = [
+  \ 'highlight Terminal ctermbg=darkred',
+  \ 'set listchars=',
+  \ ':term sh -c "printf ''one\n\ntwo\n\n''"'
+  \ ]
+  call writefile(lines, 'XtermHlTerm', 'D')
+  let buf = RunVimInTerminal('-S XtermHlTerm', #{rows: 10})
+  call WaitForAssert({-> assert_match('\[finished\]', term_getline(buf, 5))})
+  call VerifyScreenDump(buf, 'Test_terminal_hl_empty_1', {})
+
+  call term_sendkeys(buf, "\<C-W>N")
+  call term_wait(buf)
+  call VerifyScreenDump(buf, 'Test_terminal_hl_empty_2', {})
+
+  " The Visual selection must still show on the first cell of an empty line.
+  call term_sendkeys(buf, "ggVG")
+  call term_wait(buf)
+  call VerifyScreenDump(buf, 'Test_terminal_hl_empty_3', {})
+
+  call StopVimInTerminal(buf)
+endfunc
+
 func Test_terminal_ansi_color_windows_cui()
   if !has('win32') || has('gui_running')
     throw 'Skipped: only for the Windows CUI'
diff --git a/src/version.c b/src/version.c
index 2bea460a9..326f1df47 100644
--- a/src/version.c
+++ b/src/version.c
@@ -763,6 +763,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    978,
 /**/
     977,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups "vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/vim_dev/E1wwlkg-00CJr9-RG%40256bit.org.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.