Fix unintended interpretation of ranges length syntax

Ranges specified with a +<length> were inconsistent, with +0 meaning
an empty range, while +1 meant a two character long range (first character
+ the following one). Change that to mean a single character.

Fixes #3479
This commit is contained in:
Maxime Coste 2020-05-29 12:22:27 +10:00
parent 63371da8aa
commit 08e0b663f7
6 changed files with 12 additions and 2 deletions

View File

@ -58,7 +58,7 @@ define-command -params ..1 -docstring %{
}
else if (/^[#&]/) {
word_len = length($2) - 1
word_len = length($2)
word_pos = substr($0, 1, 1) == "&" ? substr($4, 1, length($4) - 1) : $3;
regions = regions " " line_num "." word_pos "+" word_len "|Error"
}

View File

@ -1481,7 +1481,7 @@ InclusiveBufferRange option_from_string(Meta::Type<InclusiveBufferRange>, String
if (*sep == '+')
{
auto len = str_to_int({sep+1, str.end()});
return {first, len == 0 ? BufferCoord{-1,-1} : BufferCoord{first.line, first.column + len}};
return {first, len == 0 ? BufferCoord{-1,-1} : BufferCoord{first.line, first.column + len - 1}};
}
const BufferCoord last{str_to_int({sep+1, dot_end}) - 1, str_to_int({dot_end+1, str.end()}) - 1};

View File

@ -0,0 +1 @@

4
test/highlight/ranges/in Normal file
View File

@ -0,0 +1,4 @@
foo
bar
baz
%( )

3
test/highlight/ranges/rc Normal file
View File

@ -0,0 +1,3 @@
declare-option range-specs r
add-highlighter window/ ranges r
set window r %val{timestamp} 1.1+0|default,red 2.1,2.1|default,red 3.1+2|default,red

View File

@ -0,0 +1,2 @@
ui_out '{ "jsonrpc": "2.0", "method": "set_ui_options", "params": [{}] }'
ui_out '{ "jsonrpc": "2.0", "method": "draw", "params": [[[{ "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": "foo\u000a" }], [{ "face": { "fg": "default", "bg": "red", "attributes": [] }, "contents": "b" }, { "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": "ar\u000a" }], [{ "face": { "fg": "default", "bg": "red", "attributes": [] }, "contents": "ba" }, { "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": "z\u000a" }], [{ "face": { "fg": "black", "bg": "white", "attributes": [] }, "contents": " " }, { "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": "\u000a" }]], { "fg": "default", "bg": "default", "attributes": [] }, { "fg": "blue", "bg": "default", "attributes": [] }] }'