-
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
base: main
Are you sure you want to change the base?
Conversation
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.
Just left some comments.
I have a similar, albeit much simpler, rg command to look for various 'tasks'. Having this in the core makes sense IMO.
Side note:
Maybe it is worth discussing what tasks feature obsidian.nvim
wants to implement in the long-term.
Obsidian comes with the fairly popular tasks plugin: https://github.com/obsidian-tasks-group/obsidian-tasks
And there are a few issues/PR related to task in the original repo.
lua/obsidian/client.lua
Outdated
|
||
---@return obsidian.Task[] | ||
Client.find_tasks = function(self) | ||
local openTasks = search.search(self.dir, "- \\[(.)\\]", search.SearchOpts.default()) |
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:
'([-+*]|[0-9]+\.) \[[- x/<>?!*"lb~]\] .+'
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:
$ cat test.md
- [ ] normal
+ [ ] plus
* [ ] star
- [x] normal x-ed
- [!] normal !-ed
- [~] normal ~-ed (render-markdown)
1. [ ] ordered
2. [x] ordered x-ed
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
@andrewinci I just gave this a test run. With With
|
Much interest from my side. I just tried out your branch and it's how I would imagine such a feature. What I am missing is:
I use the todo plugin in obsidian, although I like the idea of having a floating todo list like this even better. It's available everywhere and not tied to a specific document and it is not adding a big new concept of a dynamically updating markdown document. |
@andrewinci do you want to push this feature along? This would be highly appreciated. |
Hey @sotte, I'll try to pick this up this weekend |
41c2571
to
cd0ebbd
Compare
This seems to happen for telescope when newlines are encountered in the input. I could get rid of it by replacing newlines: diff --git a/lua/obsidian/commands/tasks.lua b/lua/obsidian/commands/tasks.lua
index 8be0995..e839581 100644
--- a/lua/obsidian/commands/tasks.lua
+++ b/lua/obsidian/commands/tasks.lua
@@ -51,8 +51,9 @@ local function showTasks(client, data)
for _, task in ipairs(tasks) do
local tStatus = checkboxes[task.status]
if tStatus and (not filter or tStatus.name == filter) then
+ descr_trimmed = string.gsub(task.description, "\n"," ")
table.insert(toShow, {
- display = string.format(" %s", task.description),
+ display = string.format(" %s", descr_trimmed),
filename = task.path,
lnum = task.line,
icon = tStatus.char, Not sure if that is the appropriate place or even method for this, but at least that would work for a first approach perhaps. See also: nvim-telescope/telescope.nvim#3163 |
@sstark, thank you for the suggestion, I've just updated the client to strip out \n from the description as suggested. |
@andrewinci Cool! Thank you for doing that. Some comments from my side:
|
ade5ddb
to
95cc004
Compare
Add the command
ObsidianTasks
to allow users to quickly filter all the todos.Changes: