mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 830600 - Improve the performance of pasting into the location bar by rewriting the O(n^2) algorithm used there to be O(n); r=roc
This commit is contained in:
parent
3e72e50bdb
commit
34fe9d9f64
@ -514,22 +514,25 @@ nsTextEditRules::HandleNewLines(nsString &aString,
|
||||
break;
|
||||
case nsIPlaintextEditor::eNewlinesStripSurroundingWhitespace:
|
||||
{
|
||||
// find each newline, and strip all the whitespace before
|
||||
// and after it
|
||||
int32_t firstCRLF = aString.FindCharInSet(CRLF);
|
||||
while (firstCRLF >= 0)
|
||||
nsString result;
|
||||
uint32_t offset = 0;
|
||||
while (offset < aString.Length())
|
||||
{
|
||||
uint32_t wsBegin = firstCRLF, wsEnd = firstCRLF + 1;
|
||||
int32_t nextCRLF = aString.FindCharInSet(CRLF, offset);
|
||||
if (nextCRLF < 0) {
|
||||
result.Append(nsDependentSubstring(aString, offset));
|
||||
break;
|
||||
}
|
||||
uint32_t wsBegin = nextCRLF;
|
||||
// look backwards for the first non-whitespace char
|
||||
while (wsBegin > 0 && NS_IS_SPACE(aString[wsBegin - 1]))
|
||||
while (wsBegin > offset && NS_IS_SPACE(aString[wsBegin - 1]))
|
||||
--wsBegin;
|
||||
while (wsEnd < aString.Length() && NS_IS_SPACE(aString[wsEnd]))
|
||||
++wsEnd;
|
||||
// now cut this range out of the string
|
||||
aString.Cut(wsBegin, wsEnd - wsBegin);
|
||||
// look for another CR or LF
|
||||
firstCRLF = aString.FindCharInSet(CRLF);
|
||||
result.Append(nsDependentSubstring(aString, offset, wsBegin - offset));
|
||||
offset = nextCRLF + 1;
|
||||
while (offset < aString.Length() && NS_IS_SPACE(aString[offset]))
|
||||
++offset;
|
||||
}
|
||||
aString = result;
|
||||
}
|
||||
break;
|
||||
case nsIPlaintextEditor::eNewlinesPasteIntact:
|
||||
|
@ -49,6 +49,7 @@ MOCHITEST_CHROME_FILES = \
|
||||
test_bug471319.html \
|
||||
test_bug483651.html \
|
||||
test_bug636465.xul \
|
||||
test_bug830600.html \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
101
editor/libeditor/text/tests/test_bug830600.html
Normal file
101
editor/libeditor/text/tests/test_bug830600.html
Normal file
@ -0,0 +1,101 @@
|
||||
<!DOCTYPE HTML>
|
||||
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=830600
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 830600</title>
|
||||
<script type="application/javascript"
|
||||
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="application/javascript"
|
||||
src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=830600">Mozilla Bug 830600</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
</div>
|
||||
<input type="text" id="t1" />
|
||||
<pre id="test">
|
||||
<script type="application/javascript;version=1.7">
|
||||
|
||||
/** Test for Bug 830600 **/
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
SimpleTest.waitForFocus(function() {
|
||||
const Ci = Components.interfaces;
|
||||
function test(str, expected, callback) {
|
||||
var t = document.getElementById("t1");
|
||||
t.QueryInterface(Ci.nsIDOMNSEditableElement);
|
||||
t.focus();
|
||||
t.value = "";
|
||||
t.editor.QueryInterface(Ci.nsIPlaintextEditor);
|
||||
var origNewlineHandling = t.editor.newlineHandling;
|
||||
t.editor.newlineHandling = Ci.nsIPlaintextEditor.eNewlinesStripSurroundingWhitespace
|
||||
SimpleTest.waitForClipboard(str,
|
||||
function() {
|
||||
Components.classes["@mozilla.org/widget/clipboardhelper;1"]
|
||||
.getService(Components.interfaces.nsIClipboardHelper)
|
||||
.copyString(str, document);
|
||||
},
|
||||
function() {
|
||||
synthesizeKey("V", {accelKey: true});
|
||||
is(t.value, expected, "New line handling works correctly");
|
||||
t.value = "";
|
||||
callback();
|
||||
},
|
||||
function() {
|
||||
ok(false, "Failed to copy the string");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function runNextTest() {
|
||||
if (tests.length) {
|
||||
var currentTest = tests.shift();
|
||||
test(currentTest[0], currentTest[1], runNextTest);
|
||||
} else {
|
||||
SimpleTest.finish();
|
||||
}
|
||||
}
|
||||
|
||||
var tests = [
|
||||
["abc", "abc"],
|
||||
["\n", ""],
|
||||
[" \n", ""],
|
||||
["\n ", ""],
|
||||
[" \n ", ""],
|
||||
[" a", " a"],
|
||||
["a ", "a "],
|
||||
[" a ", " a "],
|
||||
[" \nabc", "abc"],
|
||||
["\n abc", "abc"],
|
||||
[" \n abc", "abc"],
|
||||
[" \nabc ", "abc "],
|
||||
["\n abc ", "abc "],
|
||||
[" \n abc ", "abc "],
|
||||
["abc\n ", "abc"],
|
||||
["abc \n", "abc"],
|
||||
["abc \n ", "abc"],
|
||||
[" abc\n ", " abc"],
|
||||
[" abc \n", " abc"],
|
||||
[" abc \n ", " abc"],
|
||||
[" abc \n def \n ", " abcdef"],
|
||||
["\n abc \n def \n ", "abcdef"],
|
||||
[" \n abc \n def ", "abcdef "],
|
||||
[" abc\n\ndef ", " abcdef "],
|
||||
[" abc \n\n def ", " abcdef "],
|
||||
];
|
||||
|
||||
runNextTest();
|
||||
});
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user