File size: 4,619 Bytes
8086c81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
(window["webpackJsonpGUI"] = window["webpackJsonpGUI"] || []).push([["addon-entry-editor-extra-keys"],{

/***/ "./src/addons/addons/editor-extra-keys/_runtime_entry.js":
/*!***************************************************************!*\
  !*** ./src/addons/addons/editor-extra-keys/_runtime_entry.js ***!
  \***************************************************************/
/*! exports provided: resources */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "resources", function() { return resources; });
/* harmony import */ var _userscript_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./userscript.js */ "./src/addons/addons/editor-extra-keys/userscript.js");
/* generated by pull.js */

const resources = {
  "userscript.js": _userscript_js__WEBPACK_IMPORTED_MODULE_0__["default"]
};

/***/ }),

/***/ "./src/addons/addons/editor-extra-keys/userscript.js":
/*!***********************************************************!*\
  !*** ./src/addons/addons/editor-extra-keys/userscript.js ***!
  \***********************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony default export */ __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);
});

/***/ })

}]);
//# sourceMappingURL=addon-entry-editor-extra-keys.js.map