diff --git a/AppKit/CPTokenField.j b/AppKit/CPTokenField.j index 7762eb502..9c38b2ef8 100755 --- a/AppKit/CPTokenField.j +++ b/AppKit/CPTokenField.j @@ -64,6 +64,7 @@ var CPScrollDestinationNone = 0, CPRange _selectedRange; _CPAutocompleteMenu _autocompleteMenu; + CGRect _inputFrame; CPTimeInterval _completionDelay; @@ -924,16 +925,16 @@ var CPScrollDestinationNone = 0, textWidth = MAX(contentSize.width - offset.x - 1, textWidth); } - var inputFrame = fitAndFrame(textWidth, tokenHeight); + _inputFrame = fitAndFrame(textWidth, tokenHeight); - element.style.left = inputFrame.origin.x + "px"; - element.style.top = inputFrame.origin.y + "px"; - element.style.width = inputFrame.size.width + "px"; - element.style.height = inputFrame.size.height + "px"; + element.style.left = _inputFrame.origin.x + "px"; + element.style.top = _inputFrame.origin.y + "px"; + element.style.width = _inputFrame.size.width + "px"; + element.style.height = _inputFrame.size.height + "px"; // When editing, always scroll to the cursor. if (_selectedRange.length == 0) - [[_tokenScrollView documentView] scrollRectToVisible:inputFrame]; + [[_tokenScrollView documentView] scrollRectToVisible:_inputFrame]; }; for (var i = 0, count = [tokens count]; i < count; i++) @@ -964,6 +965,7 @@ var CPScrollDestinationNone = 0, // so we can continue using our standard keyboard handling events. if (isEditing && _selectedRange.length) { + _inputFrame = nil; [self _inputElement].style.left = "-10000px"; [self _inputElement].focus(); } @@ -1021,6 +1023,15 @@ var CPScrollDestinationNone = 0, return []; } +/*! + Private API used by the _CPAutocompleteMenu to determine where to place the menu in local coordinates. +*/ +- (CGPoint)_completionOrigin:(_CPAutocompleteMenu)anAutocompleteMenu +{ + var relativeFrame = _inputFrame ? [[_tokenScrollView documentView] convertRect:_inputFrame toView:self ] : [self bounds]; + return CGPointMake(CGRectGetMinX(relativeFrame), CGRectGetMaxY(relativeFrame)); +} + /*! Private API to get the delegate tokenField:displayStringForRepresentedObject: result. diff --git a/AppKit/_CPAutocompleteMenu.j b/AppKit/_CPAutocompleteMenu.j index a8be9d0ef..aed0ce1bb 100644 --- a/AppKit/_CPAutocompleteMenu.j +++ b/AppKit/_CPAutocompleteMenu.j @@ -114,25 +114,33 @@ { // TODO /* - The autocompletion menu should be underneath the word/text being autocompleted. It should at least be wide enough to - fit the widest - option but no wider than the width of the text field. It might stick out on the right side, so that if the edited text - is on the right of the text field the menu might extend a full text field width more into space on the right - side. It should not stick out outside of the screen. The height should be the smallest possible to fit all options - or at most ~307px (based on Cocoa). If the options don't fit horizontally they should be truncated with an ellipsis. + The autocompletion menu should be underneath the word/text being + autocompleted. It should at least be wide enough to fit the widest option + but no wider than the width of the text field. It might stick out on the + right side, so that if the edited text is on the right of the text field + the menu might extend a full text field width more into space on the right + side. It should not stick out outside of the screen. The height should be + the smallest possible to fit all options or at most ~307px (based on + Cocoa). If the options don't fit horizontally they should be truncated + with an ellipsis. */ - var frame = [textField frame]; + var frame = [textField frame], + origin = frame.origin; + if ([textField respondsToSelector:@selector(_completionOrigin:)]) + origin = [textField _completionOrigin:self]; + + + // Manually sizeToFit because CPTableView's sizeToFit doesn't work properly + var frameOrigin = [textField convertPoint:origin toView:nil], + newFrame = CGRectMake(frameOrigin.x, frameOrigin.y, CPRectGetWidth([textField bounds]), 92.0); + newFrame = [_menuWindow frameRectForContentRect:newFrame]; + [_menuWindow setFrame:newFrame]; + [scrollView setFrame:CGRectInset([[_menuWindow contentView] bounds], 1.0, 1.0)]; // Correctly size the tableview // FIXME Horizontal scrolling will not work because we are not actually looking at the content to set the width for the table column [[[tableView tableColumns] firstObject] setWidth:[[scrollView contentView] frame].size.width]; - - // Manually sizeToFit because CPTableView's sizeToFit doesn't work properly - var frameOrigin = [textField convertPoint:[textField bounds].origin toView:nil], - newFrame = CGRectMake(frameOrigin.x, frameOrigin.y + frame.size.height, CPRectGetWidth([textField bounds]), 92.0); - [_menuWindow setFrame:[_menuWindow frameRectForContentRect:newFrame]]; - [scrollView setFrame:CGRectInset([[_menuWindow contentView] bounds], 1.0, 1.0)]; } - (void)_showCompletions:(CPTimer)timer