diff options
author | Guldoman <giulio.lettieri@gmail.com> | 2022-06-11 06:17:31 +0200 |
---|---|---|
committer | Guldoman <giulio.lettieri@gmail.com> | 2022-06-11 06:18:05 +0200 |
commit | b1d8fc4c6f911f21422900203dc798ae883cde8f (patch) | |
tree | 94f5bcd7b654ad435982817ca661ca2230df8fdc /plugins/minimap.lua | |
parent | 9a391a88a3e7e7d85188dd6cd5ac64695df7ae06 (diff) | |
download | lite-xl-plugins-b1d8fc4c6f911f21422900203dc798ae883cde8f.tar.gz lite-xl-plugins-b1d8fc4c6f911f21422900203dc798ae883cde8f.zip |
`minimap`: correctly manage inserted/removed lines
Diffstat (limited to 'plugins/minimap.lua')
-rw-r--r-- | plugins/minimap.lua | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/plugins/minimap.lua b/plugins/minimap.lua index 6a89b4d..f307053 100644 --- a/plugins/minimap.lua +++ b/plugins/minimap.lua @@ -215,6 +215,41 @@ local char_height = 1 * SCALE * config.plugins.minimap.scale local char_spacing = 0.8 * SCALE * config.plugins.minimap.scale local line_spacing = 2 * SCALE * config.plugins.minimap.scale + +-- Move cache to make space for new lines +local prev_insert_notify = Highlighter.insert_notify +function Highlighter:insert_notify(line, n, ...) + prev_insert_notify(self, line, n, ...) + local blanks = { } + if not highlighter_cache[self] then + highlighter_cache[self] = {} + else + local to = math.min(line + n, #self.doc.lines) + for i=#self.doc.lines+n,to,-1 do + highlighter_cache[self][i] = highlighter_cache[self][i - n] + end + for i=line,to do + highlighter_cache[self][i] = nil + end + end +end + + +-- Close the cache gap created by removed lines +local prev_remove_notify = Highlighter.remove_notify +function Highlighter:remove_notify(line, n, ...) + prev_remove_notify(self, line, n, ...) + if not highlighter_cache[self] then + highlighter_cache[self] = {} + else + local to = math.max(line + n, #self.doc.lines) + for i=line,to do + highlighter_cache[self][i] = highlighter_cache[self][i + n] + end + end +end + + -- Remove changed lines from the cache local prev_tokenize_line = Highlighter.tokenize_line function Highlighter:tokenize_line(idx, state, ...) |