Open SamuelLarkin opened 8 months ago
The problem is, if you set include_surrounding_whitespace = true
and then use linewise
mode, then it will try to include the whitespace before pass
and then it will change into a line selection mode. That way the pass
also gets deleted.
A possible solution is to change the include_surrounding_whitespace
mode to activate only when it is a char-wise selection mode.
Another option would be to set the selection_modes
of @function.outer
to charwise
, as it is the default. Therefore, it can be removed from the table. I encountered the same issue, and not only did this change fix it, but it also worked very well. If you set include_surrounding_whitespace
to false
, it will select the function from def
to the first pass
. Conversely, if you set it to true
, it will select until the start of the second pass
.
For reference
include_surrounding_whitespace = false
|def ff2(b: int):
b = 2
pass|
include_surrounding_whitespace = true
|def ff2(b: int):
b = 2
pass
|pass
Changing @function.outer
to charwise works for most operations (delete, yank, etc..) but it doesn't work with commenting actions (gc
) since the cursor is still on the beginning of the next line and ends up commenting it out, for example (indentiation is important here) doing gcaf
in fun1
(whether it's charwise or linewise):
def fun1(self):
pass
def fun2(self):
pass
becomes:
# def fun1(self):
# pass
# def fun2(self):
pass
It is also better to yank/delete a method linewise to move it around. Yanking/deleteting it charwise results in weird indentation issues if you're not accounting for that. I have gotten it to work by adding a check if the selection mode is linewise to update the column end position to 0 before the update.selection call. Realize it's not the best solution but it seems to work well. I can get a pr out for this if the solution seems decent.
Describe the bug After configuring
daf
to delete outer function lines, more than the function is deleted.To Reproduce Given LazyVim and the following snippet configuration
And the following sample code
if you go online
:18
and pressdaf
, you will deleteExpected behavior I'm expecting to delete exactly
the
pass
on line 22 should still be there afterdap
.Output of
:checkhealth nvim-treesitter
────────────────────────────────────────────────────────────────────────────── nvim-treesitter: require("nvim-treesitter.health").check() Installation - WARNING tree-sitter executable not found (parser generator, only needed for :TSInstallFromGrammar, not required for :TSInstall) - OK node found v21.1.0 (only needed for :TSInstallFromGrammar) - OK git executable found. - OK cc executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" } Version: cc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0 - OK Neovim was compiled with tree-sitter runtime ABI version 14 (required >=13). Parsers must be compatible with runtime ABI. OS Info: { machine = "x86_64", release = "5.4.0-132-generic", sysname = "Linux", version = "#148-Ubuntu SMP Mon Oct 17 16:02:06 UTC 2022" } Parser/Features H L F I J - bash ✓ ✓ ✓ . ✓ - c ✓ ✓ ✓ ✓ ✓ - diff ✓ . . . . - html ✓ ✓ ✓ ✓ ✓ - javascript ✓ ✓ ✓ ✓ ✓ - jsdoc ✓ . . . . - json ✓ ✓ ✓ ✓ . - jsonc ✓ ✓ ✓ ✓ ✓ - lua ✓ ✓ ✓ ✓ ✓ - luadoc ✓ . . . . - luap ✓ . . . . - markdown ✓ . ✓ ✓ ✓ - markdown_inline ✓ . . . ✓ - python ✓ ✓ ✓ ✓ ✓ - query ✓ ✓ ✓ ✓ ✓ - regex ✓ . . . . - toml ✓ ✓ ✓ ✓ ✓ - tsx ✓ ✓ ✓ ✓ ✓ - typescript ✓ ✓ ✓ ✓ ✓ - vim ✓ ✓ ✓ . ✓ - vimdoc ✓ . . . ✓ - yaml ✓ ✓ ✓ ✓ ✓ Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections +) multiple parsers found, only one will be used x) errors found in the query, try to run :TSUpdate {lang}
Output of
nvim --version
Additional context Add any other context about the problem here.