|
(window["webpackJsonpGUI"] = window["webpackJsonpGUI"] || []).push([["addon-entry-editor-extra-keys"],{ |
|
|
|
"./src/addons/addons/editor-extra-keys/_runtime_entry.js": |
|
|
|
|
|
|
|
|
|
(function(module, __webpack_exports__, __webpack_require__) { |
|
|
|
"use strict"; |
|
__webpack_require__.r(__webpack_exports__); |
|
__webpack_require__.d(__webpack_exports__, "resources", function() { return resources; }); |
|
var _userscript_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__( "./src/addons/addons/editor-extra-keys/userscript.js"); |
|
|
|
|
|
const resources = { |
|
"userscript.js": _userscript_js__WEBPACK_IMPORTED_MODULE_0__["default"] |
|
}; |
|
|
|
}), |
|
|
|
"./src/addons/addons/editor-extra-keys/userscript.js": |
|
|
|
|
|
|
|
|
|
(function(module, __webpack_exports__, __webpack_require__) { |
|
|
|
"use strict"; |
|
__webpack_require__.r(__webpack_exports__); |
|
__webpack_exports__["default"] = (async function (_ref) { |
|
let { |
|
addon, |
|
msg |
|
} = _ref; |
|
const ScratchBlocks = await addon.tab.traps.getBlockly(); |
|
let defaultKeys = null; |
|
function appendKeys(keys, enableShiftKeys) { |
|
if (!defaultKeys) { |
|
defaultKeys = [...keys]; |
|
} |
|
if (!addon.self.disabled) { |
|
keys.push(...[["-", "-"], [",", ","], [".", "."]]); |
|
keys.splice(5, 0, [msg("enter-key"), "enter"]); |
|
if (addon.settings.get("experimentalKeys")) { |
|
keys.push(...[["`", "`"], ["=", "="], ["[", "["], ["]", "]"], ["\\", "\\"], [";", ";"], ["'", "'"], ["/", "/"]]); |
|
} |
|
if (enableShiftKeys && addon.settings.get("shiftKeys")) { |
|
keys.push(...[["!", "!"], ["@", "@"], ["#", "#"], ["$", "$"], ["%", "%"], ["^", "^"], ["&", "&"], ["*", "*"], ["(", "("], [")", ")"], ["_", "_"], ["+", "+"], ["{", "{"], ["}", "}"], ["|", "|"], [":", ":"], ['"', '"'], ["?", "?"], ["<", "<"], [">", ">"], ["~", "~"]]); |
|
} |
|
if (addon.settings.get("twKeys")) { |
|
keys.push(...[["backspace", "backspace"], ["delete", "delete"], ["shift", "shift"], ["caps lock", "caps lock"], ["scroll lock", "scroll lock"], ["control", "control"], ["escape", "escape"], ["insert", "insert"], ["home", "home"], ["end", "end"], ["page up", "page up"], ["page down", "page down"]]); |
|
} |
|
} |
|
return keys; |
|
} |
|
for (const opcode of ["sensing_keyoptions", "event_whenkeypressed", "event_whenkeyhit"]) { |
|
const block = ScratchBlocks.Blocks[opcode]; |
|
const originalInit = block.init; |
|
block.init = function () { |
|
const originalJsonInit = this.jsonInit; |
|
this.jsonInit = function (obj) { |
|
appendKeys(obj.args0[0].options, opcode === "event_whenkeypressed" || opcode === "event_whenkeyhit"); |
|
return originalJsonInit.call(this, obj); |
|
}; |
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { |
|
args[_key] = arguments[_key]; |
|
} |
|
return originalInit.call(this, ...args); |
|
}; |
|
} |
|
const updateExistingBlocks = () => { |
|
const workspace = Blockly.getMainWorkspace(); |
|
const flyout = workspace && workspace.getFlyout(); |
|
if (workspace && flyout) { |
|
const allBlocks = [...workspace.getAllBlocks(), ...flyout.getWorkspace().getAllBlocks()]; |
|
for (const block of allBlocks) { |
|
if (block.type !== "event_whenkeypressed" && block.type !== "event_whenkeyhit" && block.type !== "sensing_keyoptions") { |
|
continue; |
|
} |
|
const input = block.inputList[0]; |
|
if (!input) { |
|
continue; |
|
} |
|
const field = input.fieldRow.find(i => i && Array.isArray(i.menuGenerator_)); |
|
if (!field) { |
|
continue; |
|
} |
|
field.menuGenerator_ = appendKeys(defaultKeys ? [...defaultKeys] : field.menuGenerator_, block.type === "event_whenkeypressed" || block.type === "event_whenkeyhit"); |
|
} |
|
} |
|
}; |
|
updateExistingBlocks(); |
|
addon.settings.addEventListener("change", updateExistingBlocks); |
|
addon.self.addEventListener("disabled", updateExistingBlocks); |
|
addon.self.addEventListener("reenabled", updateExistingBlocks); |
|
}); |
|
|
|
}) |
|
|
|
}]); |
|
|