Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
fix(preview): update SelectionArea & HighlightArea on every frame
Browse files Browse the repository at this point in the history
  • Loading branch information
faselbaum committed Sep 13, 2018
1 parent ec3b87e commit 7987231
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions src/preview/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,24 +128,6 @@ function main(): void {
}
);

Mobx.autorun(
() => {
const selectionArea = store.getSelectionArea();
const selectionNode = document.getElementById('preview-selection') as HTMLElement;
selectionArea.write(selectionNode, { scrollPositon: store.getScrollPosition() });
},
{ scheduler: window.requestAnimationFrame }
);

Mobx.autorun(
() => {
const highlightNode = document.getElementById('preview-highlight') as HTMLElement;
const highlightArea = store.getHighlightArea();
highlightArea.write(highlightNode, { scrollPositon: store.getScrollPosition() });
},
{ scheduler: window.requestAnimationFrame }
);

Mobx.reaction(
() => store.getMetaDown(),
metaDown => {
Expand Down Expand Up @@ -177,6 +159,21 @@ function main(): void {
scheduler: window.requestIdleCallback
}
);

const selectionNode = document.getElementById('preview-selection') as HTMLElement;
const highlightNode = document.getElementById('preview-highlight') as HTMLElement;

const updateHighlightAndSelectionAreas = () => {
const selectionArea = store.getSelectionArea();
selectionArea.write(selectionNode, { scrollPositon: store.getScrollPosition() });

const highlightArea = store.getHighlightArea();
highlightArea.write(highlightNode, { scrollPositon: store.getScrollPosition() });

window.requestAnimationFrame(updateHighlightAndSelectionAreas);
};

window.requestAnimationFrame(updateHighlightAndSelectionAreas);
}
}

Expand Down

0 comments on commit 7987231

Please sign in to comment.