Skip to content

Commit 25c6757

Browse files
authored
Merge branch 'obsidian-nvim:main' into main
2 parents 9a0051d + 3c967d0 commit 25c6757

File tree

5 files changed

+29
-3
lines changed

5 files changed

+29
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Added default `image_name_func` similar to Obsidian's.
1313
- Added support `text/uri-list` to `ObsidianPasteImg`.
14-
- Added support for obsidian style `%%` comment
14+
- Added support for obsidian style `%%` comment.
1515

1616
### Changed
1717

@@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020
- `ObsidianToggleCheckbox` now works in visual mode for multiline toggle.
2121
- `ObsidianRename` input field is pre-filled filled with the current note id to ease renaming.
2222
- Improved type annotations for user commands: add `CommandArgs` type.
23+
- `smart_action` now can also toggle heading folds.
2324

2425
### Fixed
2526

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ This is a complete list of all of the options that can be passed to `require("ob
331331
end,
332332
opts = { buffer = true },
333333
},
334-
-- Smart action depending on context: follow link, show notes with tag, or toggle checkbox.
334+
-- Smart action depending on context: follow link, show notes with tag, toggle checkbox, or toggle heading fold
335335
["<cr>"] = {
336336
action = function()
337337
return require("obsidian").util.smart_action()

doc/obsidian.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ carefully and customize it to your needs:
389389
end,
390390
opts = { buffer = true },
391391
},
392-
-- Smart action depending on context: follow link, show notes with tag, or toggle checkbox.
392+
-- Smart action depending on context: follow link, show notes with tag, toggle checkbox, or toggle heading fold
393393
["<cr>"] = {
394394
action = function()
395395
return require("obsidian").util.smart_action()

lua/obsidian/init.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,17 @@ obsidian.setup = function(opts)
148148
require("obsidian.completion.plugin_initializers.blink").inject_sources()
149149
end
150150

151+
local win = vim.api.nvim_get_current_win()
152+
153+
vim.treesitter.start(ev.buf, "markdown") -- for when user don't use nvim-treesitter
154+
155+
vim.wo[win].foldmethod = "expr"
156+
vim.wo[win].foldexpr = "v:lua.vim.treesitter.foldexpr()"
157+
vim.wo[win].fillchars = "foldopen:,foldclose:,fold: ,foldsep: "
158+
vim.wo[win].foldtext = ""
159+
vim.wo[win].foldlevel = 99
160+
vim.wo[win].smoothscroll = true
161+
151162
-- Run enter-note callback.
152163
client.callback_manager:enter_note(function()
153164
return obsidian.Note.from_buffer(ev.bufnr)

lua/obsidian/util.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,16 @@ util.cursor_tag = function(line, col)
771771
return nil
772772
end
773773

774+
--- Get the heading under the cursor, if there is one.
775+
---
776+
---@param line string|?
777+
---
778+
---@return string|?
779+
util.cursor_heading = function(line)
780+
local current_line = line and line or vim.api.nvim_get_current_line()
781+
return current_line:match "^(%s*)(#+)%s*(.*)$"
782+
end
783+
774784
util.gf_passthrough = function()
775785
local legacy = require("obsidian").get_client().opts.legacy_commands
776786
if util.cursor_on_markdown_link(nil, nil, true) then
@@ -792,6 +802,10 @@ util.smart_action = function()
792802
return legacy and "<cmd>ObsidianTags<cr>" or "<cmd>Obsidian tags<cr>"
793803
end
794804

805+
if util.cursor_heading() then
806+
return "za"
807+
end
808+
795809
-- toggle task if possible
796810
-- cycles through your custom UI checkboxes, default: [ ] [~] [>] [x]
797811
return legacy and "<cmd>ObsidianToggleCheckbox<cr>" or "<cmd>Obsidian toggle_checkbox<cr>"

0 commit comments

Comments
 (0)