Avoid over-selecting when include_surrounding_whitespace - #902
Open
yjyao wants to merge 1 commit into
Open
Conversation
…e=true`. Fixes nvim-treesitter#575 Fixes nvim-treesitter#850 The following examples come from issues nvim-treesitter#575 and nvim-treesitter#850: - nvim-treesitter#575 (comment) - nvim-treesitter#850 (comment) --- ```python 1 def a(): 2 x = 1 3 4 def b(): 5 6 pass 7 8 pass ``` `5Gvaf` (`af` for linewise `@function.outer`) selects lines [4,7], correctly omitting line 8 which starts with leading whitespaces. --- ```python 1 def a(): 2 pass␣␣ 3 4 def c(): 5 pass ``` `5Gvaf` (`af` for linewise `@function.outer`) selects lines [3,5], correctly omitting line 2 which ends with trailing whitespaces. --- ```python 1 arr = [ 2 x, # comment␣␣ 3 y, 4 ] ``` `5Gvac` (`ac` for charwise `@comment.outer`) selects only `# comment `, correctly omitting the leading whitespaces on line 3.
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.
Fixes #575
Fixes #850
The fix
When expanding to include surrounding whitespaces,
selection_mode, only include whitespaces from the current line;selection_mode, include surrounding blank lines, but not non-empty lines with leading/trailing whitespaces.Important
I'm not sure what's the intended usecase for blockwise selection when it comes to selecting textobjects, and how
include_surrounding_whitespaceis designed to work in that mode. This change currently DOES NOT handle blockwise mode correctly. PLEASE let me know what's the best way to handle it.Tests
The following examples come from issues #575 and #850:
include_surrounding_whitespaceshould adjust whitespace characters included based on mode #850 (comment)5Gvaf(affor linewise@function.outer)selects lines [4,7],
correctly omitting line 8 which starts with leading whitespaces.
5Gvaf(affor linewise@function.outer)selects lines [3,5],
correctly omitting line 2 which ends with trailing whitespaces.
5Gvac(acfor charwise@comment.outer)selects only
# comment,correctly omitting the leading whitespaces on line 3.