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

<C-n> flip fix #1082

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

jeremybobbin
Copy link
Contributor

Fixes: #1022

Unfortunately I had to change Filerange sel to Filerange range in selections_match_next for clarity.
This seemed to be a theme used in a number of other functions.

Also, though the behavior in this patch seems more correct,
I struggle to imagine a case wherein this fix is useful.

@rnpnr
Copy link
Collaborator

rnpnr commented Mar 13, 2023

Why did you change Filerange sel to Filerange range?
It seems less clear now. The Filerange in those functions wasn't some arbitrary range; it was a range representing the current selections.

PS: 3 newlines snuck in at the end of main.c.

roughly:
x/^static.*\)\s+\{$/ {
	.,/^\}$/ g/Filerange sel/ {
		x/\b(new)?sel\b/ x/sel/c/range/
	}
}
@jeremybobbin
Copy link
Contributor Author

Thanks - I've addressed the newlines.

I had to introduce Selection *sel in selections_match_next so that we could run view_selections_flip on it.

I believe the distinction is useful since a range's beginning must come before its end.
With the selection, however, the anchor & cursor can come in any order.

@rnpnr
Copy link
Collaborator

rnpnr commented Mar 14, 2023

That part seems fine. I'm talking about all of the changes in the commit:
"replace instances of Filerange sel with Filerange range"

@jeremybobbin
Copy link
Contributor Author

You're probably right. It may be more confusing than before.

@ninewise
Copy link
Collaborator

diff --git a/main.c b/main.c
index 858af23..266d70c 100644
--- a/main.c
+++ b/main.c
@@ -1394,25 +1394,37 @@ static const char *selections_match_next(Vis *vis, const char *keys, const Arg *
        if (!buf)
                return keys;

+       bool flip;
        bool match_all = arg->b;
        Filerange primary = sel;
+       Selection *new_sel;

        for (;;) {
+               flip = view_cursor_get(view) == primary.start;
                sel = find_next(txt, sel.end, buf);
                if (!text_range_valid(&sel))
                        break;
-               if (selection_new(view, &sel, !match_all) && !match_all)
-                       goto out;
+               if (new_sel = selection_new(view, &sel, !match_all) {
+                       if (flip)
+                               view_selections_flip(new_sel);
+                       if (!match_all)
+                               goto out;
+               }
        }

        sel = primary;

        for (;;) {
+               flip = view_cursor_get(view) == primary.start;
                sel = find_prev(txt, sel.start, buf);
                if (!text_range_valid(&sel))
                        break;
-               if (selection_new(view, &sel, !match_all) && !match_all)
-                       break;
+               if (new_sel = selection_new(view, &sel, !match_all) {
+                       if (flip)
+                               view_selections_flip(new_sel);
+                       if (!match_all)
+                               break;
+               }
        }

 out:

I'm considering applying it like this.

It all seems correct to me, but indeed, it might not be helpful. Perhaps ctrl-n should simply change the current selection to be not flipped before doing anything?

@jeremybobbin
Copy link
Contributor Author

There's a coherence issue with selection_new, in that information is lost when going from a selection to a range.
selection_new takes a range, and given selection_new is only called in selections_match_next, either selection_new needs a bool flip argument, or, as you suggested:

Perhaps ctrl-n should simply change the current selection to be not flipped before doing anything?

@mcepl
Copy link
Contributor

mcepl commented May 24, 2024

@jeremybobbin Is this still alive? Could we get rebase here for the current master, please?

Thank you

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.

C-n to select next matching region doesn't honor cursor position
4 participants