diff options
author | zeertzjq <zeertzjq@outlook.com> | 2025-02-20 21:47:12 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-20 21:47:12 +0800 |
commit | 51cf84daf9612574978731e66db45a52136b8899 (patch) | |
tree | 5ac6f72c40e5219356ac198e1c20ca4df55354cf /src/nvim/api | |
parent | 574ea6a1911b740bb611f0b658a83f606b6837bc (diff) | |
download | rneovim-51cf84daf9612574978731e66db45a52136b8899.tar.gz rneovim-51cf84daf9612574978731e66db45a52136b8899.tar.bz2 rneovim-51cf84daf9612574978731e66db45a52136b8899.zip |
feat(marks): virtual lines support horizontal scrolling (#32497)
Add a new field `virt_lines_overflow` that enables horizontal scrolling
for virtual lines when set to "scroll".
Diffstat (limited to 'src/nvim/api')
-rw-r--r-- | src/nvim/api/extmark.c | 20 | ||||
-rw-r--r-- | src/nvim/api/keysets_defs.h | 1 | ||||
-rw-r--r-- | src/nvim/api/private/helpers.h | 4 |
3 files changed, 20 insertions, 5 deletions
diff --git a/src/nvim/api/extmark.c b/src/nvim/api/extmark.c index 2cf9221e52..ef09dbb0aa 100644 --- a/src/nvim/api/extmark.c +++ b/src/nvim/api/extmark.c @@ -448,7 +448,11 @@ Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id, Object start, Object e /// - virt_lines_leftcol: Place virtual lines in the leftmost /// column of the window, bypassing /// sign and number columns. -/// +/// - virt_lines_overflow: controls how to handle virtual lines wider +/// than the window. Currently takes the one of the following values: +/// - "trunc": truncate virtual lines on the right (default). +/// - "scroll": virtual lines can scroll horizontally with 'nowrap', +/// otherwise the same as "trunc". /// - ephemeral : for use with |nvim_set_decoration_provider()| /// callbacks. The mark will only be used for the current /// redraw cycle, and not be permantently stored in the @@ -669,7 +673,17 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer } } - bool virt_lines_leftcol = opts->virt_lines_leftcol; + int virt_lines_flags = opts->virt_lines_leftcol ? kVLLeftcol : 0; + if (HAS_KEY(opts, set_extmark, virt_lines_overflow)) { + String str = opts->virt_lines_overflow; + if (strequal("scroll", str.data)) { + virt_lines_flags |= kVLScroll; + } else if (!strequal("trunc", str.data)) { + VALIDATE_S(false, "virt_lines_overflow", str.data, { + goto error; + }); + } + } if (HAS_KEY(opts, set_extmark, virt_lines)) { Array a = opts->virt_lines; @@ -679,7 +693,7 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer }); int dummig; VirtText jtem = parse_virt_text(a.items[j].data.array, err, &dummig); - kv_push(virt_lines.data.virt_lines, ((struct virt_line){ jtem, virt_lines_leftcol })); + kv_push(virt_lines.data.virt_lines, ((struct virt_line){ jtem, virt_lines_flags })); if (ERROR_SET(err)) { goto error; } diff --git a/src/nvim/api/keysets_defs.h b/src/nvim/api/keysets_defs.h index 6625908cda..b3015911f9 100644 --- a/src/nvim/api/keysets_defs.h +++ b/src/nvim/api/keysets_defs.h @@ -45,6 +45,7 @@ typedef struct { Array virt_lines; Boolean virt_lines_above; Boolean virt_lines_leftcol; + String virt_lines_overflow; Boolean strict; String sign_text; HLGroupID sign_hl_group; diff --git a/src/nvim/api/private/helpers.h b/src/nvim/api/private/helpers.h index d581c6bc10..5cf1ca4d34 100644 --- a/src/nvim/api/private/helpers.h +++ b/src/nvim/api/private/helpers.h @@ -64,7 +64,7 @@ #define NIL ((Object)OBJECT_INIT) #define NULL_STRING ((String)STRING_INIT) -#define HAS_KEY(d, typ, key) (((d)->is_set__##typ##_ & (1 << KEYSET_OPTIDX_##typ##__##key)) != 0) +#define HAS_KEY(d, typ, key) (((d)->is_set__##typ##_ & (1ULL << KEYSET_OPTIDX_##typ##__##key)) != 0) #define GET_BOOL_OR_TRUE(d, typ, key) (HAS_KEY(d, typ, key) ? (d)->key : true) @@ -75,7 +75,7 @@ kv_push_c(dict, ((KeyValuePair) { .key = cstr_as_string(k), .value = v })) #define PUT_KEY(d, typ, key, v) \ - do { (d).is_set__##typ##_ |= (1 << KEYSET_OPTIDX_##typ##__##key); (d).key = v; } while (0) + do { (d).is_set__##typ##_ |= (1ULL << KEYSET_OPTIDX_##typ##__##key); (d).key = v; } while (0) #define ADD(array, item) \ kv_push(array, item) |