mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 06:11:37 +00:00
set the url bar's field editor to have the correct font when its
text is empty. bug 182570, from nhamblen@mac.com.
This commit is contained in:
parent
3fc6ab8240
commit
5dbc2dc8d5
@ -493,6 +493,8 @@ NS_IMPL_ISUPPORTS1(AutoCompleteListener, nsIAutoCompleteListener)
|
||||
NSRange range = NSMakeRange(aLocation,[[fieldEditor string] length] - aLocation);
|
||||
if ([fieldEditor shouldChangeTextInRange:range replacementString:aString]) {
|
||||
[[fieldEditor textStorage] replaceCharactersInRange:range withString:aString];
|
||||
if (NSMaxRange(range) == 0) // will only be true if the field is empty
|
||||
[fieldEditor setFont:[self font]]; // wrong font will be used otherwise
|
||||
// Whenever we send [self didChangeText], we trigger the
|
||||
// textDidChange method, which will begin a new search with
|
||||
// a new search string (which we just inserted) if the selection
|
||||
|
@ -115,11 +115,22 @@ static NSArray* sToolbarDefaults = nil;
|
||||
//////////////////////////////////////
|
||||
@interface AutoCompleteTextFieldEditor : NSTextView
|
||||
{
|
||||
NSFont* mDefaultFont; // will be needed if editing empty field
|
||||
}
|
||||
- (id)initWithFrame:(NSRect)bounds defaultFont:(NSFont*)defaultFont;
|
||||
@end
|
||||
|
||||
@implementation AutoCompleteTextFieldEditor
|
||||
|
||||
// sets the defaultFont so that we don't paste in the wrong one
|
||||
- (id)initWithFrame:(NSRect)bounds defaultFont:(NSFont*)defaultFont
|
||||
{
|
||||
if ((self = [super initWithFrame:bounds])) {
|
||||
mDefaultFont = defaultFont;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)paste:(id)sender
|
||||
{
|
||||
NSPasteboard *pboard = [NSPasteboard generalPasteboard];
|
||||
@ -132,6 +143,8 @@ static NSArray* sToolbarDefaults = nil;
|
||||
NSRange aRange = [self selectedRange];
|
||||
if ([self shouldChangeTextInRange:aRange replacementString:newText]) {
|
||||
[[self textStorage] replaceCharactersInRange:aRange withString:newText];
|
||||
if (NSMaxRange(aRange) == 0 && mDefaultFont) // will only be true if the field is empty
|
||||
[self setFont:mDefaultFont]; // wrong font will be used otherwise
|
||||
[self didChangeText];
|
||||
}
|
||||
// after a paste, the insertion point should be after the pasted text
|
||||
@ -2129,7 +2142,8 @@ static NSArray* sToolbarDefaults = nil;
|
||||
{
|
||||
if ([anObject isEqual:mURLBar]) {
|
||||
if (!mURLFieldEditor) {
|
||||
mURLFieldEditor = [[AutoCompleteTextFieldEditor alloc] init];
|
||||
mURLFieldEditor = [[AutoCompleteTextFieldEditor alloc] initWithFrame:[anObject bounds]
|
||||
defaultFont:[mURLBar font]];
|
||||
[mURLFieldEditor setFieldEditor:YES];
|
||||
[mURLFieldEditor setAllowsUndo:YES];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user