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
StyledEditView::GetStyledText(BPositionIO* stream)
{

View File

@ -22,17 +22,18 @@ class BPositionIO;
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);

View File

@ -1364,8 +1364,11 @@ StyledEditWindow::Replace(BString findthis, BString replaceWith, bool caseSensit
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 @@ StyledEditWindow::Replace(BString findthis, BString replaceWith, bool caseSensit
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);
}