From 93b76059ee9a4716dae3c0424c1d5e7841a9b469 Mon Sep 17 00:00:00 2001
From: Yourself <user@shredder.(none)>
Date: Sun, 22 Jul 2012 10:46:40 +0000
Subject: [PATCH] Fixes non-terminating ReplaceAll in cases such as when in
text "A B", "B" is replaced by "A B" again.
---
src/apps/deskbar/ExpandoMenuBar.cpp | 5 +++++
src/apps/deskbar/ExpandoMenuBar.h | 2 ++
src/apps/stylededit/StyledEditWindow.cpp | 23 ++++++++++++++++++-----
src/apps/stylededit/StyledEditWindow.h | 3 ++-
4 files changed, 27 insertions(+), 6 deletions(-)
diff --git a/src/apps/deskbar/ExpandoMenuBar.cpp b/src/apps/deskbar/ExpandoMenuBar.cpp
index 997c0d1..4ee0b04 100644
a
|
b
|
TExpandoMenuBar::TExpandoMenuBar(TBarView* bar, BRect frame, const char* name,
|
104 | 104 | } |
105 | 105 | } |
106 | 106 | |
| 107 | TExpandoMenuBar::~TExpandoMenuBar() |
| 108 | { |
| 109 | int breakHere = 88; |
| 110 | breakHere = breakHere -1; |
| 111 | } |
107 | 112 | |
108 | 113 | int |
109 | 114 | TExpandoMenuBar::CompareByName(const void* first, const void* second) |
diff --git a/src/apps/deskbar/ExpandoMenuBar.h b/src/apps/deskbar/ExpandoMenuBar.h
index 4eabc96..de0190a 100644
a
|
b
|
class TExpandoMenuBar : public BMenuBar {
|
63 | 63 | public: |
64 | 64 | TExpandoMenuBar(TBarView* bar, BRect frame, const char* name, |
65 | 65 | bool vertical, bool drawLabel = true); |
| 66 | |
| 67 | ~TExpandoMenuBar(); |
66 | 68 | |
67 | 69 | virtual void AttachedToWindow(); |
68 | 70 | virtual void DetachedFromWindow(); |
diff --git a/src/apps/stylededit/StyledEditWindow.cpp b/src/apps/stylededit/StyledEditWindow.cpp
index 3ac8541..37fa6ac 100644
a
|
b
|
StyledEditWindow::_RevertToSaved()
|
1408 | 1408 | |
1409 | 1409 | bool |
1410 | 1410 | StyledEditWindow::_Search(BString string, bool caseSensitive, bool wrap, |
1411 | | bool backSearch) |
| 1411 | bool backSearch, bool scrollToOccurence) |
1412 | 1412 | { |
1413 | 1413 | int32 start; |
1414 | 1414 | int32 finish; |
… |
… |
StyledEditWindow::_Search(BString string, bool caseSensitive, bool wrap,
|
1450 | 1450 | if (start != B_ERROR) { |
1451 | 1451 | finish = start + length; |
1452 | 1452 | fTextView->Select(start, finish); |
1453 | | fTextView->ScrollToSelection(); |
| 1453 | |
| 1454 | if (scrollToOccurence) |
| 1455 | fTextView->ScrollToSelection(); |
1454 | 1456 | return true; |
1455 | 1457 | } |
1456 | 1458 | |
… |
… |
StyledEditWindow::_ReplaceAll(BString findThis, BString replaceWith,
|
1501 | 1503 | { |
1502 | 1504 | bool first = true; |
1503 | 1505 | 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)) { |
1505 | 1514 | if (first) { |
1506 | 1515 | _UpdateCleanUndoRedoSaveRevert(); |
1507 | 1516 | first = false; |
1508 | 1517 | } |
1509 | | int32 start, finish; |
| 1518 | |
1510 | 1519 | fTextView->GetSelection(&start, &finish); |
1511 | | |
1512 | 1520 | fTextView->Delete(start, start + findThis.Length()); |
1513 | 1521 | 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); |
1514 | 1526 | } |
| 1527 | fTextView->ScrollToSelection(); |
1515 | 1528 | fTextView->SetSuppressChanges(false); |
1516 | 1529 | } |
1517 | 1530 | |
diff --git a/src/apps/stylededit/StyledEditWindow.h b/src/apps/stylededit/StyledEditWindow.h
index 241de30..d107917 100644
a
|
b
|
private:
|
57 | 57 | status_t _LoadFile(entry_ref* ref); |
58 | 58 | void _RevertToSaved(); |
59 | 59 | bool _Search(BString searchFor, bool caseSensitive, |
60 | | bool wrap, bool backSearch); |
| 60 | bool wrap, bool backSearch, |
| 61 | bool scrollToOccurence = true); |
61 | 62 | void _FindSelection(); |
62 | 63 | bool _Replace(BString findThis, BString replaceWith, |
63 | 64 | bool caseSensitive, bool wrap, |