Skip to content

Commit

Permalink
refactor(#194): scroll method
Browse files Browse the repository at this point in the history
  • Loading branch information
jannis-baum committed Jan 21, 2025
1 parent f4825dc commit 86566fc
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions static/client.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,6 @@ try {
} catch {}
}

function viv_scrollTo(value) {
let line = parseInt(value);
while (line) {
const targets = document.querySelectorAll(`[data-source-line="${line - 1}"]`);
if (targets.length) {
targets[0].scrollIntoView({
behavior: 'smooth',
block: 'nearest',
});
break;
}
line -= 1;
}
}

const ws = new WebSocket(`ws://localhost:${window.VIV_PORT}`);

ws.addEventListener('message', (event) => {
Expand All @@ -48,7 +33,18 @@ ws.addEventListener('message', (event) => {
})();
break;
case 'SCROLL':
viv_scrollTo(value);
let line = parseInt(value);
while (line) {
const targets = document.querySelectorAll(`[data-source-line="${line - 1}"]`);
if (targets.length) {
targets[0].scrollIntoView({
behavior: 'smooth',
block: 'nearest',
});
break;
}
line -= 1;
}
break;
case 'RELOAD':
window.location.reload();
Expand Down

0 comments on commit 86566fc

Please sign in to comment.