sublimehq / sublime_text

Issue tracker for Sublime Text
https://www.sublimetext.com
807 stars 39 forks source link

"convert indentations to tabs" does not work well #6086

Open chr-bakk opened 1 year ago

chr-bakk commented 1 year ago

Problem description

I use tabs and tab-size 4. When I copy CSS or JS with two spaces, ST does not recognize that the new code has 2 spaces indention and I have to first change it to 2, then convert, then change size back to 4.

Preferred solution

I'd want it to recognize stepping indentations and convert it regardless of how many spaces are used.

Alternatives

Could add a submenu under "convert indentations to tabs" to choose how many spaces to convert.

Additional Information

image

deathaxe commented 1 year ago

ST auto-detects indentation of pasted content by default.

Starting with ST (SAFE MODE) set up to 4 tabs by default, copying CSS content from Notepad to ST is correctly detected as 2 space indented and can than be converted to tabs and changed in width.

Animation

Note, that ST does not change indentation on purpose, if a view already contains content.

You can however run "Indentation: Detect" manually via Command Palette than.

Note that indentation detection takes the first few lines into account, using what seems most appropriate.

chr-bakk commented 1 year ago

Yeah, I wasn't specific enough.

With further testing I find that if I only copy CSS-rules, they will automatically change to tabs, but when I paste an entire selection with rules it does not change the spaces.

div{
  display: block;
  margin-block-start: 1em;
  margin-block-end: 1em;
  margin-inline-start: 0px;
  margin-inline-end: 0px;
}

Neither does it work for HTML

      <div class="container">
        <label class="switch">
          <input id="dark_ages" type="checkbox" onchange="toggleDarkAges()">
          <div class="slider round"></div>
        </label>
        <span>Dark ages</span>
      </div>

and the same with JS, and I guess other places. I've also tested the JavaScript in SAFE-MODE.

let GUI = {
    squareAttacked: false,
    hideDelay: 2000
}
deathaxe commented 1 year ago

To be sure: Do you expect ST to auto-detect and convert indentation of pasted content to match the target document's style? So if you paste content with 2spaces indentation into a 4tabs document, indentation is automatically converted from the former to the latter?

The only conversion ST does by design at the moment is to convert tabs to spaces if "translate_tabs_to_spaces": true is set.

I don't think automatically changing content while pasting is always desirable. It would however probably be a possible enhancement for existing paste_and_indent command.

chr-bakk commented 1 year ago

No, that's not what I expect, all thought if I can turn it on that would be better. What I expect is for ST to convert whatever indentations with spaces in the current document when I press 'convert to tabs' without the need to count them and temporary change to that specific setting.