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

Added smart action to perform depending on the cursor context (#329) #518

Merged
merged 4 commits into from
Apr 1, 2024

Conversation

CaeChao
Copy link
Contributor

@CaeChao CaeChao commented Mar 27, 2024

Added

  • Added a smart action to perform depending on the context (textobject the cursor is on).

Changed

  • Added custom UI opts for toggle checkbox utils, and changed its behavior to cycle through checkboxes

Copy link
Owner

@epwalsh epwalsh left a 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

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" }
Copy link
Owner

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:

Suggested change
local checkboxes = opts and opts or { " ", "~", ">", "x" }
local checkboxes = opts or { " ", "x" }

Comment on lines 6 to 12
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
Copy link
Owner

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:

Suggested change
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)

Copy link
Contributor Author

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

@CaeChao CaeChao requested a review from epwalsh March 27, 2024 19:13
@sotte
Copy link
Contributor

sotte commented Mar 31, 2024

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.

Copy link
Owner

@epwalsh epwalsh left a 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!

@epwalsh epwalsh merged commit 2f9b95a into epwalsh:main Apr 1, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants