From 0300557bb801cbfee42504fb6602f47c938c7054 Mon Sep 17 00:00:00 2001 From: "varga%nixcorp.com" Date: Thu, 30 Oct 2003 10:32:59 +0000 Subject: [PATCH] Fix for bug 221361. right click context speed is very slow with large selections r=jan,neil sr=alecf patch by gemal --- browser/base/content/browser.js | 18 +++++++++++++----- .../resources/content/nsContextMenu.js | 18 +++++++++++++----- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 1214ab8a01c5..c7d466f7752e 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -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; }, diff --git a/xpfe/communicator/resources/content/nsContextMenu.js b/xpfe/communicator/resources/content/nsContextMenu.js index 38cbe1b5bfc8..0e8b3679446f 100644 --- a/xpfe/communicator/resources/content/nsContextMenu.js +++ b/xpfe/communicator/resources/content/nsContextMenu.js @@ -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; },