aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Lingelbach <m.j.lbach@gmail.com>2022-01-12 12:01:29 -0800
committerMichael Lingelbach <m.j.lbach@gmail.com>2022-01-12 12:28:18 -0800
commitd0d4fb792f2b3ac40a00b7929c8653968821e5ae (patch)
tree1a2a2a23312cfd4d133c55e0e81836179732391b
parent11142f6ffe46da1f20c570333a2c05b6e3015f56 (diff)
downloadrneovim-d0d4fb792f2b3ac40a00b7929c8653968821e5ae.tar.gz
rneovim-d0d4fb792f2b3ac40a00b7929c8653968821e5ae.tar.bz2
rneovim-d0d4fb792f2b3ac40a00b7929c8653968821e5ae.zip
Address 'review'
-rw-r--r--src/nvim/api/extmark.c33
1 files changed, 26 insertions, 7 deletions
diff --git a/src/nvim/api/extmark.c b/src/nvim/api/extmark.c
index 04456eee01..ab97ff114c 100644
--- a/src/nvim/api/extmark.c
+++ b/src/nvim/api/extmark.c
@@ -404,8 +404,8 @@ Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id, Object start, Object e
/// for left). Defaults to false.
/// - priority: a priority value for the highlight group. For
/// example treesitter highlighting uses a value of 100.
-/// - strict: boolean that indicates extmark should be placed
-/// even if the line or column value is past the end of the
+/// - strict: boolean that indicates extmark should not be placed
+/// if the line or column value is past the end of the
/// buffer or end of the line respectively. Defaults to true.
///
/// @param[out] err Error details, if any
@@ -603,16 +603,31 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer
bool strict = true;
OPTION_TO_BOOL(strict, strict, true);
- if (line < 0 || (line > buf->b_ml.ml_line_count && strict)) {
+ if (line < 0 ) {
api_set_error(err, kErrorTypeValidation, "line value outside range");
goto error;
+ }
+ else if (line > buf->b_ml.ml_line_count) {
+ if (strict) {
+ api_set_error(err, kErrorTypeValidation, "line value outside range");
+ goto error;
+ } else {
+ line = buf->b_ml.ml_line_count;
+ }
} else if (line < buf->b_ml.ml_line_count) {
len = ephemeral ? MAXCOL : STRLEN(ml_get_buf(buf, (linenr_T)line+1, false));
}
if (col == -1) {
col = (Integer)len;
- } else if (col < -1 || (col > (Integer)len && strict)) {
+ } else if (col > (Integer)len) {
+ if (strict) {
+ api_set_error(err, kErrorTypeValidation, "col value outside range");
+ goto error;
+ } else {
+ col = (Integer)len;
+ }
+ } else if (col < -1 ) {
api_set_error(err, kErrorTypeValidation, "col value outside range");
goto error;
}
@@ -627,9 +642,13 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer
// reuse len from before
line2 = (int)line;
}
- if (col2 > (Integer)len && strict) {
- api_set_error(err, kErrorTypeValidation, "end_col value outside range");
- goto error;
+ if (col2 > (Integer)len) {
+ if (strict) {
+ api_set_error(err, kErrorTypeValidation, "end_col value outside range");
+ goto error;
+ } else {
+ col2 = (int)len;
+ }
}
} else if (line2 >= 0) {
col2 = 0;