Bug 952724 - Make InputContext#replaceSurroundingText match spec. r=janjongboom

This commit is contained in:
Yuan Xulei
2014-01-03 09:17:28 -05:00
parent 518828ceb6
commit c4482b16d3
4 changed files with 20 additions and 21 deletions

View File

@@ -585,13 +585,13 @@ let FormAssistant = {
case "Forms:ReplaceSurroundingText": {
CompositionManager.endComposition('');
let text = json.text;
let beforeLength = json.beforeLength;
let afterLength = json.afterLength;
let selectionRange = getSelectionRange(target);
replaceSurroundingText(target, text, selectionRange[0], beforeLength,
afterLength);
replaceSurroundingText(target,
json.text,
selectionRange[0],
selectionRange[1],
json.offset,
json.length);
if (json.requestId) {
sendAsyncMessage("Forms:ReplaceSurroundingText:Result:OK", {
@@ -1064,25 +1064,24 @@ function getPlaintextEditor(element) {
return editor;
}
function replaceSurroundingText(element, text, selectionStart, beforeLength,
afterLength) {
function replaceSurroundingText(element, text, selectionStart, selectionEnd,
offset, length) {
let editor = FormAssistant.editor;
if (!editor) {
return;
}
// Check the parameters.
if (beforeLength < 0) {
beforeLength = 0;
let start = selectionStart + offset;
if (start < 0) {
start = 0;
}
if (afterLength < 0) {
afterLength = 0;
if (length < 0) {
length = 0;
}
let end = start + length;
let start = selectionStart - beforeLength;
let end = selectionStart + afterLength;
if (beforeLength != 0 || afterLength != 0) {
if (selectionStart != start || selectionEnd != end) {
// Change selection range before replacing.
setSelectionRange(element, start, end);
}