From 3e5a6986f97f8b65e65b60b0845bded1476c02e7 Mon Sep 17 00:00:00 2001 From: Alexandre Wilhelm Date: Fri, 24 Oct 2014 23:26:48 -0700 Subject: [PATCH] Fixed: arrow cursor when the cursor is hover a CPTextField Previously, when the cursor was hover a CPTextField the cursor was an arrow till we selected the textField. Now when the cursor is hover a CPTextField, and if this textField is enabled and editable or selectable we show the selecting cursor. This is the default behavior in Cocoa as well. Updated manual test Tests/Manual/CPTextField/ --- AppKit/CPTextField.j | 17 +++++++++++++++++ Tests/Manual/CPTextField/AppController.j | 5 +++++ 2 files changed, 22 insertions(+) diff --git a/AppKit/CPTextField.j b/AppKit/CPTextField.j index 89de8be0a..6cd39a6fb 100644 --- a/AppKit/CPTextField.j +++ b/AppKit/CPTextField.j @@ -31,6 +31,7 @@ @global CPApp @global CPStringPboardType +@global CPCursor @protocol CPTextFieldDelegate @@ -981,6 +982,22 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder"); return [[[anEvent window] platformWindow] _propagateCurrentDOMEvent:YES]; } +- (void)mouseEntered:(CPEvent)anEvent +{ + [super mouseEntered:anEvent]; + + if ([self isEnabled] && ([self isSelectable] || [self isEditable])) + [[CPCursor IBeamCursor] set]; +} + +- (void)mouseExited:(CPEvent)anEvent +{ + [super mouseExited:anEvent]; + + // Make sure to have the arrow cursor when leaving a textField + [[CPCursor arrowCursor] set]; +} + - (void)keyUp:(CPEvent)anEvent { if (!([self isEnabled] && [self isEditable])) diff --git a/Tests/Manual/CPTextField/AppController.j b/Tests/Manual/CPTextField/AppController.j index 52cbb591b..389cf3c8e 100644 --- a/Tests/Manual/CPTextField/AppController.j +++ b/Tests/Manual/CPTextField/AppController.j @@ -50,8 +50,13 @@ [shadowLabel setFrame:CGRectMake(15, CGRectGetMaxY([textField frame]) + 10, 300, 18)]; [championOfLightLabel setFrame:CGRectMake(15, CGRectGetMaxY([shadowLabel frame]) + 2, 300, 18)]; + var selectableLabel = [CPTextField labelWithTitle:@"This text should be selectable and you should see the selectable cursor."]; + [selectableLabel setSelectable:YES]; + [selectableLabel setFrame:CGRectMake(15, CGRectGetMaxY([championOfLightLabel frame]) + 8, 600, 18)]; + [contentView addSubview:shadowLabel]; [contentView addSubview:championOfLightLabel]; + [contentView addSubview:selectableLabel]; var jumpLabel = [CPTextField labelWithTitle:@"The text of these text fields should not move ('jump') when a field becomes the first responder. Labels on the right should replicate the input."];