decoration: split out "decoration" from "extmark" module

Decorations will only grow more complex. move the to a separate
file, so that extmark.c remains about extmarks.
This commit is contained in:
Björn Linse
2020-11-07 09:24:00 +01:00
parent da134270d3
commit 8497d4b3ea
15 changed files with 471 additions and 428 deletions

View File

@@ -28,6 +28,7 @@
#include "nvim/map.h"
#include "nvim/mark.h"
#include "nvim/extmark.h"
#include "nvim/decoration.h"
#include "nvim/fileio.h"
#include "nvim/move.h"
#include "nvim/syntax.h"
@@ -1470,15 +1471,15 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id,
}
// TODO(bfredl): synergize these two branches even more
if (ephemeral && redrawn_win && redrawn_win->w_buffer == buf) {
if (ephemeral && decor_state.buf == buf) {
int attr_id = hl_id > 0 ? syn_id2attr(hl_id) : 0;
VirtText *vt_allocated = NULL;
if (kv_size(virt_text)) {
vt_allocated = xmalloc(sizeof *vt_allocated);
*vt_allocated = virt_text;
}
decorations_add_ephemeral(attr_id, (int)line, (colnr_T)col,
(int)line2, (colnr_T)col2, vt_allocated);
decor_add_ephemeral(attr_id, (int)line, (colnr_T)col,
(int)line2, (colnr_T)col2, vt_allocated);
} else {
if (ephemeral) {
api_set_error(err, kErrorTypeException, "not yet implemented");
@@ -1490,7 +1491,7 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id,
decor->hl_id = hl_id;
decor->virt_text = virt_text;
} else if (hl_id) {
decor = decoration_hl(hl_id);
decor = decor_hl(hl_id);
}
id = extmark_set(buf, (uint64_t)ns_id, id, (int)line, (colnr_T)col,
@@ -1609,7 +1610,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,
decoration_hl(hl_id), kExtmarkNoUndo);
decor_hl(hl_id), kExtmarkNoUndo);
return src_id;
}
@@ -1728,7 +1729,7 @@ Integer nvim_buf_set_virtual_text(Buffer buffer,
}
VirtText *existing = extmark_find_virttext(buf, (int)line, ns_id);
VirtText *existing = decor_find_virttext(buf, (int)line, ns_id);
if (existing) {
clear_virttext(existing);

View File

@@ -27,6 +27,7 @@
#include "nvim/map_defs.h"
#include "nvim/map.h"
#include "nvim/extmark.h"
#include "nvim/decoration.h"
#include "nvim/option.h"
#include "nvim/option_defs.h"
#include "nvim/version.h"
@@ -1652,11 +1653,11 @@ const char *describe_ns(NS ns_id)
return "(UNKNOWN PLUGIN)";
}
DecorationProvider *get_provider(NS ns_id, bool force)
DecorProvider *get_provider(NS ns_id, bool force)
{
ssize_t i;
for (i = 0; i < (ssize_t)kv_size(decoration_providers); i++) {
DecorationProvider *item = &kv_A(decoration_providers, i);
for (i = 0; i < (ssize_t)kv_size(decor_providers); i++) {
DecorProvider *item = &kv_A(decor_providers, i);
if (item->ns_id == ns_id) {
return item;
} else if (item->ns_id > ns_id) {
@@ -1668,12 +1669,12 @@ DecorationProvider *get_provider(NS ns_id, bool force)
return NULL;
}
for (ssize_t j = (ssize_t)kv_size(decoration_providers)-1; j >= i; j++) {
for (ssize_t j = (ssize_t)kv_size(decor_providers)-1; j >= i; j++) {
// allocates if needed:
(void)kv_a(decoration_providers, (size_t)j+1);
kv_A(decoration_providers, (size_t)j+1) = kv_A(decoration_providers, j);
(void)kv_a(decor_providers, (size_t)j+1);
kv_A(decor_providers, (size_t)j+1) = kv_A(decor_providers, j);
}
DecorationProvider *item = &kv_a(decoration_providers, (size_t)i);
DecorProvider *item = &kv_a(decor_providers, (size_t)i);
*item = DECORATION_PROVIDER_INIT(ns_id);
return item;

View File

@@ -7,6 +7,7 @@
#include "nvim/vim.h"
#include "nvim/getchar.h"
#include "nvim/memory.h"
#include "nvim/decoration.h"
#include "nvim/ex_eval.h"
#include "nvim/lib/kvec.h"

View File

@@ -355,7 +355,7 @@ void nvim_ui_pum_set_height(uint64_t channel_id, Integer height, Error *err)
/// Note that this method is not to be confused with |nvim_ui_pum_set_height()|,
/// which sets the number of visible items in the popup menu, while this
/// function sets the bounding box of the popup menu, including visual
/// decorations such as boarders and sliders. Floats need not use the same font
/// elements such as borders and sliders. Floats need not use the same font
/// size, nor be anchored to exact grid corners, so one can set floating-point
/// numbers to the popup menu geometry.
///

View File

@@ -41,7 +41,7 @@
#include "nvim/ops.h"
#include "nvim/option.h"
#include "nvim/state.h"
#include "nvim/extmark.h"
#include "nvim/decoration.h"
#include "nvim/syntax.h"
#include "nvim/getchar.h"
#include "nvim/os/input.h"
@@ -2685,7 +2685,7 @@ void nvim__screenshot(String path)
ui_call_screenshot(path);
}
static void clear_provider(DecorationProvider *p)
static void clear_provider(DecorProvider *p)
{
NLUA_CLEAR_REF(p->redraw_start);
NLUA_CLEAR_REF(p->redraw_buf);
@@ -2711,7 +2711,7 @@ static void clear_provider(DecorationProvider *p)
/// callback can return `false` to disable the provider until the next redraw.
/// Similarily, return `false` in `on_win` will skip the `on_lines` calls
/// for that window (but any extmarks set in `on_win` will still be used).
/// A plugin managing multiple sources of decorations should ideally only set
/// A plugin managing multiple sources of decoration should ideally only set
/// one provider, and merge the sources internally. You can use multiple `ns_id`
/// for the extmarks set/modified inside the callback anyway.
///
@@ -2739,7 +2739,7 @@ void nvim_set_decoration_provider(Integer ns_id, DictionaryOf(LuaRef) opts,
Error *err)
FUNC_API_SINCE(7) FUNC_API_LUA_ONLY
{
DecorationProvider *p = get_provider((NS)ns_id, true);
DecorProvider *p = get_provider((NS)ns_id, true);
clear_provider(p);
// regardless of what happens, it seems good idea to redraw