diff options
author | Joshua Minor <github@pixelverse.org> | 2021-11-21 15:25:45 -0800 |
---|---|---|
committer | Joshua Minor <github@pixelverse.org> | 2021-11-21 15:25:45 -0800 |
commit | c916e5cda7df66b9affae73b707435a614d7f4b3 (patch) | |
tree | 3b6d519633b8dc562dd7de15b03942d91902b7d4 /plugins | |
parent | a5f06db1bbaa1b315ae88d157a2135b0d6631ad6 (diff) | |
download | lite-xl-plugins-c916e5cda7df66b9affae73b707435a614d7f4b3.tar.gz lite-xl-plugins-c916e5cda7df66b9affae73b707435a614d7f4b3.zip |
Switched to TreeView:color_for_item(abs_path)
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/gitstatus.lua | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/plugins/gitstatus.lua b/plugins/gitstatus.lua index 4de2267..bb1882c 100644 --- a/plugins/gitstatus.lua +++ b/plugins/gitstatus.lua @@ -3,16 +3,18 @@ local core = require "core" local common = require "core.common" local config = require "core.config" local style = require "core.style" -local _, TreeView = pcall(require, "plugins.treeview") local StatusView = require "core.statusview" +local TreeView = require "plugins.treeview" + local scan_rate = config.project_scan_rate or 5 +local cached_color_for_item = {} -if TreeView then - if not (TreeView["set_color_override"] and TreeView["clear_all_color_overrides"]) then - -- TreeView doesn't have the color override feature we rely on, so skip it. - TreeView = nil - end +-- Override TreeView's color_for_item, but first +-- stash the old one (using [] in case it is not there at all) +local old_color_for_item = TreeView["color_for_item"] +function TreeView:color_for_item(abs_path) + return cached_color_for_item[abs_path] or old_color_for_item(abs_path) end @@ -60,29 +62,26 @@ core.add_thread(function() diff = diff .. diff2 end - if TreeView then - TreeView:clear_all_color_overrides() - end + -- forget the old state + cached_color_for_item = {} - local root = "" + local folder = core.project_dir for line in string.gmatch(diff, "[^\n]+") do local submodule = line:match("^Entering '(.+)'$") if submodule then - root = submodule.."/" + folder = core.project_dir .. PATHSEP .. submodule else local ins, dels, path = line:match("(%d+)%s+(%d+)%s+(.+)") if path then inserts = inserts + (tonumber(ins) or 0) deletes = deletes + (tonumber(dels) or 0) - local abs_path = core.project_dir.."/"..root..path - if TreeView then - -- Color this file, and each parent folder, - -- so you can see at a glance which folders - -- have modified files in them. - while abs_path do - TreeView:set_color_override(abs_path, style.gitstatus_modification) - abs_path = common.dirname(abs_path) - end + local abs_path = folder .. PATHSEP .. path + -- Color this file, and each parent folder, + -- so you can see at a glance which folders + -- have modified files in them. + while abs_path do + cached_color_for_item[abs_path] = style.gitstatus_modification + abs_path = common.dirname(abs_path) end end end |