zdcthomas / yop.nvim

make you some user operators for great good

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] When the lines parameter is { "" }, it doesn't work as expected.

singlexyz opened this issue · comments

Hi, I found that it doesn't work as expected when motion or textobj is an empty string.

Here is my configuration, it simply replacing textobj/motion with the specified text.

-- replace text
local function replace_to_lorem_text(lines)
  return {
    "Replaced!!",
  }
end
require("yop").op_map({ "n", "v" }, "<leader>jp", replace_to_lorem_text)
"text"      -- works
" "         -- works, 1 space inside.
""          -- doesn't works,  lines parameter is { "" }

Thanks for finding this!
What kind of motion are you using to get an empty string for the lines param, and what type of output do you expect?

Thanks for finding this! What kind of motion are you using to get an empty string for the lines param, and what type of output do you expect?

When using textobj like i", it, i[, if get an empty string, it happens like that.
Logically, it should have the same result as a non-empty string.

so for me, with your mapping, if I have my cursor on the first " of the text "" and I run your mapping with <leader>jpi", I get "Replaced!!"

Is that different than what you'd expect?

so for me, with your mapping, if I have my cursor on the first " of the text "" and I run your mapping with <leader>jpi", I get "Replaced!!"

Is that different than what you'd expect?

Exactly, that's correct.
but there needs to be content inside "", even if it's just a space.

I record a video to explain this:

Screen.Recording.2024-01-05.at.05.09.34.mov

That's super interesting, I'm seeing totally different behavior. For me, it inserts the text Replaced!! unlike in your video. I have a few questions then:

  1. in the video your mapping you're using is <leader>jl, is that the same as the mapping you posted above which is <leader>jp?
  2. What version of Nvim are you using?
  3. What system are you on?

That's super interesting, I'm seeing totally different behavior. For me, it inserts the text Replaced!! unlike in your video. I have a few questions then:

  1. in the video your mapping you're using is <leader>jl, is that the same as the mapping you posted above which is <leader>jp?
  2. What version of Nvim are you using?
  3. What system are you on?

Thank you for your feedback.
I used to think everyone was experiencing this, and it seemed unrelated to the version and operating system.
I checked the plugins related to my text objects and found that the issue was caused by https://github.com/wellle/targets.vim.
It appears to be altering the default behavior of text objects like i", it, etc.
After disabling this plugin, the operator works fine. 🥹

Ok awesome! and thanks for closing the issue!
I might look more into this type of interaction and see what's causing it in targets, but in the mean time, I'm glad it's working for you