Skip to content
Merged
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
20 changes: 11 additions & 9 deletions lua/telescope-orgmode/actions.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require('telescope-orgmode.typehints')
local finders = require('telescope-orgmode.finders')
local org = require('telescope-orgmode.org')

Expand Down Expand Up @@ -60,13 +61,14 @@ function M.insert(_)
---@type MatchEntry
local entry = action_state.get_selected_entry()

-- Link to the filename by default
local destination = entry.value.file.filename

-- Link to a specific heading if is set
if entry.value.headline then
destination = 'file:' .. entry.value.file.filename .. '::*' .. entry.value.headline.title
end
local destination = (function()
if entry.value.headline then
-- Link to a specific heading if is set
return entry.value.headline:get_link()
else
return entry.value.file:get_link()
end
end)()

org.insert_link(destination)
return true
Expand All @@ -83,11 +85,11 @@ function M._find_orgfiles(opts, prompt_bufnr)
M._update_picker(orgfiles, opts.prompt_titles.orgfiles, prompt_bufnr)
end

function M._update_picker(results, title, prompt_bufnr)
function M._update_picker(finder, title, prompt_bufnr)
local current_picker = action_state.get_current_picker(prompt_bufnr)

current_picker.layout.prompt.border:change_title(title)
current_picker:refresh(results)
current_picker:refresh(finder)
end

return M
8 changes: 1 addition & 7 deletions lua/telescope-orgmode/entry_maker/headlines.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
require('telescope-orgmode.typehints')
require('telescope-orgmode.entry_maker.types')
local org = require('telescope-orgmode.org')
local entry_display = require('telescope.pickers.entry_display')

---@class OrgHeadlineEntry
---@field file OrgApiFile
---@field filename string
---@field headline OrgApiHeadline

---@param file_results { file: OrgApiFile, filename: string }[]
---@return OrgHeadlineEntry[]
local function index_headlines(file_results, opts)
Expand All @@ -20,7 +15,6 @@ local function index_headlines(file_results, opts)
file = file_entry.file,
filename = file_entry.filename,
headline = headline,
title = nil,
}
table.insert(results, entry)
end
Expand Down
7 changes: 1 addition & 6 deletions lua/telescope-orgmode/entry_maker/orgfiles.lua
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
require('telescope-orgmode.typehints')
require('telescope-orgmode.entry_maker.types')
local org = require('telescope-orgmode.org')
local entry_display = require('telescope.pickers.entry_display')

local M = {}

---@class OrgFileEntry
---@field file OrgApiFile
---@field filename string
---@field title string?

---@param file_results { file: OrgApiFile, filename: string }[]
---@return OrgFileEntry[]
local function index_orgfiles(file_results)
Expand Down
Empty file.
1 change: 0 additions & 1 deletion lua/telescope-orgmode/mappings.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
local config = require('telescope-orgmode.config')
local to_actions = require('telescope-orgmode.actions')

local M = {}
Expand Down
2 changes: 2 additions & 0 deletions lua/telescope-orgmode/org.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require('telescope-orgmode.typehints')

local OrgApiHeadline = require('orgmode.api.headline')
local OrgApiFile = require('orgmode.api.file')
local OrgApi = require('orgmode.api')

local M = {}
Expand Down
21 changes: 10 additions & 11 deletions lua/telescope-orgmode/typehints.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
---@class MatchEntry
---@field value OrgHeadlineEntry | OrgFileEntry
---@field ordinal string
---@field filename string
---@field lnum number
---@field display function
---@field location string,
---@field line string,
---@field tags string,

-- Type-hints copied from nvim-orgmode to simplify development

---@class OrgFileMetadata
Expand All @@ -32,13 +22,18 @@
---@field filename string absolute path of the current file
---@field headlines OrgApiHeadline[]
---@field is_archive_file boolean
---@field get_link string
---@field private _file OrgFile
--
---@class OrgRange
---@field start_line number
---@field start_col number
---@field end_line number
---@field end_col number
---
---@class OrgHeadline
---@field headline TSNode
---@field file OrgFile

---@class OrgApiHeadline
---@field title string headline title without todo keyword, tags and priority. Ex. `* TODO I am a headline :SOMETAG:` returns `I am a headline`
Expand All @@ -59,7 +54,11 @@
---@field priority string|nil
---@field is_archived boolean headline marked with the `:ARCHIVE:` tag
---@field headlines OrgApiHeadline[]
--
---@field id_get_or_create number
---@field get_link string
---@field private _section OrgHeadline
---@field private _index number

---@class OrgApiRefileOpts
---@field source OrgApiHeadline
---@field destination OrgApiFile | OrgApiHeadline
Expand Down