X-Git-Url: https://git.xangelo.ca/?a=blobdiff_plain;f=src%2Fcursor.ts;fp=src%2Fcursor.ts;h=cd44b6d69539a691ef419ac84245c752c081cf1c;hb=f3a8b6fe0a0f68a43103347fc065734fbaedddb6;hp=4dc7cc704723b9546d5a13cc46928f02644f1a49;hpb=a503478efc4434ec26cbac146e85e48c0d76da96;p=apps%2Foutliner%2F.git diff --git a/src/cursor.ts b/src/cursor.ts index 4dc7cc7..cd44b6d 100644 --- a/src/cursor.ts +++ b/src/cursor.ts @@ -1,3 +1,5 @@ +import {isVisible} from "dom"; + export class Cursor { constructor() { @@ -20,11 +22,11 @@ export class Cursor { set(elementId: string) { this.unset(); - const el = document.querySelector(elementId); + const el = document.querySelector(elementId) as HTMLElement; if(el) { el.classList.add('cursor'); - if(!this.isVisible(elementId)) { + if(!isVisible(el)) { el.scrollIntoView(true); } } @@ -47,15 +49,4 @@ export class Cursor { isNodeExpanded(): boolean { return this.get().classList.contains('expanded'); } - - isVisible(elementId: string) { - const el = document.querySelector(elementId) as HTMLElement; - var rect = el.getBoundingClientRect(); - return ( - rect.top >= 0 && - rect.left >= 0 && - rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && - rect.right <= (window.innerWidth || document.documentElement.clientWidth) - ); - } }