From b28e76ac4ed2f29d1f466ac084cd31ce9c283c42 Mon Sep 17 00:00:00 2001 From: Andrea Dragotta Date: Tue, 26 Apr 2022 09:14:24 +0200 Subject: [PATCH 1/4] Added option to exclude filetypes --- lua/shade.lua | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/lua/shade.lua b/lua/shade.lua index 991f168..b630595 100644 --- a/lua/shade.lua +++ b/lua/shade.lua @@ -148,6 +148,33 @@ local function map_key(mode, key, action) end +-- + +local function is_filetype_excluded(filetype) + for _, value in ipairs(state.exclude_filetypes) do + if value == filetype then + return true + end + + end + return false +end + +local function can_shade(winid) + if #state.exclude_filetypes == 0 then + return true + end + local buf_id = vim.api.nvim_win_get_buf(winid) + local filetype = vim.api.nvim_buf_get_option(buf_id, "filetype") + + if is_filetype_excluded(filetype) then + return false + end + + return true +end + +-- local function shade_window(winid) local overlay = state.active_overlays[winid] @@ -181,8 +208,10 @@ local function shade_tabpage(winid) for overlay_winid, _ in pairs(state.active_overlays) do local diff_enabled = api.nvim_win_get_option(overlay_winid, 'diff') if overlay_winid ~= winid and diff_enabled == false then - log("deactivating window", overlay_winid) - shade_window(overlay_winid) + if can_shade(overlay_winid) then + log("deactivating window", overlay_winid) + shade_window(overlay_winid) + end end end end @@ -232,6 +261,7 @@ shade.init = function(opts) E.DEFAULT_OVERLAY_OPACITY) state.opacity_step = opts.opacity_step or E.DEFAULT_OPACITY_STEP state.shade_under_float = opts.shade_under_float or true + state.exclude_filetypes = opts.exclude_filetypes or {} state.shade_nsid = api.nvim_create_namespace("shade") From 5afa45d3555c184db35a0ab05d78779b07f3a0f0 Mon Sep 17 00:00:00 2001 From: andreadev-it <68549121+andreadev-it@users.noreply.github.com> Date: Tue, 26 Apr 2022 09:16:44 +0200 Subject: [PATCH 2/4] Update README.md --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f227265..8ab9adb 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,8 @@ require'shade'.setup({ brightness_up = '', brightness_down = '', toggle = 's', - } + }, + exclude_filetypes = { "neo-tree", "markdown" } }) ``` @@ -35,6 +36,8 @@ require'shade'.setup({ * The color of the numbers in the brightness control popup can be customized by creating a highlight group named: `ShadeBrightnessPopup` and setting the attributes to your liking. +* The `exclude_filetypes` table above is just an example. No filetypes are excluded by default. + ## License Copyright (c) Senghan Bright. Distributed under the MIT license From 43372ca2ab5d9bc8ece7799fb9d84a05df21e25c Mon Sep 17 00:00:00 2001 From: Andrea Dragotta Date: Tue, 26 Apr 2022 09:33:58 +0200 Subject: [PATCH 3/4] Prevent shading of filetypes when navigating tabs --- lua/shade.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lua/shade.lua b/lua/shade.lua index b630595..f7877d0 100644 --- a/lua/shade.lua +++ b/lua/shade.lua @@ -242,7 +242,9 @@ local function create_tabpage_overlays(tabid) local wincfg for _, winid in pairs(api.nvim_tabpage_list_wins(tabid)) do wincfg = api.nvim_call_function("getwininfo", {winid})[1] - create_overlay_window(winid, filter_wininfo(wincfg)) + if can_shade(winid) then + create_overlay_window(winid, filter_wininfo(wincfg)) + end end unshade_window(api.nvim_get_current_win()) end From 423cdb9be77ae64af29e770ef985e30c1c96d690 Mon Sep 17 00:00:00 2001 From: Andrea Dragotta Date: Tue, 26 Apr 2022 09:43:52 +0200 Subject: [PATCH 4/4] Fixed indentation to make it coherent --- lua/shade.lua | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/lua/shade.lua b/lua/shade.lua index f7877d0..4fe803e 100644 --- a/lua/shade.lua +++ b/lua/shade.lua @@ -151,27 +151,27 @@ end -- local function is_filetype_excluded(filetype) - for _, value in ipairs(state.exclude_filetypes) do - if value == filetype then - return true - end - + for _, value in ipairs(state.exclude_filetypes) do + if value == filetype then + return true end - return false + + end + return false end local function can_shade(winid) - if #state.exclude_filetypes == 0 then - return true - end - local buf_id = vim.api.nvim_win_get_buf(winid) - local filetype = vim.api.nvim_buf_get_option(buf_id, "filetype") + if #state.exclude_filetypes == 0 then + return true + end + local buf_id = vim.api.nvim_win_get_buf(winid) + local filetype = vim.api.nvim_buf_get_option(buf_id, "filetype") - if is_filetype_excluded(filetype) then - return false - end + if is_filetype_excluded(filetype) then + return false + end - return true + return true end --