Vim icon indicating copy to clipboard operation
Vim copied to clipboard

Text cursor is moved to the start of the line after the indentation is done by another extension

Open p-himik opened this issue 4 years ago • 10 comments

Describe the bug The other extension is Calva. On Vim v1.21.5, whatever cursor position Calva set upon hitting Enter was preserved. On Vim v1.21.6, the cursor is always moved to the start of the line.

To Reproduce Steps to reproduce the behavior:

  1. Install Calva and Vim
  2. Open an empty directory in VSCode
  3. Create a new file there and type in (ns a.b)
  4. Put the text cursor on ), enter the Insert mode (the cursor should be before the ))
  5. Hit Enter

Expected behavior It should end up looking like this, with | representing the cursor position:

(ns a.b
  |)

But instead it looks like this:

(ns a.b
|  )

Screenshots Untitled

Environment (please complete the following information):

  • Extension (VsCodeVim) version: v1.21.6
  • VSCode version: 1.59.0
  • OS: Ubuntu 20.04

Additional context Perhaps it is related to how Calva does that indentation. Relevant lines in its code:

  • https://github.com/BetterThanTomorrow/calva/blob/01b50b95214bd55809285a1fe9e099db8b9ac944/src/calva-fmt/src/extension.ts#L12
  • https://github.com/BetterThanTomorrow/calva/blob/01b50b95214bd55809285a1fe9e099db8b9ac944/src/calva-fmt/src/format.ts#L82

If you know of a better way to indent the code and put the text cursor at the right position when editing Clojure files, regardless of any other extensions and VSCode settings, please do tell.

p-himik avatar Aug 12 '21 13:08 p-himik

Second this issue as I am facing the same problem.

introom avatar Aug 15 '21 13:08 introom

The problem occurs not only with the (ns) form but also other forms.

For example, when we define the function with defn,

(defn some-func|)

Pressing <Enter> when the caret is at | would give

(defn some-func
|  )

Instead of

(defn some-func
  |)

Which basically means it is no longer practical to write Clojure (Calva) with the Vim v1.21.6

introom avatar Aug 15 '21 13:08 introom

Perhaps important - the initially described behavior seems to be erratic. Suddenly, I can't reproduce it using the original steps. However, pressing o in the Normal mode still results in the suboptimal behavior, and it seems that the cursor is placed not at the beginning of the line but at the position of the indentation of the previous line. But using o might be a different thing altogether.

p-himik avatar Aug 15 '21 13:08 p-himik

The V1.21.7 version still has this issue.

introom avatar Sep 19 '21 07:09 introom

@p-himik, @introom: is the o behaviour new as well?

PEZ avatar Sep 19 '21 07:09 PEZ

Not sure about what the =o= behavior refers to. Maybe @p-himik can answer.

introom avatar Sep 19 '21 07:09 introom

@PEZ Can't say - I switched to NeoVim for now.

p-himik avatar Sep 19 '21 08:09 p-himik

Moving my finding from Calva slack to this issue. It seems that disabling the New Indent Engine setting of Calva has “fixed” this issue for me, at least in the enter case.

Will copy @PEZ response for posterity:

You could add that finding to the issue, @cjsauer , that the old indent engine works for you. Though I think it might be a matter of timing. The old engine is much slower so “wins“ over the VIM extension by getting later to the party.

Can others confirm/deny that disabling this setting is a workaround? It might aid in diagnosing the root issue.

cjsauer avatar Sep 26 '21 14:09 cjsauer

Thanks @cjsauer, I can confirm that the issue disappears when the =new indent engine= is disabled!

introom avatar Sep 26 '21 14:09 introom

Perhaps important - the initially described behavior seems to be erratic. Suddenly, I can't reproduce it using the original steps. However, pressing o in the Normal mode still results in the suboptimal behavior, and it seems that the cursor is placed not at the beginning of the line but at the position of the indentation of the previous line. But using o might be a different thing altogether.

I think a decent workaround for the above is to put the following in the vscode settings.json (essentially has the same effect as pressing tab manually after pressing o):

    "vim.normalModeKeyBindings": [
        {
            "before": [
                "o"
            ],
            "after": [
                "o",
            ],
            "commands": [
                "calva-fmt.formatCurrentForm"
            ]
        }
    ]

Dexterminator avatar Sep 20 '22 18:09 Dexterminator

Still seeing this issue with calva 2.0.353 and vim 1.25.2. @Dexterminator thanks for the tip. Your keybindings worked better for me than disabling the new indent engine. In particular, two cases that worked better were pressing 'o' after a try and pressing 'o' after a let binding whose value is set by (->> ..)

cldwalker avatar Apr 27 '23 16:04 cldwalker