keep preceding indentation when formatting selected text #8

Closed
jdc0589 opened this Issue Mar 5, 2012 · 3 comments

Comments

Projects
None yet
2 participants
Owner

jdc0589 commented Mar 5, 2012

When running JsFormat on a selected area of text, the contextual indentation is lost.

Reported by rdougan: http://www.sublimetext.com/forum/viewtopic.php?f=5&t=2430&start=10

Owner

jdc0589 commented Mar 5, 2012

This is a little weird. The current behavior definitely isn't optimal, but I'm not sure what would be.
The only thing I can think of is to look at the leading whitespace on the first line of the selection and pad all the lines of formatted text with that same amount of whitespace.

Thoughts?

Contributor

timonwong commented Sep 28, 2012

@jdc0589:

There's a pretty tricky way to achieve that:

  1. Get line start position.
  2. Start from this position, count the number of unpaired character '{' => indention_count.
  3. Prepend '{' * indention_count to the selection text before formatting.
  4. Remove '{'s previously added.

You can see what I have it done in SublimeAstyleFormatter, in function get_indentation_count()

@jdc0589 jdc0589 closed this Sep 28, 2012

@jdc0589 jdc0589 reopened this Sep 28, 2012

timonwong added a commit to timonwong/JsFormat that referenced this issue Mar 15, 2013

fix selection formatting; fix unicode libpath on windows for py2k
Also take cares of preceding indentation while formatting selection

Refers: jdc0589/JsFormat#49
Refers: jdc0589/JsFormat#8
Owner

jdc0589 commented May 22, 2013

Looks like this got pulled in a while ago and I forgot to close the issue.

@jdc0589 jdc0589 closed this May 22, 2013

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