atom / find-and-replace

Find and replace in a single buffer and in the project
MIT License
242 stars 197 forks source link

Add undo to replace all in project #331

Open hachpai opened 9 years ago

hachpai commented 9 years ago

Hello,

I've spent 2 hours to undo a bad replace all in project. An not-undoable operation for the moment. It's REALLY dangerous :-1:

Miss this function truly.

thank you

ph

benogle commented 9 years ago

Super sorry about losing work :(. Are you using git?

hachpai commented 9 years ago

Yeah, but one day of work in trash. The really surprising thing is that atom saves directly all the modified files. I try to separate new things unaltered from all the others and git back the distant copy. Imagine, i've changed all 'user' occurences by 'role' without case-sensitivity, in a authorization/authentication project...Nightmare! :-)

samtuke commented 9 years ago

Yeah this is crazy. I just experienced:

Replaced " with ' 41197 times in 961 files

Why does Atom replace in files which aren't open? Why did it replace in multiple files in the first place? I see only a "replace all" button, I'm unsure if the changes were saved across all affected files already (appears so, no blue icons on tabs of open files indicating unsaved changes).

Ouch :(

benogle commented 9 years ago

Why did it replace in multiple files in the first place?

There are two kinds of find and replace UIs: find in buffer, and find in project. Sound like find in buffer was what you wanted, but you used find in project.

JacobEvelyn commented 9 years ago

+1, I've run into this several times (including now) and it's a huge pain to fix the mistake.

dk253 commented 9 years ago

twice this week... the last one was 1350 changes in 58 files. Woohoo.

samtuke commented 9 years ago

On 03/03/15 15:33, dk253 wrote:

twice this week... the last one was 1350 changes in 58 files. Woohoo.

Heck. I feel your pain.

btm1 commented 9 years ago

i just had this happen too... also where is there only a replace all when you find in project? I just want to find all instances of something. I could have sworn there used to be just a find button.

buildc0de commented 9 years ago

Wow. Danger :mouse: :-) Just got bitten by this as well.

park9140 commented 9 years ago

Perhaps a confirm when replacing in unopened files would be appropriate until we can get undo?

ghost commented 9 years ago

:+1: it would be really really useful

graemeworthy commented 9 years ago

+1

zaz commented 9 years ago

I just did this on my entire ~/.atom directory when trying to replace something in package file. If I'd accidentally opened my home directory instead (which is quite possible for a newb to do by accident), I likely would have lost data.

IMO, this feature should be removed entirely until some safeguards can be put in place, such as:

Because this feature is dangerous (or at the very least a major PITA) when used incorrectly, please consider changing the enchancement label.

@benogle

ghost commented 9 years ago

Maybe the most straightforward temporary way could be to remove the find-in-project keybinding from defaults (as it seems problems arise when we accidentally fire it up instead of find-in-file)... I think that completely removing the ability to mass replace would completely prevent atom from spreading now that we are next to 1.0...

zaz commented 9 years ago

Good idea. Although it still doesn't behave how you would expect when you open your home directory, then browse to your project. It's not find-in-project, it's find-and-replace-everything-atom-currently-has-access-to. I really think it should display a warning when you try to replace in a directory that is not version controlled. Just something along the lines of:

Make replacement in every file in `/User/john/`?

By the way, I just realized that I ended up making this mistake because Vim-mode rebinds ctrlf to page-down, so I tried ctrlshiftf instead.

ghost commented 9 years ago

@jb Yes, its because it considers the folder you start from to be your project, not the last one you enter...

zaz commented 9 years ago

@andya9: I realized that when I ran find-in-project and it messed up my ~/.atom/ directory...

julius-retzer commented 9 years ago

+1. Just accidentally replaced 'Content-Type' with empty string in the whole project. No way back, I have to revert to last commit.

mystist commented 9 years ago

Suffered from the same issue just now... :sob:

xPaw commented 9 years ago

Just occurred to me by mistake. Why is there no confirmation dialog for replace all?

PrestonStahley commented 9 years ago

Ouch. +1 for confirmation dialog.

DiogoAndre commented 9 years ago

bummer.. same thing happened to me.

hachpai commented 9 years ago

When I opened this issue 6 months ago, i didn't expect all those moments of empathy for other coders.

mzampetti commented 9 years ago

+1

xPaw commented 9 years ago

Atom 1.0 shipped without fixing this? :angry:

dorianfm commented 9 years ago

Would also be good to be able to cancel the operation once started, and to be able to just do a find in project, which was what I was trying to do when Atom replaced the search string with empty space across 38 files

EDIT: Scratch the find in project - that was my stupidity, through muscle memory I hit cmd+enter not enter ... hence did a 'replace all' rather than a find. Confirmation dialog and cancel ability would still be nice.

SECOND EDIT: I really shouldn't file reports when tired. There is an interface design issue with find all in project; it seems there is no 'find all' button shown when you bring this up, just 'replace all'. Hitting 'enter' after putting in your find term executes the find, but having a visible 'find all' button would make the functionality clearer.

as @xpaw said, this is the kinda thing that shouldn't have made it to 1.0!

arthursw commented 9 years ago

+1! 1995 changes in 135 files

kmattimo commented 9 years ago

yow, in atom 1.0 undoing that is broken AND it writes to all the files. That is harsh.

chiefGui commented 9 years ago

+1! :cry:

image

At least ask for saving, please!

bergwerf commented 9 years ago

Yes please. I wanted to replace four spaces with one tab in the opened file but since I typed way too fast I actually replaced two spaces by one tab in 52 files 10895 times. I'm going to cry out loud somewhere now.

r-murphy commented 9 years ago

+1. I like the Sublime approach to this, which is to open all the files and require them to be saved. Along with the corresponding menu opens to save-all and close-all. Although it could probably be improved upon with a warning system or confirmation dialog.

onemoreahmad commented 9 years ago

I just replaced all ' to " Of course Atom crashed, and my heart as well!

A sad short story!

hachpai commented 9 years ago

I've let 30 minutes to myself to find how to just add a confirmation box, but time is over and I've to work... I've never found the definition of replace-all command, seems like auto-generated from the command file or I don't know... Maybe I'll give it another chance in few times.

thomasjo commented 9 years ago

@hachpai Here it is: lib/find-view.coffee#L271-L275. The actual command is registered at line 194 in the same file.

South-Paw commented 9 years ago

Lost a few hours of work because the find/replace went for the whole file instead of the selection & then I realised there was no undo for it.

It was a fantastic few hours putting that back together.

On a side note; also noticed that general highlighting/selection of text in the editor is rather buggy and the find/replace functions don't always seem to work as expected (such as highlighting a section and then clicking 'in selection' only to have it seemingly deselect your selection)

But anyway. Find/replace needs an undo really badly.

MauricioMoraes commented 9 years ago

+1 For this. I was trying to replace within a file and miss-replaced on all files. Lost some time too.

Eclipse has a way to preview the changes that is very useful. You can view the "Future diff" and choose which files you want to modify. It could serve as inspiration for a new tool.

RiFi2k commented 9 years ago

" for ' 34406 in 178 files, beat that.... Edit: Didn't see someone had 41k, well I was close

park9140 commented 9 years ago

@benogle, could we get some attention to this?

zaz commented 9 years ago

446 temporarily disables ctrl + F, the hotkey for project-find, until a better solution is found.

Am I right in thinking that most people are having this issue because they accidentally used ctrl + F instead of ctrl + f?

RiFi2k commented 9 years ago

Yup I was just moving real fast not paying attention, I would think just having something like if more than 10 files or 100 find and replace actions are going to happen you need to confirm or something to that effect I can't even sudo apt-get update without putting in my password, seems stupid you can find and replace 40,000 things in half a second without a prompt or anything

park9140 commented 9 years ago

@zaz, for me it's not really that the command is to easy to hit. It is that there is no catch for the replace action on replace in all files, and it is to easy to trigger the actual replace via keyboard when you are doing a find all.

RiFi2k commented 9 years ago

Yeah, agreed. I was sour earlier but now I'm over it. Atom is still my favorite editor I have ever used hands down. Even if I did it 5 more times I still wouldn't switch. Keep up the good work!

r-murphy commented 9 years ago

For me, I meant to hit cmd + F, in order to do a find all across the project, but I did a replace all by accident. I entered the find value then tabbed into the replace field to clear it, so the find result wasn't displaying an unrelated replace value. Then I meant to shift+tab back to the find field and press enter to execute. But my right hand was faster than my left and I hit enter when the cursor was still in the replace field.

park9140 commented 9 years ago

@r-murphy, definitely done it that way at least once.

South-Paw commented 9 years ago

as @park9140 said, its not the command that's the issue (for me) its the way that it acts when finding/replacing and the fact there's no undo for it.

zaz commented 9 years ago

Well if any of you has an idea of how Atom works internally, a lot of people would appreciate a fix. I don't know how to do much more than just disable hotkeys.

danShumway commented 9 years ago

This is a pretty big issue for me as well - I don't think the command is bad, I think the lack of undo for it is just kind of broken in general. Would there be any internal problems if Atom logged the results of directory-wide actions like this and gave you a way to do some type of global undo?

I can see this being an issue for other commands from plugins as well. (Okay, whitespace cleanup on all of my code; oh I didn't commit my actual changes yet and now everything is mixed together)

ioquatix commented 9 years ago

Ouch, just got bitten by this.

Could we copy the behaviour from TextMate or something similar? (give you a preview first).

soukiassianb commented 9 years ago

+1, currently discarding changes manually on 292 files :hammer: If anyone knows a better way..

chiefGui commented 9 years ago

@soukiassianb unfortunately, the best way is reverting through Git—but this is not always an option. :(