Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Added 'All' button to FindReplace functionality. #4686

Merged
merged 1 commit into from
Aug 17, 2013
Merged

Added 'All' button to FindReplace functionality. #4686

merged 1 commit into from
Aug 17, 2013

Conversation

zaggino
Copy link
Contributor

@zaggino zaggino commented Aug 7, 2013

I've been missing 'All' button when replacing too many occurrences of a string in file. I can add tests if this gets considered for merge.

@TomMalbran
Copy link
Contributor

Nice feature!

I was thinking that after doing a replace All, we could show what was replaced, in similar format to find in files. So you could go through every replace and check if the result is what you expected and easily undo a replace if it wasn't.

Any thoughts?

@zaggino
Copy link
Contributor Author

zaggino commented Aug 7, 2013

Yes, it could certainly be useful to see what was replaced. This was just a quick idea because I was stuck with pressing 'Yes' for 50 times in one file :)

Are you thinking of doing it for current file, or global style command "Replace in Files" (Ctrl + Shift + H) ?

@TomMalbran
Copy link
Contributor

Hehe. I did that before, and even worse I ended clicking so fast that clicked in between the closing and opening of the dialog, making it disappear...

It is a nice feature to add, and we really need it. But I think it should be well implemented too.

I was actually thinking it just for the current file, since we don't have a Replace in Files yet. Anyway, it should be useful for both commands.

@zaggino
Copy link
Contributor Author

zaggino commented Aug 7, 2013

Ok, I'll give it a try in spare time, maybe I'll come up with something usable.

@TomMalbran
Copy link
Contributor

Or wait to see what others have to say about it. Maybe we don't need it yet or don't need it for the current Replace command. But if you still want to try it, go ahead.

I was thinking of saving for each replacement, the line, the string, and the column position and length of the new string. Then use this information to fill a bottom panel. Similar to how Find in Files works.

@zaggino
Copy link
Contributor Author

zaggino commented Aug 8, 2013

@TomMalbran can you look at the last commit ? I can't figure out why AppInit.htmlReady gets launched when no #status-bar element is available, which causes PanelManager.createBottomPanel to attach panel to nowhere.

There is no check in PanelManager.createBottomPanel to see if #status-bar exists.

    function createBottomPanel(id, $panel, minSize) {
        $panel.insertBefore("#status-bar");
        $panel.hide();
        updateResizeLimits();  // initialize panel's max size

        return new Panel($panel, minSize);
    }

@TomMalbran
Copy link
Contributor

The status bar is also created on htmlReady. Which means that the html ready for this file could be called before the html ready of the Status bar code.

To solve this, the status bar div (empty) should be included in the main view template, and when creating the status bar, it should just include the content inside the status bar div.

@julianasuh
Copy link
Contributor

Hi @TomMalbran, do you want to review this pull request?

@julianasuh
Copy link
Contributor

@larz0 to review UI

@TomMalbran
Copy link
Contributor

@julianasuh Sure. I can.

@larz0
Copy link
Member

larz0 commented Aug 8, 2013

@zaggino UI looks good but nothing happens when I click "All". Not sure if it's just me.

@zaggino
Copy link
Contributor Author

zaggino commented Aug 8, 2013

@larz0 I haven't fully submitted it yet, working on it right now. I'll let you know today when I have first reviewable version.

@larz0
Copy link
Member

larz0 commented Aug 8, 2013

@zaggino ahh cool. Thanks for this BTW.

@zaggino
Copy link
Contributor Author

zaggino commented Aug 8, 2013

Ok, first go at UI, right now it looks like this, probably you can get an idea where it is heading from it.
image

@zaggino
Copy link
Contributor Author

zaggino commented Aug 8, 2013

Check All - None should probably be replaced by checkbox left of "Search for ..."

@TomMalbran
Copy link
Contributor

Wow nice. I was thinking of something like replace all, and then just show the lines that changed with the the replaced word highlighted. Anyway I like this approach.

@zaggino
Copy link
Contributor Author

zaggino commented Aug 9, 2013

Thanks, lets see if anyone else would like to comment before I go further, I have some other stuff to do and then will take a look at pull-4661 in the meantime. @larz0 what do you think about this?

@larz0
Copy link
Member

larz0 commented Aug 9, 2013

Damn that's really nice! Can't wait!

@ghost ghost assigned JeffryBooher Aug 9, 2013
@zaggino
Copy link
Contributor Author

zaggino commented Aug 12, 2013

@TomMalbran do you have any idea, why would brackets freeze after calling document.replaceRange ? All my instances will just freeze after this line and there's no breakpoint in developer tools. I have to close brackets with task manager - end process in windows.

@TomMalbran
Copy link
Contributor

@zaggino The line and ch values from the cursor positions need to be numbers, and you are passing strings. It also would be simpler to store the selections (start and end cursor positions) in an array and just store the index in the array in the data values in the elements.

After this change, it works nice. There are other issues, like replacing twice (not sure what to do here, since it might be nice to undo and try to replace again, but without undoing replacing again wont give good results), but the replace works.

@zaggino
Copy link
Contributor Author

zaggino commented Aug 12, 2013

@TomMalbran thanks for that, setSelection was working even with strings and since everything just froze without and error I wasn't able to figure it out ... anyway I was planning to close the panel after replacing selected matches so replacing twice would not be possible. Do you think the "replace twice" feature would be somehow useful ?

There are few other issues for me to solve like switching between files and modifying current file while the panel is opened.

@TomMalbran
Copy link
Contributor

No problem. I saw that, not sure why select did worked, maybe select doesn't care if the param is a string.

Actually, closing the panel after replacing sounds good. You can easily undo and use the same replace to get the panel back and try again.

For switching panels, you can just add a listener for the document change, and close the panel it when it does change. You should also close it when switching projects. I think that you might not get a current document change event if when opening a new project no document opens, but check if you need both.

Changing the results while editing is hard. I submitted a pull request to do this for the find in files. You can check my code in PR #4729. But if this ends up being too hard, maybe you could go with an easier solution of replacing all first and then showing what was replaced with no option to replace again, so you don't really need to update the results.

@zaggino
Copy link
Contributor Author

zaggino commented Aug 12, 2013

I was thinking more of just closing the panel when user starts typing into the document, so he won't get unexpected outcome since results will be outdated after modifying part of the file before matches.

As I understand your code, you refresh results after every key stroke? Doesn't that affect performance when user starts typing rapidly?

@TomMalbran
Copy link
Contributor

Closing the panel could be an option for now. Another option can be to remove the replace button and replace with something like search, so that it updates the panel. We can improve it later with an auto-update if required.

Is not really every keystroke, is every change. CodeMirror joins close updates and sends them as a change. Is like if you type really fast and then undo, you might undo several keystrokes. I haven't tested how fast it is, but is not slow.

@zaggino
Copy link
Contributor Author

zaggino commented Aug 12, 2013

I've done some thinking and refactoring on this, now it refreshes when user modifies current document - you were right, it's not slow at all.

I'll have to test everything and read code again so there are no loose ends but I think it's nearing it's final version.

@TomMalbran
Copy link
Contributor

It looks like you are searching the entire document on every change? I tried that first, but that is actually pretty slow on really big files like CodeMirror. What I did instead is search only over the new lines, remove the the results on the removed lines, and modify the rest of the line numbers. But that is harder to have it done right. So if we want to do that here, we could try to do it using one code only, later when my PR gets accepted.

@zaggino
Copy link
Contributor Author

zaggino commented Aug 12, 2013

Ok @TomMalbran , I've removed automatic refresh on every change for now and replaced it with search button that will appear after user modifes a document when the panel is open. I should probably add some tests now, for me the feature works pretty well right now.

@TomMalbran
Copy link
Contributor

I wasn't able to actually test the re-search the entire file before. Was it actually slow on a file like codemirror.js? I might test it later. Anyway I don't think that researching the entire file is a good idea.

If you are done with the code. I will give it a full review and test it more.

@larz0 I have a few questions about the design/usability:

  • Should the buttons on the replace panel have the same style as the buttons on the modal bar? They need some style.
  • We haven't used any checkboxes in Brackets yet, so we will need a new style for them here. You can style them after this is merged too, if we will style the checkboxes.
  • Is it ok to replace the "Replace" button with a "Search" button when the content of the file changed, or should we just close it. We can later fix this with a search over the new content and update the panel, but I want to have PR Find in Files Improvements (Part 3: Auto-update) #4729 merged first and move the core of that code to an utils files to use here.

@larz0
Copy link
Member

larz0 commented Aug 13, 2013

@TomMalbran

  • Yes you're right, they need to have the same style. I can do it after the merge if that's easier.
  • I can style the checkboxes once this is merged.
  • We should just close it for now instead of replacing it with the "Search" button.

@TomMalbran
Copy link
Contributor

Done with second review.

@zaggino
Copy link
Contributor Author

zaggino commented Aug 14, 2013

Fixed according to second review.

@TomMalbran
Copy link
Contributor

This feature is working great and the code looks nice, just 2 more thing before merging:

  • I just run the FindReplace tests and after the last one, the replace bar isn't dismissed, you will have to trigger a click on the stop button.
  • I am thinking that we would need to add some tests for Replace All, or can be added on another PR, not sure about it, but there is time till the end of Sprint 30.

@zaggino
Copy link
Contributor Author

zaggino commented Aug 15, 2013

@TomMalbran I'll take a look at it little bit later and set-up a test for this.

@TomMalbran
Copy link
Contributor

I am not sure if we need the tests done in this PR, since replace doesn't had any test either. But if you can still make them, that would be great.

@ghost ghost assigned TomMalbran Aug 16, 2013
@zaggino
Copy link
Contributor Author

zaggino commented Aug 16, 2013

@TomMalbran - I fixed that test issue with stop button and merged with current master. I can take a look at the tests later but not right now, so feel free to merge so @larz0 can start working on styling the UI.

@TomMalbran
Copy link
Contributor

Sure. If you don't have time to work on the tests right now, we can merge this and complete them later.

Just 2 last things. There was a merge issue after your other fix was merged, could you fix the conflict here. And second, could you rebase this PR, since it has lots of commits and we try to keep the git source small? Thanks

@zaggino
Copy link
Contributor Author

zaggino commented Aug 16, 2013

Did the rebase @TomMalbran , you can squash commits now?

@zaggino
Copy link
Contributor Author

zaggino commented Aug 17, 2013

Nevermind squash, I studied a thing or two and did that myself, so now it's all in one commit ;-)

@TomMalbran
Copy link
Contributor

Nice job. I was about to merge it, but I went and run the test first and unfortunately your test is failing now because of the modal bar transition, which was merged today and also broke all the other find tests. Can you fix that fast and then I merge?

Work in progress, problem with htmlReady and createBottomPanel.

Still work in progress, version with some UI to review.

Work in progress, brackets freezing on document.replaceRange

Fixed freezing issue and close panel after replacing.

Added document change handler to close the replace panel if it's open.

Replace all panel now automatically refreshes on document change.

Refactoring and fixing JSLint errors.

Replace button is now switched to Search button after a document is modified.

Deleting wrongly added file.

Added test for simple find-replace case.

Changes according to comments.

Added limit of 300 search results.

Modified string to show when limit is reached.

Refactoring after code-review #1

Refactoring after code-review #2

Refactoring after code-review #3

Refactoring after code-review #4

Click on the stop button so the replace bar is dismissed.

Fixed failing testcase.
@zaggino
Copy link
Contributor Author

zaggino commented Aug 17, 2013

Ok @TomMalbran , merged master, fixed testcase and squashed again into one commit. That test is now passing.

@TomMalbran
Copy link
Contributor

Awesome. Merging :)

TomMalbran added a commit that referenced this pull request Aug 17, 2013
Added 'All' button to FindReplace functionality.
@TomMalbran TomMalbran merged commit a9d2a17 into adobe:master Aug 17, 2013
@TomMalbran
Copy link
Contributor

@larz0 You can now change the style of the replace all panel :)

@larz0
Copy link
Member

larz0 commented Aug 17, 2013

@TomMalbran excellent ☑️

@larz0
Copy link
Member

larz0 commented Aug 17, 2013

@TomMalbran @zaggino FYI I did a find on "<p>", replacing with "<p1>" and it did this:

screen shot 2013-08-17 at 1 34 44 pm

@TomMalbran
Copy link
Contributor

Woops, nice catch. Is not doing a html escape on the replace strings. Is easy to fix thought. @zaggino Want to post a fix? Or should I?

@zaggino zaggino deleted the replace_all branch August 17, 2013 22:44
@zaggino
Copy link
Contributor Author

zaggino commented Aug 17, 2013

@TomMalbran can you actually add commits to already merged branch to be merged again? This only came to my mind after creating a new PR :/

@TomMalbran
Copy link
Contributor

No. Is better to have new branches for fixes after a merged branch. I guess you can probably add commits to your branch, but you will need to create a new PR. Anyway use new branches for the fixes after the branch was merged.

@njx
Copy link
Contributor

njx commented Aug 19, 2013

Wow, this is really cool! Wasn't expecting to get a preview panel to let you tweak what gets replaced. Nice idea.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants