MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / onKeyDown

Method onKeyDown

tools/xsbug/behaviors.js:246–323  ·  view source on GitHub ↗
(code, key, repeat, ticks)

Source from the content-addressed store, hash-verified

244 code.select(0, code.length)
245 }
246 onKeyDown(code, key, repeat, ticks) {
247 var charCode = this.filterKey(code, key);
248 if (!charCode) return false
249 var insertions = null;
250 if (charCode == 28) /* left */
251 this.onCursorX(code, -1);
252 else if (charCode == 29) /* right */
253 this.onCursorX(code, 1);
254 else if (charCode == 30) /* up */
255 this.onCursorY(code, -1);
256 else if (charCode == 31) /* down */
257 this.onCursorY(code, 1);
258 else {
259 if (controlKey) return false;
260 this.onCursorCancel(code);
261 switch (charCode) {
262 case 1: /* home */
263 code.select(0, 0);
264 this.onSelected(code);
265 break;
266 case 2: /* delete selection */
267 insertions = "";
268 break;
269 case 4: /* end */
270 code.select(code.length, 0);
271 this.onSelected(code);
272 break;
273 case 8: /* backspace */
274 if (code.selectionLength == 0)
275 code.select(code.selectionOffset - 1, 1)
276 insertions = "";
277 break;
278 case 9: /* tab */
279 if (code.selectionLength > 0) {
280 this.onChanging(code);
281 code.tab(true);
282 this.onChanged(code);
283 this.onReveal(code);
284 return true;
285 }
286 insertions = key;
287 break;
288 case 25: /* shift tab */
289 if (code.selectionLength > 0) {
290 this.onChanging(code);
291 code.tab(false);
292 this.onChanged(code);
293 this.onReveal(code);
294 return true;
295 }
296 insertions = "\t";
297 break;
298 case 3: /* enter */
299 case 13: /* return */
300 insertions = "\n";
301 var from = code.findLineBreak(code.selectionOffset, false);
302 if ((from < code.selectionOffset) && code.isSpace(from)) {
303 var to = code.findWordBreak(from, true);

Callers

nothing calls this directly

Calls 11

filterKeyMethod · 0.95
onCursorXMethod · 0.95
onCursorYMethod · 0.95
onCursorCancelMethod · 0.95
onSelectedMethod · 0.95
onChangingMethod · 0.95
onChangedMethod · 0.95
onRevealMethod · 0.95
tabMethod · 0.80
insertMethod · 0.80
selectMethod · 0.45

Tested by

no test coverage detected