diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2018-10-13 10:53:05 +0200 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2018-10-13 16:37:17 +0200 |
commit | 3d84cf6ff4361e318a0571c87d44e8a77c1c2839 (patch) | |
tree | 11e2b25522bc061c1ece66825e07cd018c68c377 /src/nvim/api/buffer.c | |
parent | 8bbb28b9732bfa430a963f16498d8ec42c637ca9 (diff) | |
download | rneovim-3d84cf6ff4361e318a0571c87d44e8a77c1c2839.tar.gz rneovim-3d84cf6ff4361e318a0571c87d44e8a77c1c2839.tar.bz2 rneovim-3d84cf6ff4361e318a0571c87d44e8a77c1c2839.zip |
api: make nvim_buf_set_virtual_text handle invalid chars
Clients are supposed to supply only valid text, but if it is
invalid, translate it rather than messing up the screen
Diffstat (limited to 'src/nvim/api/buffer.c')
-rw-r--r-- | src/nvim/api/buffer.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 16196ec910..1491901877 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -13,6 +13,7 @@ #include "nvim/api/private/defs.h" #include "nvim/vim.h" #include "nvim/buffer.h" +#include "nvim/charset.h" #include "nvim/cursor.h" #include "nvim/memline.h" #include "nvim/memory.h" @@ -933,7 +934,7 @@ Integer nvim_buf_add_highlight(Buffer buffer, return src_id; } -/// Clears highlights from a given source group and a range of lines +/// Clears highlights and virtual text from a given source id and range of lines /// /// To clear a source group in the entire buffer, pass in 0 and -1 to /// line_start and line_end respectively. @@ -976,6 +977,10 @@ void nvim_buf_clear_highlight(Buffer buffer, /// begin after one cell to the right of the ordinary text, this will contain /// the |lcs-eol| char if set, otherwise just be a space. /// +/// The same src_id can be used for both virtual text and highlights added by +/// nvim_buf_add_highlight. Virtual text is cleared using +/// nvim_buf_clear_highlight. +/// /// @param buffer Buffer handle /// @param src_id Source group to use or 0 to use a new group, /// or -1 for a ungrouped annotation @@ -1025,7 +1030,7 @@ Integer nvim_buf_set_virtual_text(Buffer buffer, } String str = chunk.items[0].data.string; - char *text = xstrdup(str.size > 0 ? str.data : ""); + char *text = transstr(str.size > 0 ? str.data : ""); // allocates int hl_id = 0; if (chunk.size == 2) { |