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

Method onTouchBeganMode

tools/xsbug/CodeView.js:328–409  ·  view source on GitHub ↗
(code, id, x, y, ticks, mode)

Source from the content-addressed store, hash-verified

326 this.onTouchBeganMode(code, id, x, y, ticks, CHAR_MODE);
327 }
328 onTouchBeganMode(code, id, x, y, ticks, mode) {
329 code.focus();
330 if ((ticks - this.touchTicks < 1000) && (this.touchX == x) && (this.touchY == y)) {
331 this.touchCount++;
332 if (this.touchCount == 4)
333 this.touchCount = 1;
334 }
335 else {
336 this.touchCount = 1;
337 this.touchX = x;
338 this.touchY = y;
339 }
340 this.touchTicks = ticks;
341 if (mode == CHAR_MODE) {
342 if (this.touchCount == 2)
343 mode = WORD_MODE;
344 else if (this.touchCount == 3)
345 mode = LINE_MODE;
346 }
347 this.mode = mode;
348 var anchor = this.anchor;
349 var bounds = code.bounds;
350 var offset = code.hitOffset(x - bounds.x, y - bounds.y);
351 var from, to;
352 if (this.mode == LINE_MODE) {
353 if (shiftKey) {
354 if (offset < anchor.to) {
355 from = code.findLineBreak(offset, false);
356 to = code.selectionOffset + code.selectionLength;
357 }
358 else {
359 from = code.selectionOffset;
360 to = code.findLineBreak(offset, true);
361 }
362 }
363 else {
364 from = anchor.from = code.findLineBreak(offset, false);
365 to = anchor.to = code.findLineBreak(offset, true);
366 }
367 }
368 else if (this.mode == WORD_MODE) {
369 if (shiftKey) {
370 if (offset < anchor.to) {
371 from = code.findWordBreak(offset, false);
372 to = code.selectionOffset + code.selectionLength;
373 }
374 else {
375 from = code.selectionOffset;
376 to = code.findWordBreak(offset, true);
377 }
378 }
379 else {
380 var range = code.findBlock(offset);
381 if (range) {
382 from = range.from;
383 to = range.to;
384 anchor.from = anchor.to = offset;
385 }

Callers 1

onTouchBeganMethod · 0.95

Calls 2

focusMethod · 0.80
selectMethod · 0.45

Tested by

no test coverage detected