Skip to content

Commit 02c2d77

Browse files
authored
feat(title): add title configuration for window (#4)
* feat(title): add title configuration for window The title can now be configured in the `setup` or when toggling the window. * fix: toggle_gitpad called without opts
1 parent 0b66fe1 commit 02c2d77

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ using [lazy.nvim](https://github.com/folke/lazy.nvim):
3737
{
3838
'<leader>pp',
3939
function()
40-
require('gitpad').toggle_gitpad()
40+
require('gitpad').toggle_gitpad() -- or require('gitpad').toggle_gitpad({ title = 'Project notes' })
4141
end,
4242
desc = 'gitpad project',
4343
},
4444
{
4545
'<leader>pb',
4646
function()
47-
require('gitpad').toggle_gitpad_branch()
47+
require('gitpad').toggle_gitpad_branch() -- or require('gitpad').toggle_gitpad_branch({ title = 'Branch notes' })
4848
end,
4949
desc = 'gitpad branch',
5050
},
@@ -53,7 +53,7 @@ using [lazy.nvim](https://github.com/folke/lazy.nvim):
5353
'<leader>pd',
5454
function()
5555
local date_filename = 'daily-' .. os.date('%Y-%m-%d.md')
56-
require('gitpad').toggle_gitpad({ filename = date_filename })
56+
require('gitpad').toggle_gitpad({ filename = date_filename }) -- or require('gitpad').toggle_gitpad({ filename = date_filename, title = 'Daily notes' })
5757
end,
5858
desc = 'gitpad daily notes',
5959
},
@@ -67,7 +67,7 @@ using [lazy.nvim](https://github.com/folke/lazy.nvim):
6767
return
6868
end
6969
filename = vim.fn.pathshorten(filename, 2) .. '.md'
70-
require('gitpad').toggle_gitpad({ filename = filename })
70+
require('gitpad').toggle_gitpad({ filename = filename }) -- or require('gitpad').toggle_gitpad({ filename = filename, title = 'Current file notes' })
7171
end,
7272
desc = 'gitpad per file notes',
7373
},
@@ -84,6 +84,7 @@ gitpad.nvim comes with the following defaults:
8484

8585
```lua
8686
{
87+
title = 'gitpad', -- The title of the floating window
8788
border = 'single', -- The border style of the floating window. Possible values are `'single'`, `'double'`, `'shadow'`, `'rounded'`, and `''` (no border).
8889
style = '', -- The style of the floating window. Possible values are `'minimal'` (no line numbers, statusline, or sign column. See :help nvim_open_win() '), and `''` (default Neovim style).
8990
dir = vim.fn.stdpath('data') .. '/gitpad', -- The directory where the notes are stored. Possible value is a valid path ie '~/notes'

lua/gitpad/init.lua

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local uv = vim.uv or vim.loop
44
local gitpad_win_id = nil
55

66
M.config = {
7+
title = 'gitpad',
78
border = 'single',
89
dir = vim.fs.normalize(vim.fn.stdpath('data') .. '/gitpad'),
910
style = '',
@@ -125,7 +126,7 @@ end
125126

126127
function M.open_window(opts)
127128
local path = opts.path
128-
local title = ' gitpad '
129+
local title = opts.title or M.config.title
129130

130131
local ui = vim.api.nvim_list_uis()[1]
131132
local width = math.floor((ui.width * 0.5) + 0.5)
@@ -142,7 +143,7 @@ function M.open_window(opts)
142143
}
143144

144145
if vim.fn.has('nvim-0.9.0') == 1 then
145-
win_opts.title = title
146+
win_opts.title = ' ' .. title .. ' '
146147
win_opts.title_pos = 'left'
147148
end
148149

@@ -191,11 +192,13 @@ end
191192
function M.toggle_gitpad(opts)
192193
opts = opts or {}
193194
local path = M.init_gitpad_file(opts)
194-
M.toggle_window { path = path }
195+
196+
M.toggle_window(vim.tbl_deep_extend('force', opts, { path = path }))
195197
end
196198

197-
function M.toggle_gitpad_branch()
198-
M.toggle_gitpad { filename = H.get_branch_filename() }
199+
function M.toggle_gitpad_branch(opts)
200+
opts = vim.tbl_deep_extend('force', opts or {}, { filename = H.get_branch_filename() })
201+
M.toggle_gitpad(opts)
199202
end
200203

201204
M.setup = function(opts)

0 commit comments

Comments
 (0)