Skip to content

fix: incorrect multiline autoindent#1002

Open
joeljohansson99 wants to merge 4 commits intoeclipse-tm4e:mainfrom
joeljohansson99:multiline-autoindent
Open

fix: incorrect multiline autoindent#1002
joeljohansson99 wants to merge 4 commits intoeclipse-tm4e:mainfrom
joeljohansson99:multiline-autoindent

Conversation

@joeljohansson99
Copy link
Copy Markdown

Fixes #1000

Open to suggestions. I feel like there is no very good way of do this. This is the best I could come up with.
If we want to preserve the relative indent, then we would just need to handle the midline paste case.

Let me know what you think

Thanks!

@sebthom
Copy link
Copy Markdown
Member

sebthom commented Mar 24, 2026

Thanks for your PR! Can you please add some inline comments and if possible a test case?

@joeljohansson99
Copy link
Copy Markdown
Author

Hi @sebthom. Thanks for the reply!
I added comments and also discovered a potential bug in the process. String.stripLeading() removes newlines as well as whitespaces, which we dont want, so instead I used a regex.

I also added two new test cases. Both which are failing for the old implementation but with this fix are succeding.
With the previous implementation it failed like this:

expected: 
  "public class Foo {
   function bar() {
    
   }
  }"
 but was: 
  "public class Foo {
   function bar() {
     
    }
  }"

And

expected: 
  "public class Foo {
   function foo() {
    if (cond) {
    } else {
    }
   }
  }"
 but was: 
  "public class Foo {
   function foo() {
    if (cond) {
    }   else {
      }
   }
  }"

Let me know if you have any questions! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Auto-indent on paste incorrectly adds extra indentation to multi-line text

2 participants