mirror of
https://github.com/neovim/neovim
synced 2025-07-17 17:51:48 +00:00
fix(api): allow nvim_buf_set_extmark to accept end_row key (#16686)
nvim_buf_get_extmark uses "end_row" rather than "end_line" in its 'details' dict, which means callers must modify the key names if they want to re-use the information. Allow nvim_buf_set_extmark to take "end_row" as an alias to "end_line" to make this more compatible. See [1]. [1]: https://github.com/neovim/neovim/pull/15011#discussion_r665336968
This commit is contained in:
committed by
GitHub
parent
5c8e5432c0
commit
1b54344c11
@ -2353,7 +2353,7 @@ nvim_buf_set_extmark({buffer}, {ns_id}, {line}, {col}, {*opts})
|
|||||||
|api-indexing|
|
|api-indexing|
|
||||||
{opts} Optional parameters.
|
{opts} Optional parameters.
|
||||||
• id : id of the extmark to edit.
|
• id : id of the extmark to edit.
|
||||||
• end_line : ending line of the mark, 0-based
|
• end_row : ending line of the mark, 0-based
|
||||||
inclusive.
|
inclusive.
|
||||||
• end_col : ending col of the mark, 0-based
|
• end_col : ending col of the mark, 0-based
|
||||||
exclusive.
|
exclusive.
|
||||||
|
@ -339,7 +339,7 @@ Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id, Object start, Object e
|
|||||||
/// @param col Column where to place the mark, 0-based. |api-indexing|
|
/// @param col Column where to place the mark, 0-based. |api-indexing|
|
||||||
/// @param opts Optional parameters.
|
/// @param opts Optional parameters.
|
||||||
/// - id : id of the extmark to edit.
|
/// - id : id of the extmark to edit.
|
||||||
/// - end_line : ending line of the mark, 0-based inclusive.
|
/// - end_row : ending line of the mark, 0-based inclusive.
|
||||||
/// - end_col : ending col of the mark, 0-based exclusive.
|
/// - end_col : ending col of the mark, 0-based exclusive.
|
||||||
/// - hl_group : name of the highlight group used to highlight
|
/// - hl_group : name of the highlight group used to highlight
|
||||||
/// this mark.
|
/// this mark.
|
||||||
@ -431,16 +431,26 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer
|
|||||||
}
|
}
|
||||||
|
|
||||||
int line2 = -1;
|
int line2 = -1;
|
||||||
if (opts->end_line.type == kObjectTypeInteger) {
|
|
||||||
Integer val = opts->end_line.data.integer;
|
// For backward compatibility we support "end_line" as an alias for "end_row"
|
||||||
|
if (HAS_KEY(opts->end_line)) {
|
||||||
|
if (HAS_KEY(opts->end_row)) {
|
||||||
|
api_set_error(err, kErrorTypeValidation, "cannot use both end_row and end_line");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
opts->end_row = opts->end_line;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (opts->end_row.type == kObjectTypeInteger) {
|
||||||
|
Integer val = opts->end_row.data.integer;
|
||||||
if (val < 0 || val > buf->b_ml.ml_line_count) {
|
if (val < 0 || val > buf->b_ml.ml_line_count) {
|
||||||
api_set_error(err, kErrorTypeValidation, "end_line value outside range");
|
api_set_error(err, kErrorTypeValidation, "end_row value outside range");
|
||||||
goto error;
|
goto error;
|
||||||
} else {
|
} else {
|
||||||
line2 = (int)val;
|
line2 = (int)val;
|
||||||
}
|
}
|
||||||
} else if (HAS_KEY(opts->end_line)) {
|
} else if (HAS_KEY(opts->end_row)) {
|
||||||
api_set_error(err, kErrorTypeValidation, "end_line is not an integer");
|
api_set_error(err, kErrorTypeValidation, "end_row is not an integer");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -571,10 +581,10 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer
|
|||||||
OPTION_TO_BOOL(right_gravity, right_gravity, true);
|
OPTION_TO_BOOL(right_gravity, right_gravity, true);
|
||||||
|
|
||||||
// Only error out if they try to set end_right_gravity without
|
// Only error out if they try to set end_right_gravity without
|
||||||
// setting end_col or end_line
|
// setting end_col or end_row
|
||||||
if (line2 == -1 && col2 == -1 && HAS_KEY(opts->end_right_gravity)) {
|
if (line2 == -1 && col2 == -1 && HAS_KEY(opts->end_right_gravity)) {
|
||||||
api_set_error(err, kErrorTypeValidation,
|
api_set_error(err, kErrorTypeValidation,
|
||||||
"cannot set end_right_gravity without setting end_line or end_col");
|
"cannot set end_right_gravity without setting end_row or end_col");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ return {
|
|||||||
set_extmark = {
|
set_extmark = {
|
||||||
"id";
|
"id";
|
||||||
"end_line";
|
"end_line";
|
||||||
|
"end_row";
|
||||||
"end_col";
|
"end_col";
|
||||||
"hl_group";
|
"hl_group";
|
||||||
"virt_text";
|
"virt_text";
|
||||||
|
@ -104,10 +104,10 @@ describe('API/extmarks', function()
|
|||||||
it("can end extranges past final newline using end_col = 0", function()
|
it("can end extranges past final newline using end_col = 0", function()
|
||||||
set_extmark(ns, marks[1], 0, 0, {
|
set_extmark(ns, marks[1], 0, 0, {
|
||||||
end_col = 0,
|
end_col = 0,
|
||||||
end_line = 1
|
end_row = 1
|
||||||
})
|
})
|
||||||
eq("end_col value outside range",
|
eq("end_col value outside range",
|
||||||
pcall_err(set_extmark, ns, marks[2], 0, 0, { end_col = 1, end_line = 1 }))
|
pcall_err(set_extmark, ns, marks[2], 0, 0, { end_col = 1, end_row = 1 }))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('adds, updates and deletes marks', function()
|
it('adds, updates and deletes marks', function()
|
||||||
@ -1424,6 +1424,14 @@ describe('API/extmarks', function()
|
|||||||
eq({ {1, 0, 0}, {2, 0, 8} },
|
eq({ {1, 0, 0}, {2, 0, 8} },
|
||||||
meths.buf_get_extmarks(0, ns, 0, -1, {}))
|
meths.buf_get_extmarks(0, ns, 0, -1, {}))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('can accept "end_row" or "end_line" #16548', function()
|
||||||
|
set_extmark(ns, marks[1], 0, 0, {
|
||||||
|
end_col = 0,
|
||||||
|
end_line = 1
|
||||||
|
})
|
||||||
|
eq({ {1, 0, 0, { end_col = 0, end_row = 1 }} }, get_extmarks(ns, 0, -1, {details=true}))
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('Extmarks buffer api with many marks', function()
|
describe('Extmarks buffer api with many marks', function()
|
||||||
|
Reference in New Issue
Block a user