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

Unexpected current buffer change on new note #30

Closed
vihu opened this issue Oct 12, 2022 · 4 comments · Fixed by #32
Closed

Unexpected current buffer change on new note #30

vihu opened this issue Oct 12, 2022 · 4 comments · Fixed by #32
Labels
bug Something isn't working

Comments

@vihu
Copy link
Contributor

vihu commented Oct 12, 2022

🐛 Describe the bug

I recently started using this plugin and noticed an oddity (which admittedly could be something to do with my setup).

I have the following keybind:

vim.keymap.set("n", "<leader>nn", function()
    return "<Cmd>ObsidianNew " .. vim.fn.input('Title: ') .. "<CR>"
end, { expr = true })

Essentially to make creating a new note with user supplied title.

I notice that for some reason as soon as I press enter, the new note indeed gets created as expected, but something in the currently opened buffer also changes.

Below is a video demonstrating the issue (note the little blue dot in the tabline next to obsidian.lua was not present before I created the note but is present after the creating of the note, indicating that the currrent buffer, obsidian.lua in this case has changed in some way). This causes an error when trying to exit nvim, because it thinks that the currently opened buffer has changed.

obsidian-new-note.mp4

Versions

nvim --version

NVIM v0.8.0
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by brew@HMBRW-A-001-M1-004.local

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/opt/homebrew/Cellar/neovim/0.8.0/share/nvim"
nvim --headless -c 'lua print(require("obsidian").VERSION)' -c q
1.4.0%
@vihu vihu added the bug Something isn't working label Oct 12, 2022
@epwalsh
Copy link
Owner

epwalsh commented Oct 12, 2022

Hey @vihu, :ObsidianNew will call :w on the current file before switching to the new note. That could be the source of the issue. Maybe you have some autocmd that modifies lua files on write?

It's not really necessary that :ObsidianNew writes the current buffer before switching, so maybe we should remove that if it causes more problems.

@vihu
Copy link
Contributor Author

vihu commented Oct 12, 2022

t's not really necessary that :ObsidianNew writes the current buffer before switching, so maybe we should remove that if it causes more problems.

I agree with this. Having :ObsidianNew and :ObsidianToday write out the currently opened buffer seems like unexpectedly introduced behavior to me. That's the responsibility of the user to specifically choose when to write the open buffer imo.

@epwalsh
Copy link
Owner

epwalsh commented Oct 12, 2022

Having :ObsidianNew and :ObsidianToday write out the currently opened buffer seems like unexpectedly introduced behavior to me.

Fair enough. Do you want to make a PR to remove the writes? The lines are here and here.

@epwalsh
Copy link
Owner

epwalsh commented Oct 12, 2022

Ah, beat me to it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants