Ticket #8141: ReplaceAll2.patch

File ReplaceAll2.patch, 2.3 KB (added by x-ist, 12 years ago)

Added a final ScrollToSelection()

  • src/apps/stylededit/StyledEditWindow.cpp

    diff --git a/src/apps/stylededit/StyledEditWindow.cpp b/src/apps/stylededit/StyledEditWindow.cpp
    index 3ac8541..37fa6ac 100644
    a b StyledEditWindow::_RevertToSaved()  
    14081408
    14091409bool
    14101410StyledEditWindow::_Search(BString string, bool caseSensitive, bool wrap,
    1411     bool backSearch)
     1411    bool backSearch, bool scrollToOccurence)
    14121412{
    14131413    int32 start;
    14141414    int32 finish;
    StyledEditWindow::_Search(BString string, bool caseSensitive, bool wrap,  
    14501450    if (start != B_ERROR) {
    14511451        finish = start + length;
    14521452        fTextView->Select(start, finish);
    1453         fTextView->ScrollToSelection();
     1453       
     1454        if (scrollToOccurence)
     1455            fTextView->ScrollToSelection();
    14541456        return true;
    14551457    }
    14561458
    StyledEditWindow::_ReplaceAll(BString findThis, BString replaceWith,  
    15011503{
    15021504    bool first = true;
    15031505    fTextView->SetSuppressChanges(true);
    1504     while (_Search(findThis, caseSensitive, true, false)) {
     1506   
     1507    // start from the beginning of text
     1508    fTextView->Select(0,0);
     1509       
     1510    int32 start, finish;
     1511
     1512    // iterate occurences of findThis without wrapping around
     1513    while (_Search(findThis, caseSensitive, false, false, false)) {
    15051514        if (first) {
    15061515            _UpdateCleanUndoRedoSaveRevert();
    15071516            first = false;
    15081517        }
    1509         int32 start, finish;
     1518       
    15101519        fTextView->GetSelection(&start, &finish);
    1511 
    15121520        fTextView->Delete(start, start + findThis.Length());
    15131521        fTextView->Insert(start, replaceWith.String(), replaceWith.Length());
     1522       
     1523        // advance the caret behind the inserted text
     1524        start += replaceWith.Length();
     1525        fTextView->Select(start, start);
    15141526    }
     1527    fTextView->ScrollToSelection();
    15151528    fTextView->SetSuppressChanges(false);
    15161529}
    15171530
  • src/apps/stylededit/StyledEditWindow.h

    diff --git a/src/apps/stylededit/StyledEditWindow.h b/src/apps/stylededit/StyledEditWindow.h
    index 241de30..d107917 100644
    a b private:  
    5757            status_t            _LoadFile(entry_ref* ref);
    5858            void                _RevertToSaved();
    5959            bool                _Search(BString searchFor, bool caseSensitive,
    60                                     bool wrap, bool backSearch);
     60                                    bool wrap, bool backSearch,
     61                                    bool scrollToOccurence = true);
    6162            void                _FindSelection();
    6263            bool                _Replace(BString findThis, BString replaceWith,
    6364                                    bool caseSensitive, bool wrap,