aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/api')
-rw-r--r--src/nvim/api/extmark.c23
-rw-r--r--src/nvim/api/keysets_defs.h2
-rw-r--r--src/nvim/api/ui.c8
-rw-r--r--src/nvim/api/vim.c6
4 files changed, 39 insertions, 0 deletions
diff --git a/src/nvim/api/extmark.c b/src/nvim/api/extmark.c
index 1f0e867162..27a4b7854f 100644
--- a/src/nvim/api/extmark.c
+++ b/src/nvim/api/extmark.c
@@ -481,6 +481,8 @@ Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id, Object start, Object e
/// by a UI. When set, the UI will receive win_extmark events.
/// Note: the mark is positioned by virt_text attributes. Can be
/// used together with virt_text.
+/// - url: A URL to associate with this extmark. In the TUI, the OSC 8 control
+/// sequence is used to generate a clickable hyperlink to this URL.
///
/// @param[out] err Error details, if any
/// @return Id of the created/updated extmark
@@ -494,6 +496,7 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer
DecorSignHighlight sign = DECOR_SIGN_HIGHLIGHT_INIT;
DecorVirtText virt_text = DECOR_VIRT_TEXT_INIT;
DecorVirtText virt_lines = DECOR_VIRT_LINES_INIT;
+ char *url = NULL;
bool has_hl = false;
buf_T *buf = find_buffer_by_handle(buffer, err);
@@ -678,6 +681,10 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer
has_hl = true;
}
+ if (HAS_KEY(opts, set_extmark, url)) {
+ url = string_to_cstr(opts->url);
+ }
+
if (opts->ui_watched) {
hl.flags |= kSHUIWatched;
if (virt_text.pos == kVPosOverlay) {
@@ -747,6 +754,11 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer
if (kv_size(virt_lines.data.virt_lines)) {
decor_range_add_virt(&decor_state, r, c, line2, col2, decor_put_vt(virt_lines, NULL), true);
}
+ if (url != NULL) {
+ DecorSignHighlight sh = DECOR_SIGN_HIGHLIGHT_INIT;
+ sh.url = url;
+ decor_range_add_sh(&decor_state, r, c, line2, col2, &sh, true, 0, 0);
+ }
if (has_hl) {
DecorSignHighlight sh = decor_sh_from_inline(hl);
decor_range_add_sh(&decor_state, r, c, line2, col2, &sh, true, (uint32_t)ns_id, id);
@@ -772,7 +784,14 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer
}
uint32_t decor_indexed = DECOR_ID_INVALID;
+ if (url != NULL) {
+ DecorSignHighlight sh = DECOR_SIGN_HIGHLIGHT_INIT;
+ sh.url = url;
+ sh.next = decor_indexed;
+ decor_indexed = decor_put_sh(sh);
+ }
if (sign.flags & kSHIsSign) {
+ sign.next = decor_indexed;
decor_indexed = decor_put_sh(sign);
if (sign.text[0]) {
decor_flags |= MT_FLAG_DECOR_SIGNTEXT;
@@ -814,6 +833,10 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer
error:
clear_virttext(&virt_text.data.virt_text);
clear_virtlines(&virt_lines.data.virt_lines);
+ if (url != NULL) {
+ xfree(url);
+ }
+
return 0;
}
diff --git a/src/nvim/api/keysets_defs.h b/src/nvim/api/keysets_defs.h
index b2f0039eb9..811f60f4d6 100644
--- a/src/nvim/api/keysets_defs.h
+++ b/src/nvim/api/keysets_defs.h
@@ -54,6 +54,7 @@ typedef struct {
Boolean spell;
Boolean ui_watched;
Boolean undo_restore;
+ String url;
} Dict(set_extmark);
typedef struct {
@@ -183,6 +184,7 @@ typedef struct {
Boolean fg_indexed;
Boolean bg_indexed;
Boolean force;
+ String url;
} Dict(highlight);
typedef struct {
diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c
index b42c274411..f955b315a8 100644
--- a/src/nvim/api/ui.c
+++ b/src/nvim/api/ui.c
@@ -784,6 +784,14 @@ void remote_ui_hl_attr_define(UI *ui, Integer id, HlAttrs rgb_attrs, HlAttrs cte
MAXSIZE_TEMP_DICT(cterm, HLATTRS_DICT_SIZE);
hlattrs2dict(&rgb, NULL, rgb_attrs, true, false);
hlattrs2dict(&cterm, NULL, rgb_attrs, false, false);
+
+ // URLs are not added in hlattrs2dict since they are used only by UIs and not by the highlight
+ // system. So we add them here.
+ if (rgb_attrs.url >= 0) {
+ const char *url = hl_get_url((uint32_t)rgb_attrs.url);
+ PUT_C(rgb, "url", STRING_OBJ(cstr_as_string((char *)url)));
+ }
+
ADD_C(args, DICTIONARY_OBJ(rgb));
ADD_C(args, DICTIONARY_OBJ(cterm));
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
index e5a5cc059f..eea9b54a5c 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -176,6 +176,12 @@ void nvim_set_hl(Integer ns_id, String name, Dict(highlight) *val, Error *err)
});
int link_id = -1;
+ // Setting URLs directly through highlight attributes is not supported
+ if (HAS_KEY(val, highlight, url)) {
+ api_free_string(val->url);
+ val->url = NULL_STRING;
+ }
+
HlAttrs attrs = dict2hlattrs(val, true, &link_id, err);
if (!ERROR_SET(err)) {
ns_hl_def((NS)ns_id, hl_id, attrs, link_id, val);