Wansmer / sibling-swap.nvim

Neovim plugin for swaps closest siblings with Tree-Sitter
MIT License
162 stars 1 forks source link

Feature Request: Limit swap to node context #14

Closed kevintraver closed 7 months ago

kevintraver commented 7 months ago

Example:

{
  "name": "Project A",
  "details": {
    "started": "2021-01-01",
    "completed": "2023-01-01",
    "tasks": ["Task 1", "Task 2", "^Task 3", "Task 4"] <-- cursor on Task 3
  }
}

When the cursor is on Task 3, the swap should be limited to the items in array, and should stop when Task 3 is at the beginning or end of the array.

Instead the swap operation is allowed to continue after Task 3 is at the beginning of the list, and the swap then performs on the next outer node, which then swaps the tasks and completed objects.

{
  "name": "Project A",
  "details": {
    "started": "2021-01-01",
    "tasks": ["^Task 3", "Task 1", "Task 2", "Task 4"],
    "completed": "2023-01-01"
  }
}
Wansmer commented 7 months ago

Instead the swap operation is allowed to continue after Task 3 is at the beginning of the list, and the swap then performs on the next outer node, which then swaps the tasks and completed objects.

What continues on the external node is correct and expected sibling-swap behavior. The plugin looks for a suitable node to move to. At the moment when ^Task 3 is leftmost, the next suitable one is tasks. This approach allows you to move any neighboring nodes in any language without any additional configuration.

However, you can try to implement the context restriction yourself using the fallback option.

If you need tighter restrictions, have a look at other plugins with similar functionality: iswap.nvim or nvim-treesitter-textobjects.

kevintraver commented 7 months ago

Ok. Thank you for the explanation!