-
Notifications
You must be signed in to change notification settings - Fork 249
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
Added smart action to perform depending on the cursor context (#329) #518
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.
Thanks for this @CaeChao! Just a few comments
lua/obsidian/util.lua
Outdated
local line_num = unpack(vim.api.nvim_win_get_cursor(0)) -- 1-indexed | ||
local line = vim.api.nvim_get_current_line() | ||
|
||
local checkbox_pattern = "^%s*- %[.] " | ||
local checkboxes = opts and opts or { " ", "~", ">", "x" } |
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.
Should just default to the basics:
local checkboxes = opts and opts or { " ", "~", ">", "x" } | |
local checkboxes = opts or { " ", "x" } |
lua/obsidian/commands/checkbox.lua
Outdated
for k, v in pairs(client.opts.ui.checkboxes) do | ||
local order = v.order | ||
if order and type(order) == "number" then | ||
-- sort the checkboxes based on order | ||
checkboxes[order] = k | ||
end | ||
end |
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.
I think sorting here based on order would be more robust. Something like:
for k, v in pairs(client.opts.ui.checkboxes) do | |
local order = v.order | |
if order and type(order) == "number" then | |
-- sort the checkboxes based on order | |
checkboxes[order] = k | |
end | |
end | |
table.sort(checkboxes, function(a, b) | |
return client.opts.ui.checkboxes[a].order < client.opts.ui.checkboxes[b].order | |
end) |
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.
Thanks for the advice! I'll commit the changes
b923a3c
to
db5e519
Compare
fcd5e97
to
3e2128f
Compare
Not sure if we want to add something like this, but accessing the tags via the "smart action" is quite handy IMO: -- show tags if possible
local current_wrod = vim.fn.expand("<cWORD>")
if current_wrod:match("^#") then
vim.cmd("ObsidianTags")
return
end @CaeChao thanks for bringing this feature over the finish line. |
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.
Looks great, thanks @CaeChao!
Added
Changed