Xi-editor: InsertTab should adjust indentation when multiple lines are selected

Created on 7 Apr 2018  路  7Comments  路  Source: xi-editor/xi-editor

Breaking this out from #586: currently the insert_tab RPC will replace any selections with \t. In many editors, the tab key will increase indentation of lines when multiple lines are selected.

I think this makes sense as the default behaviour; it matches the default behaviour of ST3 on macOS.

As of #586 this should be easy to implement; in Editor::insert_tab check to see if the selection contains multiple regions, or if a single region spans multiple lines, and in that case forward the call to Editor::modify_indent.

easy enhancement help wanted

All 7 comments

in Editor::insert_tab check to see if the selection contains multiple regions, or if a single region spans multiple lines

This is a bit different from the behavior of Sublime (and VS Code). (Tested on macOS and Linux builds of each)

In Sublime, if any region spans multiple lines, it will indent rather than insert a tab. However, if none of the regions contain a newline, then a tab will be inserted in place of each region.

In VS Code, only regions that span multiple lines will have their indentation changed. This is consistent even if one region spans multiple lines and another does not.

I'm personally a fan of the VS Code approach, but then I use VS Code as my daily editor.

@Reificator cool, thanks for the more complete tests.

I agree that inserting a tab makes sense when none of the regions span a newline. I'm curious about your preference, though; if I'm undertanding then if I have a caret on one line and elsewhere I have a selection that spans multiple lines, hitting tab will insert a tab in the first location and increase indentation in the second? The mixed behaviour feels weird to me, hard to imagine it being something anyone would use (although I refuse to be surprised by how people use their text editors 馃槒).

You're understanding correctly.

The choice is to be consistent in the action performed by one keypress or to be consistent in the action performed in one context. I prefer the latter, but it's a mild preference personally, and I can see the other point of view.

I too think this will be the correct approach(consistency in action performed).
@cmyr making changes in #609 to handle this case.

Updated #609 @cmyr

@virattara okay thanks! I'll take a look tomorrow at some point. :)

closed in #609

Was this page helpful?
0 / 5 - 0 ratings

Related issues

betterclever picture betterclever  路  5Comments

cmyr picture cmyr  路  4Comments

cmyr picture cmyr  路  6Comments

leonardohn picture leonardohn  路  3Comments

theduke picture theduke  路  3Comments