Author Topic: Find backwards doesn't work  (Read 3196 times)

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Find backwards doesn't work
« on: October 26, 2014, 12:17:46 am »
Steps to reproduce:
1. Place the cursor on a word that has more than two occurrences in the file
2. Ctrl-F to open the search dialog
3. Change the direction to Up
4. Press Find
5. Ctrl-F to open the dialog once again
6. Press Find

The result is that the third occurrence of the word is not selected, but the selection stays at the second occurrence.

This is the code that causes the problem (src/src/find_replace.cpp:320, FindReplace::CalculateFindReplaceStartEnd)
Code
        // when the user initially had a selection, but then changed the scope
        // to entire scope, the values of ssta and send will have a bad influence in
        // the following calculations, therefor check for the scenario
        // and set the ssta en send to cpos (in the case there would be no selection
        // that's the value they have [no selection : ssta=send=cpos])
        // only do this when it's a new search (when the search is continued (F3/Shift-F3)
        // there can be a selection, the last found match)
        if ((data->scope == 0) && data->NewSearch && (ssta != cpos || send != cpos))
        {
            // Don't do this in replace mode, because we want to start the replacement
            // with the current selection, not the first match after the selection.
            if (!replace)
            {
                ssta = cpos;
                send = cpos;
            }
        }

Does someone knows why this is needed? The blame reported that the code is written by Killerbot in 2006 rev3164...
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]