mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 19:38:20 +00:00
feat(sign):Allow signs to be 0 width (#13290)
Adds support for signs to be 0 cells wide. If all signs of the same group have no width, the signcolumn will not be rendered for that group.
This commit is contained in:
@@ -5479,8 +5479,10 @@ int buf_signcols(buf_T *buf)
|
||||
curline = sign->lnum;
|
||||
linesum = 0;
|
||||
}
|
||||
if (sign->has_text_or_icon) {
|
||||
linesum++;
|
||||
}
|
||||
}
|
||||
if (linesum > buf->b_signcols_max) {
|
||||
buf->b_signcols_max = linesum;
|
||||
}
|
||||
|
@@ -173,13 +173,15 @@ static void insert_sign(
|
||||
const char_u *group, // sign group; NULL for global group
|
||||
int prio, // sign priority
|
||||
linenr_T lnum, // line number which gets the mark
|
||||
int typenr // typenr of sign we are adding
|
||||
int typenr, // typenr of sign we are adding
|
||||
bool has_text_or_icon // sign has text or icon
|
||||
)
|
||||
{
|
||||
signlist_T *newsign = xmalloc(sizeof(signlist_T));
|
||||
newsign->id = id;
|
||||
newsign->lnum = lnum;
|
||||
newsign->typenr = typenr;
|
||||
newsign->has_text_or_icon = has_text_or_icon;
|
||||
if (group != NULL) {
|
||||
newsign->group = sign_group_ref(group);
|
||||
} else {
|
||||
@@ -216,7 +218,8 @@ static void insert_sign_by_lnum_prio(
|
||||
const char_u *group, // sign group; NULL for global group
|
||||
int prio, // sign priority
|
||||
linenr_T lnum, // line number which gets the mark
|
||||
int typenr // typenr of sign we are adding
|
||||
int typenr, // typenr of sign we are adding
|
||||
bool has_text_or_icon // sign has text or icon
|
||||
)
|
||||
{
|
||||
signlist_T *sign;
|
||||
@@ -234,7 +237,7 @@ static void insert_sign_by_lnum_prio(
|
||||
sign = prev->next;
|
||||
}
|
||||
|
||||
insert_sign(buf, prev, sign, id, group, prio, lnum, typenr);
|
||||
insert_sign(buf, prev, sign, id, group, prio, lnum, typenr, has_text_or_icon);
|
||||
}
|
||||
|
||||
/// Get the name of a sign by its typenr.
|
||||
@@ -347,7 +350,8 @@ void buf_addsign(
|
||||
const char_u *groupname, // sign group
|
||||
int prio, // sign priority
|
||||
linenr_T lnum, // line number which gets the mark
|
||||
int typenr // typenr of sign we are adding
|
||||
int typenr, // typenr of sign we are adding
|
||||
bool has_text_or_icon // sign has text or icon
|
||||
)
|
||||
{
|
||||
signlist_T *sign; // a sign in the signlist
|
||||
@@ -363,13 +367,29 @@ void buf_addsign(
|
||||
sign_sort_by_prio_on_line(buf, sign);
|
||||
return;
|
||||
} else if (lnum < sign->lnum) {
|
||||
insert_sign_by_lnum_prio(buf, prev, id, groupname, prio, lnum, typenr);
|
||||
insert_sign_by_lnum_prio(
|
||||
buf,
|
||||
prev,
|
||||
id,
|
||||
groupname,
|
||||
prio,
|
||||
lnum,
|
||||
typenr,
|
||||
has_text_or_icon);
|
||||
return;
|
||||
}
|
||||
prev = sign;
|
||||
}
|
||||
|
||||
insert_sign_by_lnum_prio(buf, prev, id, groupname, prio, lnum, typenr);
|
||||
insert_sign_by_lnum_prio(
|
||||
buf,
|
||||
prev,
|
||||
id,
|
||||
groupname,
|
||||
prio,
|
||||
lnum,
|
||||
typenr,
|
||||
has_text_or_icon);
|
||||
}
|
||||
|
||||
// For an existing, placed sign "markId" change the type to "typenr".
|
||||
@@ -786,11 +806,15 @@ static int sign_define_init_text(sign_T *sp, char_u *text)
|
||||
}
|
||||
cells += utf_ptr2cells(s);
|
||||
}
|
||||
// Currently must be one or two display cells
|
||||
if (s != endp || cells < 1 || cells > 2) {
|
||||
// Currently must be empty, one or two display cells
|
||||
if (s != endp || cells > 2) {
|
||||
EMSG2(_("E239: Invalid sign text: %s"), text);
|
||||
return FAIL;
|
||||
}
|
||||
if (cells < 1) {
|
||||
sp->sn_text = NULL;
|
||||
return OK;
|
||||
}
|
||||
|
||||
xfree(sp->sn_text);
|
||||
// Allocate one byte more if we need to pad up
|
||||
@@ -939,7 +963,15 @@ int sign_place(
|
||||
if (lnum > 0) {
|
||||
// ":sign place {id} line={lnum} name={name} file={fname}":
|
||||
// place a sign
|
||||
buf_addsign(buf, *sign_id, sign_group, prio, lnum, sp->sn_typenr);
|
||||
bool has_text_or_icon = sp->sn_text != NULL || sp->sn_icon != NULL;
|
||||
buf_addsign(
|
||||
buf,
|
||||
*sign_id,
|
||||
sign_group,
|
||||
prio,
|
||||
lnum,
|
||||
sp->sn_typenr,
|
||||
has_text_or_icon);
|
||||
} else {
|
||||
// ":sign place {id} file={fname}": change sign type
|
||||
lnum = buf_change_sign_type(buf, *sign_id, sign_group, sp->sn_typenr);
|
||||
|
@@ -1,6 +1,7 @@
|
||||
#ifndef NVIM_SIGN_DEFS_H
|
||||
#define NVIM_SIGN_DEFS_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "nvim/pos.h"
|
||||
#include "nvim/types.h"
|
||||
|
||||
@@ -25,6 +26,7 @@ struct signlist
|
||||
int id; // unique identifier for each placed sign
|
||||
linenr_T lnum; // line number which has this sign
|
||||
int typenr; // typenr of sign
|
||||
bool has_text_or_icon; // has text or icon
|
||||
signgroup_T *group; // sign group
|
||||
int priority; // priority for highlighting
|
||||
signlist_T *next; // next signlist entry
|
||||
|
@@ -122,9 +122,9 @@ func Test_sign()
|
||||
call assert_fails("sign define Sign4 text=a\e linehl=Comment", 'E239:')
|
||||
call assert_fails("sign define Sign4 text=\ea linehl=Comment", 'E239:')
|
||||
|
||||
" Only 1 or 2 character text is allowed
|
||||
" Only 0, 1 or 2 character text is allowed
|
||||
call assert_fails("sign define Sign4 text=abc linehl=Comment", 'E239:')
|
||||
call assert_fails("sign define Sign4 text= linehl=Comment", 'E239:')
|
||||
" call assert_fails("sign define Sign4 text= linehl=Comment", 'E239:')
|
||||
call assert_fails("sign define Sign4 text=\\ ab linehl=Comment", 'E239:')
|
||||
|
||||
" define sign with whitespace
|
||||
@@ -306,7 +306,7 @@ func Test_sign_invalid_commands()
|
||||
call assert_fails('sign jump 1 name=', 'E474:')
|
||||
call assert_fails('sign jump 1 name=Sign1', 'E474:')
|
||||
call assert_fails('sign jump 1 line=100', '474:')
|
||||
call assert_fails('sign define Sign2 text=', 'E239:')
|
||||
" call assert_fails('sign define Sign2 text=', 'E239:')
|
||||
" Non-numeric identifier for :sign place
|
||||
call assert_fails("sign place abc line=3 name=Sign1 buffer=" . bufnr(''),
|
||||
\ 'E474:')
|
||||
@@ -415,7 +415,7 @@ func Test_sign_funcs()
|
||||
|
||||
" Tests for invalid arguments to sign_define()
|
||||
call assert_fails('call sign_define("sign4", {"text" : "===>"})', 'E239:')
|
||||
call assert_fails('call sign_define("sign5", {"text" : ""})', 'E239:')
|
||||
" call assert_fails('call sign_define("sign5", {"text" : ""})', 'E239:')
|
||||
call assert_fails('call sign_define([])', 'E730:')
|
||||
call assert_fails('call sign_define("sign6", [])', 'E715:')
|
||||
|
||||
|
@@ -76,6 +76,28 @@ describe('Signs', function()
|
||||
]])
|
||||
end)
|
||||
|
||||
it('allows signs with no text', function()
|
||||
feed('ia<cr>b<cr><esc>')
|
||||
command('sign define piet1 text= texthl=Search')
|
||||
command('sign place 1 line=1 name=piet1 buffer=1')
|
||||
screen:expect([[
|
||||
a |
|
||||
b |
|
||||
^ |
|
||||
{0:~ }|
|
||||
{0:~ }|
|
||||
{0:~ }|
|
||||
{0:~ }|
|
||||
{0:~ }|
|
||||
{0:~ }|
|
||||
{0:~ }|
|
||||
{0:~ }|
|
||||
{0:~ }|
|
||||
{0:~ }|
|
||||
|
|
||||
]])
|
||||
end)
|
||||
|
||||
it('can be called right after :split', function()
|
||||
feed('ia<cr>b<cr>c<cr><esc>gg')
|
||||
-- This used to cause a crash due to :sign using a special redraw
|
||||
@@ -244,6 +266,50 @@ describe('Signs', function()
|
||||
]]}
|
||||
end)
|
||||
|
||||
it('ignores signs with no icon and text when calculting the signcolumn width', function()
|
||||
feed('ia<cr>b<cr>c<cr><esc>')
|
||||
command('set number')
|
||||
command('set signcolumn=auto:2')
|
||||
command('sign define pietSearch text=>> texthl=Search')
|
||||
command('sign define pietError text= texthl=Error')
|
||||
command('sign place 2 line=1 name=pietError buffer=1')
|
||||
-- no signcolumn with only empty sign
|
||||
screen:expect([[
|
||||
{6: 1 }a |
|
||||
{6: 2 }b |
|
||||
{6: 3 }c |
|
||||
{6: 4 }^ |
|
||||
{0:~ }|
|
||||
{0:~ }|
|
||||
{0:~ }|
|
||||
{0:~ }|
|
||||
{0:~ }|
|
||||
{0:~ }|
|
||||
{0:~ }|
|
||||
{0:~ }|
|
||||
{0:~ }|
|
||||
|
|
||||
]])
|
||||
-- single column with 1 sign with text and one sign without
|
||||
command('sign place 1 line=1 name=pietSearch buffer=1')
|
||||
screen:expect([[
|
||||
{1:>>}{6: 1 }a |
|
||||
{2: }{6: 2 }b |
|
||||
{2: }{6: 3 }c |
|
||||
{2: }{6: ^4 } |
|
||||
{0:~ }|
|
||||
{0:~ }|
|
||||
{0:~ }|
|
||||
{0:~ }|
|
||||
{0:~ }|
|
||||
{0:~ }|
|
||||
{0:~ }|
|
||||
{0:~ }|
|
||||
{0:~ }|
|
||||
|
|
||||
]])
|
||||
end)
|
||||
|
||||
it('can have 32bit sign IDs', function()
|
||||
command('sign define piet text=>> texthl=Search')
|
||||
command('sign place 100000 line=1 name=piet buffer=1')
|
||||
|
Reference in New Issue
Block a user