This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 207532

Summary: Find/Replace missing "in selection" option
Product: editor Reporter: theosib
Component: SearchAssignee: Milutin Kristofic <mkristofic>
Status: REOPENED ---    
Severity: normal CC: AE56, jhcaiced, markiewb
Priority: P2    
Version: 7.1   
Hardware: PC   
OS: Windows 7 x64   
Issue Type: ENHANCEMENT Exception Reporter:

Description theosib 2012-01-19 17:32:31 UTC
Product Version = NetBeans IDE Dev (Build 201110150600)
Operating System = Mac OS X version 10.7.2 running on x86_64
Java; VM; Vendor = 1.6.0_29
Runtime = Java HotSpot(TM) 64-Bit Server VM 20.4-b02-402

Netbeans' search and replace feature is missing an option to allow one to perform a replace or replace-all confined to a selection.  This is a feature I use quite frequently in other editors, so I really miss it in Netbeans.
Comment 1 Milutin Kristofic 2012-01-25 14:03:39 UTC
This is already implemented and automatical. If you selected multilines and start search or replace bar then you search or replace only inside selected text.


See:
http://blogs.oracle.com/geertjan/entry/hidden_netbeans_feature_search_in
Comment 2 theosib 2012-01-25 23:11:07 UTC
It isn't at all clear that this is the case.  So that you can meet common expectations about this, you may want to add an option to turn it on or off, or you may want to add "(in selection)" to strategic places to indicate to the user that their action will be confined to the selection.

In other words, I'd call this a human factors bug.
Comment 3 Milutin Kristofic 2012-05-16 15:30:10 UTC
I will discuss about ui changes to 7.3, but this is more enhancement than bug
Comment 4 sargac 2012-05-28 11:15:51 UTC
But it doesn't work with "Regular Expression" option checked. Is this a feature I don't understand (maybe with Regex there is a possibility to tell NetBeans to search only within selection) or there is a bug indeed?

Best,

(In reply to comment #1)
> This is already implemented and automatical. If you selected multilines and
> start search or replace bar then you search or replace only inside selected
> text.
> 
> 
> See:
> http://blogs.oracle.com/geertjan/entry/hidden_netbeans_feature_search_in
Comment 5 Milutin Kristofic 2012-05-29 11:41:40 UTC
It works for me with regexp in 7.2 dev. What's your version sargac?

I have a file :
word1
word2
word3

select both 
word1
word2

find: ^word (select regular expression)

next is jumping from word1 to word2, not to word3
Comment 6 kilyo 2012-06-04 21:21:09 UTC
Product Version: NetBeans IDE 7.1.1 (Build 201203012225)
Java: 1.7.0_03; Java HotSpot(TM) 64-Bit Server VM 22.1-b02
System: Windows 7 version 6.1 running on amd64; Cp1252; en_US (nb)

Search in selection as per https://blogs.oracle.com/geertjan/entry/hidden_netbeans_feature_search_in works only in multiple lines of code. 6.8 (and I believe 7.0) allowed selection within a single line.

This is a breaking change and interferes with usability.
Comment 7 cafecat 2012-08-31 08:29:49 UTC
(In reply to comment #1)
> This is already implemented and automatical. If you selected multilines and
> start search or replace bar then you search or replace only inside selected
> text.
> 
> 
> See:
> http://blogs.oracle.com/geertjan/entry/hidden_netbeans_feature_search_in

It's true. Also it works partially, because you need to toggle on or off the panel on the bottom if you want to change the text selection to do Find/Replace.
Comment 8 Milutin Kristofic 2012-09-06 15:36:53 UTC
*** Bug 217312 has been marked as a duplicate of this bug. ***
Comment 9 mclaborn 2012-11-29 17:35:59 UTC
Needs to be obvious in the search panel that is limited to selected text only, and/or allow "selected text" to be turned off and on.
Comment 10 mdm42 2013-12-10 11:42:10 UTC
I confirm sargac's report (comment 4) that it emphatically does NOT work in 7.4.
Replaced a string with some text selected, and it replaced all occurrences in the entire file. Thank goodness for undo! ;)
Comment 11 Mte90 2014-06-03 17:39:44 UTC
Any news about this feature request?
An ide full of features that don'th ave this simple feature :-(
Comment 12 x3cion 2014-07-20 11:52:15 UTC
This is working, just not obvious enough. If you select text and hit ctrl+h, you'll replace only in this selection. Make sure you select first and hit ctrl+h after, it'll not accept a new selection without "reopening" the replace dialog.
Comment 13 chris_m 2014-07-20 12:07:33 UTC
(In reply to x3cion from comment #12)
> This is working, just not obvious enough. If you select text and hit ctrl+h,
> you'll replace only in this selection. Make sure you select first and hit
> ctrl+h after, it'll not accept a new selection without "reopening" the
> replace dialog.

It works if you select more than one line. Try selecting a single line and you'll see a case where it does _not_ work.

(With there being more instances of whatever it is you try to search/replace outside of that line).


There is a ton of open space in the UI and the solution that was there previously was superior to the current one. 
I'm struggeling with understanding the reasons for changing it. But at this point that might be a moot point considering the time that has passed and the resistance to change for this particular feature.
Comment 14 exolon 2014-07-23 12:53:09 UTC
It doesn't seem to be working properly in Netbeans 8.0 -- I selected a one-line array and did a search and replace, and had to undo because it seemed to execute the replace on the entire document.
Comment 15 chasdouglass 2014-08-17 15:50:22 UTC
In 8.0 (not tested in earlier versions) it seems to be completely broken for "rectangular selection".

That is, it does not limit the replace to the rectangular selection, but replaces all.
Comment 16 otisjenkins85 2015-12-15 11:51:08 UTC
In Netbeans 8.1 when Regex is enabled there is no way to enable/disable an "in selection" option, and it doesn't work automatically.
Comment 17 Manachi 2016-09-08 10:46:46 UTC
In Netbeans 8.1 this feature does not work when selecting a single line. (It will replace all occurrences in the document).

Hope it's fixed soon - this feature really should work on an IDE like netbeans!
Comment 18 error403 2016-09-22 12:48:01 UTC
In Netbeans 8.1 this issue is not fixed
Comment 19 markiewb 2016-09-22 19:04:42 UTC
(In reply to error403 from comment #18)
> In Netbeans 8.1 this issue is not fixed

@error403: Do not change the version field! It is supposed for the version the issue was reported initially. Vote instead!

Reverting the change.
Comment 20 CaptainStarbuck 2017-08-02 19:01:06 UTC
I'm running 8.2 over Windows 8.1/64, JRE 1.8.141,, came here to report this same issue and found this ticket. But I've had success with the test case documented below, so this ticket might be a candidate for Fixed/Completed. For a while I was not having success with Ctrl+H, which would be a different issue.

I want to reformat a block of PHP comments with RegEx. Example:

/**
 * This can be a very long line which goes beyond line
 * wrap and comes down to a second line.
 **/

I want to reformat that to:

/**
 * This can be a very long
 * line which goes beyond line
 * wrap and comes down to a
 * second line.
 **/

That needs to be done in two parts: Convert the selected block to a single line. Then do a multi-line conversion of that same block to comment lines.

First, select "* This" through the period. Ctrl+H.
Find: (\s)*\*
Replace: .. nothing here ...
Click Replace All.

In my current configuration, that works, which invalidates this ticket. It also verifies that it works with RegEx, which invalidates one of the notes in this ticket.

To continue... The text, now a single line remains selected.

Click back in Find:
Find: (\b.{1,40})(?:\s+|\n|$)
Replace: * $1\n

Again, that does work For Me. I recommend that others test this, and if it does not work, be specific about your JRE version, 32/64bit, locale, code language, and any other system-specific nuances that might influence results.

HTH