diff options
author | rohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-12 15:51:34 +0000 |
---|---|---|
committer | rohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-12 15:51:34 +0000 |
commit | 1af51337cab0b011f8fe9ecdf5a99b3e0c2bca7d (patch) | |
tree | df824f396215b06beaf406c3184ee8f94f130b77 /chrome/browser/cocoa | |
parent | 34740a9613c84c572da3a01f3b5637734dac671e (diff) | |
download | chromium_src-1af51337cab0b011f8fe9ecdf5a99b3e0c2bca7d.zip chromium_src-1af51337cab0b011f8fe9ecdf5a99b3e0c2bca7d.tar.gz chromium_src-1af51337cab0b011f8fe9ecdf5a99b3e0c2bca7d.tar.bz2 |
[Mac] Support undo in the omnibox.
BUG=http://crbug.com/18084
TEST=You should be able to undo and redo typing and pasting in the omnibox, unless autocomplete has kicked in or you selected/highlighted an entry in the popup.
Review URL: http://codereview.chromium.org/246009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31785 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa')
-rw-r--r-- | chrome/browser/cocoa/autocomplete_text_field.h | 9 | ||||
-rw-r--r-- | chrome/browser/cocoa/autocomplete_text_field.mm | 10 | ||||
-rw-r--r-- | chrome/browser/cocoa/autocomplete_text_field_unittest.mm | 11 |
3 files changed, 30 insertions, 0 deletions
diff --git a/chrome/browser/cocoa/autocomplete_text_field.h b/chrome/browser/cocoa/autocomplete_text_field.h index 112212c..7c21527 100644 --- a/chrome/browser/cocoa/autocomplete_text_field.h +++ b/chrome/browser/cocoa/autocomplete_text_field.h @@ -8,6 +8,8 @@ #import <Cocoa/Cocoa.h> #import "chrome/browser/cocoa/styled_text_field.h" +#include "base/scoped_nsobject.h" + @class AutocompleteTextFieldCell; // AutocompleteTextField intercepts UI actions for forwarding to @@ -55,6 +57,10 @@ class AutocompleteTextFieldObserver { @interface AutocompleteTextField : StyledTextField { @private + // Undo manager for this text field. We use a specific instance rather than + // the standard undo manager in order to let us clear the undo stack at will. + scoped_nsobject<NSUndoManager> undoManager_; + AutocompleteTextFieldObserver* observer_; // weak, owned by location bar. } @@ -68,6 +74,9 @@ class AutocompleteTextFieldObserver { // contents if the control is already being edited. - (void)setAttributedStringValue:(NSAttributedString*)aString; +// Clears the undo chain for this text field. +- (void)clearUndoChain; + @end #endif // CHROME_BROWSER_COCOA_AUTOCOMPLETE_TEXT_FIELD_H_ diff --git a/chrome/browser/cocoa/autocomplete_text_field.mm b/chrome/browser/cocoa/autocomplete_text_field.mm index c89fd17..1fb8aa5 100644 --- a/chrome/browser/cocoa/autocomplete_text_field.mm +++ b/chrome/browser/cocoa/autocomplete_text_field.mm @@ -160,4 +160,14 @@ } } +- (NSUndoManager*)undoManagerForTextView:(NSTextView*)textView { + if (!undoManager_.get()) + undoManager_.reset([[NSUndoManager alloc] init]); + return undoManager_.get(); +} + +- (void)clearUndoChain { + [undoManager_ removeAllActions]; +} + @end diff --git a/chrome/browser/cocoa/autocomplete_text_field_unittest.mm b/chrome/browser/cocoa/autocomplete_text_field_unittest.mm index 7dd65f6..66574ee 100644 --- a/chrome/browser/cocoa/autocomplete_text_field_unittest.mm +++ b/chrome/browser/cocoa/autocomplete_text_field_unittest.mm @@ -671,6 +671,17 @@ TEST_F(AutocompleteTextFieldTest, SetAttributedStringUndo) { EXPECT_TRUE([undoManager canUndo]); [field_ setAttributedStringValue:attributedString]; EXPECT_TRUE([undoManager canUndo]); + + // Verify that calling -clearUndoChain clears the undo chain. + [field_ clearUndoChain]; + EXPECT_FALSE([undoManager canUndo]); } +TEST_F(AutocompleteTextFieldTest, EditorGetsCorrectUndoManager) { + cocoa_helper_.makeFirstResponder(field_); + + NSTextView* editor = static_cast<NSTextView*>([field_ currentEditor]); + EXPECT_TRUE(editor); + EXPECT_EQ([field_ undoManagerForTextView:editor], [editor undoManager]); +} } // namespace |