Add editor.preserveAlignmentSpacesOnIndent option#309369
Open
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
Open
Add editor.preserveAlignmentSpacesOnIndent option#309369yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
Conversation
When a tab-indented line contains spaces after the last tab that are used to visually align content with a token on a previous line, the existing Tab/Shift+Tab behavior on a selection rewrites the leading whitespace as pure tab indentation and destroys the alignment. Introduce a new boolean editor option `editor.preserveAlignmentSpacesOnIndent` (default: false). When enabled and the file is indented with tabs, `ShiftCommand` treats spaces that follow the last tab in the leading whitespace as alignment spaces and preserves them across shift and unshift operations so that the column alignment within the code is kept intact. Fixes microsoft#277764
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When a tab-indented line contains spaces after the last tab that are used to visually align content with a token on a previous line, the existing Tab/Shift+Tab behavior on a selection rewrites the leading whitespace as pure tab indentation and destroys the alignment. For example, pressing Shift+Tab on:
currently produces
<TAB><TAB>arg(the two alignment spaces are gone) instead of<TAB> arg(one level less of tab indentation, alignment preserved).This PR introduces a new boolean editor option,
editor.preserveAlignmentSpacesOnIndent, defaulting tofalseso existing behavior is unchanged. When the option is enabled and the file is indented with tabs (editor.insertSpaces === false),ShiftCommandtreats spaces that follow the last tab in the leading whitespace as alignment spaces and preserves them across shift and unshift operations. This keeps column alignment within the code intact when adjusting the indentation level with Tab or Shift+Tab on a selection.Changes:
preserveAlignmentSpacesOnIndentoption (editorOptions.ts,standaloneEnums.ts).CursorConfiguration(cursorCommon.ts) to theShiftCommandconstruction sites incursorTypeOperations.tsandcursorTypeEditOperations.ts.ShiftCommand.getEditOperationsgains an alignment-spaces-stripping step when the new option is enabled, and re-appends the preserved spaces after the re-computed indent.shiftCommand.test.tscovering: Tab with preservation, Shift+Tab with preservation, Shift+Tab with the option off (the previous behavior), and a no-op case when the file uses spaces for indentation.Fixes #277764
Test plan
yarn test-browser --run test/browser/commands/shiftCommand.test.tspasses (new + existing tests).editor.preserveAlignmentSpacesOnIndent, select lines that have alignment spaces after the tabs, and confirm Tab / Shift+Tab shift the tab indentation while preserving the trailing alignment spaces. With the option off, behavior is unchanged.