Author: korli Date: 2010-06-04 21:59:33 +0200 (Fri, 04 Jun 2010) New Revision: 37008 Changeset: http://dev.haiku-os.org/changeset/37008/haiku Modified: haiku/trunk/src/apps/stylededit/StyledEditView.cpp haiku/trunk/src/apps/stylededit/StyledEditView.h haiku/trunk/src/apps/stylededit/StyledEditWindow.cpp Log: Fixed ReplaceAll behavior with mixed styles. Also suppress undo for replacements as it doesn't seem supported by BTextView. Modified: haiku/trunk/src/apps/stylededit/StyledEditView.cpp =================================================================== --- haiku/trunk/src/apps/stylededit/StyledEditView.cpp 2010-06-04 08:03:02 UTC (rev 37007) +++ haiku/trunk/src/apps/stylededit/StyledEditView.cpp 2010-06-04 19:59:33 UTC (rev 37008) @@ -64,6 +64,13 @@ } +void +StyledEditView::SetSuppressChanges(bool suppressChanges) +{ + fSuppressChanges = suppressChanges; +} + + status_t StyledEditView::GetStyledText(BPositionIO* stream) { Modified: haiku/trunk/src/apps/stylededit/StyledEditView.h =================================================================== --- haiku/trunk/src/apps/stylededit/StyledEditView.h 2010-06-04 08:03:02 UTC (rev 37007) +++ haiku/trunk/src/apps/stylededit/StyledEditView.h 2010-06-04 19:59:33 UTC (rev 37008) @@ -22,17 +22,18 @@ class StyledEditView : public BTextView { public: - StyledEditView(BRect viewframe, BRect textframe, + StyledEditView(BRect viewframe, BRect textframe, BHandler *handler); virtual ~StyledEditView(); virtual void Select(int32 start, int32 finish); virtual void DeleteText(int32 start, int32 finish); virtual void FrameResized(float width, float height); - virtual void InsertText(const char *text, int32 length, int32 offset, + virtual void InsertText(const char *text, int32 length, int32 offset, const text_run_array *runs = NULL); - + void Reset(); + void SetSuppressChanges(bool suppressChanges); status_t GetStyledText(BPositionIO* stream); status_t WriteStyledEditFile(BFile* file); Modified: haiku/trunk/src/apps/stylededit/StyledEditWindow.cpp =================================================================== --- haiku/trunk/src/apps/stylededit/StyledEditWindow.cpp 2010-06-04 08:03:02 UTC (rev 37007) +++ haiku/trunk/src/apps/stylededit/StyledEditWindow.cpp 2010-06-04 19:59:33 UTC (rev 37008) @@ -1364,8 +1364,11 @@ int32 start, finish; fTextView->GetSelection(&start, &finish); + _UpdateCleanUndoRedoSaveRevert(); + fTextView->SetSuppressChanges(true); fTextView->Delete(start, start + findthis.Length()); fTextView->Insert(start, replaceWith.String(), replaceWith.Length()); + fTextView->SetSuppressChanges(false); fTextView->Select(start, start + replaceWith.Length()); fTextView->ScrollToSelection(); return true; @@ -1376,33 +1379,22 @@ void -StyledEditWindow::ReplaceAll(BString findIt, BString replaceWith, bool caseSensitive) +StyledEditWindow::ReplaceAll(BString findthis, BString replaceWith, bool caseSensitive) { - BString viewText(fTextView->Text()); - if (caseSensitive) - viewText.ReplaceAll(findIt.String(), replaceWith.String()); - else - viewText.IReplaceAll(findIt.String(), replaceWith.String()); + bool first = true; + fTextView->SetSuppressChanges(true); + while (Search(findthis, caseSensitive, true, false)) { + if (first) { + _UpdateCleanUndoRedoSaveRevert(); + first = false; + } + int32 start, finish; + fTextView->GetSelection(&start, &finish); - if (viewText.Compare(fTextView->Text()) == 0) { - // they are the same - return; + fTextView->Delete(start, start + findthis.Length()); + fTextView->Insert(start, replaceWith.String(), replaceWith.Length()); } - - int32 textStart, textFinish; - fTextView->GetSelection(&textStart, &textFinish); - - fTextView->SetText(viewText.String()); - - if (viewText.Length() < textStart) - textStart = viewText.Length(); - if (viewText.Length() < textFinish) - textFinish = viewText.Length(); - - fTextView->Select(textStart, textFinish); - fTextView->ScrollToSelection(); - - _UpdateCleanUndoRedoSaveRevert(); + fTextView->SetSuppressChanges(false); }