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

Smear goes to top-left corner when saving files #78

Open
craftgear opened this issue Dec 31, 2024 · 16 comments
Open

Smear goes to top-left corner when saving files #78

craftgear opened this issue Dec 31, 2024 · 16 comments
Labels
bug Something isn't working

Comments

@craftgear
Copy link

craftgear commented Dec 31, 2024

Hi, I noticed flashing moves on saving files which you can see in the following clip.

smear-cursor.mov

I expected the newly added flag disable smear to cmd line might get rid of this behavior but no luck.

Does anyone know how to prevent this?

Environment (optional)

  • OS: macOS Sonoma 14.7
  • Terminal: iTerm2 build 3.5.2
  • Neovim version:
    • NVIM v0.10.0
    • Build type: Release
    • LuaJIT 2.1.1713484068
  • Smear-cursor version/commit: 051fe67
@craftgear craftgear added the question General question label Dec 31, 2024
@craftgear craftgear changed the title Q: how to prevent a flashing move to top-left corner when saving files? Q: how to prevent flashing moves to top-left corner when saving files? Dec 31, 2024
@sphamba
Copy link
Owner

sphamba commented Dec 31, 2024

Hi, could you try on Neovim v0.10.2 (at least)? The get cursor position functions may have changed

@craftgear
Copy link
Author

Hi, thank you for such a quick response.

I updated neovim v0.10.3 but it doesn't change anything.

Do tell me if you need me to try to do anything else.

@craftgear
Copy link
Author

Oh one more thing I noticed is after :w (with the flashing move) when you move cursor up or down, you see another flashing move from top-left to current cursor position.

bbb.mov

@tan-wei
Copy link

tan-wei commented Jan 2, 2025

Hmm, the same issue with nightly. I remember that neovide had the same issue before (and I don't know whether exists the latest version have)

@sphamba sphamba added bug Something isn't working and removed question General question labels Jan 5, 2025
@sphamba sphamba changed the title Q: how to prevent flashing moves to top-left corner when saving files? Smear goes to top-left corner when saving files Jan 5, 2025
@sphamba
Copy link
Owner

sphamba commented Jan 5, 2025

@tan-wei In which environment do you observe this behavior? I wonder if the issue is linked to iTerm2. I also noticed that in OP's video, the :w takes some time, so that could be another reason

@tan-wei
Copy link

tan-wei commented Jan 5, 2025

@tan-wei In which environment do you observe this behavior? I wonder if the issue is linked to iTerm2. I also noticed that in OP's video, the :w takes some time, so that could be another reason

For me, I use neovim in MacOS and archlinux with nightly neovim (now: NVIM v0.11.0-dev-1466+g7ddadd0fee
). They both meet the same issue. And your notice may be a reason, for me, :w will do code formatting, and it takes several milliseconds.

@sphamba
Copy link
Owner

sphamba commented Jan 5, 2025

@craftgear @tan-wei Could you test revision 7e23d64 and see if it solves the issue?

@tan-wei
Copy link

tan-wei commented Jan 5, 2025

I've tries the branch "fix-jump-cmd", still the same.
What about @craftgear ?

@sphamba
Copy link
Owner

sphamba commented Jan 5, 2025

I tried setting pauses on BufWritePre and BufWritePost events to try and reproduce the issue but did not manage. What config do you have that makes :w take time?

@tan-wei
Copy link

tan-wei commented Jan 6, 2025

I tried setting pauses on BufWritePre and BufWritePost events to try and reproduce the issue but did not manage. What config do you have that makes :w take time?

I use conform.nvim as a formatter pulgin, so when we :w, the plugin could call external commands to format the code, I think it will take some time to format, it seems that the process will block neovim? I don't know. If so, I think the cursor jumping is reasonable and could not be solved I guess?

@craftgear
Copy link
Author

craftgear commented Jan 6, 2025

@tan-wei @sphamba I've tried @7ed3264 and the jumping still remains.

Like @tan-wei does, I too use conform.nvim to auto lint and format when saving files.

And when I turn off conform.nvim the jumping problem disappears.

So this might be smth outside smear-cursor can controll?

@tan-wei
Copy link

tan-wei commented Jan 6, 2025

@tan-wei @sphamba I've tried @7ed3264 and the jumping still remains.

Like @tan-wei does, I too use conform.nvim to auto lint and format when saving files.

And when I turn off conform.nvim the jumping problem disappears.

So this might be smth outside smear-cursor can controll?

So could conform.nvim be changed into async?

@sphamba
Copy link
Owner

sphamba commented Jan 6, 2025

Apparently, using a keybinding instead of opening the command line for writing the buffer (ie typing :w<cr>) does not cause a jump to the to left corner. That would be a temporary workaround. I did not manage to test conform.nvim in async mode though.

Looking at the conform.nvim code, I found out that the behavior can be "explained" with the following snippet:

vim.api.nvim_create_autocmd("BufWritePre", {
    desc = "Do something on save",
    pattern = "*",
    callback = function(args)
        vim.defer_fn(function() print("Before wait:", vim.fn.screenrow(), vim.fn.screencol()) end, 0)
        vim.wait(0, function() end)
        vim.defer_fn(function() print("After wait:", vim.fn.screenrow(), vim.fn.screencol()) end, 0)
    end,
})

Running :w<cr> results in vim.fn.screenrow() and vim.fn.screenrow() to return the cursor position of the command line instead of the current window's. I don't have a fix yet.

@tan-wei
Copy link

tan-wei commented Jan 7, 2025

@

Apparently, using a keybinding instead of opening the command line for writing the buffer (ie typing :w<cr>) does not cause a jump to the to left corner. That would be a temporary workaround. I did not manage to test conform.nvim in async mode though.

Looking at the conform.nvim code, I found out that the behavior can be "explained" with the following snippet:

vim.api.nvim_create_autocmd("BufWritePre", {
    desc = "Do something on save",
    pattern = "*",
    callback = function(args)
        vim.defer_fn(function() print("Before wait:", vim.fn.screenrow(), vim.fn.screencol()) end, 0)
        vim.wait(0, function() end)
        vim.defer_fn(function() print("After wait:", vim.fn.screenrow(), vim.fn.screencol()) end, 0)
    end,
})

Running :w<cr> results in vim.fn.screenrow() and vim.fn.screenrow() to return the cursor position of the command line instead of the current window's. I don't have a fix yet.

Got it. I think it is not a big deal that if it is not going to be fixed for me. Thanks for your great plugin.

@tan-wei
Copy link

tan-wei commented Jan 12, 2025

Good news. conform.nvim supports async format by config with this:

opts = {
    -- ...
    format_after_save = function(bufnr)
      if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then
        return
      end
      return { timeout_ms = 1000, lsp_fallback = true, async = true }
  -- ...
}

And the issue does not occur.

@sphamba
Copy link
Owner

sphamba commented Jan 12, 2025

Let's keep this open for now. The synchronous behavior may still be adressed by fixing how cmd smears are handled

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

No branches or pull requests

3 participants