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

Function PiuCodeHitOffset

modules/piu/PC/Code/piuCode.c:536–590  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

534}
535
536int32_t PiuCodeHitOffset(PiuCode* self, double x, double y)
537{
538 xsMachine* the = (*self)->the;
539 xsStringValue string = PiuToString((*self)->string);
540 PiuStyle* style = (*self)->computedStyle;
541 xsBooleanValue flag = 0;
542 double left = 0;
543 double right = 0;
544 double top = 0;
545 double bottom = (*self)->lineHeight;
546 PiuTextBuffer* runs = (*self)->runs;
547 PiuCodeRun run = (PiuCodeRun)((uint8_t*)(*runs) + sizeof(PiuTextBufferRecord));
548 xsStringValue text = string;
549 x -= (*style)->margins.left;
550 y -= (*style)->margins.top;
551 if (x < 0)
552 x = 0;
553 if (y < 0)
554 y = 0;
555 x += (*self)->columnWidth / 2;
556 if ((top <= y) && (y < bottom))
557 flag = 1;
558 while (*text) {
559 switch(run->kind) {
560 case piuCodeLineKind:
561 if (flag)
562 return fxUTF8ToUnicodeOffset(string, text - string);
563 left = 0;
564 top = bottom;
565 bottom += (*self)->lineHeight;
566 if ((top <= y) && (y < bottom))
567 flag = 1;
568 break;
569 case piuCodeTabKind:
570 if (flag) {
571 right = left + (run->color * (*self)->columnWidth);
572 if ((left <= x) && (x < right))
573 return fxUTF8ToUnicodeOffset(string, text - string);
574 left = right;
575 }
576 break;
577 default:
578 if (flag) {
579 right = left + (fxUTF8ToUnicodeOffset(string, run->count) * (*self)->columnWidth);
580 if ((left <= x) && (x < right))
581 return fxUTF8ToUnicodeOffset(string, text - string) + fxUnicodeToUTF8Offset(text, (xsIntegerValue)((x - left) / (*self)->columnWidth));
582 left = right;
583 }
584 break;
585 }
586 text += run->count;
587 run++;
588 }
589 return (*self)->length;
590}
591
592void PiuCodeInvalidate(void* it, PiuRectangle area)
593{

Callers 1

PiuCode_hitOffsetFunction · 0.85

Calls 2

fxUTF8ToUnicodeOffsetFunction · 0.85
fxUnicodeToUTF8OffsetFunction · 0.85

Tested by

no test coverage detected