aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2018-06-21 05:15:11 -0400
committerJustin M. Keyes <justinkz@gmail.com>2018-06-21 11:15:11 +0200
commit52ebe34eebf361f28b1a374399cd7e3d8201bfb2 (patch)
treef63a610d51b3ef9b88fe3f621b117d3bc6c99c25 /src
parent8794a551bdbc4c31ed212bbb69e9ce946e5612dd (diff)
downloadrneovim-52ebe34eebf361f28b1a374399cd7e3d8201bfb2.tar.gz
rneovim-52ebe34eebf361f28b1a374399cd7e3d8201bfb2.tar.bz2
rneovim-52ebe34eebf361f28b1a374399cd7e3d8201bfb2.zip
vim-patch:8.0.0616: not always setting 'background' correctly after :hi Normal (#8606)
Problem: When setting the cterm background with ":hi Normal" the value of 'background' may be set wrongly. Solution: Check that the color is less than 16. Don't set 'background' when it was set explicitly. (Lemonboy, closes vim/vim#1710) https://github.com/vim/vim/commit/1615b36b91b094263240d7b555283ddf33208f62 Restore reset_option_was_set(), removed in 419da839e0cbdf6251bc31dc218fa629ccc91b44 ref #8595 ref #8597
Diffstat (limited to 'src')
-rw-r--r--src/nvim/option.c14
-rw-r--r--src/nvim/syntax.c16
-rw-r--r--src/nvim/testdir/test_syntax.vim23
3 files changed, 47 insertions, 6 deletions
diff --git a/src/nvim/option.c b/src/nvim/option.c
index 68b0a525f1..61570a75b1 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -6599,7 +6599,7 @@ void vimrc_found(char_u *fname, char_u *envname)
/// @param[in] name Option name.
///
/// @return True if it was set.
-static bool option_was_set(const char *name)
+bool option_was_set(const char *name)
{
int idx;
@@ -6612,6 +6612,18 @@ static bool option_was_set(const char *name)
return false;
}
+/// Reset the flag indicating option "name" was set.
+///
+/// @param[in] name Option name.
+void reset_option_was_set(const char *name)
+{
+ const int idx = findoption(name);
+
+ if (idx >= 0) {
+ options[idx].flags &= ~P_WAS_SET;
+ }
+}
+
/*
* fill_breakat_flags() -- called when 'breakat' changes value.
*/
diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c
index 63c7ffbadf..45f40e8592 100644
--- a/src/nvim/syntax.c
+++ b/src/nvim/syntax.c
@@ -6812,15 +6812,21 @@ void do_highlight(const char *line, const bool forceit, const bool init)
if (!ui_rgb_attached()) {
must_redraw = CLEAR;
if (color >= 0) {
+ int dark = -1;
+
if (t_colors < 16) {
- i = (color == 0 || color == 4);
- } else {
- i = (color < 7 || color == 8);
+ dark = (color == 0 || color == 4);
+ } else if (color < 16) {
+ // Limit the heuristic to the standard 16 colors
+ dark = (color < 7 || color == 8);
}
// Set the 'background' option if the value is
// wrong.
- if (i != (*p_bg == 'd')) {
- set_option_value("bg", 0L, (i ? "dark" : "light"), 0);
+ if (dark != -1
+ && dark != (*p_bg == 'd')
+ && !option_was_set("bg")) {
+ set_option_value("bg", 0L, (dark ? "dark" : "light"), 0);
+ reset_option_was_set("bg");
}
}
}
diff --git a/src/nvim/testdir/test_syntax.vim b/src/nvim/testdir/test_syntax.vim
index ebdfc250aa..6d164ac895 100644
--- a/src/nvim/testdir/test_syntax.vim
+++ b/src/nvim/testdir/test_syntax.vim
@@ -435,3 +435,26 @@ func Test_conceal()
bw!
endfunc
+func Test_bg_detection()
+ if has('gui_running')
+ return
+ endif
+ " auto-detection of &bg, make sure sure it isn't set anywhere before
+ " this test
+ hi Normal ctermbg=0
+ call assert_equal('dark', &bg)
+ hi Normal ctermbg=4
+ call assert_equal('dark', &bg)
+ hi Normal ctermbg=12
+ call assert_equal('light', &bg)
+ hi Normal ctermbg=15
+ call assert_equal('light', &bg)
+
+ " manually-set &bg takes precendence over auto-detection
+ set bg=light
+ hi Normal ctermbg=4
+ call assert_equal('light', &bg)
+ set bg=dark
+ hi Normal ctermbg=12
+ call assert_equal('dark', &bg)
+endfunc