-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: integrate with nvim-tree to avoid collisions
close #163
- Loading branch information
Showing
8 changed files
with
88 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
local M = {} | ||
|
||
M.options = { | ||
["nvim-tree"] = require("fidget.integration.nvim-tree") | ||
} | ||
|
||
require("fidget.options").declare(M, "integration", M.options) | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,53 @@ | ||
local M = {} | ||
|
||
require("fidget.options").declare(M, "integration.nvim-tree", { | ||
enable = false, | ||
}, function() | ||
if M.option.enable == true then | ||
local ntree = require("nvim-tree") | ||
local win = require("fidget.notification.window") | ||
-- Only register one callback, so setup() can be called multiple times. | ||
local already_subscribed = false | ||
|
||
ntree.api.events.subscribe(ntree.api.events.TreeOpen, function() | ||
if win.relative == "editor" then | ||
---@options integration.nvim-tree [[ | ||
--- nvim-tree integration | ||
M.options = { | ||
--- Integrate with nvim-tree/nvim-tree.lua (if installed) | ||
--- | ||
--- Dynamically offset Fidget's notifications window when the nvim-tree window | ||
--- is open on the right side + the Fidget window is "editor"-relative. | ||
--- | ||
---@type boolean | ||
enable = true, | ||
} | ||
---@options ]] | ||
|
||
end | ||
end) | ||
require("fidget.options").declare(M, "integration.nvim-tree", M.options, function() | ||
if not M.options.enable or already_subscribed then | ||
return | ||
end | ||
|
||
local ok, api = pcall(function() return require("nvim-tree.api") end) | ||
if not ok then | ||
return | ||
end | ||
|
||
ntree.api.events.subscribe(ntree.api.events.TreeClose, function() | ||
win.set_x_offset(0) | ||
end) | ||
already_subscribed = true | ||
|
||
ntree.api.events.subscripe(ntree.api.events.Resize, function(size) | ||
local win = require("fidget.notification.window") | ||
|
||
end) | ||
local function resize() | ||
if win.options.relative == "editor" then | ||
local winid = api.tree.winid() | ||
local col = vim.api.nvim_win_get_position(winid)[2] | ||
if col > 1 then | ||
local width = vim.api.nvim_win_get_width(winid) | ||
win.set_x_offset(width) | ||
end | ||
end | ||
end | ||
|
||
local function reset() | ||
win.set_x_offset(0) | ||
end | ||
|
||
api.events.subscribe(api.events.Event.TreeOpen, resize) | ||
api.events.subscribe(api.events.Event.Resize, resize) | ||
api.events.subscribe(api.events.Event.TreeClose, reset) | ||
end) | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters