diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2018-10-13 20:15:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-13 20:15:28 +0200 |
commit | 79a11ecfd39cec59701a80daaca8d718234fbb57 (patch) | |
tree | f9c826b74c6d09d124ad191727b3900b8f357ef9 | |
parent | 824f36a980a52f2173bce96bb911ab19460a72d0 (diff) | |
parent | 3d84cf6ff4361e318a0571c87d44e8a77c1c2839 (diff) | |
download | rneovim-79a11ecfd39cec59701a80daaca8d718234fbb57.tar.gz rneovim-79a11ecfd39cec59701a80daaca8d718234fbb57.tar.bz2 rneovim-79a11ecfd39cec59701a80daaca8d718234fbb57.zip |
Merge pull request #9121 from bfredl/virt_invalid
API: make nvim_buf_set_virtual_text handle invalid chars
-rw-r--r-- | src/nvim/api/buffer.c | 9 | ||||
-rw-r--r-- | test/functional/ui/bufhl_spec.lua | 11 |
2 files changed, 18 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) { diff --git a/test/functional/ui/bufhl_spec.lua b/test/functional/ui/bufhl_spec.lua index ba3e44b677..29173ed7ee 100644 --- a/test/functional/ui/bufhl_spec.lua +++ b/test/functional/ui/bufhl_spec.lua @@ -413,5 +413,16 @@ describe('Buffer highlighting', function() | ]]) + set_virtual_text(0, 0, {{"x\tx\ny\ry", "Statement"}, {"aa\000bb", "Number"}}, {}) + screen:expect([[ + 1 + 2 {3:x^Ix^@y^My}{2:aa} | + ^5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5| + , 5, 5, 5, 5, 5, 5,{1:-} | + x = 4 | + {1:~ }| + {1:~ }| + {1:~ }| + | + ]]) end) end) |