feat(api/ui): win_extmarks

This commit is contained in:
Yatao Li
2021-09-16 07:53:56 +08:00
parent 8ea84eee57
commit 29a6cda3ff
13 changed files with 332 additions and 28 deletions

View File

@@ -146,6 +146,10 @@ static Array extmark_to_array(ExtmarkInfo extmark, bool id, bool add_dict)
STRING_OBJ(cstr_to_string(virt_text_pos_str[decor->virt_text_pos])));
}
if (decor->ui_watched) {
PUT(dict, "ui_watched", BOOLEAN_OBJ(true));
}
if (kv_size(decor->virt_lines)) {
Array all_chunks = ARRAY_DICT_INIT;
bool virt_lines_leftcol = false;
@@ -170,7 +174,7 @@ static Array extmark_to_array(ExtmarkInfo extmark, bool id, bool add_dict)
PUT(dict, "virt_lines_leftcol", BOOLEAN_OBJ(virt_lines_leftcol));
}
if (decor->hl_id || kv_size(decor->virt_text)) {
if (decor->hl_id || kv_size(decor->virt_text) || decor->ui_watched) {
PUT(dict, "priority", INTEGER_OBJ(decor->priority));
}
@@ -472,6 +476,10 @@ Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id, Object start, Object e
/// When a character is supplied it is used as |:syn-cchar|.
/// "hl_group" is used as highlight for the cchar if provided,
/// otherwise it defaults to |hl-Conceal|.
/// - ui_watched: boolean that indicates the mark should be drawn
/// 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.
///
/// @param[out] err Error details, if any
/// @return Id of the created/updated extmark
@@ -709,6 +717,8 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer
bool ephemeral = false;
OPTION_TO_BOOL(ephemeral, ephemeral, false);
OPTION_TO_BOOL(decor.ui_watched, ui_watched, false);
if (line < 0) {
api_set_error(err, kErrorTypeValidation, "line value outside range");
goto error;
@@ -762,7 +772,7 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer
// TODO(bfredl): synergize these two branches even more
if (ephemeral && decor_state.buf == buf) {
decor_add_ephemeral((int)line, (int)col, line2, col2, &decor);
decor_add_ephemeral((int)line, (int)col, line2, col2, &decor, (uint64_t)ns_id, id);
} else {
if (ephemeral) {
api_set_error(err, kErrorTypeException, "not yet implemented");

View File

@@ -28,6 +28,7 @@ return {
"line_hl_group";
"cursorline_hl_group";
"conceal";
"ui_watched";
};
keymap = {
"noremap";

View File

@@ -810,3 +810,4 @@ static void remote_ui_inspect(UI *ui, Dictionary *info)
UIData *data = ui->data;
PUT(*info, "chan", INTEGER_OBJ((Integer)data->channel_id));
}

View File

@@ -4,6 +4,7 @@
#include <stdint.h>
#include "nvim/api/private/defs.h"
#include "nvim/map.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "api/ui.h.generated.h"

View File

@@ -123,6 +123,10 @@ void win_viewport(Integer grid, Window win, Integer topline,
Integer line_count)
FUNC_API_SINCE(7) FUNC_API_REMOTE_ONLY;
void win_extmark(Integer grid, Window win, Integer ns_id, Integer mark_id,
Integer row, Integer col)
FUNC_API_SINCE(10) FUNC_API_REMOTE_ONLY;
void popupmenu_show(Array items, Integer selected,
Integer row, Integer col, Integer grid)
FUNC_API_SINCE(3) FUNC_API_REMOTE_ONLY;