Bug 462188: Fix deletion of words (Ctrl-Backspace/Option-Delete) in HTML editing. r+sr=peterv

This commit is contained in:
Theppitak Karoonboonyanan 2009-01-16 13:32:09 -08:00
Родитель ecc57f0920
Коммит 79bdda85ad
2 изменённых файлов: 50 добавлений и 3 удалений

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

@ -1948,10 +1948,24 @@ nsHTMLEditRules::WillDeleteSelection(nsISelection *aSelection,
if (NS_FAILED(res)) return res;
if (*aCancel) return NS_OK;
res = mHTMLEditor->ExtendSelectionForDelete(aSelection, &aAction);
NS_ENSURE_SUCCESS(res, res);
// We should delete nothing.
if (aAction == nsIEditor::eNone)
return NS_OK;
// ExtendSelectionForDelete() may have changed the selection, update it
res = mHTMLEditor->GetStartNodeAndOffset(aSelection, address_of(startNode), &startOffset);
if (NS_FAILED(res)) return res;
if (!startNode) return NS_ERROR_FAILURE;
res = aSelection->GetIsCollapsed(&bCollapsed);
if (NS_FAILED(res)) return res;
}
if (bCollapsed)
{
// what's in the direction we are deleting?
nsWSRunObject wsObj(mHTMLEditor, startNode, startOffset);
nsCOMPtr<nsIDOMNode> visNode;
@ -1996,9 +2010,6 @@ nsHTMLEditRules::WillDeleteSelection(nsISelection *aSelection,
}
else
{
res = mHTMLEditor->ExtendSelectionForDelete(aSelection, &aAction);
NS_ENSURE_SUCCESS(res, res);
nsCOMPtr<nsIDOMRange> range;
res = aSelection->GetRangeAt(0, getter_AddRefs(range));
NS_ENSURE_SUCCESS(res, res);
@ -2015,6 +2026,8 @@ nsHTMLEditRules::WillDeleteSelection(nsISelection *aSelection,
NS_ASSERTION(container == visNode, "selection end not in visNode");
#endif
res = range->GetStartOffset(&so);
NS_ENSURE_SUCCESS(res, res);
res = range->GetEndOffset(&eo);
NS_ENSURE_SUCCESS(res, res);
}

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

@ -50,6 +50,8 @@ function test() {
var wordSelModifiers =
(navigator.platform.indexOf("Mac") >= 0) ?
{shiftKey:true, altKey:true} : {shiftKey:true, ctrlKey:true};
var wordModifiers =
(navigator.platform.indexOf("Mac") >= 0) ? {altKey:true} : {ctrlKey:true};
var sel = window.getSelection();
var editor = document.getElementById("editor");
@ -86,6 +88,18 @@ function test() {
is(editor.textContent, text, "Backspace broken in \"" + editor.innerHTML + "\"");
}
function testDeletePrevWord(node, offset, text) {
synthesizeKey("VK_BACK_SPACE", wordModifiers);
is(sel.anchorNode, node, "Delete previous word broken in \"" + editor.innerHTML + "\"");
is(sel.anchorOffset, offset, "Delete previous word broken in \"" + editor.innerHTML + "\"");
}
function testDeleteNextWord(node, offset, text) {
synthesizeKey("VK_DELETE", wordModifiers);
is(sel.anchorNode, node, "Delete next word broken in \"" + editor.innerHTML + "\"");
is(sel.anchorOffset, offset, "Delete next word broken in \"" + editor.innerHTML + "\"");
}
// Test cell-wise deletion of Delete
editor.innerHTML = "สวัสดีพ่อแม่พี่น้อง";
sel.collapse(editor.firstChild, 0);
@ -169,6 +183,26 @@ function test() {
testRight(editor.firstChild, 5);
testDelete(editor.firstChild, 5, "helloשלום");
// Tests for Bug 462188
editor.innerHTML = "You should not see this text.";
sel.collapse(editor.firstChild, 29);
testDeletePrevWord(editor.firstChild, 24, "You should not see this ");
testDeletePrevWord(editor.firstChild, 19, "You should not see ");
testDeletePrevWord(editor.firstChild, 15, "You should not ");
testDeletePrevWord(editor.firstChild, 11, "You should ");
testDeletePrevWord(editor.firstChild, 4, "You ");
testDeletePrevWord(editor, 0, "");
editor.innerHTML = "You should not see this text.";
sel.collapse(editor.firstChild, 0);
testDeleteNextWord(editor.firstChild, 0, " should not see this text.");
testDeleteNextWord(editor.firstChild, 0, " not see this text.");
testDeleteNextWord(editor.firstChild, 0, " see this text.");
testDeleteNextWord(editor.firstChild, 0, " this text.");
testDeleteNextWord(editor.firstChild, 0, " text.");
testDeleteNextWord(editor, 0, "");
SimpleTest.finish();
}