Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow opening files as temporary notes #149

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lua/dbee/api/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ function ui.editor_namespace_create_note(id, name)
return state.editor():namespace_create_note(id, name)
end

--- Opens a file as a temporary note in the global namespace
---@param id namespace_id
---@param file string
---@return note_id
function ui.editor_open_file_as_note(file)
return state.editor():open_file_as_note(file)
end

--- Get notes of a specified namespace.
---@param id namespace_id
---@return note_details[]
Expand Down
11 changes: 11 additions & 0 deletions lua/dbee/ui/drawer/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ function DrawerUI:new(handler, editor, result, opts)
o:on_current_note_changed(data)
end)

editor:register_event_listener("note_created",
function (data)
o:on_note_created(data)
end)

return o
end

Expand All @@ -130,6 +135,12 @@ function DrawerUI:on_current_note_changed(data)
self:refresh()
end

-- event listener for new note created
---@private
function DrawerUI:on_note_created(_)
self:refresh()
end

---@private
---@param bufnr integer
---@return NuiTree tree
Expand Down
22 changes: 22 additions & 0 deletions lua/dbee/ui/editor/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,28 @@ function EditorUI:namespace_create_note(id, name)
return note_id
end

-- Creates a new note in namespace.
-- Errors if id or name is nil or there is a note with the same
-- name in namespace already.
---@param file string
---@return note_id
function EditorUI:open_file_as_note(file)
---@type note_details
local s = {
id = file,
name = file,
file = file,
}

-- a bit shitty
self.notes["global"] = self.notes["global"] or {}
self.notes["global"][file] = s

self:trigger_event("note_created", { note = s })

return file
end

---@param id namespace_id
---@return note_details[]
function EditorUI:namespace_get_notes(id)
Expand Down