@happy-nut/monacori 0.1.15 → 0.1.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/viewer.client.js +28 -3
- package/package.json +1 -1
package/dist/viewer.client.js
CHANGED
|
@@ -509,6 +509,15 @@ function scheduleDiffScroll(row) {
|
|
|
509
509
|
// reflow-forcing scrollIntoView can run, so collapse them to one (latest element) per animation frame and
|
|
510
510
|
// use block:nearest (no per-row center-jump). Shared by the tree, source caret, and diff caret.
|
|
511
511
|
var pendingScrollEl = null, scrollElRaf = 0;
|
|
512
|
+
// Reveal `el` by keeping it ~fraction of the way down its scroller, scrolling minimally on EVERY move so the
|
|
513
|
+
// view follows the caret CONTINUOUSLY. scrollIntoView('nearest') instead leaves the view still until the
|
|
514
|
+
// caret reaches the edge and then jumps — stuttering ~every viewport while an arrow key is held.
|
|
515
|
+
function revealAt(el, scroller, fraction) {
|
|
516
|
+
if (!el) return;
|
|
517
|
+
if (!scroller || !scroller.clientHeight) { try { el.scrollIntoView({ block: 'nearest', inline: 'nearest' }); } catch (x) {} return; }
|
|
518
|
+
var off = el.getBoundingClientRect().top - scroller.getBoundingClientRect().top;
|
|
519
|
+
scroller.scrollTop += off - scroller.clientHeight * fraction;
|
|
520
|
+
}
|
|
512
521
|
function scheduleScrollIntoView(el) {
|
|
513
522
|
pendingScrollEl = el || null;
|
|
514
523
|
if (scrollElRaf) return;
|
|
@@ -897,7 +906,7 @@ function scheduleTreeFocus() {
|
|
|
897
906
|
if (treeFocusIndex < 0 || treeFocusIndex >= rows.length) return;
|
|
898
907
|
const el = rows[treeFocusIndex];
|
|
899
908
|
document.querySelectorAll('.tree-focus').forEach((e) => { if (e !== el) e.classList.remove('tree-focus'); });
|
|
900
|
-
if (el) { el.classList.add('tree-focus'); el.
|
|
909
|
+
if (el) { el.classList.add('tree-focus'); revealAt(el, document.querySelector('.sidebar-scroll'), 0.42); }
|
|
901
910
|
});
|
|
902
911
|
}
|
|
903
912
|
|
|
@@ -1008,6 +1017,15 @@ function handleTreeKey(event) {
|
|
|
1008
1017
|
return false;
|
|
1009
1018
|
}
|
|
1010
1019
|
|
|
1020
|
+
// d2h-file-side-diff is a HORIZONTAL scrollport (overflow-x:auto), so the browser swallows VERTICAL wheel
|
|
1021
|
+
// there instead of bubbling it to #diff2html-container — the diff wouldn't scroll by mouse wheel at all.
|
|
1022
|
+
// Redirect vertical wheel to the container; leave horizontal wheel (deltaX) for the side's own h-scroll.
|
|
1023
|
+
(function () {
|
|
1024
|
+
var dsc = document.getElementById('diff2html-container');
|
|
1025
|
+
if (dsc) dsc.addEventListener('wheel', function (e) {
|
|
1026
|
+
if (Math.abs(e.deltaY) >= Math.abs(e.deltaX) && e.deltaY !== 0) { dsc.scrollTop += e.deltaY; e.preventDefault(); }
|
|
1027
|
+
}, { passive: false });
|
|
1028
|
+
})();
|
|
1011
1029
|
document.addEventListener('keydown', (event) => {
|
|
1012
1030
|
if (!quickOpen?.classList.contains('hidden')) {
|
|
1013
1031
|
if (handleQuickOpenKey(event)) return;
|
|
@@ -1114,6 +1132,13 @@ document.addEventListener('keydown', (event) => {
|
|
|
1114
1132
|
}
|
|
1115
1133
|
}
|
|
1116
1134
|
|
|
1135
|
+
// PageUp/Down scroll the diff/source view. There's no focusable scroller (the diff caret is a JS cursor),
|
|
1136
|
+
// and d2h-file-side-diff's horizontal scrollport even swallows vertical wheel, so handle paging explicitly.
|
|
1137
|
+
// Only when the tree isn't focused — the tree pages itself in handleTreeKey below.
|
|
1138
|
+
if (treeFocusIndex < 0 && (event.key === 'PageDown' || event.key === 'PageUp') && !event.metaKey && !event.ctrlKey && !event.altKey) {
|
|
1139
|
+
var psc = isDiffViewVisible() ? document.getElementById('diff2html-container') : (isSourceViewerVisible() ? document.getElementById('source-body') : null);
|
|
1140
|
+
if (psc) { event.preventDefault(); psc.scrollTop += (event.key === 'PageDown' ? 0.9 : -0.9) * psc.clientHeight; return; }
|
|
1141
|
+
}
|
|
1117
1142
|
if (treeFocusIndex >= 0 && handleTreeKey(event)) return;
|
|
1118
1143
|
if (treeFocusIndex < 0 && !event.metaKey && !event.ctrlKey && !event.altKey && isSourceViewerVisible() && handleSourceCaretKey(event)) return;
|
|
1119
1144
|
if (treeFocusIndex < 0 && !event.metaKey && !event.ctrlKey && !event.altKey && isDiffViewVisible() && handleDiffCaretKey(event)) return;
|
|
@@ -1567,7 +1592,7 @@ function scheduleDiffReveal(wrapper, side, ri) {
|
|
|
1567
1592
|
applyDiffSelection();
|
|
1568
1593
|
if (!t) return;
|
|
1569
1594
|
var row = diffRowAt(t.wrapper, t.side, t.ri);
|
|
1570
|
-
|
|
1595
|
+
revealAt(row, document.getElementById('diff2html-container'), 0.42);
|
|
1571
1596
|
});
|
|
1572
1597
|
}
|
|
1573
1598
|
function navEntryOf(kind) {
|
|
@@ -3302,7 +3327,7 @@ function scheduleSourceReveal(prev) {
|
|
|
3302
3327
|
var lines = f.content.split(/\r?\n/);
|
|
3303
3328
|
updateSourceCaret(p, lines, f.language || 'text');
|
|
3304
3329
|
var cl = document.querySelector('.source-row.cursor-line');
|
|
3305
|
-
|
|
3330
|
+
revealAt(cl, document.getElementById('source-body'), 0.42);
|
|
3306
3331
|
});
|
|
3307
3332
|
}
|
|
3308
3333
|
|