From a9112961b9f0b3fc1566eb58bc6fcc48c5fc94a5 Mon Sep 17 00:00:00 2001 From: leavengood Date: Wed, 29 Dec 2010 22:51:13 +0000 Subject: [PATCH] Restore the original URL text when the escape key is pressed. git-svn-id: http://svn.haiku-os.org/webpositive/webkit/trunk@563 94f232f2-1747-11df-bad5-a5bfde151594 --- .../autocompletion/TextViewCompleter.cpp | 16 ++++++++++++++-- .../autocompletion/TextViewCompleter.h | 2 ++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/apps/webpositive/autocompletion/TextViewCompleter.cpp b/src/apps/webpositive/autocompletion/TextViewCompleter.cpp index 66e95e9ae6..4e76f7255a 100644 --- a/src/apps/webpositive/autocompletion/TextViewCompleter.cpp +++ b/src/apps/webpositive/autocompletion/TextViewCompleter.cpp @@ -73,7 +73,8 @@ TextViewCompleter::TextViewCompleter(BTextView* textView, ChoiceModel* model, new BDefaultChoiceView(), patternSelector), BMessageFilter(B_KEY_DOWN), fTextView(textView), - fModificationsReported(false) + fModificationsReported(false), + fOriginalTextSaved(false) { fTextView->AddFilter(this); } @@ -102,6 +103,11 @@ TextViewCompleter::TextModified(bool updateChoices) filter_result TextViewCompleter::Filter(BMessage* message, BHandler** target) { + if (!fOriginalTextSaved) { + fOriginalText = fTextView->Text(); + fOriginalTextSaved = true; + } + const char* bytes; int32 modifiers; if (!target || message->FindString("bytes", &bytes) != B_OK @@ -140,7 +146,13 @@ TextViewCompleter::Filter(BMessage* message, BHandler** target) } case B_ESCAPE: - CancelChoice(); + if (fOriginalText != fTextView->Text()) { + fModificationsReported = false; + fTextView->SetText(fOriginalText.String()); + fTextView->SelectAll(); + fModificationsReported = true; + CancelChoice(); + } return B_SKIP_MESSAGE; case B_RETURN: if (IsChoiceSelected()) { diff --git a/src/apps/webpositive/autocompletion/TextViewCompleter.h b/src/apps/webpositive/autocompletion/TextViewCompleter.h index 1a2955f6d7..aeda86a7f0 100644 --- a/src/apps/webpositive/autocompletion/TextViewCompleter.h +++ b/src/apps/webpositive/autocompletion/TextViewCompleter.h @@ -43,6 +43,8 @@ private: private: BTextView* fTextView; bool fModificationsReported; + BString fOriginalText; + bool fOriginalTextSaved; }; #endif // TEXT_CONTROL_COMPLETER_H