obsidian-vimrc-support icon indicating copy to clipboard operation
obsidian-vimrc-support copied to clipboard

`selection` fails from the second file

Open twio142 opened this issue 2 years ago • 3 comments

It seems that the selection object only works properly in the first file opened. Once switched to a second one, it begins to fail. No error thrown in the console.

twio142 avatar Jun 26 '22 16:06 twio142

I can confirm this behavior, I've filled out the issue template here to help out:

Please Review Before Posting!

  • [x] I checked that the bug does not happen in the CodeMirror Vim demo. If it does, please report it there and not here.
  • [x] I'm reasonably sure that this bug is indeed about the Vimrc file support and not a general Vim in Obsidian issue. If it's a general Vim issue, report it here.

Describe the bug:

After loading a 2nd file, either a new file or a file previously written, commands with selections no longer work. (eg: surround commands)

To Reproduce:

Steps to reproduce the behavior:

  1. Start Obsidian with plugin enabled and a surround command in your vimrc file
  2. edit a file, check that surround commands work.
  3. open a 2nd file, either new or pre-written.
  4. Attempt a 2nd surround command on either a selected word or within a word.

Environment:

  • OS: Mac OS Version 12.4
  • Vimrc plugin version: 0.7.2

Additional context: With verbose logs this is the error I get:

app.js:1 Error: can't surround on an empty line
    at surroundFunc (plugin:obsidian-vimrc-support:778:27)
    at Object.eval [as surround] (plugin:obsidian-vimrc-support:804:68)
    at ExCommandDispatcher._processCommand (vim.js:4658:34)
    at vim.js:4604:16
    at e.operation (app.js:1:1267455)
    at ExCommandDispatcher.processCommand (vim.js:4602:12)
    at Object.handleEx (vim.js:991:29)
    at Object.eval [as squote] (plugin:obsidian-vimrc-support:654:43)
    at ExCommandDispatcher._processCommand (vim.js:4658:34)
    at vim.js:4604:16

I sometimes also get cannot read property of null anchor errors when attempting the same thing.

Laharah avatar Aug 04 '22 07:08 Laharah

@Laharah Thanks for the additional informations. Though this is not exactly the same thing I was talking about. What I meant was the selection object offered by jscommand and jsfile, which, after a second file is opened, stops updating the selection range and position and always stays the same.

I suppose the surround command might also based on the same structure, whereas selection itself doesn't throw an error when it fails.

twio142 avatar Aug 04 '22 09:08 twio142

@twio142 Ah, no worries then, I'll make my own issue then, but I'll link to this one in case it's the same root cause.

Laharah avatar Aug 04 '22 16:08 Laharah

PR is merged, thank you and sorry for the huge delay :(

esm7 avatar Sep 23 '22 12:09 esm7