Skip to content

Fix nextTab/prevTab selection logic #5383

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

Merged
merged 5 commits into from
Sep 20, 2016

Conversation

facchinm
Copy link
Member

fixes #5380

@facchinm facchinm mentioned this pull request Sep 19, 2016
@matthijskooijman
Copy link
Collaborator

matthijskooijman commented Sep 19, 2016

Hey, you're stealing my PR :-)
(which I was just about to create)

When searching through all tabs, the order was accidentally reversed.
This was broken by commit d2bac86 (Remove tab switching logic from
Sketch).

This also fixes a problem where "replace all" would only work on the
first and last tab (since it would search backwards from the first tab
to the last tab and then conclude it was done).

This fixes a part of arduino#5380.
@matthijskooijman
Copy link
Collaborator

I stole it back, I replaced my commit with yours. Content is identical, but my commit message was a bit more complete :-)

@facchinm
Copy link
Member Author

LOL 😄

The snippet:

    boolean wrapNeeded = false;
    if (wrap && nextIndex == -1) {
      // if wrapping, a second chance is ok, start from the end
      wrapNeeded = true;
    }

is present on both sides of the `if` statement so it can be factored out.
The snippet:

    boolean wrapNeeded = false;
    if (wrap && nextIndex == -1) {
      // if wrapping, a second chance is ok, start from the end
      wrapNeeded = true;
    }

Can be moved inside the `if (nextIndex == -1)` that follows, this way:

    if (nextIndex == -1) {
      boolean wrapNeeded = false;
      if (wrap) {
        // if wrapping, a second chance is ok, start from the end
        wrapNeeded = true;
      }

      [...CUT...]

      if (wrapNeeded) {
        nextIndex = backwards ? text.lastIndexOf(search) : text.indexOf(search, 0);
      }
    }

but since `wrapNeeded` is used only at the very end of the `if` statement
we can move it forward:

    if (nextIndex == -1) {
      [...CUT...]

      boolean wrapNeeded = false;
      if (wrap) {
        // if wrapping, a second chance is ok, start from the end
        wrapNeeded = true;
      }
      if (wrapNeeded) {
        nextIndex = backwards ? text.lastIndexOf(search) : text.indexOf(search, 0);
      }
    }

and finally simplify it by removing `wrapNeeded` altogether:

    if (nextIndex == -1) {
      [...CUT...]

      if (wrap) {
        nextIndex = backwards ? text.lastIndexOf(search) : text.indexOf(search, 0);
      }
    }
@cmaglie
Copy link
Member

cmaglie commented Sep 20, 2016

I've pushed some more commits that solves the highlight bug and fix another corner case with foldings.
There are also 2 other commits that simplifies a bit the find algorithm.

@cmaglie cmaglie force-pushed the solve_search_replace branch from cba11e2 to 1efa07f Compare September 20, 2016 13:31
@facchinm facchinm merged commit 4c3d962 into arduino:master Sep 20, 2016
@facchinm facchinm deleted the solve_search_replace branch September 20, 2016 14:02
@matthijskooijman
Copy link
Collaborator

@cmaglie, awesome, thanks for digging into this. Commits look great to me, I especially like the long commit messages on the cleanup commits :-D

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.

Edit > Find issues
3 participants