forked from epwalsh/obsidian.nvim
-
Notifications
You must be signed in to change notification settings - Fork 39
feat: add tasks command #29
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
Open
andrewinci
wants to merge
23
commits into
obsidian-nvim:main
Choose a base branch
from
andrewinci:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
c9a0fa9
WIP: Add task command
andrewinci b0bebf0
remove hardcoded states from command
andrewinci 8ae86a5
Update task order
andrewinci 46b9f44
Use configs for task ordering
andrewinci 6cf1631
allow argument to tasks command
andrewinci 62e3a57
Merge branch 'obsidian-nvim:main' into main
andrewinci 6873cce
remove todos
andrewinci 1a6fbff
update default config
andrewinci 2ec3d7b
Merge branch 'obsidian-nvim:main' into main
andrewinci 8121681
Merge branch 'main' into main
andrewinci 052f285
support different list styles
andrewinci 3846ebb
suport 1) list style
andrewinci 64402ee
fix issue in telescope when the description includes a new line
andrewinci ed245bb
autocomplete ObsidianTasks with available options
andrewinci 6f47083
change description for c-n
andrewinci 5dfbd0b
update init and init-legacy
andrewinci f698ae7
fix style
andrewinci d7e0c7a
update documentation
andrewinci b3b9cca
fix task list when the checkbox name is not specified
andrewinci 72742d9
remove mise config file
andrewinci 9a0051d
revert chars
andrewinci 25c6757
Merge branch 'obsidian-nvim:main' into main
andrewinci d260a6b
generate docs
andrewinci File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,77 @@ | ||
---@class CheckboxConfig | ||
---@field name string | ||
---@field order integer | ||
|
||
-- Build the list of task status names sorted by order | ||
---@param checkbox_config table<string,CheckboxConfig> | ||
local function get_task_status_names(checkbox_config) | ||
-- index by status name | ||
---@type table<string, CheckboxConfig> | ||
local task_by_status_name = {} | ||
local status_names = {} | ||
for _, c in pairs(checkbox_config) do | ||
task_by_status_name[c.name] = c | ||
status_names[#status_names + 1] = c.name | ||
end | ||
|
||
-- sort list of status names | ||
table.sort(status_names, function(a, b) | ||
return (task_by_status_name[a].order or 0) < (task_by_status_name[b].order or 0) | ||
end) | ||
|
||
return status_names | ||
end | ||
|
||
---@param current string|nil | ||
---@param status_names table<integer, string> | ||
local function get_next_status(current, status_names) | ||
for i, v in ipairs(status_names) do | ||
if v == current then | ||
return status_names[i + 1] | ||
end | ||
end | ||
return status_names[1] | ||
end | ||
|
||
--- Show tasks with optional filtering | ||
---@param client obsidian.Client | ||
---@param data table | ||
local function showTasks(client, data) | ||
assert(client, "Client is required") | ||
|
||
local filter = data.fargs[1] | ||
local picker = assert(client:picker(), "No picker configured") | ||
|
||
local checkboxes = client.opts.ui.checkboxes | ||
local status_names = get_task_status_names(checkboxes) | ||
|
||
local tasks = client:find_tasks() | ||
local toShow = {} | ||
|
||
for _, task in ipairs(tasks) do | ||
local tStatus = checkboxes[task.status] | ||
if tStatus and (not filter or tStatus.name == filter) then | ||
table.insert(toShow, { | ||
display = string.format(" %s", task.description), | ||
filename = task.path, | ||
lnum = task.line, | ||
icon = tStatus.char, | ||
}) | ||
end | ||
end | ||
|
||
picker:pick(toShow, { | ||
prompt_title = filter and (filter .. " tasks") or "tasks", | ||
query_mappings = { | ||
["<C-n>"] = { | ||
desc = "Toggle task status", | ||
callback = function() | ||
local next_state_name = get_next_status(filter, status_names) | ||
showTasks(client, { fargs = { next_state_name } }) | ||
end, | ||
}, | ||
}, | ||
}) | ||
end | ||
|
||
return showTasks |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tasks can also be
* [ ] like this
.One probably wants to adjust where to search for tasks: specific file, current file, folder, regex. Not everybody closes or moves their tasks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And since recently also
<number> [ ] like this
. We probably want something like this:That's grep -E syntax, I am not sure how it correctly translates to lua regexp string. The various states I got from https://publish.obsidian.md/tasks/Getting+Started/Statuses, perhaps that could be reduced to the ones supported by obsidian.nvim. I also included
~
, which is supported by render-markdown. I used this to test the regex:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are actually quite a few ways to define checkbox lists. We should consolidate once this #48 is merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The different types of list items should be supported now. I'm not restricting the supported statuses beside needing to be only one char since they are configurable in the
ui.checkboxes
config