nvim-treesitter / nvim-treesitter-textobjects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Linewise selections should include all empty lines below

rwblokzijl opened this issue · comments

Linewise selecetions should include all empty lines below. This behaviour is how vim does it (dap).

Currently a linewise function delete:

require'nvim-treesitter.configs'.setup {
  textobjects = {
    select = {
      enable = true,
      keymaps = {
        ["af"] = "@function.outer",
      },
      selection_modes = {
        ["@function.outer"] = 'V', 
      }
    },
  },
}

dap (removes the newlines after):

local function hello()     =>     -- something else
  print("world")                  
end                               

-- something else

daf (leaves the newlines):

local function hello()            
  print("world")           =>     -- something else
end                               

-- something else

I think these actions should have the same effect in this context.

If I understand correctly, this is already possible using the include_surrounding_whitespace option.
See this excerpt of the README:

      -- If you set this to `true` (default is `false`) then any textobject is
      -- extended to include preceding or succeeding whitespace. Succeeding
      -- whitespace has priority in order to act similarly to eg the built-in
      -- `ap`.
      --
      -- Can also be a function which gets passed a table with the keys
      -- * query_string: eg '@function.inner'
      -- * selection_mode: eg 'v'
      -- and should return true of false
      include_surrounding_whitespace = true,

O wow, even uses the same example, this is resolved then.