private getWordIndexFromPosition()

in client/src/components/translation-selector/word-scroll-list.ts [306:322]


  private getWordIndexFromPosition(x: number, y: number): number {
    if (!this.scrollContent) {
      return 0;
    }
    const scrollContent = this.scrollContent.nativeElement;
    const items = scrollContent.getElementsByTagName('li');
    for (let k = 0; k < items.length; k++) {
      const child = items[k];
      let childRect = child.getBoundingClientRect();
      if (x >= childRect.left && x <= childRect.right
        && y >= childRect.top && y <= childRect.bottom) {
        // position is within child bounds
        return k;
      }
    }
    return -1;
  }