parinfer / parinfer.js

Let's simplify the way we write Lisp
https://shaunlebron.github.io/parinfer
MIT License
1.76k stars 40 forks source link

Overlapping changes resulting from paste operation produces incorrect result #177

Closed cursive-ide closed 6 years ago

cursive-ide commented 7 years ago

When pasting multi-line code, IntelliJ will first paste the code and then indent the pasted code according to the current style rules.

Starting with:

(let [a 1]
  (foo))

I then copy the whole form (not including the final newline) and I want to paste it inside the let block. Starting with:

(let [a 1]
  |
  (foo))

I then paste the following text:

(let [a 1]
  (foo))

Hoping to get:

(let [a 1]
  (let [a 1]
    (foo))
  (foo))

After the paste but before the re-indent, the document will look like this:

(let [a 1]
  (let [a 1]
  (foo))
  (foo))

IntelliJ will then indent line 3 by two spaces, and parinfer will run when that is complete. Note that the indentation change overlaps with the previous change from the paste, not sure if that is significant or not.

Sandbox code to reproduce:

const code = `
(let [a 1]
  (let [a 1]
    (foo))
  (foo))
`;

console.log(parinfer.smartMode(code, {
  changes: [
    {lineNo:2, x:2, oldText: '', newText: '(let [a 1]\n  (foo))'},
    {lineNo:3, x:2, oldText: '', newText: '  '},
  ],
}).text);

This produces:

(let [a 1]
  (let [a 1])
    (foo)
  (foo))

This may be related to/the same as #176.

shaunlebron commented 6 years ago

fixed by #181