mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-05 15:49:11 +00:00
LibWebView: Add keyboard navigation to the Inspector
This commit is contained in:
parent
8357f18e9b
commit
e59048e90f
Notes:
sideshowbarker
2024-07-18 23:45:22 +09:00
Author: https://github.com/circl-lastname
Commit: e59048e90f
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/628
Reviewed-by: https://github.com/ADKaster ✅
Reviewed-by: https://github.com/AtkinsSJ
1 changed files with 68 additions and 0 deletions
|
@ -7,6 +7,8 @@ let selectedBottomTabButton = null;
|
||||||
let selectedDOMNode = null;
|
let selectedDOMNode = null;
|
||||||
let pendingEditDOMNode = null;
|
let pendingEditDOMNode = null;
|
||||||
|
|
||||||
|
let visibleDOMNodes = [];
|
||||||
|
|
||||||
let consoleGroupStack = [];
|
let consoleGroupStack = [];
|
||||||
let consoleGroupNextID = 0;
|
let consoleGroupNextID = 0;
|
||||||
|
|
||||||
|
@ -123,6 +125,16 @@ inspector.loadDOMTree = tree => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
domNodes = domTree.querySelectorAll("details");
|
||||||
|
|
||||||
|
for (let domNode of domNodes) {
|
||||||
|
domNode.addEventListener("toggle", event => {
|
||||||
|
updateVisibleDOMNodes();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
updateVisibleDOMNodes();
|
||||||
};
|
};
|
||||||
|
|
||||||
inspector.loadAccessibilityTree = tree => {
|
inspector.loadAccessibilityTree = tree => {
|
||||||
|
@ -343,6 +355,30 @@ const addAttributeToDOMNode = domNode => {
|
||||||
domNode.parentNode.insertBefore(container, domNode.parentNode.lastChild);
|
domNode.parentNode.insertBefore(container, domNode.parentNode.lastChild);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const updateVisibleDOMNodes = () => {
|
||||||
|
let domTree = document.getElementById("dom-tree");
|
||||||
|
|
||||||
|
visibleDOMNodes = [];
|
||||||
|
|
||||||
|
function recurseDOMNodes(node) {
|
||||||
|
for (let child of node.children) {
|
||||||
|
if (child.classList.contains("hoverable")) {
|
||||||
|
visibleDOMNodes.push(child);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (child.tagName === "DIV") {
|
||||||
|
if (node.open) {
|
||||||
|
recurseDOMNodes(child);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
recurseDOMNodes(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
recurseDOMNodes(domTree);
|
||||||
|
};
|
||||||
|
|
||||||
const requestContextMenu = (clientX, clientY, domNode) => {
|
const requestContextMenu = (clientX, clientY, domNode) => {
|
||||||
pendingEditDOMNode = null;
|
pendingEditDOMNode = null;
|
||||||
|
|
||||||
|
@ -516,5 +552,37 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
document.addEventListener("keydown", event => {
|
||||||
|
const UP_ARROW_KEYCODE = 38;
|
||||||
|
const DOWN_ARROW_KEYCODE = 40;
|
||||||
|
const RETURN_KEYCODE = 13;
|
||||||
|
const SPACE_KEYCODE = 32;
|
||||||
|
|
||||||
|
if (document.activeElement.tagName !== "INPUT") {
|
||||||
|
if (event.keyCode == UP_ARROW_KEYCODE || event.keyCode == DOWN_ARROW_KEYCODE) {
|
||||||
|
let selectedIndex = visibleDOMNodes.indexOf(selectedDOMNode);
|
||||||
|
if (selectedIndex < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let newIndex;
|
||||||
|
|
||||||
|
if (event.keyCode == UP_ARROW_KEYCODE) {
|
||||||
|
newIndex = selectedIndex - 1;
|
||||||
|
} else if (event.keyCode == DOWN_ARROW_KEYCODE) {
|
||||||
|
newIndex = selectedIndex + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (visibleDOMNodes[newIndex]) {
|
||||||
|
inspectDOMNode(visibleDOMNodes[newIndex]);
|
||||||
|
}
|
||||||
|
} else if (event.keyCode == RETURN_KEYCODE || event.keyCode == SPACE_KEYCODE) {
|
||||||
|
if (selectedDOMNode.parentNode.tagName === "SUMMARY") {
|
||||||
|
selectedDOMNode.parentNode.click();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
inspector.inspectorLoaded();
|
inspector.inspectorLoaded();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue