Fixed ReplaceAll behavior with mixed styles. Also suppress undo for replacements as it doesn't seem supported by BTextView.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37008 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval
2010-06-04 19:59:33 +00:00
parent db3aa13aaf
commit e7d3e55ad6
3 changed files with 27 additions and 27 deletions
+7
View File
@@ -64,6 +64,13 @@ StyledEditView::Reset()
} }
void
StyledEditView::SetSuppressChanges(bool suppressChanges)
{
fSuppressChanges = suppressChanges;
}
status_t status_t
StyledEditView::GetStyledText(BPositionIO* stream) StyledEditView::GetStyledText(BPositionIO* stream)
{ {
+4 -3
View File
@@ -22,17 +22,18 @@ class BPositionIO;
class StyledEditView : public BTextView { class StyledEditView : public BTextView {
public: public:
StyledEditView(BRect viewframe, BRect textframe, StyledEditView(BRect viewframe, BRect textframe,
BHandler *handler); BHandler *handler);
virtual ~StyledEditView(); virtual ~StyledEditView();
virtual void Select(int32 start, int32 finish); virtual void Select(int32 start, int32 finish);
virtual void DeleteText(int32 start, int32 finish); virtual void DeleteText(int32 start, int32 finish);
virtual void FrameResized(float width, float height); 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); const text_run_array *runs = NULL);
void Reset(); void Reset();
void SetSuppressChanges(bool suppressChanges);
status_t GetStyledText(BPositionIO* stream); status_t GetStyledText(BPositionIO* stream);
status_t WriteStyledEditFile(BFile* file); status_t WriteStyledEditFile(BFile* file);
+16 -24
View File
@@ -1364,8 +1364,11 @@ StyledEditWindow::Replace(BString findthis, BString replaceWith, bool caseSensit
int32 start, finish; int32 start, finish;
fTextView->GetSelection(&start, &finish); fTextView->GetSelection(&start, &finish);
_UpdateCleanUndoRedoSaveRevert();
fTextView->SetSuppressChanges(true);
fTextView->Delete(start, start + findthis.Length()); fTextView->Delete(start, start + findthis.Length());
fTextView->Insert(start, replaceWith.String(), replaceWith.Length()); fTextView->Insert(start, replaceWith.String(), replaceWith.Length());
fTextView->SetSuppressChanges(false);
fTextView->Select(start, start + replaceWith.Length()); fTextView->Select(start, start + replaceWith.Length());
fTextView->ScrollToSelection(); fTextView->ScrollToSelection();
return true; return true;
@@ -1376,33 +1379,22 @@ StyledEditWindow::Replace(BString findthis, BString replaceWith, bool caseSensit
void void
StyledEditWindow::ReplaceAll(BString findIt, BString replaceWith, bool caseSensitive) StyledEditWindow::ReplaceAll(BString findthis, BString replaceWith, bool caseSensitive)
{ {
BString viewText(fTextView->Text()); bool first = true;
if (caseSensitive) fTextView->SetSuppressChanges(true);
viewText.ReplaceAll(findIt.String(), replaceWith.String()); while (Search(findthis, caseSensitive, true, false)) {
else if (first) {
viewText.IReplaceAll(findIt.String(), replaceWith.String()); _UpdateCleanUndoRedoSaveRevert();
first = false;
}
int32 start, finish;
fTextView->GetSelection(&start, &finish);
if (viewText.Compare(fTextView->Text()) == 0) { fTextView->Delete(start, start + findthis.Length());
// they are the same fTextView->Insert(start, replaceWith.String(), replaceWith.Length());
return;
} }
fTextView->SetSuppressChanges(false);
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();
} }