Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand key and Visual Mode selection #83

Draft
wants to merge 23 commits into
base: master
Choose a base branch
from

Conversation

IndianBoy42
Copy link
Contributor

@IndianBoy42 IndianBoy42 commented Jun 6, 2023

This branch is based on #81 so that should be merged first.

  • expand_key
    • ISwap, ISwapWith
    • ISwapNodeWith
    • ISwapNode already can select arbitrary nesting
  • visual mode select (all the at_cursor functions need to handle visual mode and ranges)
    • make it work from cmdline (hitting : ends the visual selection)

Address #79

@IndianBoy42
Copy link
Contributor Author

IndianBoy42 commented Jun 6, 2023

ISwapWith visual mode behaviour is obvious to me. The selection range should be equal to or subset of a child node of the list. The selection is serving to choose the child node, the way the cursor does in normal mode. Then the normal mode behaviour is equivalent to visual mode behaviour with a single width selection.

ISwap visual mode behaviour I think has two choices

  1. the selection range is the user trying to define one of the child nodes, even though the selection is not actually the node that will be swapped. so it works the same as ISwapWith
  2. the selection range is the user trying to define the list node, so if there is a list node with range equal to or smaller than the selection (picking the largest one), we should use that, and the labels will be 'inside' the selection range. and if there is no list node contained within the selection... give up or fallback to option 1?

Note that in the second case the normal mode behaviour is not equivalent to visual mode behaviour with a single width selection. but intuitively this seems to make more sense. One argument against the second is that its more keystrokes when trying to deal with lists nested with the same kind of braces: for { {...}, {...}, {...} } with the cursor in the most nested list, doing vib<cmd>ISwap<cr> or <cmd>ISwap<cr> is the same, you would need vibib<cmd>ISwap<cr> to select and swap in the outer list.

How do you think visual mode selection should work?

@IndianBoy42 IndianBoy42 force-pushed the expand_key branch 5 times, most recently from 9c347d9 to b9de506 Compare June 6, 2023 14:43
@mizlan
Copy link
Owner

mizlan commented Jun 6, 2023

What if cursor was just a special case of range with length 1, for purposes of calculating things?

@IndianBoy42
Copy link
Contributor Author

IndianBoy42 commented Jun 6, 2023

Yeah that would be the first solution. I'm just wondering if that's really the best way in terms of utility or intuitive behavior. This branch is in a working state so you can try it out. I've implemented both behaviors controlled by a config variable

@IndianBoy42 IndianBoy42 force-pushed the expand_key branch 2 times, most recently from 91f1a08 to 2837ab7 Compare June 19, 2023 11:16
@IndianBoy42
Copy link
Contributor Author

IndianBoy42 commented Jun 19, 2023

Have you got the chance to try this out?

@mizlan
Copy link
Owner

mizlan commented Jun 19, 2023

not yet... been busy, i will definitely try it by EOD Wednesday

@mizlan
Copy link
Owner

mizlan commented Jun 22, 2023

Flash-confirm highlighting is broken on a case like this:

{'a', 'bcdefg'}

The 'a' is supposed to be highlighted first but something happens. I can look into it.

By the way, I am certain this is not related to this PR, just something I've noticed.

@IndianBoy42
Copy link
Contributor Author

Yeah I think its actually related to the refactor of swap_ranges_and_return_new_ranges that I did in my last PR

@IndianBoy42
Copy link
Contributor Author

IndianBoy42 commented Jun 25, 2023

New idea implemented, not sure how visually clear it is, but basically it labels the parents of the node, hitting one of those labels relabels which nodes will be swapped (basically the same as hitting expand/shrink a few times). Now ISwapNodeWith is kind of similar but mostly better than ISwapNode (2 keypresses for any 2 nodes, 1 keypress if you started it at the correct nesting level). I even think if ISwapNodeWith was made to use the list query to find the initial list, it would be strictly better than ISwapWith (1 key for the most common case, able to swap almost any 2 nodes with 2 keys).

EDIT: that second part is done, I feel like ISwapNodeWith should be the default, its fast and flexible

@IndianBoy42 IndianBoy42 force-pushed the expand_key branch 2 times, most recently from 376e33b to 9141a4a Compare July 16, 2023 07:54
@IndianBoy42 IndianBoy42 force-pushed the expand_key branch 2 times, most recently from e3a9d2c to 4134746 Compare July 30, 2023 13:14
The old behaviour was basically a worse version of the new ISwapNodeWith. now its basically ISwapNodeWith but select two children (can still adjust parent, but may not need to with smart initial parent selection, so its almost always better than ISwap)
will always paint the children+parent labels (so doesn't autoswap on the first iteration)

The user either selects child(ren) to swap. Or selects a parent, which may autoswap if only 2 children

Is this name good?
No need to take up another keymapping for incremental swapping, The ISwapNodeWith keymapping can satisfy 99% of cases.
Also allows selecting the parent to do swaps in, which wasnt possible with incremental swaps before

Issues:
- everything is refactored to keep ranges rather than tsnodes
no longer skips comment nodes as a result
- swap_ranges doesn't seem to return the correct new ranges always (known but now is problematic not just visually wrong)
WIP: buggy with move or incremental swap, may be because swap_ranges doesn't return the correct new range.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants