Bug 1108212 - In the DevTools Inspector tree, pressing delete should move to the next element. r=bgrins

This commit is contained in:
Fayolle Florent 2014-12-07 14:54:00 -05:00
Родитель 18bb6d0861
Коммит ac08f68a13
4 изменённых файлов: 39 добавлений и 10 удалений

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

@ -42,7 +42,7 @@ add_task(function* () {
yield inspector.once("inspector-updated");
info("Inspector updated, performing checks.");
yield assertNodeSelectedAndPanelsUpdated("#deleteChildren", "ul#deleteChildren");
yield assertNodeSelectedAndPanelsUpdated("#selectedAfterDelete", "li#selectedAfterDelete");
}
function* testAutomaticallyDeleteSelectedNode() {

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

@ -7,6 +7,7 @@
<body>
<ul id="deleteChildren">
<li id="deleteManually">Delete me via the inspector</li>
<li id="selectedAfterDelete">This node is selected after manual delete</li>
<li id="deleteAutomatically">Delete me via javascript</li>
</ul>
<iframe id="deleteIframe" src="data:text/html,%3C!DOCTYPE%20html%3E%3Chtml%20lang%3D%22en%22%3E%3Cbody%3E%3Cp%20id%3D%22deleteInIframe%22%3EDelete my container iframe%3C%2Fp%3E%3C%2Fbody%3E%3C%2Fhtml%3E"></iframe>

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

@ -426,9 +426,11 @@ MarkupView.prototype = {
}
break;
case Ci.nsIDOMKeyEvent.DOM_VK_DELETE:
case Ci.nsIDOMKeyEvent.DOM_VK_BACK_SPACE:
this.deleteNode(this._selectedContainer.node);
break;
case Ci.nsIDOMKeyEvent.DOM_VK_BACK_SPACE:
this.deleteNode(this._selectedContainer.node, true);
break;
case Ci.nsIDOMKeyEvent.DOM_VK_HOME:
let rootContainer = this.getContainer(this._rootNode);
this.navigate(rootContainer.children.firstChild.container);
@ -508,8 +510,12 @@ MarkupView.prototype = {
/**
* Delete a node from the DOM.
* This is an undoable action.
*
* @param {NodeFront} aNode The node to remove.
* @param {boolean} moveBackward If set to true, focus the previous sibling,
* otherwise the next one.
*/
deleteNode: function(aNode) {
deleteNode: function(aNode, moveBackward) {
if (aNode.isDocumentElement ||
aNode.nodeType == Ci.nsIDOMNode.DOCUMENT_TYPE_NODE ||
aNode.isAnonymous) {
@ -524,8 +530,15 @@ MarkupView.prototype = {
let nextSibling = null;
this.undo.do(() => {
this.walker.removeNode(aNode).then(siblings => {
let focusNode = siblings.previousSibling || parent;
nextSibling = siblings.nextSibling;
let focusNode = moveBackward ? siblings.previousSibling : nextSibling;
// If we can't move as the user wants, we move to the other direction.
// If there is no sibling elements anymore, move to the parent node.
if (!focusNode) {
focusNode = nextSibling || siblings.previousSibling || parent;
}
if (container.selected) {
this.navigate(this.getContainer(focusNode));
}

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

@ -10,13 +10,13 @@
const TEST_URL = "data:text/html,<div id='parent'><div id='first'></div><div id='second'></div><div id='third'></div></div>";
function* checkDeleteAndSelection(inspector, nodeSelector, focusedNodeSelector) {
function* checkDeleteAndSelection(inspector, key, nodeSelector, focusedNodeSelector) {
yield selectNode(nodeSelector, inspector);
yield clickContainer(nodeSelector, inspector);
info("Deleting the element \"" + nodeSelector + "\" with the keyboard");
info(`Deleting the element "${nodeSelector}" using the ${key} key`);
let mutated = inspector.once("markupmutation");
EventUtils.sendKey("delete", inspector.panelWin);
EventUtils.sendKey(key, inspector.panelWin);
yield Promise.all([mutated, inspector.once("inspector-updated")]);
@ -36,9 +36,24 @@ let test = asyncTest(function*() {
info("Selecting the test node by clicking on it to make sure it receives focus");
yield checkDeleteAndSelection(inspector, "#first", "#parent");
yield checkDeleteAndSelection(inspector, "#second", "#first");
yield checkDeleteAndSelection(inspector, "#third", "#second");
yield checkDeleteAndSelection(inspector, "delete", "#first", "#second");
yield checkDeleteAndSelection(inspector, "delete", "#second", "#third");
yield checkDeleteAndSelection(inspector, "delete", "#third", "#second");
yield checkDeleteAndSelection(inspector, "back_space", "#first", "#second");
yield checkDeleteAndSelection(inspector, "back_space", "#second", "#first");
yield checkDeleteAndSelection(inspector, "back_space", "#third", "#second");
// Removing the siblings of #first.
let mutated = inspector.once("markupmutation");
for (let node of content.document.querySelectorAll("#second, #third")) {
node.remove();
}
yield mutated;
// Testing with an only child.
info("testing with an only child");
yield checkDeleteAndSelection(inspector, "delete", "#first", "#parent");
yield checkDeleteAndSelection(inspector, "back_space", "#first", "#parent");
yield inspector.once("inspector-updated");
});