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

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)
{ {

View File

@ -33,6 +33,7 @@ class StyledEditView : public BTextView {
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);

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());
if (viewText.Compare(fTextView->Text()) == 0) {
// they are the same
return;
}
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(); _UpdateCleanUndoRedoSaveRevert();
first = false;
}
int32 start, finish;
fTextView->GetSelection(&start, &finish);
fTextView->Delete(start, start + findthis.Length());
fTextView->Insert(start, replaceWith.String(), replaceWith.Length());
}
fTextView->SetSuppressChanges(false);
} }