diff options
author | Gregory Anders <8965202+gpanders@users.noreply.github.com> | 2021-12-08 08:44:48 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-08 08:44:48 -0700 |
commit | cf32053d6005bb13c41434dea7127713ad46346a (patch) | |
tree | 49d4d786334c837791ab6a247caee211bf0b2b48 | |
parent | 5abd7c2c1487976f538ce510b06497fffd7e5252 (diff) | |
download | rneovim-cf32053d6005bb13c41434dea7127713ad46346a.tar.gz rneovim-cf32053d6005bb13c41434dea7127713ad46346a.tar.bz2 rneovim-cf32053d6005bb13c41434dea7127713ad46346a.zip |
fix(api): allow nvim_buf_set_extmark to accept end_row key (#16548)
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. Change the parameter name in
nvim_buf_set_extmark to "end_row" and use "end_line" as an alias
to make this more consistent.
-rw-r--r-- | runtime/doc/api.txt | 2 | ||||
-rw-r--r-- | src/nvim/api/extmark.c | 26 | ||||
-rw-r--r-- | src/nvim/api/keysets.lua | 1 | ||||
-rw-r--r-- | test/functional/api/extmark_spec.lua | 12 |
4 files changed, 30 insertions, 11 deletions
diff --git a/runtime/doc/api.txt b/runtime/doc/api.txt index 482d8c198d..d2d010882e 100644 --- a/runtime/doc/api.txt +++ b/runtime/doc/api.txt @@ -2353,7 +2353,7 @@ nvim_buf_set_extmark({buffer}, {ns_id}, {line}, {col}, {*opts}) |api-indexing| {opts} Optional parameters. • 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. • end_col : ending col of the mark, 0-based exclusive. diff --git a/src/nvim/api/extmark.c b/src/nvim/api/extmark.c index 6e25e627b9..742b953c2a 100644 --- a/src/nvim/api/extmark.c +++ b/src/nvim/api/extmark.c @@ -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 opts Optional parameters. /// - 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. /// - hl_group : name of the highlight group used to highlight /// this mark. @@ -431,16 +431,26 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer } 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) { - api_set_error(err, kErrorTypeValidation, "end_line value outside range"); + api_set_error(err, kErrorTypeValidation, "end_row value outside range"); goto error; } else { line2 = (int)val; } - } else if (HAS_KEY(opts->end_line)) { - api_set_error(err, kErrorTypeValidation, "end_line is not an integer"); + } else if (HAS_KEY(opts->end_row)) { + api_set_error(err, kErrorTypeValidation, "end_row is not an integer"); 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); // 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)) { 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; } diff --git a/src/nvim/api/keysets.lua b/src/nvim/api/keysets.lua index e956a54dbc..f3e7f2f1dc 100644 --- a/src/nvim/api/keysets.lua +++ b/src/nvim/api/keysets.lua @@ -5,6 +5,7 @@ return { set_extmark = { "id"; "end_line"; + "end_row"; "end_col"; "hl_group"; "virt_text"; diff --git a/test/functional/api/extmark_spec.lua b/test/functional/api/extmark_spec.lua index 50b4b85d2a..45a01be620 100644 --- a/test/functional/api/extmark_spec.lua +++ b/test/functional/api/extmark_spec.lua @@ -104,10 +104,10 @@ describe('API/extmarks', function() it("can end extranges past final newline using end_col = 0", function() set_extmark(ns, marks[1], 0, 0, { end_col = 0, - end_line = 1 + end_row = 1 }) 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) it('adds, updates and deletes marks', function() @@ -1424,6 +1424,14 @@ describe('API/extmarks', function() eq({ {1, 0, 0}, {2, 0, 8} }, meths.buf_get_extmarks(0, ns, 0, -1, {})) 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) describe('Extmarks buffer api with many marks', function() |