Keyboard.py : ajout de enabled dans add(), nouveau render() retournant (Script,
control_div), et méthodes mk_enable / mk_disable - keyboard.js : nouvelle signature add_keyboard_support(elementId, controlDivId, combinationsJson), fonction isCombinationEnabled(), vérification avant déclenchement - test_Keyboard.py : 8 tests couvrant les comportements et le rendu
This commit is contained in:
@@ -217,10 +217,11 @@
|
||||
anyHasLongerSequence = true;
|
||||
}
|
||||
|
||||
// Collect matches, respecting require_inside flag
|
||||
// Collect matches, respecting require_inside and enabled flags
|
||||
if (hasMatch) {
|
||||
const requireInside = currentNode.config["require_inside"] === true;
|
||||
if (!requireInside || isInside) {
|
||||
const enabled = isCombinationEnabled(data.controlDivId, currentNode.combinationStr);
|
||||
if (enabled && (!requireInside || isInside)) {
|
||||
currentMatches.push({
|
||||
elementId: elementId,
|
||||
config: currentNode.config,
|
||||
@@ -328,12 +329,29 @@
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a combination is enabled via the control div
|
||||
* @param {string} controlDivId - The ID of the keyboard control div
|
||||
* @param {string} combinationStr - The combination string (e.g., "esc")
|
||||
* @returns {boolean} - True if enabled (default: true if entry not found)
|
||||
*/
|
||||
function isCombinationEnabled(controlDivId, combinationStr) {
|
||||
const controlDiv = document.getElementById(controlDivId);
|
||||
if (!controlDiv) return true;
|
||||
|
||||
const entry = controlDiv.querySelector(`[data-combination="${combinationStr}"]`);
|
||||
if (!entry) return true;
|
||||
|
||||
return entry.dataset.enabled !== 'false';
|
||||
}
|
||||
|
||||
/**
|
||||
* Add keyboard support to an element
|
||||
* @param {string} elementId - The ID of the element
|
||||
* @param {string} controlDivId - The ID of the keyboard control div
|
||||
* @param {string} combinationsJson - JSON string of combinations mapping
|
||||
*/
|
||||
window.add_keyboard_support = function (elementId, combinationsJson) {
|
||||
window.add_keyboard_support = function (elementId, controlDivId, combinationsJson) {
|
||||
// Parse the combinations JSON
|
||||
const combinations = JSON.parse(combinationsJson);
|
||||
|
||||
@@ -350,7 +368,8 @@
|
||||
// Add to registry
|
||||
KeyboardRegistry.elements.set(elementId, {
|
||||
tree: tree,
|
||||
element: element
|
||||
element: element,
|
||||
controlDivId: controlDivId
|
||||
});
|
||||
|
||||
// Attach global listener if not already attached
|
||||
|
||||
Reference in New Issue
Block a user