зеркало из https://github.com/mozilla/pjs.git
Make autocomplete behave like mozilla in that it won't fill in the textfield
unless you select something from the list and tab tabs into the list. This is preffed in the defaults system so you can go back to the old way.
This commit is contained in:
Родитель
6b16463592
Коммит
dfc44a4e80
|
@ -47,6 +47,9 @@
|
|||
BOOL mBackspaced;
|
||||
// determines if the search currently pending should complete the default result when it is ready
|
||||
BOOL mCompleteResult;
|
||||
// should the autocomplete fill in the default completion into the text field? The default
|
||||
// is no, but this can be set with a user default pref.
|
||||
BOOL mCompleteWhileTyping;
|
||||
|
||||
NSTimer *mOpenTimer;
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "nsIServiceManager.h"
|
||||
#include "nsMemory.h"
|
||||
#include "nsString.h"
|
||||
#include "CHUserDefaults.h"
|
||||
|
||||
static const int kMaxRows = 6;
|
||||
static const int kFrameMargin = 1;
|
||||
|
@ -137,6 +138,10 @@ NS_IMPL_ISUPPORTS1(AutoCompleteListener, nsIAutoCompleteListener)
|
|||
name:NSWindowWillMoveNotification object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onResize:)
|
||||
name:NSWindowDidResizeNotification object:nil];
|
||||
|
||||
// read the user default on if we should auto-complete the text field as the user
|
||||
// types or make them pick something from a list (a-la mozilla).
|
||||
mCompleteWhileTyping = [[NSUserDefaults standardUserDefaults] boolForKey:USER_DEFAULTS_AUTOCOMPLETE_WHILE_TYPING];
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
|
@ -322,7 +327,7 @@ NS_IMPL_ISUPPORTS1(AutoCompleteListener, nsIAutoCompleteListener)
|
|||
PRInt32 defaultRow;
|
||||
mResults->GetDefaultItemIndex(&defaultRow);
|
||||
|
||||
if (mCompleteResult) {
|
||||
if (mCompleteResult && mCompleteWhileTyping) {
|
||||
[self selectRowAt:defaultRow];
|
||||
[self completeResult:defaultRow];
|
||||
} else {
|
||||
|
@ -353,12 +358,14 @@ NS_IMPL_ISUPPORTS1(AutoCompleteListener, nsIAutoCompleteListener)
|
|||
// cut off everything in the result string before the search string
|
||||
result1 = [result1 substringWithRange:NSMakeRange(matchRange.location, [result1 length]-matchRange.location)];
|
||||
|
||||
#if 1
|
||||
// fill in the textfield with the matching string
|
||||
[self setStringValue:result1];
|
||||
|
||||
// select the text after the search string
|
||||
text = [[self window] fieldEditor:NO forObject:self];
|
||||
[text setSelectedRange:NSMakeRange([mSearchString length], [result1 length]-[mSearchString length])];
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -496,8 +503,12 @@ NS_IMPL_ISUPPORTS1(AutoCompleteListener, nsIAutoCompleteListener)
|
|||
} else if (command == @selector(moveToEndOfDocument:)) {
|
||||
[self selectRowAt:[mTableView numberOfRows]-1];
|
||||
[self completeSelectedResult];
|
||||
} else if (command == @selector(insertTab:) || command == @selector(insertNewline:)) {
|
||||
[self closePopup];
|
||||
} else if (command == @selector(insertTab:)) {
|
||||
if ([mPopupWin isVisible]) {
|
||||
[self selectRowBy:1];
|
||||
[self completeSelectedResult];
|
||||
return YES;
|
||||
}
|
||||
} else if (command == @selector(deleteBackward:) ||
|
||||
command == @selector(deleteForward:)) {
|
||||
// if the user deletes characters, we need to know so that
|
||||
|
|
|
@ -1,54 +0,0 @@
|
|||
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001, 2002
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Simon Fraser <sfraser@netscape.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
|
||||
/*
|
||||
This file contains a list of #defines for our user default entries. They
|
||||
are collected here, rather than being scattered throughout the code, for
|
||||
easier documentation.
|
||||
*/
|
||||
|
||||
|
||||
#define USER_DEFAULTS_AUTOREGISTER_KEY @"autoRegister" /* Boolean */
|
||||
#define USER_DEFAULTS_URL_KEY @"url" /* String */
|
||||
|
||||
#define USER_DEFAULTS_HIDE_PERS_TOOLBAR_KEY @"Hide Personal Toolbar" /* Integer */
|
||||
#define USER_DEFAULTS_HOMEPAGE_KEY @"HomePage" /* String */
|
||||
|
||||
|
||||
|
|
@ -50,5 +50,6 @@
|
|||
#define USER_DEFAULTS_HIDE_PERS_TOOLBAR_KEY @"Hide Personal Toolbar" /* Integer */
|
||||
#define USER_DEFAULTS_HOMEPAGE_KEY @"HomePage" /* String */
|
||||
|
||||
#define USER_DEFAULTS_AUTOCOMPLETE_WHILE_TYPING @"Autocomplete While Typing" /* Boolean */
|
||||
|
||||
|
||||
|
|
|
@ -47,6 +47,9 @@
|
|||
BOOL mBackspaced;
|
||||
// determines if the search currently pending should complete the default result when it is ready
|
||||
BOOL mCompleteResult;
|
||||
// should the autocomplete fill in the default completion into the text field? The default
|
||||
// is no, but this can be set with a user default pref.
|
||||
BOOL mCompleteWhileTyping;
|
||||
|
||||
NSTimer *mOpenTimer;
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "nsIServiceManager.h"
|
||||
#include "nsMemory.h"
|
||||
#include "nsString.h"
|
||||
#include "CHUserDefaults.h"
|
||||
|
||||
static const int kMaxRows = 6;
|
||||
static const int kFrameMargin = 1;
|
||||
|
@ -137,6 +138,10 @@ NS_IMPL_ISUPPORTS1(AutoCompleteListener, nsIAutoCompleteListener)
|
|||
name:NSWindowWillMoveNotification object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onResize:)
|
||||
name:NSWindowDidResizeNotification object:nil];
|
||||
|
||||
// read the user default on if we should auto-complete the text field as the user
|
||||
// types or make them pick something from a list (a-la mozilla).
|
||||
mCompleteWhileTyping = [[NSUserDefaults standardUserDefaults] boolForKey:USER_DEFAULTS_AUTOCOMPLETE_WHILE_TYPING];
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
|
@ -322,7 +327,7 @@ NS_IMPL_ISUPPORTS1(AutoCompleteListener, nsIAutoCompleteListener)
|
|||
PRInt32 defaultRow;
|
||||
mResults->GetDefaultItemIndex(&defaultRow);
|
||||
|
||||
if (mCompleteResult) {
|
||||
if (mCompleteResult && mCompleteWhileTyping) {
|
||||
[self selectRowAt:defaultRow];
|
||||
[self completeResult:defaultRow];
|
||||
} else {
|
||||
|
@ -353,12 +358,14 @@ NS_IMPL_ISUPPORTS1(AutoCompleteListener, nsIAutoCompleteListener)
|
|||
// cut off everything in the result string before the search string
|
||||
result1 = [result1 substringWithRange:NSMakeRange(matchRange.location, [result1 length]-matchRange.location)];
|
||||
|
||||
#if 1
|
||||
// fill in the textfield with the matching string
|
||||
[self setStringValue:result1];
|
||||
|
||||
// select the text after the search string
|
||||
text = [[self window] fieldEditor:NO forObject:self];
|
||||
[text setSelectedRange:NSMakeRange([mSearchString length], [result1 length]-[mSearchString length])];
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -496,8 +503,12 @@ NS_IMPL_ISUPPORTS1(AutoCompleteListener, nsIAutoCompleteListener)
|
|||
} else if (command == @selector(moveToEndOfDocument:)) {
|
||||
[self selectRowAt:[mTableView numberOfRows]-1];
|
||||
[self completeSelectedResult];
|
||||
} else if (command == @selector(insertTab:) || command == @selector(insertNewline:)) {
|
||||
[self closePopup];
|
||||
} else if (command == @selector(insertTab:)) {
|
||||
if ([mPopupWin isVisible]) {
|
||||
[self selectRowBy:1];
|
||||
[self completeSelectedResult];
|
||||
return YES;
|
||||
}
|
||||
} else if (command == @selector(deleteBackward:) ||
|
||||
command == @selector(deleteForward:)) {
|
||||
// if the user deletes characters, we need to know so that
|
||||
|
|
|
@ -47,6 +47,9 @@
|
|||
BOOL mBackspaced;
|
||||
// determines if the search currently pending should complete the default result when it is ready
|
||||
BOOL mCompleteResult;
|
||||
// should the autocomplete fill in the default completion into the text field? The default
|
||||
// is no, but this can be set with a user default pref.
|
||||
BOOL mCompleteWhileTyping;
|
||||
|
||||
NSTimer *mOpenTimer;
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "nsIServiceManager.h"
|
||||
#include "nsMemory.h"
|
||||
#include "nsString.h"
|
||||
#include "CHUserDefaults.h"
|
||||
|
||||
static const int kMaxRows = 6;
|
||||
static const int kFrameMargin = 1;
|
||||
|
@ -137,6 +138,10 @@ NS_IMPL_ISUPPORTS1(AutoCompleteListener, nsIAutoCompleteListener)
|
|||
name:NSWindowWillMoveNotification object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onResize:)
|
||||
name:NSWindowDidResizeNotification object:nil];
|
||||
|
||||
// read the user default on if we should auto-complete the text field as the user
|
||||
// types or make them pick something from a list (a-la mozilla).
|
||||
mCompleteWhileTyping = [[NSUserDefaults standardUserDefaults] boolForKey:USER_DEFAULTS_AUTOCOMPLETE_WHILE_TYPING];
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
|
@ -322,7 +327,7 @@ NS_IMPL_ISUPPORTS1(AutoCompleteListener, nsIAutoCompleteListener)
|
|||
PRInt32 defaultRow;
|
||||
mResults->GetDefaultItemIndex(&defaultRow);
|
||||
|
||||
if (mCompleteResult) {
|
||||
if (mCompleteResult && mCompleteWhileTyping) {
|
||||
[self selectRowAt:defaultRow];
|
||||
[self completeResult:defaultRow];
|
||||
} else {
|
||||
|
@ -353,12 +358,14 @@ NS_IMPL_ISUPPORTS1(AutoCompleteListener, nsIAutoCompleteListener)
|
|||
// cut off everything in the result string before the search string
|
||||
result1 = [result1 substringWithRange:NSMakeRange(matchRange.location, [result1 length]-matchRange.location)];
|
||||
|
||||
#if 1
|
||||
// fill in the textfield with the matching string
|
||||
[self setStringValue:result1];
|
||||
|
||||
// select the text after the search string
|
||||
text = [[self window] fieldEditor:NO forObject:self];
|
||||
[text setSelectedRange:NSMakeRange([mSearchString length], [result1 length]-[mSearchString length])];
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -496,8 +503,12 @@ NS_IMPL_ISUPPORTS1(AutoCompleteListener, nsIAutoCompleteListener)
|
|||
} else if (command == @selector(moveToEndOfDocument:)) {
|
||||
[self selectRowAt:[mTableView numberOfRows]-1];
|
||||
[self completeSelectedResult];
|
||||
} else if (command == @selector(insertTab:) || command == @selector(insertNewline:)) {
|
||||
[self closePopup];
|
||||
} else if (command == @selector(insertTab:)) {
|
||||
if ([mPopupWin isVisible]) {
|
||||
[self selectRowBy:1];
|
||||
[self completeSelectedResult];
|
||||
return YES;
|
||||
}
|
||||
} else if (command == @selector(deleteBackward:) ||
|
||||
command == @selector(deleteForward:)) {
|
||||
// if the user deletes characters, we need to know so that
|
||||
|
|
|
@ -1,54 +0,0 @@
|
|||
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001, 2002
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Simon Fraser <sfraser@netscape.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
|
||||
/*
|
||||
This file contains a list of #defines for our user default entries. They
|
||||
are collected here, rather than being scattered throughout the code, for
|
||||
easier documentation.
|
||||
*/
|
||||
|
||||
|
||||
#define USER_DEFAULTS_AUTOREGISTER_KEY @"autoRegister" /* Boolean */
|
||||
#define USER_DEFAULTS_URL_KEY @"url" /* String */
|
||||
|
||||
#define USER_DEFAULTS_HIDE_PERS_TOOLBAR_KEY @"Hide Personal Toolbar" /* Integer */
|
||||
#define USER_DEFAULTS_HOMEPAGE_KEY @"HomePage" /* String */
|
||||
|
||||
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001, 2002
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Simon Fraser <sfraser@netscape.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
|
||||
/*
|
||||
This file contains a list of #defines for our user default entries. They
|
||||
are collected here, rather than being scattered throughout the code, for
|
||||
easier documentation.
|
||||
*/
|
||||
|
||||
|
||||
#define USER_DEFAULTS_AUTOREGISTER_KEY @"autoRegister" /* Boolean */
|
||||
#define USER_DEFAULTS_URL_KEY @"url" /* String */
|
||||
|
||||
#define USER_DEFAULTS_HIDE_PERS_TOOLBAR_KEY @"Hide Personal Toolbar" /* Integer */
|
||||
#define USER_DEFAULTS_HOMEPAGE_KEY @"HomePage" /* String */
|
||||
|
||||
|
||||
|
|
@ -47,6 +47,9 @@
|
|||
BOOL mBackspaced;
|
||||
// determines if the search currently pending should complete the default result when it is ready
|
||||
BOOL mCompleteResult;
|
||||
// should the autocomplete fill in the default completion into the text field? The default
|
||||
// is no, but this can be set with a user default pref.
|
||||
BOOL mCompleteWhileTyping;
|
||||
|
||||
NSTimer *mOpenTimer;
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "nsIServiceManager.h"
|
||||
#include "nsMemory.h"
|
||||
#include "nsString.h"
|
||||
#include "CHUserDefaults.h"
|
||||
|
||||
static const int kMaxRows = 6;
|
||||
static const int kFrameMargin = 1;
|
||||
|
@ -137,6 +138,10 @@ NS_IMPL_ISUPPORTS1(AutoCompleteListener, nsIAutoCompleteListener)
|
|||
name:NSWindowWillMoveNotification object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onResize:)
|
||||
name:NSWindowDidResizeNotification object:nil];
|
||||
|
||||
// read the user default on if we should auto-complete the text field as the user
|
||||
// types or make them pick something from a list (a-la mozilla).
|
||||
mCompleteWhileTyping = [[NSUserDefaults standardUserDefaults] boolForKey:USER_DEFAULTS_AUTOCOMPLETE_WHILE_TYPING];
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
|
@ -322,7 +327,7 @@ NS_IMPL_ISUPPORTS1(AutoCompleteListener, nsIAutoCompleteListener)
|
|||
PRInt32 defaultRow;
|
||||
mResults->GetDefaultItemIndex(&defaultRow);
|
||||
|
||||
if (mCompleteResult) {
|
||||
if (mCompleteResult && mCompleteWhileTyping) {
|
||||
[self selectRowAt:defaultRow];
|
||||
[self completeResult:defaultRow];
|
||||
} else {
|
||||
|
@ -353,12 +358,14 @@ NS_IMPL_ISUPPORTS1(AutoCompleteListener, nsIAutoCompleteListener)
|
|||
// cut off everything in the result string before the search string
|
||||
result1 = [result1 substringWithRange:NSMakeRange(matchRange.location, [result1 length]-matchRange.location)];
|
||||
|
||||
#if 1
|
||||
// fill in the textfield with the matching string
|
||||
[self setStringValue:result1];
|
||||
|
||||
// select the text after the search string
|
||||
text = [[self window] fieldEditor:NO forObject:self];
|
||||
[text setSelectedRange:NSMakeRange([mSearchString length], [result1 length]-[mSearchString length])];
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -496,8 +503,12 @@ NS_IMPL_ISUPPORTS1(AutoCompleteListener, nsIAutoCompleteListener)
|
|||
} else if (command == @selector(moveToEndOfDocument:)) {
|
||||
[self selectRowAt:[mTableView numberOfRows]-1];
|
||||
[self completeSelectedResult];
|
||||
} else if (command == @selector(insertTab:) || command == @selector(insertNewline:)) {
|
||||
[self closePopup];
|
||||
} else if (command == @selector(insertTab:)) {
|
||||
if ([mPopupWin isVisible]) {
|
||||
[self selectRowBy:1];
|
||||
[self completeSelectedResult];
|
||||
return YES;
|
||||
}
|
||||
} else if (command == @selector(deleteBackward:) ||
|
||||
command == @selector(deleteForward:)) {
|
||||
// if the user deletes characters, we need to know so that
|
||||
|
|
Загрузка…
Ссылка в новой задаче