Author Topic: Search & Replace behaviour discussion  (Read 9924 times)

Offline tiwag

  • Developer
  • Lives here!
  • *****
  • Posts: 1196
  • sailing away ...
    • tiwag.cb
Search & Replace behaviour discussion
« on: June 21, 2006, 04:04:37 pm »
Replace text bug is still there ( http://forums.codeblocks.org/index.php?topic=3365.msg26597#msg26597 )

Quote
Replase dialog ignores flag "Entire scope" and searches for replace from cursor

There might be several problems, let's compare with regular searching.

1) from cursor
  a) the 'search' start from the current position of the cursor, when it reaches the end it wraps around (without asking) The fact that it wraps around is due to the editor setting being ticked ("Auto-wrap search when EOF reached")
  b) the 'replace' starts from the current position, when it reaches the end : it does NOT wrap around

2) entire scope
  a) the search starts from the start of the document (and when the end is reached and you continue to 'find next' it will wrap around (due to the setting))
  b) the 'replace' starts from the current position and NOT from the start

2)b) ==> BUG
1)b) because no wrap around, it can be considered a bug, but on the other hand it could have been the intention only to replace something from the start till the end

My suggestion would be (next to fixing the bug 2)b)) :
 - have the wrap around setting move, so no longer in Settings->Editor, but also a setting in the search/replace dialog (like the other settings which are there : up/down cursor/scope, ...), then this is more consistent
 - have the replace command also have the ability to wrap around ( case 1)b) ) (mathematically one would say this derives easily from the previous suggestion)

Does this sounds plausible ?


...Does this sounds plausible ?
It does :)
But there is a remark for searching (and replacing also) from cursor. I think "search from cursor" means seaching from word at cursor, not from current cursor position. I mean if you search word "lalala" and cursor is in this word, text editor have to find this word first.

Offline Denis

  • Multiple posting newcomer
  • *
  • Posts: 48
Re: Search & Replace behaviour discussion
« Reply #1 on: June 21, 2006, 04:28:41 pm »
I thought a little and decide that my idea about searching from word at cursor was wrong :)

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5529
Re: Search & Replace behaviour discussion
« Reply #2 on: June 24, 2006, 10:01:51 am »
Quote
Quote from: KirkD on Today at 06:14:40 AM
The Search/Replace function seems to extend to global scope despite having the Selected Text option clicked.
That's right. It seems, that after the first match the scope is changed to global.
Can you report it as a bug on berlios?

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5529
Re: Search & Replace behaviour discussion
« Reply #3 on: June 25, 2006, 03:11:40 pm »
Quote
Quote from: KirkD on Today at 06:14:40 AM
The Search/Replace function seems to extend to global scope despite having the Selected Text option clicked.
That's right. It seems, that after the first match the scope is changed to global.
Can you report it as a bug on berlios?

This has been fixed for "search", will fix later also for "replace". Revision 2609.

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5529
Re: Search & Replace behaviour discussion
« Reply #4 on: June 25, 2006, 03:31:34 pm »
We have a shortcoming in our searching mechanism, I have compared this to M$ Developer Studio 2005.

Here are some use cases (say we are looking for the word test, and that word is in the current editor 4 times):

1) Use case 1 :
The search is started (direction : down) from the top :
 - hit 1
 - F3 (find next) -> hit 2
 - now the cursor is manually moved past the 3rd occurence
 - find next -> hit 4

Basically it comes down to : when doing a find next, the search is carried out with the settings from the previous search, but overruling the starting position

2) Use case 2 :
The search is started (direction : up) from the bottom :
 - hit 4
 - "find the next one" -> hit 3
 - now the cursor is manually moved before the 2nd occurence
 - "find the next one" -> hit 1

Basically it comes down to : when doing a "find next one" in the direction "up", the search is carried out with the settings from the previous search, but overruling the starting position

3) Use case 3 :
The search is started (direction : up) from between the 3rd and 4h occurence:
 - hit 3
 - F3 (find next) -> hit 4 (!!!!!)
 - now the cursor is manually moved before the 2nd occurence
 - F3 (find next) - hit 3

There's a difference in the "next" thing to look for.
One can have the cursor somewhere and wants to find the "next" occurence, where the direction is discarded (and falling back on the natural direction : down), BUT on the other hand one would want to search backwards (direction : up) and then the "next hit" is to be considered before the current hit.

Currently CB supports use case 1 and 3. We have no solution for use case 2, the closest we get is that when you know you are searching upwards, you could use "find previous (shift F3) to have a similar effect.
The "inverse" situation where "next" -> "previous" suffers from the same problem.

Now how does M$ Developer Sudio (and I have seen it in other editors too) solve this :
a) F3 (find next) / Shift F3 (find previous) is always according to the natural direction (== DOWN).
b) when a search is started (through the search dialog (no other way to start a new search [well when never a search has been carried out and you press (shift)F3], CB will show the search dialog)), you get a similar dialog to the one in CB (with direction : up/down), BUT the dialog remains open during the search, AND the dialog has a button "find next" where it has the meaning of Use case 2.

I think to support Use Case 2, we will also nee such a dialog remaining open. Since at the momnt we don't have it, you will need to workaround by using the  "find next" or "find previous" commands in accordance to the search direction (up/down).
« Last Edit: June 25, 2006, 03:34:05 pm by killerbot »

Offline tiwag

  • Developer
  • Lives here!
  • *****
  • Posts: 1196
  • sailing away ...
    • tiwag.cb
Re: Search & Replace behaviour discussion
« Reply #5 on: June 26, 2006, 09:00:09 am »
we could put the find & replace dialog in a Message-pane tab, where it would be alive all the time,
even more we could display some messages there like
"search passed end of file / top of file" if wrap around is enabled,
"no more occurences" if wrap around is disabled,
"not found" if no occurence of the search string was found,
etc ...
« Last Edit: June 26, 2006, 09:02:29 am by tiwag »

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5529
Re: Search & Replace behaviour discussion
« Reply #6 on: June 26, 2006, 09:22:13 am »
we could put the find & replace dialog in a Message-pane tab, where it would be alive all the time,
even more we could display some messages there like
"search passed end of file / top of file" if wrap around is enabled,
"no more occurences" if wrap around is disabled,
"not found" if no occurence of the search string was found,
etc ...

excellent idea (it will give a bit more mouse-miles, compared with a dialog floating around in your editor) but it has the benefit that your hit is not hidden by that floating dialog.
You've got my 100% support :-)

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5529
Re: Search & Replace behaviour discussion
« Reply #7 on: June 27, 2006, 09:51:18 am »
replace now honors also the scope of "in selection". The last bug was probably caused by some copy/paste (?), the replace dialog was reading out a radiobox as a checkbox. (yes, yes, : XRC so nice to dump the real types. That way c++ get's defeated and type checking by the compiler is lost.)
Revision : 2618.

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Search & Replace behaviour discussion
« Reply #8 on: August 29, 2006, 05:29:49 pm »
One good solution could be to put the dialog into a normal dock window.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2875
Re: Search & Replace behaviour discussion
« Reply #9 on: August 29, 2006, 06:13:19 pm »
How about a search & replace tool bar like the compiler tool bar?
It's movable, docable and you could add all sorts of button options like "next", "previous", "selection type", etc.

You could make it a plugin with tool bar/menu support.
Maybe main.cpp would let us share the copy/paste tool bar/menu items.
 :D

Later, plugin additions could be made to allow it to search any window in CB. It might even search the search results. jeez...
« Last Edit: August 29, 2006, 06:20:44 pm by Pecan »