diff options
author | chentau <tchen1998@gmail.com> | 2021-01-03 13:59:24 -0800 |
---|---|---|
committer | chentau <tchen1998@gmail.com> | 2021-01-03 13:59:24 -0800 |
commit | 10b278bdae4227ab1fdc1257e09bfa6524cbf63c (patch) | |
tree | 53ff036315125930fd48b46dbe53bbb6de5b7123 /src/nvim/api/buffer.c | |
parent | 7718826edf0a4af175d230a691d9d9559f9d8acc (diff) | |
download | rneovim-10b278bdae4227ab1fdc1257e09bfa6524cbf63c.tar.gz rneovim-10b278bdae4227ab1fdc1257e09bfa6524cbf63c.tar.bz2 rneovim-10b278bdae4227ab1fdc1257e09bfa6524cbf63c.zip |
allow for extmark gravity to be set through api
Diffstat (limited to 'src/nvim/api/buffer.c')
-rw-r--r-- | src/nvim/api/buffer.c | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 8d82d22040..7c381ac1ed 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -1400,6 +1400,9 @@ Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id, /// callbacks. The mark will only be used for the current /// redraw cycle, and not be permantently stored in the /// buffer. +/// - gravity : the direction the extmark will be shifted in +/// when new text is inserted. Must be either 'left' or +/// 'right'. /// @param[out] err Error details, if any /// @return Id of the created/updated extmark Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, @@ -1440,6 +1443,7 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, DecorPriority priority = DECOR_PRIORITY_BASE; colnr_T col2 = 0; VirtText virt_text = KV_INITIAL_VALUE; + bool right_gravity = true; for (size_t i = 0; i < opts.size; i++) { String k = opts.items[i].key; Object *v = &opts.items[i].value; @@ -1522,6 +1526,19 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, goto error; } priority = (DecorPriority)v->data.integer; + } else if (strequal("gravity", k.data)) { + if (v->type != kObjectTypeString) { + api_set_error(err, kErrorTypeValidation, + "gravity must be a string"); + goto error; + } + if (strequal("left", v->data.string.data)) { + right_gravity = false; + } else if (!strequal("right", v->data.string.data)) { + api_set_error(err, kErrorTypeValidation, + "invalid option for gravity: must be 'left' or 'right'"); + goto error; + } } else { api_set_error(err, kErrorTypeValidation, "unexpected key: %s", k.data); goto error; @@ -1572,7 +1589,7 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, } id = extmark_set(buf, (uint64_t)ns_id, id, (int)line, (colnr_T)col, - line2, col2, decor, kExtmarkNoUndo); + line2, col2, decor, right_gravity, kExtmarkNoUndo); } return (Integer)id; @@ -1687,7 +1704,7 @@ Integer nvim_buf_add_highlight(Buffer buffer, extmark_set(buf, ns_id, 0, (int)line, (colnr_T)col_start, end_line, (colnr_T)col_end, - decor_hl(hl_id), kExtmarkNoUndo); + decor_hl(hl_id), true, kExtmarkNoUndo); return src_id; } @@ -1796,7 +1813,7 @@ Integer nvim_buf_set_virtual_text(Buffer buffer, Decoration *decor = xcalloc(1, sizeof(*decor)); decor->virt_text = virt_text; - extmark_set(buf, ns_id, 0, (int)line, 0, -1, -1, decor, kExtmarkNoUndo); + extmark_set(buf, ns_id, 0, (int)line, 0, -1, -1, decor, true, kExtmarkNoUndo); return src_id; } |