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

Incorrect result when wrapping forms #176

Closed cursive-ide closed 6 years ago

cursive-ide commented 7 years ago

When wrapping an existing form, parinfer currently produces a broken result. I start with:

(let [a 1]
  (foo))

I want to wrap (foo) in another form, perhaps an if. So I create a new line:

(let [a 1]
  |
  (foo))

And then wrap the following form. This will cause an open paren to be inserted at the caret, and a close paren to be inserted after the (foo). Cursive will also indent the (foo).

Sandbox code to reproduce:

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

console.log(parinfer.smartMode(code, {
  changes: [
    {lineNo:2, x:2, oldText: '', newText: '('},
    {lineNo:3, x:2, oldText: '', newText: '  '},
    {lineNo:3, x:9, oldText: '', newText: ')'},
  ],
}).text);

Produces:

(let [a 1]
  ()
    (foo))
shaunlebron commented 6 years ago

fixed by #181