Fix for bug 221361. right click context speed is very slow with large selections

r=jan,neil sr=alecf patch by gemal
This commit is contained in:
varga%nixcorp.com 2003-10-30 10:32:59 +00:00
Родитель 732bccfc0d
Коммит 0300557bb8
2 изменённых файлов: 26 добавлений и 10 удалений

Просмотреть файл

@ -3236,7 +3236,7 @@ nsContextMenu.prototype = {
//selected text. Only use the first 15 chars.
isTextSelection : function() {
var result = false;
var selection = this.searchSelected();
var selection = this.searchSelected(16);
var searchSelectText;
if (selection != "") {
@ -3252,13 +3252,21 @@ nsContextMenu.prototype = {
return result;
},
searchSelected : function() {
searchSelected : function( charlen ) {
var focusedWindow = document.commandDispatcher.focusedWindow;
var searchStr = focusedWindow.__proto__.getSelection.call(focusedWindow);
searchStr = searchStr.toString();
searchStr = searchStr.replace( /^\s+/, "" );
searchStr = searchStr.replace(/(\n|\r|\t)+/g, " ");
searchStr = searchStr.replace(/\s+$/,"");
// searching for more than 150 chars makes no sense
if (!charlen)
charlen = 150;
if (charlen < searchStr.length) {
// only use the first charlen important chars. see bug 221361
var pattern = new RegExp("^(?:\\s*.){0," + charlen + "}");
pattern.test(searchStr);
searchStr = RegExp.lastMatch;
}
searchStr = searchStr.replace(/\s*(.*?)\s*$/, "$1");
searchStr = searchStr.replace(/\s+/g, " ");
return searchStr;
},

Просмотреть файл

@ -784,7 +784,7 @@ nsContextMenu.prototype = {
//selected text. Only use the first 15 chars.
isTextSelection : function() {
var result = false;
var selection = this.searchSelected();
var selection = this.searchSelected(16);
var bundle = srGetStrBundle("chrome://communicator/locale/contentAreaCommands.properties");
@ -803,13 +803,21 @@ nsContextMenu.prototype = {
return result;
},
searchSelected : function() {
searchSelected : function( charlen ) {
var focusedWindow = document.commandDispatcher.focusedWindow;
var searchStr = focusedWindow.__proto__.getSelection.call(focusedWindow);
searchStr = searchStr.toString();
searchStr = searchStr.replace( /^\s+/, "" );
searchStr = searchStr.replace(/(\n|\r|\t)+/g, " ");
searchStr = searchStr.replace(/\s+$/,"");
// searching for more than 150 chars makes no sense
if (!charlen)
charlen = 150;
if (charlen < searchStr.length) {
// only use the first charlen important chars. see bug 221361
var pattern = new RegExp("^(?:\\s*.){0," + charlen + "}");
pattern.test(searchStr);
searchStr = RegExp.lastMatch;
}
searchStr = searchStr.replace(/\s*(.*?)\s*$/, "$1");
searchStr = searchStr.replace(/\s+/g, " ");
return searchStr;
},