stream-monaco 0.0.22 → 0.0.36
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/README.md +16 -2
- package/README.zh-CN.md +16 -2
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/index.legacy.cjs +1 -1
- package/dist/index.legacy.js +1 -1
- package/dist/{preloadMonacoWorkers.shared-B-P1keRz.js → preloadMonacoWorkers.shared-B0KjUDJf.js} +1261 -1144
- package/dist/{preloadMonacoWorkers.shared-D9riw4LN.cjs → preloadMonacoWorkers.shared-kHKw8Ju_.cjs} +1261 -1144
- package/package.json +15 -7
package/dist/{preloadMonacoWorkers.shared-D9riw4LN.cjs → preloadMonacoWorkers.shared-kHKw8Ju_.cjs}
RENAMED
|
@@ -147,9 +147,14 @@ function processedLanguage(language) {
|
|
|
147
147
|
//#endregion
|
|
148
148
|
//#region src/monaco-shim.ts
|
|
149
149
|
var monaco_shim_exports = {};
|
|
150
|
-
__export(monaco_shim_exports, {
|
|
150
|
+
__export(monaco_shim_exports, {
|
|
151
|
+
ScrollType: () => ScrollType,
|
|
152
|
+
default: () => monaco
|
|
153
|
+
});
|
|
151
154
|
__reExport(monaco_shim_exports, require("monaco-editor/esm/vs/editor/editor.api"));
|
|
155
|
+
var _editor;
|
|
152
156
|
const monaco = monaco_editor_esm_vs_editor_editor_api;
|
|
157
|
+
const ScrollType = Reflect.get(monaco_editor_esm_vs_editor_editor_api, "ScrollType") ?? ((_editor = monaco_editor_esm_vs_editor_editor_api.editor) === null || _editor === void 0 ? void 0 : _editor.ScrollType);
|
|
153
158
|
|
|
154
159
|
//#endregion
|
|
155
160
|
//#region src/constant.ts
|
|
@@ -472,6 +477,809 @@ function createScrollWatcherForEditor(ed, opts) {
|
|
|
472
477
|
return api;
|
|
473
478
|
}
|
|
474
479
|
|
|
480
|
+
//#endregion
|
|
481
|
+
//#region src/core/diffAppearance.ts
|
|
482
|
+
function parseCssColorRgb(color) {
|
|
483
|
+
const normalized = color.trim().toLowerCase();
|
|
484
|
+
const rgbMatch = normalized.match(/^rgba?\(\s*([+\-.\d]+)\s*,\s*([+\-.\d]+)\s*,\s*([+\-.\d]+)/);
|
|
485
|
+
if (rgbMatch) return [
|
|
486
|
+
Number.parseFloat(rgbMatch[1]),
|
|
487
|
+
Number.parseFloat(rgbMatch[2]),
|
|
488
|
+
Number.parseFloat(rgbMatch[3])
|
|
489
|
+
];
|
|
490
|
+
const hexMatch = normalized.match(/^#([\da-f]{3,8})$/i);
|
|
491
|
+
if (!hexMatch) return null;
|
|
492
|
+
const hex = hexMatch[1];
|
|
493
|
+
if (hex.length === 3 || hex.length === 4) return [
|
|
494
|
+
Number.parseInt(`${hex[0]}${hex[0]}`, 16),
|
|
495
|
+
Number.parseInt(`${hex[1]}${hex[1]}`, 16),
|
|
496
|
+
Number.parseInt(`${hex[2]}${hex[2]}`, 16)
|
|
497
|
+
];
|
|
498
|
+
if (hex.length === 6 || hex.length === 8) return [
|
|
499
|
+
Number.parseInt(hex.slice(0, 2), 16),
|
|
500
|
+
Number.parseInt(hex.slice(2, 4), 16),
|
|
501
|
+
Number.parseInt(hex.slice(4, 6), 16)
|
|
502
|
+
];
|
|
503
|
+
return null;
|
|
504
|
+
}
|
|
505
|
+
function resolveCssColorLuminance(color) {
|
|
506
|
+
const rgb = parseCssColorRgb(color);
|
|
507
|
+
if (!rgb) return null;
|
|
508
|
+
const channel = (value) => {
|
|
509
|
+
const normalized = Math.max(0, Math.min(255, value)) / 255;
|
|
510
|
+
return normalized <= .03928 ? normalized / 12.92 : ((normalized + .055) / 1.055) ** 2.4;
|
|
511
|
+
};
|
|
512
|
+
const [r, g, b] = rgb;
|
|
513
|
+
return .2126 * channel(r) + .7152 * channel(g) + .0722 * channel(b);
|
|
514
|
+
}
|
|
515
|
+
function looksLikeDarkThemeName(themeName) {
|
|
516
|
+
if (!themeName) return false;
|
|
517
|
+
const normalized = themeName.toLowerCase();
|
|
518
|
+
return [
|
|
519
|
+
"dark",
|
|
520
|
+
"night",
|
|
521
|
+
"moon",
|
|
522
|
+
"black",
|
|
523
|
+
"dracula",
|
|
524
|
+
"mocha",
|
|
525
|
+
"frappe",
|
|
526
|
+
"macchiato",
|
|
527
|
+
"palenight",
|
|
528
|
+
"ocean",
|
|
529
|
+
"poimandres",
|
|
530
|
+
"monokai",
|
|
531
|
+
"laserwave",
|
|
532
|
+
"tokyo",
|
|
533
|
+
"slack-dark",
|
|
534
|
+
"rose-pine",
|
|
535
|
+
"github-dark",
|
|
536
|
+
"material-theme",
|
|
537
|
+
"one-dark",
|
|
538
|
+
"catppuccin-mocha",
|
|
539
|
+
"catppuccin-frappe",
|
|
540
|
+
"catppuccin-macchiato"
|
|
541
|
+
].some((token) => normalized.includes(token)) && !normalized.includes("light") && !normalized.includes("latte") && !normalized.includes("dawn") && !normalized.includes("lotus");
|
|
542
|
+
}
|
|
543
|
+
function looksLikeLightThemeName(themeName) {
|
|
544
|
+
if (!themeName) return false;
|
|
545
|
+
const normalized = themeName.toLowerCase();
|
|
546
|
+
return [
|
|
547
|
+
"light",
|
|
548
|
+
"day",
|
|
549
|
+
"dawn",
|
|
550
|
+
"latte",
|
|
551
|
+
"solarized-light",
|
|
552
|
+
"github-light",
|
|
553
|
+
"rose-pine-dawn",
|
|
554
|
+
"catppuccin-latte",
|
|
555
|
+
"one-light",
|
|
556
|
+
"vitesse-light",
|
|
557
|
+
"snazzy-light",
|
|
558
|
+
"material-lighter",
|
|
559
|
+
"material-theme-lighter",
|
|
560
|
+
"lotus"
|
|
561
|
+
].some((token) => normalized.includes(token));
|
|
562
|
+
}
|
|
563
|
+
function resolveDiffAppearance({ container, diffAppearance, diffEditorView, themeName }) {
|
|
564
|
+
var _diffEditorView$getMo, _diffEditorView$getMo2, _diffEditorView$getOr, _diffEditorView$getOr2;
|
|
565
|
+
if (diffAppearance === "light") return "light";
|
|
566
|
+
if (diffAppearance === "dark") return "dark";
|
|
567
|
+
if (looksLikeDarkThemeName(themeName)) return "dark";
|
|
568
|
+
if (looksLikeLightThemeName(themeName)) return "light";
|
|
569
|
+
const appearanceProbeNodes = [
|
|
570
|
+
diffEditorView === null || diffEditorView === void 0 || (_diffEditorView$getMo2 = (_diffEditorView$getMo = diffEditorView.getModifiedEditor()).getContainerDomNode) === null || _diffEditorView$getMo2 === void 0 ? void 0 : _diffEditorView$getMo2.call(_diffEditorView$getMo),
|
|
571
|
+
diffEditorView === null || diffEditorView === void 0 || (_diffEditorView$getOr2 = (_diffEditorView$getOr = diffEditorView.getOriginalEditor()).getContainerDomNode) === null || _diffEditorView$getOr2 === void 0 ? void 0 : _diffEditorView$getOr2.call(_diffEditorView$getOr),
|
|
572
|
+
container
|
|
573
|
+
];
|
|
574
|
+
for (const node of appearanceProbeNodes) {
|
|
575
|
+
if (!(node instanceof HTMLElement)) continue;
|
|
576
|
+
const style = globalThis.getComputedStyle(node);
|
|
577
|
+
const editorSurface = node.querySelector(".monaco-editor .monaco-editor-background, .monaco-editor .margin, .monaco-editor .lines-content");
|
|
578
|
+
const candidates = [
|
|
579
|
+
style.getPropertyValue("--stream-monaco-editor-bg"),
|
|
580
|
+
style.getPropertyValue("--vscode-editor-background"),
|
|
581
|
+
editorSurface ? globalThis.getComputedStyle(editorSurface).backgroundColor : "",
|
|
582
|
+
style.backgroundColor
|
|
583
|
+
];
|
|
584
|
+
for (const color of candidates) {
|
|
585
|
+
const luminance = resolveCssColorLuminance(color);
|
|
586
|
+
if (luminance == null) continue;
|
|
587
|
+
return luminance <= .42 ? "dark" : "light";
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
return looksLikeDarkThemeName(themeName) ? "dark" : "light";
|
|
591
|
+
}
|
|
592
|
+
function syncDiffRootThemeVariables(container, diffEditorView, appearance) {
|
|
593
|
+
var _diffEditorView$getMo3, _diffEditorView$getMo4, _diffEditorView$getOr3, _diffEditorView$getOr4;
|
|
594
|
+
const probeNodes = [
|
|
595
|
+
diffEditorView === null || diffEditorView === void 0 || (_diffEditorView$getMo4 = (_diffEditorView$getMo3 = diffEditorView.getModifiedEditor()).getContainerDomNode) === null || _diffEditorView$getMo4 === void 0 ? void 0 : _diffEditorView$getMo4.call(_diffEditorView$getMo3),
|
|
596
|
+
diffEditorView === null || diffEditorView === void 0 || (_diffEditorView$getOr4 = (_diffEditorView$getOr3 = diffEditorView.getOriginalEditor()).getContainerDomNode) === null || _diffEditorView$getOr4 === void 0 ? void 0 : _diffEditorView$getOr4.call(_diffEditorView$getOr3),
|
|
597
|
+
container
|
|
598
|
+
];
|
|
599
|
+
const containerStyle = globalThis.getComputedStyle(container);
|
|
600
|
+
const fixedBackgroundColor = containerStyle.getPropertyValue("--stream-monaco-fixed-editor-bg").trim() || null;
|
|
601
|
+
let backgroundColor = null;
|
|
602
|
+
let foregroundColor = null;
|
|
603
|
+
for (const node of probeNodes) {
|
|
604
|
+
if (!(node instanceof HTMLElement)) continue;
|
|
605
|
+
const backgroundProbe = node.querySelector(".monaco-editor-background, .margin, .lines-content") ?? node;
|
|
606
|
+
const foregroundProbe = node.querySelector(".view-lines, .monaco-editor, .view-overlays") ?? node;
|
|
607
|
+
const nextBackground = globalThis.getComputedStyle(backgroundProbe).backgroundColor;
|
|
608
|
+
if (!backgroundColor && resolveCssColorLuminance(nextBackground) != null) backgroundColor = nextBackground;
|
|
609
|
+
const nextForeground = globalThis.getComputedStyle(foregroundProbe).color;
|
|
610
|
+
if (!foregroundColor && resolveCssColorLuminance(nextForeground) != null) foregroundColor = nextForeground;
|
|
611
|
+
if (backgroundColor && foregroundColor) break;
|
|
612
|
+
}
|
|
613
|
+
const resolvedBackgroundColor = fixedBackgroundColor || backgroundColor || (appearance === "dark" ? "rgb(10 10 11)" : "rgb(255 255 255)");
|
|
614
|
+
if (resolvedBackgroundColor) container.style.setProperty("--stream-monaco-editor-bg", resolvedBackgroundColor);
|
|
615
|
+
else container.style.removeProperty("--stream-monaco-editor-bg");
|
|
616
|
+
if (foregroundColor) container.style.setProperty("--stream-monaco-editor-fg", foregroundColor);
|
|
617
|
+
else container.style.removeProperty("--stream-monaco-editor-fg");
|
|
618
|
+
}
|
|
619
|
+
function resolveDiffUnchangedLineInfoRailMetrics(node) {
|
|
620
|
+
const editorRoot = node.closest(".monaco-editor");
|
|
621
|
+
if (!editorRoot) return {
|
|
622
|
+
leftInset: 0,
|
|
623
|
+
width: null
|
|
624
|
+
};
|
|
625
|
+
const editorRect = editorRoot.getBoundingClientRect();
|
|
626
|
+
const lineNumberNode = Array.from(editorRoot.querySelectorAll(".line-numbers")).find((candidate) => {
|
|
627
|
+
const rect = candidate.getBoundingClientRect();
|
|
628
|
+
return rect.width > 0 && rect.height > 0;
|
|
629
|
+
});
|
|
630
|
+
if (!lineNumberNode) return {
|
|
631
|
+
leftInset: 0,
|
|
632
|
+
width: null
|
|
633
|
+
};
|
|
634
|
+
const lineNumberRect = lineNumberNode.getBoundingClientRect();
|
|
635
|
+
return {
|
|
636
|
+
leftInset: Math.max(0, lineNumberRect.left - editorRect.left),
|
|
637
|
+
width: Math.max(0, lineNumberRect.width) || null
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
function applyDiffRootAppearanceClass({ appearanceClasses, container, currentSignature, diffAppearance, diffEditorView, isInlineMode, layoutModeClasses, lineStyle, lineStyleClasses, themeName, unchangedRegionStyle, unchangedRegionStyleClasses }) {
|
|
641
|
+
if (!container) return currentSignature;
|
|
642
|
+
const resolvedAppearance = resolveDiffAppearance({
|
|
643
|
+
container,
|
|
644
|
+
diffAppearance,
|
|
645
|
+
diffEditorView,
|
|
646
|
+
themeName
|
|
647
|
+
});
|
|
648
|
+
syncDiffRootThemeVariables(container, diffEditorView, resolvedAppearance);
|
|
649
|
+
const containerClassList = container.classList;
|
|
650
|
+
const activeLineStyleClass = `stream-monaco-diff-style-${lineStyle}`;
|
|
651
|
+
const activeUnchangedRegionStyleClass = `stream-monaco-diff-unchanged-style-${unchangedRegionStyle}`;
|
|
652
|
+
const activeLayoutModeClass = isInlineMode ? "stream-monaco-diff-inline" : "stream-monaco-diff-side-by-side";
|
|
653
|
+
const activeAppearanceClass = `stream-monaco-diff-appearance-${resolvedAppearance}`;
|
|
654
|
+
const nextSignature = [
|
|
655
|
+
activeLineStyleClass,
|
|
656
|
+
activeUnchangedRegionStyleClass,
|
|
657
|
+
activeLayoutModeClass,
|
|
658
|
+
activeAppearanceClass
|
|
659
|
+
].join("|");
|
|
660
|
+
if (currentSignature === nextSignature && containerClassList.contains("stream-monaco-diff-root")) return currentSignature;
|
|
661
|
+
containerClassList.add("stream-monaco-diff-root");
|
|
662
|
+
for (const className of lineStyleClasses) containerClassList.toggle(className, className === activeLineStyleClass);
|
|
663
|
+
for (const className of unchangedRegionStyleClasses) containerClassList.toggle(className, className === activeUnchangedRegionStyleClass);
|
|
664
|
+
for (const className of layoutModeClasses) containerClassList.toggle(className, className === activeLayoutModeClass);
|
|
665
|
+
for (const className of appearanceClasses) containerClassList.toggle(className, className === activeAppearanceClass);
|
|
666
|
+
return nextSignature;
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
//#endregion
|
|
670
|
+
//#region src/core/diffHunk.ts
|
|
671
|
+
function createDiffHunkActionNode(side, onAction) {
|
|
672
|
+
const node = document.createElement("div");
|
|
673
|
+
node.className = "stream-monaco-diff-hunk-actions";
|
|
674
|
+
node.dataset.side = side;
|
|
675
|
+
const createButton = (action, label) => {
|
|
676
|
+
const button = document.createElement("button");
|
|
677
|
+
button.type = "button";
|
|
678
|
+
button.textContent = label;
|
|
679
|
+
button.dataset.action = action;
|
|
680
|
+
button.addEventListener("click", (event) => {
|
|
681
|
+
event.preventDefault();
|
|
682
|
+
event.stopPropagation();
|
|
683
|
+
onAction(side, action);
|
|
684
|
+
});
|
|
685
|
+
return button;
|
|
686
|
+
};
|
|
687
|
+
node.append(createButton("revert", "Revert"), createButton("stage", "Stage"));
|
|
688
|
+
return node;
|
|
689
|
+
}
|
|
690
|
+
function hasOriginalLines(change) {
|
|
691
|
+
return change.originalStartLineNumber > 0 && change.originalEndLineNumber >= change.originalStartLineNumber;
|
|
692
|
+
}
|
|
693
|
+
function hasModifiedLines(change) {
|
|
694
|
+
return change.modifiedStartLineNumber > 0 && change.modifiedEndLineNumber >= change.modifiedStartLineNumber;
|
|
695
|
+
}
|
|
696
|
+
function inferInlineDiffHunkHoverSide(change, hoverLine, targetElement) {
|
|
697
|
+
if (targetElement === null || targetElement === void 0 ? void 0 : targetElement.closest(".line-delete, .char-delete, .inline-deleted-text, .inline-deleted-margin-view-zone")) return "upper";
|
|
698
|
+
if (targetElement === null || targetElement === void 0 ? void 0 : targetElement.closest(".line-insert, .char-insert, .gutter-insert, .view-line")) return "lower";
|
|
699
|
+
if (!hasModifiedLines(change)) return "upper";
|
|
700
|
+
if (!hasOriginalLines(change)) return "lower";
|
|
701
|
+
const modifiedAnchor = Math.max(1, change.modifiedStartLineNumber || change.modifiedEndLineNumber || 1);
|
|
702
|
+
return hoverLine < modifiedAnchor ? "upper" : "lower";
|
|
703
|
+
}
|
|
704
|
+
function distanceToLineChange(side, change, line) {
|
|
705
|
+
const hasRange = side === "original" ? hasOriginalLines(change) : hasModifiedLines(change);
|
|
706
|
+
const start = side === "original" ? change.originalStartLineNumber : change.modifiedStartLineNumber;
|
|
707
|
+
const end = side === "original" ? change.originalEndLineNumber : change.modifiedEndLineNumber;
|
|
708
|
+
if (hasRange) {
|
|
709
|
+
if (line < start) return start - line;
|
|
710
|
+
if (line > end) return line - end;
|
|
711
|
+
return 0;
|
|
712
|
+
}
|
|
713
|
+
const fallbackAnchor = Math.max(1, start || end || 1);
|
|
714
|
+
return Math.abs(line - fallbackAnchor);
|
|
715
|
+
}
|
|
716
|
+
function findLineChangeByHoverLine(lineChanges, side, line) {
|
|
717
|
+
if (lineChanges.length === 0) return null;
|
|
718
|
+
let best = null;
|
|
719
|
+
let bestDistance = Number.POSITIVE_INFINITY;
|
|
720
|
+
for (const change of lineChanges) {
|
|
721
|
+
const distance = distanceToLineChange(side, change, line);
|
|
722
|
+
if (distance < bestDistance) {
|
|
723
|
+
bestDistance = distance;
|
|
724
|
+
best = change;
|
|
725
|
+
if (distance === 0) break;
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
if (bestDistance > 2) return null;
|
|
729
|
+
return best;
|
|
730
|
+
}
|
|
731
|
+
function getFullLineRange(model, startLine, endLine) {
|
|
732
|
+
if (endLine < startLine) return null;
|
|
733
|
+
const lineCount = model.getLineCount();
|
|
734
|
+
if (lineCount < 1) return null;
|
|
735
|
+
const start = Math.max(1, Math.min(startLine, lineCount));
|
|
736
|
+
const end = Math.max(start, Math.min(endLine, lineCount));
|
|
737
|
+
if (end < lineCount) return new monaco_shim_exports.Range(start, 1, end + 1, 1);
|
|
738
|
+
return new monaco_shim_exports.Range(start, 1, end, model.getLineMaxColumn(end));
|
|
739
|
+
}
|
|
740
|
+
function getLinesText(model, startLine, endLine) {
|
|
741
|
+
const range = getFullLineRange(model, startLine, endLine);
|
|
742
|
+
if (!range) return "";
|
|
743
|
+
return model.getValueInRange(range);
|
|
744
|
+
}
|
|
745
|
+
function getInsertRangeBeforeLine(model, lineNumber) {
|
|
746
|
+
const lineCount = model.getLineCount();
|
|
747
|
+
if (lineNumber <= 1) return new monaco_shim_exports.Range(1, 1, 1, 1);
|
|
748
|
+
if (lineNumber <= lineCount) return new monaco_shim_exports.Range(lineNumber, 1, lineNumber, 1);
|
|
749
|
+
const lastLine = lineCount;
|
|
750
|
+
const lastColumn = model.getLineMaxColumn(lastLine);
|
|
751
|
+
return new monaco_shim_exports.Range(lastLine, lastColumn, lastLine, lastColumn);
|
|
752
|
+
}
|
|
753
|
+
function getInsertRangeAfterLine(model, lineNumber) {
|
|
754
|
+
const lineCount = model.getLineCount();
|
|
755
|
+
if (lineNumber < 1) return new monaco_shim_exports.Range(1, 1, 1, 1);
|
|
756
|
+
if (lineNumber < lineCount) return new monaco_shim_exports.Range(lineNumber + 1, 1, lineNumber + 1, 1);
|
|
757
|
+
const lastLine = lineCount;
|
|
758
|
+
const lastColumn = model.getLineMaxColumn(lastLine);
|
|
759
|
+
return new monaco_shim_exports.Range(lastLine, lastColumn, lastLine, lastColumn);
|
|
760
|
+
}
|
|
761
|
+
function applyDefaultDiffHunkAction(context) {
|
|
762
|
+
const { action, side, lineChange, originalModel, modifiedModel } = context;
|
|
763
|
+
const hasOriginal = hasOriginalLines(lineChange);
|
|
764
|
+
const hasModified = hasModifiedLines(lineChange);
|
|
765
|
+
if (action === "revert" && side === "upper") {
|
|
766
|
+
if (!hasOriginal) return;
|
|
767
|
+
const text = getLinesText(originalModel, lineChange.originalStartLineNumber, lineChange.originalEndLineNumber);
|
|
768
|
+
if (!text) return;
|
|
769
|
+
const range = hasModified ? getInsertRangeBeforeLine(modifiedModel, lineChange.modifiedStartLineNumber) : getInsertRangeAfterLine(modifiedModel, Math.max(0, lineChange.modifiedStartLineNumber || lineChange.modifiedEndLineNumber));
|
|
770
|
+
modifiedModel.applyEdits([{
|
|
771
|
+
range,
|
|
772
|
+
text,
|
|
773
|
+
forceMoveMarkers: true
|
|
774
|
+
}]);
|
|
775
|
+
return;
|
|
776
|
+
}
|
|
777
|
+
if (action === "revert" && side === "lower") {
|
|
778
|
+
if (!hasModified) return;
|
|
779
|
+
const range = getFullLineRange(modifiedModel, lineChange.modifiedStartLineNumber, lineChange.modifiedEndLineNumber);
|
|
780
|
+
if (!range) return;
|
|
781
|
+
modifiedModel.applyEdits([{
|
|
782
|
+
range,
|
|
783
|
+
text: "",
|
|
784
|
+
forceMoveMarkers: true
|
|
785
|
+
}]);
|
|
786
|
+
return;
|
|
787
|
+
}
|
|
788
|
+
if (action === "stage" && side === "upper") {
|
|
789
|
+
if (!hasOriginal) return;
|
|
790
|
+
const range = getFullLineRange(originalModel, lineChange.originalStartLineNumber, lineChange.originalEndLineNumber);
|
|
791
|
+
if (!range) return;
|
|
792
|
+
originalModel.applyEdits([{
|
|
793
|
+
range,
|
|
794
|
+
text: "",
|
|
795
|
+
forceMoveMarkers: true
|
|
796
|
+
}]);
|
|
797
|
+
return;
|
|
798
|
+
}
|
|
799
|
+
if (action === "stage" && side === "lower") {
|
|
800
|
+
if (!hasModified) return;
|
|
801
|
+
const text = getLinesText(modifiedModel, lineChange.modifiedStartLineNumber, lineChange.modifiedEndLineNumber);
|
|
802
|
+
if (!text) return;
|
|
803
|
+
const anchor = hasOriginal ? lineChange.originalEndLineNumber : Math.max(0, lineChange.originalStartLineNumber);
|
|
804
|
+
const range = getInsertRangeAfterLine(originalModel, anchor);
|
|
805
|
+
originalModel.applyEdits([{
|
|
806
|
+
range,
|
|
807
|
+
text,
|
|
808
|
+
forceMoveMarkers: true
|
|
809
|
+
}]);
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
function setDiffHunkNodeEnabled(node, enabled) {
|
|
813
|
+
if (!node) return;
|
|
814
|
+
const buttons = node.querySelectorAll("button");
|
|
815
|
+
buttons.forEach((button) => {
|
|
816
|
+
button.disabled = !enabled;
|
|
817
|
+
});
|
|
818
|
+
}
|
|
819
|
+
function positionDiffHunkNode(node, editor, anchorLine, extraOffsetY = 0) {
|
|
820
|
+
var _editor$getScrollTop;
|
|
821
|
+
const host = editor.getContainerDomNode();
|
|
822
|
+
const line = Math.max(1, anchorLine);
|
|
823
|
+
const rawTop = editor.getTopForLineNumber(line) - (((_editor$getScrollTop = editor.getScrollTop) === null || _editor$getScrollTop === void 0 ? void 0 : _editor$getScrollTop.call(editor)) ?? 0);
|
|
824
|
+
const lineHeight = editor.getOption(monaco_shim_exports.editor.EditorOption.lineHeight);
|
|
825
|
+
const nodeWidth = node.offsetWidth || 130;
|
|
826
|
+
const nodeHeight = node.offsetHeight || 30;
|
|
827
|
+
const left = host.offsetLeft + Math.max(6, host.clientWidth - nodeWidth - 10);
|
|
828
|
+
const hostTop = host.offsetTop;
|
|
829
|
+
const minTop = hostTop + 4;
|
|
830
|
+
const maxTop = hostTop + Math.max(4, host.clientHeight - nodeHeight - 4);
|
|
831
|
+
const top = Math.min(maxTop, Math.max(minTop, hostTop + rawTop + Math.round(lineHeight * .2) + extraOffsetY));
|
|
832
|
+
node.style.transform = `translate(${Math.round(left)}px, ${Math.round(top)}px)`;
|
|
833
|
+
node.style.display = "flex";
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
//#endregion
|
|
837
|
+
//#region src/core/diffUnchanged.ts
|
|
838
|
+
function formatDiffUnchangedCountLabel(text) {
|
|
839
|
+
const match = text.match(/\d+/);
|
|
840
|
+
const count = match ? Number.parseInt(match[0], 10) : NaN;
|
|
841
|
+
if (Number.isFinite(count)) return `${count} unmodified ${count === 1 ? "line" : "lines"}`;
|
|
842
|
+
return text.replace(/hidden/gi, "unmodified");
|
|
843
|
+
}
|
|
844
|
+
function countDiffLines(startLineNumber, endLineNumber) {
|
|
845
|
+
return endLineNumber >= startLineNumber ? endLineNumber - startLineNumber + 1 : 0;
|
|
846
|
+
}
|
|
847
|
+
function measureDiffUnchangedSurroundingLines(primaryNode) {
|
|
848
|
+
const editorRoot = primaryNode.closest(".editor.modified") ?? primaryNode.closest(".monaco-editor");
|
|
849
|
+
if (!editorRoot) return {
|
|
850
|
+
previousVisibleLine: null,
|
|
851
|
+
nextVisibleLine: null
|
|
852
|
+
};
|
|
853
|
+
const widgetRect = primaryNode.getBoundingClientRect();
|
|
854
|
+
let previousVisibleLine = null;
|
|
855
|
+
let nextVisibleLine = null;
|
|
856
|
+
const lineNumberNodes = editorRoot.querySelectorAll(".line-numbers");
|
|
857
|
+
lineNumberNodes.forEach((node) => {
|
|
858
|
+
var _node$textContent;
|
|
859
|
+
const lineNumber = Number.parseInt(((_node$textContent = node.textContent) === null || _node$textContent === void 0 ? void 0 : _node$textContent.trim()) || "", 10);
|
|
860
|
+
if (!Number.isFinite(lineNumber)) return;
|
|
861
|
+
const top = node.getBoundingClientRect().top;
|
|
862
|
+
if (top < widgetRect.top - 1) previousVisibleLine = previousVisibleLine == null ? lineNumber : Math.max(previousVisibleLine, lineNumber);
|
|
863
|
+
else if (top > widgetRect.bottom + 1) nextVisibleLine = nextVisibleLine == null ? lineNumber : Math.min(nextVisibleLine, lineNumber);
|
|
864
|
+
});
|
|
865
|
+
return {
|
|
866
|
+
previousVisibleLine,
|
|
867
|
+
nextVisibleLine
|
|
868
|
+
};
|
|
869
|
+
}
|
|
870
|
+
function formatDiffMetadataRange(startLineNumber, lineCount) {
|
|
871
|
+
return `${startLineNumber},${Math.max(0, lineCount)}`;
|
|
872
|
+
}
|
|
873
|
+
function buildDiffHunkMetadataLabel(change, options) {
|
|
874
|
+
const { contextLineCount, modifiedTotalLines, originalTotalLines } = options;
|
|
875
|
+
const originalChangedCount = countDiffLines(change.originalStartLineNumber, change.originalEndLineNumber);
|
|
876
|
+
const modifiedChangedCount = countDiffLines(change.modifiedStartLineNumber, change.modifiedEndLineNumber);
|
|
877
|
+
const originalAnchor = Math.min(Math.max(change.originalStartLineNumber, 1), Math.max(1, originalTotalLines + 1));
|
|
878
|
+
const modifiedAnchor = Math.min(Math.max(change.modifiedStartLineNumber, 1), Math.max(1, modifiedTotalLines + 1));
|
|
879
|
+
const originalStart = Math.max(1, originalAnchor - contextLineCount);
|
|
880
|
+
const modifiedStart = Math.max(1, modifiedAnchor - contextLineCount);
|
|
881
|
+
const originalEnd = originalChangedCount > 0 ? Math.min(originalTotalLines, change.originalEndLineNumber + contextLineCount) : Math.min(originalTotalLines, originalAnchor + contextLineCount - 1);
|
|
882
|
+
const modifiedEnd = modifiedChangedCount > 0 ? Math.min(modifiedTotalLines, change.modifiedEndLineNumber + contextLineCount) : Math.min(modifiedTotalLines, modifiedAnchor + contextLineCount - 1);
|
|
883
|
+
const originalDisplayCount = originalEnd >= originalStart ? originalEnd - originalStart + 1 : 0;
|
|
884
|
+
const modifiedDisplayCount = modifiedEnd >= modifiedStart ? modifiedEnd - modifiedStart + 1 : 0;
|
|
885
|
+
return {
|
|
886
|
+
modifiedStart,
|
|
887
|
+
originalStart,
|
|
888
|
+
label: `@@ -${formatDiffMetadataRange(originalStart, originalDisplayCount)} +${formatDiffMetadataRange(modifiedStart, modifiedDisplayCount)} @@`
|
|
889
|
+
};
|
|
890
|
+
}
|
|
891
|
+
function resolveDiffMetadataLabel(options) {
|
|
892
|
+
var _metadataEntries$Math;
|
|
893
|
+
const { contextLineCount, lineChanges, modifiedTotalLines, originalTotalLines, pairIndex, primaryNode } = options;
|
|
894
|
+
if (lineChanges.length === 0) return null;
|
|
895
|
+
const metadataEntries = lineChanges.map((change) => buildDiffHunkMetadataLabel(change, {
|
|
896
|
+
contextLineCount,
|
|
897
|
+
modifiedTotalLines,
|
|
898
|
+
originalTotalLines
|
|
899
|
+
}));
|
|
900
|
+
const { nextVisibleLine } = measureDiffUnchangedSurroundingLines(primaryNode);
|
|
901
|
+
if (nextVisibleLine != null) {
|
|
902
|
+
const candidateStarts = [nextVisibleLine, nextVisibleLine - 1].filter((value) => value >= 1);
|
|
903
|
+
for (const candidateStart of candidateStarts) {
|
|
904
|
+
const matching = metadataEntries.find((entry) => entry.modifiedStart === candidateStart);
|
|
905
|
+
if (matching) return matching.label;
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
return ((_metadataEntries$Math = metadataEntries[Math.min(pairIndex, metadataEntries.length - 1)]) === null || _metadataEntries$Math === void 0 ? void 0 : _metadataEntries$Math.label) ?? null;
|
|
909
|
+
}
|
|
910
|
+
function resolveDiffUnchangedSummaryLabel(options) {
|
|
911
|
+
const { countText, unchangedRegionStyle,...metadataOptions } = options;
|
|
912
|
+
if (unchangedRegionStyle !== "metadata") return countText;
|
|
913
|
+
return resolveDiffMetadataLabel(metadataOptions) ?? countText;
|
|
914
|
+
}
|
|
915
|
+
function resolveDiffUnchangedRevealLayout(options) {
|
|
916
|
+
const { countText, modelLineCount, pairCount, pairIndex, primaryNode } = options;
|
|
917
|
+
let showTopHandle = pairCount === 1 || pairIndex > 0;
|
|
918
|
+
let showBottomHandle = pairCount === 1 || pairIndex < pairCount - 1;
|
|
919
|
+
const countMatch = countText.match(/\d+/);
|
|
920
|
+
const hiddenCount = countMatch ? Number.parseInt(countMatch[0], 10) : NaN;
|
|
921
|
+
if (!Number.isFinite(hiddenCount)) return {
|
|
922
|
+
showTopHandle,
|
|
923
|
+
showBottomHandle
|
|
924
|
+
};
|
|
925
|
+
const { previousVisibleLine, nextVisibleLine } = measureDiffUnchangedSurroundingLines(primaryNode);
|
|
926
|
+
if (previousVisibleLine == null && nextVisibleLine != null) {
|
|
927
|
+
showTopHandle = false;
|
|
928
|
+
showBottomHandle = true;
|
|
929
|
+
return {
|
|
930
|
+
showTopHandle,
|
|
931
|
+
showBottomHandle
|
|
932
|
+
};
|
|
933
|
+
}
|
|
934
|
+
if (nextVisibleLine == null && previousVisibleLine != null) {
|
|
935
|
+
showTopHandle = true;
|
|
936
|
+
showBottomHandle = false;
|
|
937
|
+
return {
|
|
938
|
+
showTopHandle,
|
|
939
|
+
showBottomHandle
|
|
940
|
+
};
|
|
941
|
+
}
|
|
942
|
+
if (nextVisibleLine != null && nextVisibleLine - hiddenCount === 1) {
|
|
943
|
+
showTopHandle = false;
|
|
944
|
+
showBottomHandle = true;
|
|
945
|
+
}
|
|
946
|
+
if (previousVisibleLine != null && modelLineCount != null && previousVisibleLine + hiddenCount === modelLineCount) {
|
|
947
|
+
showTopHandle = true;
|
|
948
|
+
showBottomHandle = false;
|
|
949
|
+
}
|
|
950
|
+
return {
|
|
951
|
+
showTopHandle,
|
|
952
|
+
showBottomHandle
|
|
953
|
+
};
|
|
954
|
+
}
|
|
955
|
+
function resolveDiffUnchangedMergeRole(options) {
|
|
956
|
+
const { diffRoot, modifiedHost, node, originalHost } = options;
|
|
957
|
+
if (typeof HTMLElement === "undefined") return "none";
|
|
958
|
+
if (!(diffRoot instanceof HTMLElement)) return "none";
|
|
959
|
+
const nodeRect = node.getBoundingClientRect();
|
|
960
|
+
const nodeCenter = nodeRect.left + nodeRect.width / 2;
|
|
961
|
+
if (originalHost instanceof HTMLElement && modifiedHost instanceof HTMLElement) {
|
|
962
|
+
const originalRect = originalHost.getBoundingClientRect();
|
|
963
|
+
const modifiedRect = modifiedHost.getBoundingClientRect();
|
|
964
|
+
const originalCenter = originalRect.left + originalRect.width / 2;
|
|
965
|
+
const modifiedCenter = modifiedRect.left + modifiedRect.width / 2;
|
|
966
|
+
return Math.abs(nodeCenter - originalCenter) <= Math.abs(nodeCenter - modifiedCenter) ? "secondary" : "primary";
|
|
967
|
+
}
|
|
968
|
+
const diffRect = diffRoot.getBoundingClientRect();
|
|
969
|
+
return nodeCenter < diffRect.left + diffRect.width / 2 ? "secondary" : "primary";
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
//#endregion
|
|
973
|
+
//#region src/core/diffUnchangedDom.ts
|
|
974
|
+
const diffUnchangedSummaryStyleClasses = [
|
|
975
|
+
"stream-monaco-unchanged-summary-line-info",
|
|
976
|
+
"stream-monaco-unchanged-summary-line-info-basic",
|
|
977
|
+
"stream-monaco-unchanged-summary-metadata",
|
|
978
|
+
"stream-monaco-unchanged-summary-simple"
|
|
979
|
+
];
|
|
980
|
+
function createDiffUnchangedBridgeScaffold() {
|
|
981
|
+
const bridge = document.createElement("div");
|
|
982
|
+
bridge.className = "stream-monaco-diff-unchanged-bridge";
|
|
983
|
+
bridge.setAttribute("role", "group");
|
|
984
|
+
syncDiffUnchangedBridgeVisibility(bridge, false);
|
|
985
|
+
const summary = document.createElement("button");
|
|
986
|
+
summary.type = "button";
|
|
987
|
+
summary.className = "stream-monaco-unchanged-summary";
|
|
988
|
+
const visualMeta = document.createElement("div");
|
|
989
|
+
visualMeta.className = "stream-monaco-unchanged-meta";
|
|
990
|
+
summary.append(visualMeta);
|
|
991
|
+
const divider = document.createElement("span");
|
|
992
|
+
divider.className = "stream-monaco-unchanged-pane-divider";
|
|
993
|
+
divider.setAttribute("aria-hidden", "true");
|
|
994
|
+
bridge.append(summary, divider);
|
|
995
|
+
return {
|
|
996
|
+
bridge,
|
|
997
|
+
summary,
|
|
998
|
+
visualMeta,
|
|
999
|
+
divider
|
|
1000
|
+
};
|
|
1001
|
+
}
|
|
1002
|
+
function createDiffUnchangedBridgeOverlay() {
|
|
1003
|
+
const overlay = document.createElement("div");
|
|
1004
|
+
overlay.className = "stream-monaco-diff-unchanged-overlay";
|
|
1005
|
+
return overlay;
|
|
1006
|
+
}
|
|
1007
|
+
function syncDiffUnchangedBridgeVisibility(bridge, visible) {
|
|
1008
|
+
bridge.hidden = !visible;
|
|
1009
|
+
bridge.toggleAttribute("aria-hidden", !visible);
|
|
1010
|
+
}
|
|
1011
|
+
function clearDiffUnchangedBridgeSourceClasses(container) {
|
|
1012
|
+
const bridgedCenters = container.querySelectorAll(".stream-monaco-unchanged-bridge-source");
|
|
1013
|
+
bridgedCenters.forEach((node) => node.classList.remove("stream-monaco-unchanged-bridge-source"));
|
|
1014
|
+
}
|
|
1015
|
+
function resetDiffUnchangedOverlayTransform(overlay) {
|
|
1016
|
+
if (!overlay) return;
|
|
1017
|
+
overlay.style.transform = "translate3d(0px, 0px, 0px)";
|
|
1018
|
+
}
|
|
1019
|
+
function resolveDiffUnchangedViewZoneHeight(unchangedRegionStyle) {
|
|
1020
|
+
return unchangedRegionStyle === "simple" ? 28 : 32;
|
|
1021
|
+
}
|
|
1022
|
+
function collectDiffUnchangedViewZoneIds(editorRoot, scrollTop) {
|
|
1023
|
+
const widgetTopValues = Array.from(editorRoot.querySelectorAll(".diff-hidden-lines-widget")).map((node) => Number.parseFloat(node.style.top || "NaN")).filter((value) => Number.isFinite(value) && value > -1e5);
|
|
1024
|
+
if (widgetTopValues.length === 0) return [];
|
|
1025
|
+
return Array.from(editorRoot.querySelectorAll(".view-zones > div[monaco-view-zone][monaco-visible-view-zone=\"true\"]")).filter((node) => {
|
|
1026
|
+
const zoneTop = Number.parseFloat(node.style.top || "NaN");
|
|
1027
|
+
const currentHeight = Number.parseFloat(node.style.height || "0");
|
|
1028
|
+
return Number.isFinite(zoneTop) && Number.isFinite(currentHeight) && currentHeight > 0 && widgetTopValues.some((widgetTop) => Math.abs(zoneTop - scrollTop - widgetTop) < .5);
|
|
1029
|
+
}).map((node) => node.getAttribute("monaco-view-zone")).filter((value) => Boolean(value));
|
|
1030
|
+
}
|
|
1031
|
+
function findDiffUnchangedActivationAction(...roots) {
|
|
1032
|
+
for (const root of roots) {
|
|
1033
|
+
const action = (root === null || root === void 0 ? void 0 : root.querySelector("a, button")) ?? null;
|
|
1034
|
+
if (action) return action;
|
|
1035
|
+
}
|
|
1036
|
+
return null;
|
|
1037
|
+
}
|
|
1038
|
+
function findDiffUnchangedExpandAction(root) {
|
|
1039
|
+
return (root === null || root === void 0 ? void 0 : root.querySelector("a")) ?? null;
|
|
1040
|
+
}
|
|
1041
|
+
function shouldIgnoreDiffUnchangedCenterClickTarget(target) {
|
|
1042
|
+
return target instanceof HTMLElement && Boolean(target.closest("a, .breadcrumb-item"));
|
|
1043
|
+
}
|
|
1044
|
+
function shouldHandleDiffUnchangedCenterClick(event) {
|
|
1045
|
+
return event.button === 0 && !shouldIgnoreDiffUnchangedCenterClickTarget(event.target);
|
|
1046
|
+
}
|
|
1047
|
+
function activateDiffUnchangedExpandAction(root, onBeforeActivate) {
|
|
1048
|
+
const action = findDiffUnchangedExpandAction(root);
|
|
1049
|
+
if (!action) return false;
|
|
1050
|
+
onBeforeActivate === null || onBeforeActivate === void 0 || onBeforeActivate(action);
|
|
1051
|
+
action.click();
|
|
1052
|
+
return true;
|
|
1053
|
+
}
|
|
1054
|
+
function syncDiffUnchangedCenterNode(node, mergeRole) {
|
|
1055
|
+
node.classList.add("stream-monaco-clickable");
|
|
1056
|
+
node.title = "Click to expand all unmodified lines";
|
|
1057
|
+
node.classList.toggle("stream-monaco-unchanged-merged-secondary", mergeRole === "secondary");
|
|
1058
|
+
node.classList.toggle("stream-monaco-unchanged-merged-primary", mergeRole === "primary");
|
|
1059
|
+
}
|
|
1060
|
+
function syncDiffUnchangedMetaNode(metaNode, unchangedRegionStyle, summaryLabel) {
|
|
1061
|
+
const lastStyle = metaNode.dataset.style;
|
|
1062
|
+
const lastLabel = metaNode.dataset.label;
|
|
1063
|
+
if (lastStyle === unchangedRegionStyle && lastLabel === summaryLabel) return;
|
|
1064
|
+
metaNode.dataset.style = unchangedRegionStyle;
|
|
1065
|
+
metaNode.dataset.label = summaryLabel;
|
|
1066
|
+
metaNode.replaceChildren();
|
|
1067
|
+
metaNode.classList.toggle("stream-monaco-unchanged-meta-simple", unchangedRegionStyle === "simple");
|
|
1068
|
+
if (unchangedRegionStyle === "simple") {
|
|
1069
|
+
const simpleBar = document.createElement("span");
|
|
1070
|
+
simpleBar.className = "stream-monaco-unchanged-simple-bar";
|
|
1071
|
+
simpleBar.setAttribute("aria-hidden", "true");
|
|
1072
|
+
metaNode.append(simpleBar);
|
|
1073
|
+
return;
|
|
1074
|
+
}
|
|
1075
|
+
const label = document.createElement("span");
|
|
1076
|
+
label.className = unchangedRegionStyle === "metadata" ? "stream-monaco-unchanged-metadata-label" : "stream-monaco-unchanged-count";
|
|
1077
|
+
label.textContent = summaryLabel;
|
|
1078
|
+
metaNode.append(label);
|
|
1079
|
+
}
|
|
1080
|
+
function syncDiffUnchangedSummaryButton(summary, unchangedRegionStyle, summaryLabel) {
|
|
1081
|
+
summary.classList.remove(...diffUnchangedSummaryStyleClasses);
|
|
1082
|
+
summary.classList.add(`stream-monaco-unchanged-summary-${unchangedRegionStyle}`);
|
|
1083
|
+
const summaryInteractive = unchangedRegionStyle === "line-info" || unchangedRegionStyle === "line-info-basic";
|
|
1084
|
+
summary.disabled = !summaryInteractive;
|
|
1085
|
+
summary.tabIndex = summaryInteractive ? 0 : -1;
|
|
1086
|
+
if (summaryInteractive) {
|
|
1087
|
+
summary.removeAttribute("aria-hidden");
|
|
1088
|
+
summary.setAttribute("aria-label", `${summaryLabel}. Expand all unmodified lines`);
|
|
1089
|
+
summary.title = "Expand all unmodified lines";
|
|
1090
|
+
return;
|
|
1091
|
+
}
|
|
1092
|
+
if (unchangedRegionStyle === "simple") {
|
|
1093
|
+
summary.setAttribute("aria-hidden", "true");
|
|
1094
|
+
summary.removeAttribute("aria-label");
|
|
1095
|
+
summary.title = "";
|
|
1096
|
+
return;
|
|
1097
|
+
}
|
|
1098
|
+
summary.removeAttribute("aria-hidden");
|
|
1099
|
+
summary.removeAttribute("aria-label");
|
|
1100
|
+
summary.title = "";
|
|
1101
|
+
}
|
|
1102
|
+
function syncDiffUnchangedExpandAction(action, hidden) {
|
|
1103
|
+
action.classList.add("stream-monaco-unchanged-expand");
|
|
1104
|
+
action.dataset.streamMonacoLabel = "Expand all";
|
|
1105
|
+
action.title = "Expand all unmodified lines";
|
|
1106
|
+
action.setAttribute("aria-label", "Expand all unmodified lines");
|
|
1107
|
+
action.toggleAttribute("aria-hidden", hidden);
|
|
1108
|
+
action.tabIndex = hidden ? -1 : 0;
|
|
1109
|
+
}
|
|
1110
|
+
function createDiffUnchangedRevealButton(direction) {
|
|
1111
|
+
const button = document.createElement("button");
|
|
1112
|
+
button.type = "button";
|
|
1113
|
+
button.className = "stream-monaco-unchanged-reveal";
|
|
1114
|
+
button.innerHTML = `<span class="codicon codicon-chevron-${direction}"></span>`;
|
|
1115
|
+
button.dataset.direction = direction;
|
|
1116
|
+
return button;
|
|
1117
|
+
}
|
|
1118
|
+
function syncDiffUnchangedRevealButtonNode(button, handle, label) {
|
|
1119
|
+
button.hidden = !handle;
|
|
1120
|
+
button.disabled = !handle;
|
|
1121
|
+
button.toggleAttribute("aria-hidden", !handle);
|
|
1122
|
+
button.title = handle ? label : "";
|
|
1123
|
+
button.setAttribute("aria-label", handle ? label : "");
|
|
1124
|
+
}
|
|
1125
|
+
function bindDiffUnchangedRevealButtonAction(button, handle, onActivate) {
|
|
1126
|
+
button.onclick = handle ? (event) => {
|
|
1127
|
+
event.preventDefault();
|
|
1128
|
+
event.stopPropagation();
|
|
1129
|
+
onActivate(handle);
|
|
1130
|
+
} : null;
|
|
1131
|
+
}
|
|
1132
|
+
function shouldHandleDiffUnchangedWheel(event) {
|
|
1133
|
+
return Math.abs(event.deltaY) >= .5 || Math.abs(event.deltaX) >= .5;
|
|
1134
|
+
}
|
|
1135
|
+
function resolveDiffUnchangedWheelScrollTarget(scrollTop, scrollLeft, event) {
|
|
1136
|
+
return {
|
|
1137
|
+
targetScrollTop: scrollTop + event.deltaY,
|
|
1138
|
+
targetScrollLeft: scrollLeft + event.deltaX,
|
|
1139
|
+
syncHorizontal: Math.abs(event.deltaX) >= .5
|
|
1140
|
+
};
|
|
1141
|
+
}
|
|
1142
|
+
function syncDiffUnchangedBridgeNode(options) {
|
|
1143
|
+
const { bridge, bridgeLeftInset, bridgeRailWidth, containerRect, containerScrollLeft, containerScrollTop, editorBackgroundColor, primaryAnchorRect, primaryStyle, secondaryAnchorRect, unchangedRegionStyle } = options;
|
|
1144
|
+
bridge.className = "stream-monaco-diff-unchanged-bridge";
|
|
1145
|
+
bridge.classList.add(`stream-monaco-diff-unchanged-bridge-${unchangedRegionStyle}`);
|
|
1146
|
+
bridge.style.left = `${secondaryAnchorRect.left - containerRect.left + containerScrollLeft + bridgeLeftInset}px`;
|
|
1147
|
+
bridge.style.top = `${primaryAnchorRect.top - containerRect.top + containerScrollTop}px`;
|
|
1148
|
+
bridge.style.width = `${Math.max(0, primaryAnchorRect.right - secondaryAnchorRect.left - bridgeLeftInset)}px`;
|
|
1149
|
+
bridge.style.height = `${Math.max(secondaryAnchorRect.height, primaryAnchorRect.height)}px`;
|
|
1150
|
+
bridge.style.color = primaryStyle.color;
|
|
1151
|
+
bridge.style.fontFamily = primaryStyle.fontFamily;
|
|
1152
|
+
bridge.style.fontSize = primaryStyle.fontSize;
|
|
1153
|
+
bridge.style.lineHeight = primaryStyle.lineHeight;
|
|
1154
|
+
bridge.style.setProperty("--stream-monaco-unchanged-fg", primaryStyle.color);
|
|
1155
|
+
bridge.style.setProperty("--stream-monaco-editor-bg", editorBackgroundColor);
|
|
1156
|
+
bridge.style.setProperty("--stream-monaco-unchanged-split-offset", `${Math.max(0, secondaryAnchorRect.width - bridgeLeftInset)}px`);
|
|
1157
|
+
if (bridgeRailWidth) {
|
|
1158
|
+
bridge.style.setProperty("--stream-monaco-unchanged-rail-width", `${bridgeRailWidth}px`);
|
|
1159
|
+
return;
|
|
1160
|
+
}
|
|
1161
|
+
bridge.style.removeProperty("--stream-monaco-unchanged-rail-width");
|
|
1162
|
+
}
|
|
1163
|
+
function syncDiffUnchangedRailNode(rail, showTopHandle, showBottomHandle) {
|
|
1164
|
+
const shouldRenderRail = showTopHandle || showBottomHandle;
|
|
1165
|
+
rail.hidden = !shouldRenderRail;
|
|
1166
|
+
rail.toggleAttribute("aria-hidden", !shouldRenderRail);
|
|
1167
|
+
rail.classList.toggle("stream-monaco-unchanged-rail-top-only", showTopHandle && !showBottomHandle);
|
|
1168
|
+
rail.classList.toggle("stream-monaco-unchanged-rail-bottom-only", !showTopHandle && showBottomHandle);
|
|
1169
|
+
rail.classList.toggle("stream-monaco-unchanged-rail-both", showTopHandle && showBottomHandle);
|
|
1170
|
+
}
|
|
1171
|
+
function dispatchSyntheticPrimaryMouseDown(node) {
|
|
1172
|
+
const view = node.ownerDocument.defaultView;
|
|
1173
|
+
if (!view) return;
|
|
1174
|
+
const rect = node.getBoundingClientRect();
|
|
1175
|
+
node.dispatchEvent(new view.MouseEvent("mousedown", {
|
|
1176
|
+
bubbles: true,
|
|
1177
|
+
cancelable: true,
|
|
1178
|
+
button: 0,
|
|
1179
|
+
clientX: rect.left + rect.width / 2,
|
|
1180
|
+
clientY: rect.top + rect.height / 2
|
|
1181
|
+
}));
|
|
1182
|
+
}
|
|
1183
|
+
function dispatchSyntheticPrimaryMouseTap(node) {
|
|
1184
|
+
const view = node.ownerDocument.defaultView;
|
|
1185
|
+
if (!view) return;
|
|
1186
|
+
const rect = node.getBoundingClientRect();
|
|
1187
|
+
const clientX = rect.left + rect.width / 2;
|
|
1188
|
+
const clientY = rect.top + rect.height / 2;
|
|
1189
|
+
node.dispatchEvent(new view.MouseEvent("mousedown", {
|
|
1190
|
+
bubbles: true,
|
|
1191
|
+
cancelable: true,
|
|
1192
|
+
button: 0,
|
|
1193
|
+
clientX,
|
|
1194
|
+
clientY
|
|
1195
|
+
}));
|
|
1196
|
+
node.dispatchEvent(new view.MouseEvent("mouseup", {
|
|
1197
|
+
bubbles: true,
|
|
1198
|
+
cancelable: true,
|
|
1199
|
+
button: 0,
|
|
1200
|
+
clientX,
|
|
1201
|
+
clientY
|
|
1202
|
+
}));
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
//#endregion
|
|
1206
|
+
//#region src/core/diffViewport.ts
|
|
1207
|
+
function computeDiffRawHeight({ diffEditorView, maxHeightValue }) {
|
|
1208
|
+
var _originalEditor$getMo, _modifiedEditor$getMo, _originalEditor$getSc, _modifiedEditor$getSc;
|
|
1209
|
+
if (!diffEditorView) return Math.min(18 + padding, maxHeightValue);
|
|
1210
|
+
const modifiedEditor = diffEditorView.getModifiedEditor();
|
|
1211
|
+
const originalEditor = diffEditorView.getOriginalEditor();
|
|
1212
|
+
const lineHeight = modifiedEditor.getOption(monaco_shim_exports.editor.EditorOption.lineHeight);
|
|
1213
|
+
const originalLineCount = ((_originalEditor$getMo = originalEditor.getModel()) === null || _originalEditor$getMo === void 0 ? void 0 : _originalEditor$getMo.getLineCount()) ?? 1;
|
|
1214
|
+
const modifiedLineCount = ((_modifiedEditor$getMo = modifiedEditor.getModel()) === null || _modifiedEditor$getMo === void 0 ? void 0 : _modifiedEditor$getMo.getLineCount()) ?? 1;
|
|
1215
|
+
const lineCount = Math.max(originalLineCount, modifiedLineCount);
|
|
1216
|
+
const fromLines = lineCount * lineHeight + padding;
|
|
1217
|
+
const scrollHeight = Math.max(((_originalEditor$getSc = originalEditor.getScrollHeight) === null || _originalEditor$getSc === void 0 ? void 0 : _originalEditor$getSc.call(originalEditor)) ?? 0, ((_modifiedEditor$getSc = modifiedEditor.getScrollHeight) === null || _modifiedEditor$getSc === void 0 ? void 0 : _modifiedEditor$getSc.call(modifiedEditor)) ?? 0);
|
|
1218
|
+
return Math.min(Math.max(fromLines, scrollHeight), maxHeightValue);
|
|
1219
|
+
}
|
|
1220
|
+
function computeDiffHeight({ inlineDiffStreamingHeightFloor, inlineDiffStreamingPresentationActive, isInlineMode, rawHeight }) {
|
|
1221
|
+
if (!isInlineMode || !inlineDiffStreamingPresentationActive && inlineDiffStreamingHeightFloor <= 0) return {
|
|
1222
|
+
height: rawHeight,
|
|
1223
|
+
nextInlineDiffStreamingHeightFloor: inlineDiffStreamingHeightFloor
|
|
1224
|
+
};
|
|
1225
|
+
const nextInlineDiffStreamingHeightFloor = Math.max(rawHeight, inlineDiffStreamingHeightFloor);
|
|
1226
|
+
return {
|
|
1227
|
+
height: nextInlineDiffStreamingHeightFloor,
|
|
1228
|
+
nextInlineDiffStreamingHeightFloor
|
|
1229
|
+
};
|
|
1230
|
+
}
|
|
1231
|
+
function readContainerLayoutSize(container) {
|
|
1232
|
+
var _container$getBoundin;
|
|
1233
|
+
const rect = (_container$getBoundin = container.getBoundingClientRect) === null || _container$getBoundin === void 0 ? void 0 : _container$getBoundin.call(container);
|
|
1234
|
+
return {
|
|
1235
|
+
width: container.clientWidth || (rect === null || rect === void 0 ? void 0 : rect.width) || 0,
|
|
1236
|
+
height: container.clientHeight || (rect === null || rect === void 0 ? void 0 : rect.height) || 0
|
|
1237
|
+
};
|
|
1238
|
+
}
|
|
1239
|
+
function hasVerticalScrollbar(measurement) {
|
|
1240
|
+
const epsilon = Math.max(2, Math.round(measurement.lineHeight / 8));
|
|
1241
|
+
return measurement.scrollHeight > measurement.computedHeight + Math.max(padding / 2, epsilon);
|
|
1242
|
+
}
|
|
1243
|
+
function isUserNearBottom(measurement, options) {
|
|
1244
|
+
const lineThreshold = options.autoScrollThresholdLines * measurement.lineHeight;
|
|
1245
|
+
const threshold = Math.max(lineThreshold || 0, options.autoScrollThresholdPx);
|
|
1246
|
+
const distance = measurement.scrollHeight - (measurement.scrollTop + measurement.viewportHeight);
|
|
1247
|
+
return distance <= threshold;
|
|
1248
|
+
}
|
|
1249
|
+
function revealEditorLine(editor, line, strategy, scrollType) {
|
|
1250
|
+
if (strategy === "bottom") {
|
|
1251
|
+
if (typeof scrollType !== "undefined") editor.revealLine(line, scrollType);
|
|
1252
|
+
else editor.revealLine(line);
|
|
1253
|
+
return;
|
|
1254
|
+
}
|
|
1255
|
+
if (strategy === "center") {
|
|
1256
|
+
if (typeof scrollType !== "undefined") editor.revealLineInCenter(line, scrollType);
|
|
1257
|
+
else editor.revealLineInCenter(line);
|
|
1258
|
+
return;
|
|
1259
|
+
}
|
|
1260
|
+
if (typeof scrollType !== "undefined") editor.revealLineInCenterIfOutsideViewport(line, scrollType);
|
|
1261
|
+
else editor.revealLineInCenterIfOutsideViewport(line);
|
|
1262
|
+
}
|
|
1263
|
+
function waitForElementHeightApplied(element, target, timeoutMs = 500) {
|
|
1264
|
+
return new Promise((resolve) => {
|
|
1265
|
+
const start = typeof performance !== "undefined" && performance.now ? performance.now() : Date.now();
|
|
1266
|
+
const check = () => {
|
|
1267
|
+
const applied = element ? Number.parseFloat((element.style.height || "").replace("px", "")) || 0 : -1;
|
|
1268
|
+
if (applied >= target - 1) {
|
|
1269
|
+
resolve();
|
|
1270
|
+
return;
|
|
1271
|
+
}
|
|
1272
|
+
const now = typeof performance !== "undefined" && performance.now ? performance.now() : Date.now();
|
|
1273
|
+
if (now - start > timeoutMs) {
|
|
1274
|
+
resolve();
|
|
1275
|
+
return;
|
|
1276
|
+
}
|
|
1277
|
+
requestAnimationFrame(check);
|
|
1278
|
+
};
|
|
1279
|
+
check();
|
|
1280
|
+
});
|
|
1281
|
+
}
|
|
1282
|
+
|
|
475
1283
|
//#endregion
|
|
476
1284
|
//#region src/core/DiffEditorManager.ts
|
|
477
1285
|
var DiffEditorManager = class DiffEditorManager {
|
|
@@ -495,6 +1303,8 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
495
1303
|
lastKnownModifiedCode = null;
|
|
496
1304
|
lastKnownModifiedLineCount = null;
|
|
497
1305
|
pendingDiffUpdate = null;
|
|
1306
|
+
minimalEditMaxCharsValue = minimalEditMaxChars;
|
|
1307
|
+
minimalEditMaxChangeRatioValue = minimalEditMaxChangeRatio;
|
|
498
1308
|
shouldAutoScrollDiff = true;
|
|
499
1309
|
diffScrollWatcher = null;
|
|
500
1310
|
lastScrollTopDiff = 0;
|
|
@@ -503,6 +1313,7 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
503
1313
|
cachedLineHeightDiff = null;
|
|
504
1314
|
cachedComputedHeightDiff = null;
|
|
505
1315
|
lastKnownModifiedDirty = false;
|
|
1316
|
+
programmaticModifiedContentChangeDepth = 0;
|
|
506
1317
|
measureViewportDiff() {
|
|
507
1318
|
var _me$getLayoutInfo, _me$getScrollTop, _me$getScrollHeight;
|
|
508
1319
|
if (!this.diffEditorView) return null;
|
|
@@ -642,6 +1453,8 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
642
1453
|
this.diffAutoScroll = diffAutoScroll;
|
|
643
1454
|
this.revealDebounceMsOption = revealDebounceMsOption;
|
|
644
1455
|
this.diffUpdateThrottleMsOption = diffUpdateThrottleMsOption;
|
|
1456
|
+
this.minimalEditMaxCharsValue = this.options.minimalEditMaxChars ?? minimalEditMaxChars;
|
|
1457
|
+
this.minimalEditMaxChangeRatioValue = this.options.minimalEditMaxChangeRatio ?? minimalEditMaxChangeRatio;
|
|
645
1458
|
}
|
|
646
1459
|
resolveDiffHideUnchangedRegionsOption() {
|
|
647
1460
|
const normalize = (value) => {
|
|
@@ -682,188 +1495,21 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
682
1495
|
if (typeof explicitThrottle === "number") return explicitThrottle;
|
|
683
1496
|
return 50;
|
|
684
1497
|
}
|
|
685
|
-
parseCssColorRgb(color) {
|
|
686
|
-
const normalized = color.trim().toLowerCase();
|
|
687
|
-
const rgbMatch = normalized.match(/^rgba?\(\s*([+\-.\d]+)\s*,\s*([+\-.\d]+)\s*,\s*([+\-.\d]+)/);
|
|
688
|
-
if (rgbMatch) return [
|
|
689
|
-
Number.parseFloat(rgbMatch[1]),
|
|
690
|
-
Number.parseFloat(rgbMatch[2]),
|
|
691
|
-
Number.parseFloat(rgbMatch[3])
|
|
692
|
-
];
|
|
693
|
-
const hexMatch = normalized.match(/^#([\da-f]{3,8})$/i);
|
|
694
|
-
if (!hexMatch) return null;
|
|
695
|
-
const hex = hexMatch[1];
|
|
696
|
-
if (hex.length === 3 || hex.length === 4) return [
|
|
697
|
-
Number.parseInt(`${hex[0]}${hex[0]}`, 16),
|
|
698
|
-
Number.parseInt(`${hex[1]}${hex[1]}`, 16),
|
|
699
|
-
Number.parseInt(`${hex[2]}${hex[2]}`, 16)
|
|
700
|
-
];
|
|
701
|
-
if (hex.length === 6 || hex.length === 8) return [
|
|
702
|
-
Number.parseInt(hex.slice(0, 2), 16),
|
|
703
|
-
Number.parseInt(hex.slice(2, 4), 16),
|
|
704
|
-
Number.parseInt(hex.slice(4, 6), 16)
|
|
705
|
-
];
|
|
706
|
-
return null;
|
|
707
|
-
}
|
|
708
|
-
resolveCssColorLuminance(color) {
|
|
709
|
-
const rgb = this.parseCssColorRgb(color);
|
|
710
|
-
if (!rgb) return null;
|
|
711
|
-
const channel = (value) => {
|
|
712
|
-
const normalized = Math.max(0, Math.min(255, value)) / 255;
|
|
713
|
-
return normalized <= .03928 ? normalized / 12.92 : ((normalized + .055) / 1.055) ** 2.4;
|
|
714
|
-
};
|
|
715
|
-
const [r, g, b] = rgb;
|
|
716
|
-
return .2126 * channel(r) + .7152 * channel(g) + .0722 * channel(b);
|
|
717
|
-
}
|
|
718
|
-
resolveDiffUnchangedLineInfoRailMetrics(node) {
|
|
719
|
-
const editorRoot = node.closest(".monaco-editor");
|
|
720
|
-
if (!editorRoot) return {
|
|
721
|
-
leftInset: 0,
|
|
722
|
-
width: null
|
|
723
|
-
};
|
|
724
|
-
const editorRect = editorRoot.getBoundingClientRect();
|
|
725
|
-
const lineNumberNode = Array.from(editorRoot.querySelectorAll(".line-numbers")).find((candidate) => {
|
|
726
|
-
const rect = candidate.getBoundingClientRect();
|
|
727
|
-
return rect.width > 0 && rect.height > 0;
|
|
728
|
-
});
|
|
729
|
-
if (!lineNumberNode) return {
|
|
730
|
-
leftInset: 0,
|
|
731
|
-
width: null
|
|
732
|
-
};
|
|
733
|
-
const lineNumberRect = lineNumberNode.getBoundingClientRect();
|
|
734
|
-
return {
|
|
735
|
-
leftInset: Math.max(0, lineNumberRect.left - editorRect.left),
|
|
736
|
-
width: Math.max(0, lineNumberRect.width) || null
|
|
737
|
-
};
|
|
738
|
-
}
|
|
739
|
-
looksLikeDarkThemeName(themeName) {
|
|
740
|
-
if (!themeName) return false;
|
|
741
|
-
const normalized = themeName.toLowerCase();
|
|
742
|
-
return [
|
|
743
|
-
"dark",
|
|
744
|
-
"night",
|
|
745
|
-
"moon",
|
|
746
|
-
"black",
|
|
747
|
-
"dracula",
|
|
748
|
-
"mocha",
|
|
749
|
-
"frappe",
|
|
750
|
-
"macchiato",
|
|
751
|
-
"palenight",
|
|
752
|
-
"ocean",
|
|
753
|
-
"poimandres",
|
|
754
|
-
"monokai",
|
|
755
|
-
"laserwave",
|
|
756
|
-
"tokyo",
|
|
757
|
-
"slack-dark",
|
|
758
|
-
"rose-pine",
|
|
759
|
-
"github-dark",
|
|
760
|
-
"material-theme",
|
|
761
|
-
"one-dark",
|
|
762
|
-
"catppuccin-mocha",
|
|
763
|
-
"catppuccin-frappe",
|
|
764
|
-
"catppuccin-macchiato"
|
|
765
|
-
].some((token) => normalized.includes(token)) && !normalized.includes("light") && !normalized.includes("latte") && !normalized.includes("dawn") && !normalized.includes("lotus");
|
|
766
|
-
}
|
|
767
|
-
looksLikeLightThemeName(themeName) {
|
|
768
|
-
if (!themeName) return false;
|
|
769
|
-
const normalized = themeName.toLowerCase();
|
|
770
|
-
return [
|
|
771
|
-
"light",
|
|
772
|
-
"day",
|
|
773
|
-
"dawn",
|
|
774
|
-
"latte",
|
|
775
|
-
"solarized-light",
|
|
776
|
-
"github-light",
|
|
777
|
-
"rose-pine-dawn",
|
|
778
|
-
"catppuccin-latte",
|
|
779
|
-
"one-light",
|
|
780
|
-
"vitesse-light",
|
|
781
|
-
"snazzy-light",
|
|
782
|
-
"material-lighter",
|
|
783
|
-
"material-theme-lighter",
|
|
784
|
-
"lotus"
|
|
785
|
-
].some((token) => normalized.includes(token));
|
|
786
|
-
}
|
|
787
|
-
resolveDiffAppearanceOption() {
|
|
788
|
-
var _this$diffEditorView, _this$diffEditorView$, _this$diffEditorView$2, _this$diffEditorView2, _this$diffEditorView3, _this$diffEditorView4;
|
|
789
|
-
if (this.options.diffAppearance === "light") return "light";
|
|
790
|
-
if (this.options.diffAppearance === "dark") return "dark";
|
|
791
|
-
if (this.looksLikeDarkThemeName(this.options.theme)) return "dark";
|
|
792
|
-
if (this.looksLikeLightThemeName(this.options.theme)) return "light";
|
|
793
|
-
const appearanceProbeNodes = [
|
|
794
|
-
(_this$diffEditorView = this.diffEditorView) === null || _this$diffEditorView === void 0 || (_this$diffEditorView$2 = (_this$diffEditorView$ = _this$diffEditorView.getModifiedEditor()).getContainerDomNode) === null || _this$diffEditorView$2 === void 0 ? void 0 : _this$diffEditorView$2.call(_this$diffEditorView$),
|
|
795
|
-
(_this$diffEditorView2 = this.diffEditorView) === null || _this$diffEditorView2 === void 0 || (_this$diffEditorView4 = (_this$diffEditorView3 = _this$diffEditorView2.getOriginalEditor()).getContainerDomNode) === null || _this$diffEditorView4 === void 0 ? void 0 : _this$diffEditorView4.call(_this$diffEditorView3),
|
|
796
|
-
this.lastContainer
|
|
797
|
-
];
|
|
798
|
-
for (const node of appearanceProbeNodes) {
|
|
799
|
-
if (!(node instanceof HTMLElement)) continue;
|
|
800
|
-
const style = globalThis.getComputedStyle(node);
|
|
801
|
-
const editorSurface = node.querySelector(".monaco-editor .monaco-editor-background, .monaco-editor .margin, .monaco-editor .lines-content");
|
|
802
|
-
const candidates = [
|
|
803
|
-
style.getPropertyValue("--stream-monaco-editor-bg"),
|
|
804
|
-
style.getPropertyValue("--vscode-editor-background"),
|
|
805
|
-
editorSurface ? globalThis.getComputedStyle(editorSurface).backgroundColor : "",
|
|
806
|
-
style.backgroundColor
|
|
807
|
-
];
|
|
808
|
-
for (const color of candidates) {
|
|
809
|
-
const luminance = this.resolveCssColorLuminance(color);
|
|
810
|
-
if (luminance == null) continue;
|
|
811
|
-
return luminance <= .42 ? "dark" : "light";
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
return this.looksLikeDarkThemeName(this.options.theme) ? "dark" : "light";
|
|
815
|
-
}
|
|
816
|
-
syncDiffRootThemeVariables(appearance) {
|
|
817
|
-
var _this$diffEditorView5, _this$diffEditorView6, _this$diffEditorView7, _this$diffEditorView8, _this$diffEditorView9, _this$diffEditorView10;
|
|
818
|
-
if (!(this.lastContainer instanceof HTMLElement)) return;
|
|
819
|
-
const probeNodes = [
|
|
820
|
-
(_this$diffEditorView5 = this.diffEditorView) === null || _this$diffEditorView5 === void 0 || (_this$diffEditorView7 = (_this$diffEditorView6 = _this$diffEditorView5.getModifiedEditor()).getContainerDomNode) === null || _this$diffEditorView7 === void 0 ? void 0 : _this$diffEditorView7.call(_this$diffEditorView6),
|
|
821
|
-
(_this$diffEditorView8 = this.diffEditorView) === null || _this$diffEditorView8 === void 0 || (_this$diffEditorView10 = (_this$diffEditorView9 = _this$diffEditorView8.getOriginalEditor()).getContainerDomNode) === null || _this$diffEditorView10 === void 0 ? void 0 : _this$diffEditorView10.call(_this$diffEditorView9),
|
|
822
|
-
this.lastContainer
|
|
823
|
-
];
|
|
824
|
-
const containerStyle = globalThis.getComputedStyle(this.lastContainer);
|
|
825
|
-
const fixedBackgroundColor = containerStyle.getPropertyValue("--stream-monaco-fixed-editor-bg").trim() || null;
|
|
826
|
-
let backgroundColor = null;
|
|
827
|
-
let foregroundColor = null;
|
|
828
|
-
for (const node of probeNodes) {
|
|
829
|
-
if (!(node instanceof HTMLElement)) continue;
|
|
830
|
-
const backgroundProbe = node.querySelector(".monaco-editor-background, .margin, .lines-content") ?? node;
|
|
831
|
-
const foregroundProbe = node.querySelector(".view-lines, .monaco-editor, .view-overlays") ?? node;
|
|
832
|
-
const nextBackground = globalThis.getComputedStyle(backgroundProbe).backgroundColor;
|
|
833
|
-
if (!backgroundColor && this.resolveCssColorLuminance(nextBackground) != null) backgroundColor = nextBackground;
|
|
834
|
-
const nextForeground = globalThis.getComputedStyle(foregroundProbe).color;
|
|
835
|
-
if (!foregroundColor && this.resolveCssColorLuminance(nextForeground) != null) foregroundColor = nextForeground;
|
|
836
|
-
if (backgroundColor && foregroundColor) break;
|
|
837
|
-
}
|
|
838
|
-
const resolvedBackgroundColor = fixedBackgroundColor || backgroundColor || (appearance === "dark" ? "rgb(10 10 11)" : "rgb(255 255 255)");
|
|
839
|
-
if (resolvedBackgroundColor) this.lastContainer.style.setProperty("--stream-monaco-editor-bg", resolvedBackgroundColor);
|
|
840
|
-
else this.lastContainer.style.removeProperty("--stream-monaco-editor-bg");
|
|
841
|
-
if (foregroundColor) this.lastContainer.style.setProperty("--stream-monaco-editor-fg", foregroundColor);
|
|
842
|
-
else this.lastContainer.style.removeProperty("--stream-monaco-editor-fg");
|
|
843
|
-
}
|
|
844
1498
|
applyDiffRootAppearanceClass() {
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
].join("|");
|
|
860
|
-
if (this.diffRootAppearanceSignature === nextSignature && containerClassList.contains("stream-monaco-diff-root")) return;
|
|
861
|
-
containerClassList.add("stream-monaco-diff-root");
|
|
862
|
-
for (const className of DiffEditorManager.diffLineStyleClasses) containerClassList.toggle(className, className === activeLineStyleClass);
|
|
863
|
-
for (const className of DiffEditorManager.diffUnchangedRegionStyleClasses) containerClassList.toggle(className, className === activeUnchangedRegionStyleClass);
|
|
864
|
-
for (const className of DiffEditorManager.diffLayoutModeClasses) containerClassList.toggle(className, className === activeLayoutModeClass);
|
|
865
|
-
for (const className of DiffEditorManager.diffAppearanceClasses) containerClassList.toggle(className, className === activeAppearanceClass);
|
|
866
|
-
this.diffRootAppearanceSignature = nextSignature;
|
|
1499
|
+
this.diffRootAppearanceSignature = applyDiffRootAppearanceClass({
|
|
1500
|
+
container: this.lastContainer,
|
|
1501
|
+
diffEditorView: this.diffEditorView,
|
|
1502
|
+
diffAppearance: this.options.diffAppearance,
|
|
1503
|
+
themeName: this.options.theme ?? null,
|
|
1504
|
+
currentSignature: this.diffRootAppearanceSignature,
|
|
1505
|
+
lineStyle: this.resolveDiffLineStyleOption(),
|
|
1506
|
+
unchangedRegionStyle: this.resolveDiffUnchangedRegionStyleOption(),
|
|
1507
|
+
isInlineMode: this.isDiffInlineMode(),
|
|
1508
|
+
lineStyleClasses: DiffEditorManager.diffLineStyleClasses,
|
|
1509
|
+
unchangedRegionStyleClasses: DiffEditorManager.diffUnchangedRegionStyleClasses,
|
|
1510
|
+
layoutModeClasses: DiffEditorManager.diffLayoutModeClasses,
|
|
1511
|
+
appearanceClasses: DiffEditorManager.diffAppearanceClasses
|
|
1512
|
+
});
|
|
867
1513
|
}
|
|
868
1514
|
disposeDiffHunkInteractions() {
|
|
869
1515
|
if (this.diffHunkHideTimer != null) {
|
|
@@ -991,9 +1637,9 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
991
1637
|
});
|
|
992
1638
|
}
|
|
993
1639
|
clearFallbackDiffDecorations() {
|
|
994
|
-
var _this$
|
|
995
|
-
const originalEditor = (_this$
|
|
996
|
-
const modifiedEditor = (_this$
|
|
1640
|
+
var _this$diffEditorView, _this$diffEditorView2;
|
|
1641
|
+
const originalEditor = (_this$diffEditorView = this.diffEditorView) === null || _this$diffEditorView === void 0 ? void 0 : _this$diffEditorView.getOriginalEditor();
|
|
1642
|
+
const modifiedEditor = (_this$diffEditorView2 = this.diffEditorView) === null || _this$diffEditorView2 === void 0 ? void 0 : _this$diffEditorView2.getModifiedEditor();
|
|
997
1643
|
if (originalEditor && this.fallbackOriginalDecorationIds.length > 0) this.fallbackOriginalDecorationIds = originalEditor.deltaDecorations(this.fallbackOriginalDecorationIds, []);
|
|
998
1644
|
else this.fallbackOriginalDecorationIds = [];
|
|
999
1645
|
if (modifiedEditor && this.fallbackModifiedDecorationIds.length > 0) this.fallbackModifiedDecorationIds = modifiedEditor.deltaDecorations(this.fallbackModifiedDecorationIds, []);
|
|
@@ -1001,8 +1647,8 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
1001
1647
|
this.clearFallbackInlineDeletedZones();
|
|
1002
1648
|
}
|
|
1003
1649
|
clearFallbackInlineDeletedZones() {
|
|
1004
|
-
var _this$
|
|
1005
|
-
const modifiedEditor = (_this$
|
|
1650
|
+
var _this$diffEditorView3;
|
|
1651
|
+
const modifiedEditor = (_this$diffEditorView3 = this.diffEditorView) === null || _this$diffEditorView3 === void 0 ? void 0 : _this$diffEditorView3.getModifiedEditor();
|
|
1006
1652
|
if (modifiedEditor && this.fallbackInlineDeletedZoneIds.length > 0) try {
|
|
1007
1653
|
var _modifiedEditor$chang;
|
|
1008
1654
|
(_modifiedEditor$chang = modifiedEditor.changeViewZones) === null || _modifiedEditor$chang === void 0 || _modifiedEditor$chang.call(modifiedEditor, (accessor) => {
|
|
@@ -1031,8 +1677,7 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
1031
1677
|
}
|
|
1032
1678
|
syncDiffEditorLayoutToContainer() {
|
|
1033
1679
|
if (!this.diffEditorView || !this.lastContainer) return;
|
|
1034
|
-
const width
|
|
1035
|
-
const height = this.lastContainer.clientHeight || this.lastContainer.getBoundingClientRect().height;
|
|
1680
|
+
const { width, height } = readContainerLayoutSize(this.lastContainer);
|
|
1036
1681
|
if (!(width > 0) || !(height > 0)) return;
|
|
1037
1682
|
try {
|
|
1038
1683
|
var _layout, _ref;
|
|
@@ -1095,7 +1740,7 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
1095
1740
|
}
|
|
1096
1741
|
const lineHeightOption = (_EditorOption = monaco_shim_exports.editor.EditorOption) === null || _EditorOption === void 0 ? void 0 : _EditorOption.lineHeight;
|
|
1097
1742
|
const lineHeight = ((_modifiedEditor$getOp = modifiedEditor.getOption) === null || _modifiedEditor$getOp === void 0 ? void 0 : _modifiedEditor$getOp.call(modifiedEditor, lineHeightOption)) ?? 20;
|
|
1098
|
-
const relevantChanges = lineChanges.filter((change) =>
|
|
1743
|
+
const relevantChanges = lineChanges.filter((change) => hasOriginalLines(change));
|
|
1099
1744
|
const nativeViewWrappers = Array.from(((_this$lastContainer3 = this.lastContainer) === null || _this$lastContainer3 === void 0 || (_this$lastContainer3$ = _this$lastContainer3.querySelectorAll) === null || _this$lastContainer3$ === void 0 ? void 0 : _this$lastContainer3$.call(_this$lastContainer3, ".editor.modified .view-zones [monaco-view-zone]")) ?? []).filter((node) => {
|
|
1100
1745
|
return node instanceof HTMLElement && !!node.querySelector(".view-lines.line-delete");
|
|
1101
1746
|
});
|
|
@@ -1229,7 +1874,7 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
1229
1874
|
};
|
|
1230
1875
|
}
|
|
1231
1876
|
syncDiffPresentationDecorations() {
|
|
1232
|
-
var _this$diffEditorView
|
|
1877
|
+
var _this$diffEditorView$, _this$lastContainer$q, _this$lastContainer5;
|
|
1233
1878
|
if (!this.diffEditorView || !this.lastContainer) return;
|
|
1234
1879
|
const nativeFresh = this.hasFreshNativeDiffResult();
|
|
1235
1880
|
const useInlineMode = this.isDiffInlineMode();
|
|
@@ -1237,10 +1882,10 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
1237
1882
|
const nativeInlineDeleteZoneCount = useInlineMode ? this.countNativeInlineDeleteZoneNodes() : 0;
|
|
1238
1883
|
const hasNativeInlineDeleteZoneNodes = nativeInlineDeleteZoneCount > 0;
|
|
1239
1884
|
const hasNativeInlineDeleteNodes = useInlineMode && this.hasVisibleNativeInlineDeleteNodes();
|
|
1240
|
-
const shouldKeepInlineFallback = useInlineMode && lineChanges.some((change) =>
|
|
1885
|
+
const shouldKeepInlineFallback = useInlineMode && lineChanges.some((change) => hasOriginalLines(change)) && !hasNativeInlineDeleteZoneNodes;
|
|
1241
1886
|
const useInlineStaleFallback = shouldKeepInlineFallback;
|
|
1242
1887
|
this.lastContainer.classList.toggle("stream-monaco-diff-inline-native-ready", useInlineMode && !shouldKeepInlineFallback && (nativeFresh || hasNativeInlineDeleteNodes || hasNativeInlineDeleteZoneNodes));
|
|
1243
|
-
const keepNativeDecorationsWhileStale = !useInlineStaleFallback && !nativeFresh && this.preserveNativeDiffDecorationsOnStaleAppend && ((((_this$diffEditorView$
|
|
1888
|
+
const keepNativeDecorationsWhileStale = !useInlineStaleFallback && !nativeFresh && this.preserveNativeDiffDecorationsOnStaleAppend && ((((_this$diffEditorView$ = this.diffEditorView.getLineChanges()) === null || _this$diffEditorView$ === void 0 ? void 0 : _this$diffEditorView$.length) ?? 0) > 0 || !!((_this$lastContainer$q = (_this$lastContainer5 = this.lastContainer).querySelector) === null || _this$lastContainer$q === void 0 ? void 0 : _this$lastContainer$q.call(_this$lastContainer5, ".line-insert, .line-delete, .gutter-insert, .gutter-delete")));
|
|
1244
1889
|
this.lastContainer.classList.toggle("stream-monaco-diff-native-stale", !nativeFresh && !keepNativeDecorationsWhileStale);
|
|
1245
1890
|
if (nativeFresh && !shouldKeepInlineFallback) {
|
|
1246
1891
|
this.clearFallbackDiffDecorations();
|
|
@@ -2515,27 +3160,6 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
2515
3160
|
el.addEventListener(eventName, listener);
|
|
2516
3161
|
bucket.push({ dispose: () => el.removeEventListener(eventName, listener) });
|
|
2517
3162
|
}
|
|
2518
|
-
createDiffHunkActionNode(side) {
|
|
2519
|
-
const node = document.createElement("div");
|
|
2520
|
-
node.className = "stream-monaco-diff-hunk-actions";
|
|
2521
|
-
node.dataset.side = side;
|
|
2522
|
-
const createButton = (action, label) => {
|
|
2523
|
-
const button = document.createElement("button");
|
|
2524
|
-
button.type = "button";
|
|
2525
|
-
button.textContent = label;
|
|
2526
|
-
button.dataset.action = action;
|
|
2527
|
-
button.addEventListener("click", (event) => {
|
|
2528
|
-
event.preventDefault();
|
|
2529
|
-
event.stopPropagation();
|
|
2530
|
-
this.applyDiffHunkAction(side, action);
|
|
2531
|
-
});
|
|
2532
|
-
return button;
|
|
2533
|
-
};
|
|
2534
|
-
node.append(createButton("revert", "Revert"), createButton("stage", "Stage"));
|
|
2535
|
-
this.createDomDisposable(this.diffHunkDisposables, node, "mouseenter", () => this.cancelScheduledHideDiffHunkActions());
|
|
2536
|
-
this.createDomDisposable(this.diffHunkDisposables, node, "mouseleave", () => this.scheduleHideDiffHunkActions());
|
|
2537
|
-
return node;
|
|
2538
|
-
}
|
|
2539
3163
|
cloneSerializableValue(value) {
|
|
2540
3164
|
if (typeof structuredClone === "function") return structuredClone(value);
|
|
2541
3165
|
return JSON.parse(JSON.stringify(value));
|
|
@@ -2794,8 +3418,8 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
2794
3418
|
this.lastContainer.style.removeProperty("--stream-monaco-editor-fg");
|
|
2795
3419
|
}
|
|
2796
3420
|
this.withLockedDiffScrollPosition(() => {
|
|
2797
|
-
var _this$
|
|
2798
|
-
(_this$
|
|
3421
|
+
var _this$diffEditorView4;
|
|
3422
|
+
(_this$diffEditorView4 = this.diffEditorView) === null || _this$diffEditorView4 === void 0 || _this$diffEditorView4.updateOptions(presentationOptions);
|
|
2799
3423
|
});
|
|
2800
3424
|
(_this$diffHeightManag = this.diffHeightManager) === null || _this$diffHeightManag === void 0 || _this$diffHeightManag.update();
|
|
2801
3425
|
this.applyDiffRootAppearanceClass();
|
|
@@ -2817,8 +3441,8 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
2817
3441
|
if (!this.diffHideUnchangedRegionsDeferred) return;
|
|
2818
3442
|
this.diffHideUnchangedRegionsDeferred = false;
|
|
2819
3443
|
this.withLockedDiffScrollPosition(() => {
|
|
2820
|
-
var _this$
|
|
2821
|
-
(_this$
|
|
3444
|
+
var _this$diffEditorView5;
|
|
3445
|
+
(_this$diffEditorView5 = this.diffEditorView) === null || _this$diffEditorView5 === void 0 || _this$diffEditorView5.updateOptions({ hideUnchangedRegions });
|
|
2822
3446
|
});
|
|
2823
3447
|
this.schedulePatchDiffUnchangedRegionsAfterInteraction(1);
|
|
2824
3448
|
if (this.shouldAutoScrollDiff) {
|
|
@@ -2828,7 +3452,7 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
2828
3452
|
}
|
|
2829
3453
|
markDiffStreamingActivity() {
|
|
2830
3454
|
var _this$lastContainer6;
|
|
2831
|
-
(_this$lastContainer6 = this.lastContainer) === null || _this$lastContainer6 === void 0 || _this$lastContainer6.classList.remove("stream-monaco-diff-inline-native-ready");
|
|
3455
|
+
(_this$lastContainer6 = this.lastContainer) === null || _this$lastContainer6 === void 0 || (_this$lastContainer6 = _this$lastContainer6.classList) === null || _this$lastContainer6 === void 0 || _this$lastContainer6.remove("stream-monaco-diff-inline-native-ready");
|
|
2832
3456
|
if (this.isDiffInlineMode()) {
|
|
2833
3457
|
var _this$diffHeightManag2, _this$lastContainer7, _this$lastContainer7$;
|
|
2834
3458
|
this.inlineDiffStreamingPresentationActive = true;
|
|
@@ -2854,8 +3478,8 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
2854
3478
|
this.diffHideUnchangedRegionsDeferred = true;
|
|
2855
3479
|
this.hideAllDiffUnchangedBridgeEntries();
|
|
2856
3480
|
this.withLockedDiffScrollPosition(() => {
|
|
2857
|
-
var _this$
|
|
2858
|
-
(_this$
|
|
3481
|
+
var _this$diffEditorView6;
|
|
3482
|
+
(_this$diffEditorView6 = this.diffEditorView) === null || _this$diffEditorView6 === void 0 || _this$diffEditorView6.updateOptions({ hideUnchangedRegions: {
|
|
2859
3483
|
...hideUnchangedRegions,
|
|
2860
3484
|
enabled: false
|
|
2861
3485
|
} });
|
|
@@ -2929,7 +3553,7 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
2929
3553
|
var _this$diffUnchangedBr;
|
|
2930
3554
|
this.clearDiffUnchangedBridgeSources();
|
|
2931
3555
|
if (this.diffUnchangedBridgeOverlay) this.diffUnchangedBridgeOverlay.replaceChildren();
|
|
2932
|
-
|
|
3556
|
+
resetDiffUnchangedOverlayTransform(this.diffUnchangedBridgeOverlay);
|
|
2933
3557
|
this.diffUnchangedBridgeEntries.clear();
|
|
2934
3558
|
this.diffUnchangedBridgePool.length = 0;
|
|
2935
3559
|
this.diffUnchangedOverlayScrollTop = 0;
|
|
@@ -2939,30 +3563,27 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
2939
3563
|
}
|
|
2940
3564
|
clearDiffUnchangedBridgeSources() {
|
|
2941
3565
|
if (!this.lastContainer) return;
|
|
2942
|
-
|
|
2943
|
-
bridgedCenters.forEach((node) => node.classList.remove("stream-monaco-unchanged-bridge-source"));
|
|
3566
|
+
clearDiffUnchangedBridgeSourceClasses(this.lastContainer);
|
|
2944
3567
|
}
|
|
2945
3568
|
ensureDiffUnchangedBridgeOverlay() {
|
|
2946
3569
|
if (!this.lastContainer) return null;
|
|
2947
3570
|
if (!this.diffUnchangedBridgeOverlay) {
|
|
2948
|
-
const overlay =
|
|
2949
|
-
overlay.className = "stream-monaco-diff-unchanged-overlay";
|
|
3571
|
+
const overlay = createDiffUnchangedBridgeOverlay();
|
|
2950
3572
|
this.lastContainer.append(overlay);
|
|
2951
3573
|
this.diffUnchangedBridgeOverlay = overlay;
|
|
2952
3574
|
}
|
|
2953
3575
|
return this.diffUnchangedBridgeOverlay;
|
|
2954
3576
|
}
|
|
2955
3577
|
readDiffUnchangedOverlayScrollState() {
|
|
2956
|
-
var _this$
|
|
2957
|
-
const modifiedEditor = (_this$
|
|
3578
|
+
var _this$diffEditorView7, _modifiedEditor$getSc6, _modifiedEditor$getSc7;
|
|
3579
|
+
const modifiedEditor = (_this$diffEditorView7 = this.diffEditorView) === null || _this$diffEditorView7 === void 0 ? void 0 : _this$diffEditorView7.getModifiedEditor();
|
|
2958
3580
|
return {
|
|
2959
3581
|
top: (modifiedEditor === null || modifiedEditor === void 0 || (_modifiedEditor$getSc6 = modifiedEditor.getScrollTop) === null || _modifiedEditor$getSc6 === void 0 ? void 0 : _modifiedEditor$getSc6.call(modifiedEditor)) ?? 0,
|
|
2960
3582
|
left: (modifiedEditor === null || modifiedEditor === void 0 || (_modifiedEditor$getSc7 = modifiedEditor.getScrollLeft) === null || _modifiedEditor$getSc7 === void 0 ? void 0 : _modifiedEditor$getSc7.call(modifiedEditor)) ?? 0
|
|
2961
3583
|
};
|
|
2962
3584
|
}
|
|
2963
3585
|
syncDiffUnchangedOverlayScrollBaseline() {
|
|
2964
|
-
|
|
2965
|
-
if (overlay) overlay.style.transform = "translate3d(0px, 0px, 0px)";
|
|
3586
|
+
resetDiffUnchangedOverlayTransform(this.diffUnchangedBridgeOverlay);
|
|
2966
3587
|
const { top, left } = this.readDiffUnchangedOverlayScrollState();
|
|
2967
3588
|
this.diffUnchangedOverlayScrollTop = top;
|
|
2968
3589
|
this.diffUnchangedOverlayScrollLeft = left;
|
|
@@ -2976,28 +3597,10 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
2976
3597
|
if (Math.abs(deltaY) < .5 && Math.abs(deltaX) < .5) return;
|
|
2977
3598
|
overlay.style.transform = `translate3d(${deltaX}px, ${deltaY}px, 0px)`;
|
|
2978
3599
|
}
|
|
2979
|
-
resolveDiffUnchangedViewZoneHeight() {
|
|
2980
|
-
switch (this.resolveDiffUnchangedRegionStyleOption()) {
|
|
2981
|
-
case "line-info":
|
|
2982
|
-
case "line-info-basic":
|
|
2983
|
-
case "metadata": return 32;
|
|
2984
|
-
case "simple": return 28;
|
|
2985
|
-
default: return 32;
|
|
2986
|
-
}
|
|
2987
|
-
}
|
|
2988
|
-
collectDiffUnchangedViewZoneIds(editorRoot, scrollTop) {
|
|
2989
|
-
const widgetTopValues = Array.from(editorRoot.querySelectorAll(".diff-hidden-lines-widget")).map((node) => Number.parseFloat(node.style.top || "NaN")).filter((value) => Number.isFinite(value) && value > -1e5);
|
|
2990
|
-
if (widgetTopValues.length === 0) return [];
|
|
2991
|
-
return Array.from(editorRoot.querySelectorAll(".view-zones > div[monaco-view-zone][monaco-visible-view-zone=\"true\"]")).filter((node) => {
|
|
2992
|
-
const zoneTop = Number.parseFloat(node.style.top || "NaN");
|
|
2993
|
-
const currentHeight = Number.parseFloat(node.style.height || "0");
|
|
2994
|
-
return Number.isFinite(zoneTop) && Number.isFinite(currentHeight) && currentHeight > 0 && widgetTopValues.some((widgetTop) => Math.abs(zoneTop - scrollTop - widgetTop) < .5);
|
|
2995
|
-
}).map((node) => node.getAttribute("monaco-view-zone")).filter((value) => Boolean(value));
|
|
2996
|
-
}
|
|
2997
3600
|
syncDiffUnchangedViewZoneHeightsForEditor(editor, editorRoot, targetHeight) {
|
|
2998
3601
|
var _editor$getScrollTop, _editorInternal$_mode;
|
|
2999
3602
|
if (!editor || !(editorRoot instanceof HTMLElement)) return false;
|
|
3000
|
-
const zoneIds =
|
|
3603
|
+
const zoneIds = collectDiffUnchangedViewZoneIds(editorRoot, ((_editor$getScrollTop = editor.getScrollTop) === null || _editor$getScrollTop === void 0 ? void 0 : _editor$getScrollTop.call(editor)) ?? 0);
|
|
3001
3604
|
if (zoneIds.length === 0) return false;
|
|
3002
3605
|
const editorInternal = editor;
|
|
3003
3606
|
const zones = (_editorInternal$_mode = editorInternal._modelData) === null || _editorInternal$_mode === void 0 || (_editorInternal$_mode = _editorInternal$_mode.view) === null || _editorInternal$_mode === void 0 || (_editorInternal$_mode = _editorInternal$_mode._viewZones) === null || _editorInternal$_mode === void 0 ? void 0 : _editorInternal$_mode._zones;
|
|
@@ -3022,7 +3625,7 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
3022
3625
|
syncDiffUnchangedViewZoneHeights() {
|
|
3023
3626
|
var _originalEditor$getCo, _modifiedEditor$getCo3;
|
|
3024
3627
|
if (!this.diffEditorView) return false;
|
|
3025
|
-
const targetHeight = this.
|
|
3628
|
+
const targetHeight = resolveDiffUnchangedViewZoneHeight(this.resolveDiffUnchangedRegionStyleOption());
|
|
3026
3629
|
const originalEditor = this.diffEditorView.getOriginalEditor();
|
|
3027
3630
|
const modifiedEditor = this.diffEditorView.getModifiedEditor();
|
|
3028
3631
|
const originalChanged = this.syncDiffUnchangedViewZoneHeightsForEditor(originalEditor, (_originalEditor$getCo = originalEditor.getContainerDomNode) === null || _originalEditor$getCo === void 0 ? void 0 : _originalEditor$getCo.call(originalEditor), targetHeight);
|
|
@@ -3040,19 +3643,7 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
3040
3643
|
return `${this.getDiffUnchangedNodeId(secondaryNode)}:${this.getDiffUnchangedNodeId(primaryNode)}`;
|
|
3041
3644
|
}
|
|
3042
3645
|
createDiffUnchangedBridgeEntry(key) {
|
|
3043
|
-
const bridge =
|
|
3044
|
-
bridge.className = "stream-monaco-diff-unchanged-bridge";
|
|
3045
|
-
bridge.setAttribute("role", "group");
|
|
3046
|
-
bridge.hidden = true;
|
|
3047
|
-
const summary = document.createElement("button");
|
|
3048
|
-
summary.type = "button";
|
|
3049
|
-
summary.className = "stream-monaco-unchanged-summary";
|
|
3050
|
-
const visualMeta = document.createElement("div");
|
|
3051
|
-
visualMeta.className = "stream-monaco-unchanged-meta";
|
|
3052
|
-
summary.append(visualMeta);
|
|
3053
|
-
const divider = document.createElement("span");
|
|
3054
|
-
divider.className = "stream-monaco-unchanged-pane-divider";
|
|
3055
|
-
divider.setAttribute("aria-hidden", "true");
|
|
3646
|
+
const { bridge, summary, visualMeta, divider } = createDiffUnchangedBridgeScaffold();
|
|
3056
3647
|
const entry = {
|
|
3057
3648
|
key,
|
|
3058
3649
|
bridge,
|
|
@@ -3071,16 +3662,15 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
3071
3662
|
const onWheel = (event) => {
|
|
3072
3663
|
var _modifiedEditor$getSc8, _modifiedEditor$getSc9, _originalEditor$setSc6, _modifiedEditor$setSc6;
|
|
3073
3664
|
if (!this.diffEditorView) return;
|
|
3074
|
-
if (
|
|
3665
|
+
if (!shouldHandleDiffUnchangedWheel(event)) return;
|
|
3075
3666
|
event.preventDefault();
|
|
3076
3667
|
event.stopPropagation();
|
|
3077
3668
|
const originalEditor = this.diffEditorView.getOriginalEditor();
|
|
3078
3669
|
const modifiedEditor = this.diffEditorView.getModifiedEditor();
|
|
3079
|
-
const targetScrollTop = (((_modifiedEditor$getSc8 = modifiedEditor.getScrollTop) === null || _modifiedEditor$getSc8 === void 0 ? void 0 : _modifiedEditor$getSc8.call(modifiedEditor)) ?? 0)
|
|
3080
|
-
const targetScrollLeft = (((_modifiedEditor$getSc9 = modifiedEditor.getScrollLeft) === null || _modifiedEditor$getSc9 === void 0 ? void 0 : _modifiedEditor$getSc9.call(modifiedEditor)) ?? 0) + event.deltaX;
|
|
3670
|
+
const { syncHorizontal, targetScrollLeft, targetScrollTop } = resolveDiffUnchangedWheelScrollTarget(((_modifiedEditor$getSc8 = modifiedEditor.getScrollTop) === null || _modifiedEditor$getSc8 === void 0 ? void 0 : _modifiedEditor$getSc8.call(modifiedEditor)) ?? 0, ((_modifiedEditor$getSc9 = modifiedEditor.getScrollLeft) === null || _modifiedEditor$getSc9 === void 0 ? void 0 : _modifiedEditor$getSc9.call(modifiedEditor)) ?? 0, event);
|
|
3081
3671
|
(_originalEditor$setSc6 = originalEditor.setScrollTop) === null || _originalEditor$setSc6 === void 0 || _originalEditor$setSc6.call(originalEditor, targetScrollTop);
|
|
3082
3672
|
(_modifiedEditor$setSc6 = modifiedEditor.setScrollTop) === null || _modifiedEditor$setSc6 === void 0 || _modifiedEditor$setSc6.call(modifiedEditor, targetScrollTop);
|
|
3083
|
-
if (
|
|
3673
|
+
if (syncHorizontal) {
|
|
3084
3674
|
var _originalEditor$setSc7, _modifiedEditor$setSc7;
|
|
3085
3675
|
(_originalEditor$setSc7 = originalEditor.setScrollLeft) === null || _originalEditor$setSc7 === void 0 || _originalEditor$setSc7.call(originalEditor, targetScrollLeft);
|
|
3086
3676
|
(_modifiedEditor$setSc7 = modifiedEditor.setScrollLeft) === null || _modifiedEditor$setSc7 === void 0 || _modifiedEditor$setSc7.call(modifiedEditor, targetScrollLeft);
|
|
@@ -3089,7 +3679,6 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
3089
3679
|
};
|
|
3090
3680
|
bridge.addEventListener("wheel", onWheel, { passive: false });
|
|
3091
3681
|
this.diffUnchangedRegionDisposables.push({ dispose: () => bridge.removeEventListener("wheel", onWheel) });
|
|
3092
|
-
bridge.append(summary, divider);
|
|
3093
3682
|
return entry;
|
|
3094
3683
|
}
|
|
3095
3684
|
acquireDiffUnchangedBridgeEntry(key) {
|
|
@@ -3097,16 +3686,14 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
3097
3686
|
if (existing) return existing;
|
|
3098
3687
|
const entry = this.diffUnchangedBridgePool.pop() ?? this.createDiffUnchangedBridgeEntry(key);
|
|
3099
3688
|
entry.key = key;
|
|
3100
|
-
entry.bridge
|
|
3101
|
-
entry.bridge.removeAttribute("aria-hidden");
|
|
3689
|
+
syncDiffUnchangedBridgeVisibility(entry.bridge, true);
|
|
3102
3690
|
this.diffUnchangedBridgeEntries.set(key, entry);
|
|
3103
3691
|
return entry;
|
|
3104
3692
|
}
|
|
3105
3693
|
releaseDiffUnchangedBridgeEntry(entry) {
|
|
3106
3694
|
if (entry.key) this.diffUnchangedBridgeEntries.delete(entry.key);
|
|
3107
3695
|
entry.key = null;
|
|
3108
|
-
entry.bridge
|
|
3109
|
-
entry.bridge.setAttribute("aria-hidden", "true");
|
|
3696
|
+
syncDiffUnchangedBridgeVisibility(entry.bridge, false);
|
|
3110
3697
|
this.diffUnchangedBridgePool.push(entry);
|
|
3111
3698
|
}
|
|
3112
3699
|
hideAllDiffUnchangedBridgeEntries() {
|
|
@@ -3132,51 +3719,15 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
3132
3719
|
entry.activate();
|
|
3133
3720
|
this.schedulePatchDiffUnchangedRegionsAfterInteraction();
|
|
3134
3721
|
}
|
|
3135
|
-
updateDiffUnchangedBridgeMeta(entry, unchangedRegionStyle, summaryLabel) {
|
|
3136
|
-
this.updateDiffUnchangedMetaNode(entry.visualMeta, unchangedRegionStyle, summaryLabel);
|
|
3137
|
-
}
|
|
3138
|
-
updateDiffUnchangedMetaNode(metaNode, unchangedRegionStyle, summaryLabel) {
|
|
3139
|
-
const lastStyle = metaNode.dataset.style;
|
|
3140
|
-
const lastLabel = metaNode.dataset.label;
|
|
3141
|
-
if (lastStyle === unchangedRegionStyle && lastLabel === summaryLabel) return;
|
|
3142
|
-
metaNode.dataset.style = unchangedRegionStyle;
|
|
3143
|
-
metaNode.dataset.label = summaryLabel;
|
|
3144
|
-
metaNode.replaceChildren();
|
|
3145
|
-
metaNode.classList.toggle("stream-monaco-unchanged-meta-simple", unchangedRegionStyle === "simple");
|
|
3146
|
-
if (unchangedRegionStyle === "simple") {
|
|
3147
|
-
const simpleBar = document.createElement("span");
|
|
3148
|
-
simpleBar.className = "stream-monaco-unchanged-simple-bar";
|
|
3149
|
-
simpleBar.setAttribute("aria-hidden", "true");
|
|
3150
|
-
metaNode.append(simpleBar);
|
|
3151
|
-
return;
|
|
3152
|
-
}
|
|
3153
|
-
const label = document.createElement("span");
|
|
3154
|
-
if (unchangedRegionStyle === "metadata") label.className = "stream-monaco-unchanged-metadata-label";
|
|
3155
|
-
else label.className = "stream-monaco-unchanged-count";
|
|
3156
|
-
label.textContent = summaryLabel;
|
|
3157
|
-
metaNode.append(label);
|
|
3158
|
-
}
|
|
3159
3722
|
syncDiffUnchangedRevealButton(entry, slot, handle, direction, label) {
|
|
3160
3723
|
const existingButton = entry[slot];
|
|
3161
|
-
const button = existingButton ??
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
button.className = "stream-monaco-unchanged-reveal";
|
|
3165
|
-
button.innerHTML = `<span class="codicon codicon-chevron-${direction}"></span>`;
|
|
3166
|
-
}
|
|
3167
|
-
button.dataset.direction = direction;
|
|
3168
|
-
button.hidden = !handle;
|
|
3169
|
-
button.disabled = !handle;
|
|
3170
|
-
button.toggleAttribute("aria-hidden", !handle);
|
|
3171
|
-
button.title = handle ? label : "";
|
|
3172
|
-
button.setAttribute("aria-label", handle ? label : "");
|
|
3173
|
-
button.onclick = handle ? (event) => {
|
|
3174
|
-
event.preventDefault();
|
|
3175
|
-
event.stopPropagation();
|
|
3724
|
+
const button = existingButton ?? createDiffUnchangedRevealButton(direction);
|
|
3725
|
+
syncDiffUnchangedRevealButtonNode(button, handle, label);
|
|
3726
|
+
bindDiffUnchangedRevealButtonAction(button, handle, (nextHandle) => {
|
|
3176
3727
|
this.hideAllDiffUnchangedBridgeEntries();
|
|
3177
|
-
this.activateDiffUnchangedHandle(
|
|
3728
|
+
this.activateDiffUnchangedHandle(nextHandle);
|
|
3178
3729
|
this.schedulePatchDiffUnchangedRegionsAfterInteraction();
|
|
3179
|
-
}
|
|
3730
|
+
});
|
|
3180
3731
|
entry[slot] = button;
|
|
3181
3732
|
}
|
|
3182
3733
|
syncDiffUnchangedBridgeRail(entry, showTopHandle, topHandle, showBottomHandle, bottomHandle) {
|
|
@@ -3184,14 +3735,9 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
3184
3735
|
entry.rail = document.createElement("div");
|
|
3185
3736
|
entry.rail.className = "stream-monaco-unchanged-rail";
|
|
3186
3737
|
}
|
|
3187
|
-
const shouldRenderRail = showTopHandle || showBottomHandle;
|
|
3188
3738
|
this.syncDiffUnchangedRevealButton(entry, "topButton", showTopHandle ? topHandle : null, "down", "Reveal more unmodified lines below");
|
|
3189
3739
|
this.syncDiffUnchangedRevealButton(entry, "bottomButton", showBottomHandle ? bottomHandle : null, "up", "Reveal more unmodified lines above");
|
|
3190
|
-
entry.rail
|
|
3191
|
-
entry.rail.toggleAttribute("aria-hidden", !shouldRenderRail);
|
|
3192
|
-
entry.rail.classList.toggle("stream-monaco-unchanged-rail-top-only", showTopHandle && !showBottomHandle);
|
|
3193
|
-
entry.rail.classList.toggle("stream-monaco-unchanged-rail-bottom-only", !showTopHandle && showBottomHandle);
|
|
3194
|
-
entry.rail.classList.toggle("stream-monaco-unchanged-rail-both", showTopHandle && showBottomHandle);
|
|
3740
|
+
syncDiffUnchangedRailNode(entry.rail, showTopHandle, showBottomHandle);
|
|
3195
3741
|
if (entry.topButton && entry.topButton.parentElement !== entry.rail) entry.rail.append(entry.topButton);
|
|
3196
3742
|
if (entry.bottomButton && entry.bottomButton.parentElement !== entry.rail) entry.rail.append(entry.bottomButton);
|
|
3197
3743
|
}
|
|
@@ -3201,201 +3747,46 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
3201
3747
|
this.releaseDiffUnchangedBridgeEntry(entry);
|
|
3202
3748
|
}
|
|
3203
3749
|
}
|
|
3204
|
-
dispatchSyntheticMouseDown(node) {
|
|
3205
|
-
const view = node.ownerDocument.defaultView;
|
|
3206
|
-
if (!view) return;
|
|
3207
|
-
const rect = node.getBoundingClientRect();
|
|
3208
|
-
node.dispatchEvent(new view.MouseEvent("mousedown", {
|
|
3209
|
-
bubbles: true,
|
|
3210
|
-
cancelable: true,
|
|
3211
|
-
button: 0,
|
|
3212
|
-
clientX: rect.left + rect.width / 2,
|
|
3213
|
-
clientY: rect.top + rect.height / 2
|
|
3214
|
-
}));
|
|
3215
|
-
}
|
|
3216
|
-
dispatchSyntheticMouseTap(node) {
|
|
3217
|
-
const view = node.ownerDocument.defaultView;
|
|
3218
|
-
if (!view) return;
|
|
3219
|
-
const rect = node.getBoundingClientRect();
|
|
3220
|
-
const clientX = rect.left + rect.width / 2;
|
|
3221
|
-
const clientY = rect.top + rect.height / 2;
|
|
3222
|
-
node.dispatchEvent(new view.MouseEvent("mousedown", {
|
|
3223
|
-
bubbles: true,
|
|
3224
|
-
cancelable: true,
|
|
3225
|
-
button: 0,
|
|
3226
|
-
clientX,
|
|
3227
|
-
clientY
|
|
3228
|
-
}));
|
|
3229
|
-
node.dispatchEvent(new view.MouseEvent("mouseup", {
|
|
3230
|
-
bubbles: true,
|
|
3231
|
-
cancelable: true,
|
|
3232
|
-
button: 0,
|
|
3233
|
-
clientX,
|
|
3234
|
-
clientY
|
|
3235
|
-
}));
|
|
3236
|
-
}
|
|
3237
|
-
formatDiffUnchangedCountLabel(text) {
|
|
3238
|
-
const match = text.match(/\d+/);
|
|
3239
|
-
const count = match ? Number.parseInt(match[0], 10) : NaN;
|
|
3240
|
-
if (Number.isFinite(count)) return `${count} unmodified ${count === 1 ? "line" : "lines"}`;
|
|
3241
|
-
return text.replace(/hidden/gi, "unmodified");
|
|
3242
|
-
}
|
|
3243
|
-
countDiffLines(startLineNumber, endLineNumber) {
|
|
3244
|
-
return endLineNumber >= startLineNumber ? endLineNumber - startLineNumber + 1 : 0;
|
|
3245
|
-
}
|
|
3246
|
-
measureDiffUnchangedSurroundingLines(primaryNode) {
|
|
3247
|
-
const editorRoot = primaryNode.closest(".editor.modified") ?? primaryNode.closest(".monaco-editor");
|
|
3248
|
-
if (!editorRoot) return {
|
|
3249
|
-
previousVisibleLine: null,
|
|
3250
|
-
nextVisibleLine: null
|
|
3251
|
-
};
|
|
3252
|
-
const widgetRect = primaryNode.getBoundingClientRect();
|
|
3253
|
-
let previousVisibleLine = null;
|
|
3254
|
-
let nextVisibleLine = null;
|
|
3255
|
-
const lineNumberNodes = editorRoot.querySelectorAll(".line-numbers");
|
|
3256
|
-
lineNumberNodes.forEach((node) => {
|
|
3257
|
-
var _node$textContent3;
|
|
3258
|
-
const lineNumber = Number.parseInt(((_node$textContent3 = node.textContent) === null || _node$textContent3 === void 0 ? void 0 : _node$textContent3.trim()) || "", 10);
|
|
3259
|
-
if (!Number.isFinite(lineNumber)) return;
|
|
3260
|
-
const top = node.getBoundingClientRect().top;
|
|
3261
|
-
if (top < widgetRect.top - 1) previousVisibleLine = previousVisibleLine == null ? lineNumber : Math.max(previousVisibleLine, lineNumber);
|
|
3262
|
-
else if (top > widgetRect.bottom + 1) nextVisibleLine = nextVisibleLine == null ? lineNumber : Math.min(nextVisibleLine, lineNumber);
|
|
3263
|
-
});
|
|
3264
|
-
return {
|
|
3265
|
-
previousVisibleLine,
|
|
3266
|
-
nextVisibleLine
|
|
3267
|
-
};
|
|
3268
|
-
}
|
|
3269
|
-
formatDiffMetadataRange(startLineNumber, lineCount) {
|
|
3270
|
-
return `${startLineNumber},${Math.max(0, lineCount)}`;
|
|
3271
|
-
}
|
|
3272
|
-
buildDiffHunkMetadataLabel(change) {
|
|
3273
|
-
var _this$originalModel, _this$modifiedModel2;
|
|
3274
|
-
const contextLineCount = this.resolveDiffHideUnchangedRegionsOption().contextLineCount ?? 3;
|
|
3275
|
-
const originalTotalLines = ((_this$originalModel = this.originalModel) === null || _this$originalModel === void 0 ? void 0 : _this$originalModel.getLineCount()) ?? 0;
|
|
3276
|
-
const modifiedTotalLines = ((_this$modifiedModel2 = this.modifiedModel) === null || _this$modifiedModel2 === void 0 ? void 0 : _this$modifiedModel2.getLineCount()) ?? 0;
|
|
3277
|
-
const originalChangedCount = this.countDiffLines(change.originalStartLineNumber, change.originalEndLineNumber);
|
|
3278
|
-
const modifiedChangedCount = this.countDiffLines(change.modifiedStartLineNumber, change.modifiedEndLineNumber);
|
|
3279
|
-
const originalAnchor = Math.min(Math.max(change.originalStartLineNumber, 1), Math.max(1, originalTotalLines + 1));
|
|
3280
|
-
const modifiedAnchor = Math.min(Math.max(change.modifiedStartLineNumber, 1), Math.max(1, modifiedTotalLines + 1));
|
|
3281
|
-
const originalStart = Math.max(1, originalAnchor - contextLineCount);
|
|
3282
|
-
const modifiedStart = Math.max(1, modifiedAnchor - contextLineCount);
|
|
3283
|
-
const originalEnd = originalChangedCount > 0 ? Math.min(originalTotalLines, change.originalEndLineNumber + contextLineCount) : Math.min(originalTotalLines, originalAnchor + contextLineCount - 1);
|
|
3284
|
-
const modifiedEnd = modifiedChangedCount > 0 ? Math.min(modifiedTotalLines, change.modifiedEndLineNumber + contextLineCount) : Math.min(modifiedTotalLines, modifiedAnchor + contextLineCount - 1);
|
|
3285
|
-
const originalDisplayCount = originalEnd >= originalStart ? originalEnd - originalStart + 1 : 0;
|
|
3286
|
-
const modifiedDisplayCount = modifiedEnd >= modifiedStart ? modifiedEnd - modifiedStart + 1 : 0;
|
|
3287
|
-
return {
|
|
3288
|
-
modifiedStart,
|
|
3289
|
-
originalStart,
|
|
3290
|
-
label: `@@ -${this.formatDiffMetadataRange(originalStart, originalDisplayCount)} +${this.formatDiffMetadataRange(modifiedStart, modifiedDisplayCount)} @@`
|
|
3291
|
-
};
|
|
3292
|
-
}
|
|
3293
|
-
resolveDiffMetadataLabel(primaryNode, pairIndex) {
|
|
3294
|
-
var _metadataEntries$Math;
|
|
3295
|
-
const lineChanges = this.getEffectiveLineChanges();
|
|
3296
|
-
if (lineChanges.length === 0) return null;
|
|
3297
|
-
const metadataEntries = lineChanges.map((change) => this.buildDiffHunkMetadataLabel(change));
|
|
3298
|
-
const { nextVisibleLine } = this.measureDiffUnchangedSurroundingLines(primaryNode);
|
|
3299
|
-
if (nextVisibleLine != null) {
|
|
3300
|
-
const candidateStarts = [nextVisibleLine, nextVisibleLine - 1].filter((value) => value >= 1);
|
|
3301
|
-
for (const candidateStart of candidateStarts) {
|
|
3302
|
-
const matching = metadataEntries.find((entry) => entry.modifiedStart === candidateStart);
|
|
3303
|
-
if (matching) return matching.label;
|
|
3304
|
-
}
|
|
3305
|
-
}
|
|
3306
|
-
return ((_metadataEntries$Math = metadataEntries[Math.min(pairIndex, metadataEntries.length - 1)]) === null || _metadataEntries$Math === void 0 ? void 0 : _metadataEntries$Math.label) ?? null;
|
|
3307
|
-
}
|
|
3308
3750
|
activateDiffUnchangedHandle(node) {
|
|
3309
3751
|
if (!(node instanceof HTMLElement)) return;
|
|
3310
|
-
|
|
3752
|
+
dispatchSyntheticPrimaryMouseTap(node);
|
|
3311
3753
|
this.scheduleCapturePersistedDiffUnchangedState(1);
|
|
3312
3754
|
}
|
|
3313
|
-
resolveDiffUnchangedRevealLayout(primaryNode, countText, pairIndex, pairCount) {
|
|
3314
|
-
var _this$diffEditorView18, _this$diffEditorView19;
|
|
3315
|
-
let showTopHandle = pairCount === 1 || pairIndex > 0;
|
|
3316
|
-
let showBottomHandle = pairCount === 1 || pairIndex < pairCount - 1;
|
|
3317
|
-
const countMatch = countText.match(/\d+/);
|
|
3318
|
-
const hiddenCount = countMatch ? Number.parseInt(countMatch[0], 10) : NaN;
|
|
3319
|
-
if (!Number.isFinite(hiddenCount)) return {
|
|
3320
|
-
showTopHandle,
|
|
3321
|
-
showBottomHandle
|
|
3322
|
-
};
|
|
3323
|
-
const { previousVisibleLine, nextVisibleLine } = this.measureDiffUnchangedSurroundingLines(primaryNode);
|
|
3324
|
-
if (previousVisibleLine == null && nextVisibleLine != null) {
|
|
3325
|
-
showTopHandle = false;
|
|
3326
|
-
showBottomHandle = true;
|
|
3327
|
-
return {
|
|
3328
|
-
showTopHandle,
|
|
3329
|
-
showBottomHandle
|
|
3330
|
-
};
|
|
3331
|
-
}
|
|
3332
|
-
if (nextVisibleLine == null && previousVisibleLine != null) {
|
|
3333
|
-
showTopHandle = true;
|
|
3334
|
-
showBottomHandle = false;
|
|
3335
|
-
return {
|
|
3336
|
-
showTopHandle,
|
|
3337
|
-
showBottomHandle
|
|
3338
|
-
};
|
|
3339
|
-
}
|
|
3340
|
-
if (nextVisibleLine != null && nextVisibleLine - hiddenCount === 1) {
|
|
3341
|
-
showTopHandle = false;
|
|
3342
|
-
showBottomHandle = true;
|
|
3343
|
-
}
|
|
3344
|
-
const modelLineCount = ((_this$diffEditorView18 = this.diffEditorView) === null || _this$diffEditorView18 === void 0 || (_this$diffEditorView18 = _this$diffEditorView18.getModifiedEditor().getModel()) === null || _this$diffEditorView18 === void 0 || (_this$diffEditorView19 = _this$diffEditorView18.getLineCount) === null || _this$diffEditorView19 === void 0 ? void 0 : _this$diffEditorView19.call(_this$diffEditorView18)) ?? null;
|
|
3345
|
-
if (previousVisibleLine != null && modelLineCount != null && previousVisibleLine + hiddenCount === modelLineCount) {
|
|
3346
|
-
showTopHandle = true;
|
|
3347
|
-
showBottomHandle = false;
|
|
3348
|
-
}
|
|
3349
|
-
return {
|
|
3350
|
-
showTopHandle,
|
|
3351
|
-
showBottomHandle
|
|
3352
|
-
};
|
|
3353
|
-
}
|
|
3354
|
-
resolveDiffUnchangedMergeRole(node) {
|
|
3355
|
-
var _this$diffEditorView20, _this$diffEditorView21, _this$diffEditorView22, _this$diffEditorView23, _this$diffEditorView24, _this$diffEditorView25;
|
|
3356
|
-
const diffRoot = node.closest(".monaco-diff-editor.side-by-side");
|
|
3357
|
-
if (!(diffRoot instanceof HTMLElement)) return "none";
|
|
3358
|
-
const nodeRect = node.getBoundingClientRect();
|
|
3359
|
-
const nodeCenter = nodeRect.left + nodeRect.width / 2;
|
|
3360
|
-
const originalHost = (_this$diffEditorView20 = this.diffEditorView) === null || _this$diffEditorView20 === void 0 || (_this$diffEditorView22 = (_this$diffEditorView21 = _this$diffEditorView20.getOriginalEditor()).getContainerDomNode) === null || _this$diffEditorView22 === void 0 ? void 0 : _this$diffEditorView22.call(_this$diffEditorView21);
|
|
3361
|
-
const modifiedHost = (_this$diffEditorView23 = this.diffEditorView) === null || _this$diffEditorView23 === void 0 || (_this$diffEditorView25 = (_this$diffEditorView24 = _this$diffEditorView23.getModifiedEditor()).getContainerDomNode) === null || _this$diffEditorView25 === void 0 ? void 0 : _this$diffEditorView25.call(_this$diffEditorView24);
|
|
3362
|
-
if (originalHost instanceof HTMLElement && modifiedHost instanceof HTMLElement) {
|
|
3363
|
-
const originalRect = originalHost.getBoundingClientRect();
|
|
3364
|
-
const modifiedRect = modifiedHost.getBoundingClientRect();
|
|
3365
|
-
const originalCenter = originalRect.left + originalRect.width / 2;
|
|
3366
|
-
const modifiedCenter = modifiedRect.left + modifiedRect.width / 2;
|
|
3367
|
-
return Math.abs(nodeCenter - originalCenter) <= Math.abs(nodeCenter - modifiedCenter) ? "secondary" : "primary";
|
|
3368
|
-
}
|
|
3369
|
-
const diffRect = diffRoot.getBoundingClientRect();
|
|
3370
|
-
return nodeCenter < diffRect.left + diffRect.width / 2 ? "secondary" : "primary";
|
|
3371
|
-
}
|
|
3372
3755
|
patchDiffUnchangedCenter(node, pairIndex = 0) {
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3756
|
+
var _this$diffEditorView8, _this$diffEditorView9, _this$diffEditorView10, _this$diffEditorView11, _this$diffEditorView12, _this$diffEditorView13;
|
|
3757
|
+
const mergeRole = resolveDiffUnchangedMergeRole({
|
|
3758
|
+
node,
|
|
3759
|
+
diffRoot: node.closest(".monaco-diff-editor.side-by-side"),
|
|
3760
|
+
originalHost: (_this$diffEditorView8 = this.diffEditorView) === null || _this$diffEditorView8 === void 0 || (_this$diffEditorView10 = (_this$diffEditorView9 = _this$diffEditorView8.getOriginalEditor()).getContainerDomNode) === null || _this$diffEditorView10 === void 0 ? void 0 : _this$diffEditorView10.call(_this$diffEditorView9),
|
|
3761
|
+
modifiedHost: (_this$diffEditorView11 = this.diffEditorView) === null || _this$diffEditorView11 === void 0 || (_this$diffEditorView13 = (_this$diffEditorView12 = _this$diffEditorView11.getModifiedEditor()).getContainerDomNode) === null || _this$diffEditorView13 === void 0 ? void 0 : _this$diffEditorView13.call(_this$diffEditorView12)
|
|
3762
|
+
});
|
|
3376
3763
|
const shouldUseMergedSecondary = mergeRole === "secondary";
|
|
3377
3764
|
const unchangedRegionStyle = this.resolveDiffUnchangedRegionStyleOption();
|
|
3378
|
-
node
|
|
3379
|
-
node.classList.toggle("stream-monaco-unchanged-merged-primary", mergeRole === "primary");
|
|
3765
|
+
syncDiffUnchangedCenterNode(node, mergeRole);
|
|
3380
3766
|
const primary = node.children.item(0);
|
|
3381
3767
|
const meta = node.children.item(1);
|
|
3382
3768
|
if (primary instanceof HTMLElement) primary.classList.add("stream-monaco-unchanged-primary");
|
|
3383
3769
|
if (meta instanceof HTMLElement) {
|
|
3384
|
-
var _countSource$textCont;
|
|
3770
|
+
var _countSource$textCont, _this$originalModel, _this$modifiedModel2;
|
|
3385
3771
|
meta.classList.add("stream-monaco-unchanged-meta");
|
|
3386
3772
|
const countSource = meta.querySelector(".count") ?? meta.firstElementChild;
|
|
3387
|
-
const countText =
|
|
3388
|
-
const
|
|
3389
|
-
|
|
3773
|
+
const countText = formatDiffUnchangedCountLabel((countSource === null || countSource === void 0 || (_countSource$textCont = countSource.textContent) === null || _countSource$textCont === void 0 ? void 0 : _countSource$textCont.trim()) || "Unmodified lines");
|
|
3774
|
+
const contextLineCount = this.resolveDiffHideUnchangedRegionsOption().contextLineCount ?? 3;
|
|
3775
|
+
const summaryLabel = resolveDiffUnchangedSummaryLabel({
|
|
3776
|
+
countText,
|
|
3777
|
+
unchangedRegionStyle,
|
|
3778
|
+
lineChanges: this.getEffectiveLineChanges(),
|
|
3779
|
+
pairIndex,
|
|
3780
|
+
primaryNode: node,
|
|
3781
|
+
contextLineCount,
|
|
3782
|
+
originalTotalLines: ((_this$originalModel = this.originalModel) === null || _this$originalModel === void 0 ? void 0 : _this$originalModel.getLineCount()) ?? 0,
|
|
3783
|
+
modifiedTotalLines: ((_this$modifiedModel2 = this.modifiedModel) === null || _this$modifiedModel2 === void 0 ? void 0 : _this$modifiedModel2.getLineCount()) ?? 0
|
|
3784
|
+
});
|
|
3785
|
+
syncDiffUnchangedMetaNode(meta, unchangedRegionStyle, summaryLabel);
|
|
3390
3786
|
}
|
|
3391
|
-
const action = node
|
|
3787
|
+
const action = findDiffUnchangedExpandAction(node);
|
|
3392
3788
|
if (action instanceof HTMLElement) {
|
|
3393
|
-
action
|
|
3394
|
-
action.dataset.streamMonacoLabel = "Expand all";
|
|
3395
|
-
action.title = "Expand all unmodified lines";
|
|
3396
|
-
action.setAttribute("aria-label", "Expand all unmodified lines");
|
|
3397
|
-
action.toggleAttribute("aria-hidden", shouldUseMergedSecondary);
|
|
3398
|
-
action.tabIndex = shouldUseMergedSecondary ? -1 : 0;
|
|
3789
|
+
syncDiffUnchangedExpandAction(action, shouldUseMergedSecondary);
|
|
3399
3790
|
if (action.dataset.streamMonacoExpandPatched !== "true") {
|
|
3400
3791
|
action.dataset.streamMonacoExpandPatched = "true";
|
|
3401
3792
|
const handleCaptureExpand = () => {
|
|
@@ -3413,28 +3804,21 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
3413
3804
|
if (node.dataset.streamMonacoCenterPatched !== "true") {
|
|
3414
3805
|
node.dataset.streamMonacoCenterPatched = "true";
|
|
3415
3806
|
this.bindFocusWithinClass(this.diffUnchangedRegionDisposables, node, "stream-monaco-focus-within");
|
|
3416
|
-
const activate = () => {
|
|
3417
|
-
const action$1 = node.querySelector("a");
|
|
3418
|
-
if (action$1 instanceof HTMLElement) {
|
|
3419
|
-
this.capturePreviousDiffUnchangedState();
|
|
3420
|
-
action$1.click();
|
|
3421
|
-
}
|
|
3422
|
-
};
|
|
3423
3807
|
this.createDomDisposable(this.diffUnchangedRegionDisposables, node, "click", (event) => {
|
|
3424
3808
|
const mouseEvent = event;
|
|
3425
|
-
if (mouseEvent
|
|
3426
|
-
const target = event.target instanceof HTMLElement ? event.target : null;
|
|
3427
|
-
if (target === null || target === void 0 ? void 0 : target.closest("a, .breadcrumb-item")) return;
|
|
3809
|
+
if (!shouldHandleDiffUnchangedCenterClick(mouseEvent)) return;
|
|
3428
3810
|
event.preventDefault();
|
|
3429
3811
|
this.hideAllDiffUnchangedBridgeEntries();
|
|
3430
|
-
|
|
3812
|
+
if (!activateDiffUnchangedExpandAction(node, () => {
|
|
3813
|
+
this.capturePreviousDiffUnchangedState();
|
|
3814
|
+
})) return;
|
|
3431
3815
|
this.scheduleCapturePersistedDiffUnchangedState(1);
|
|
3432
3816
|
this.schedulePatchDiffUnchangedRegionsAfterInteraction();
|
|
3433
3817
|
});
|
|
3434
3818
|
}
|
|
3435
3819
|
}
|
|
3436
3820
|
renderMergedDiffUnchangedBridge(secondaryNode, primaryNode, pairIndex, pairCount) {
|
|
3437
|
-
var _countSource$textCont2, _secondaryNode$closes;
|
|
3821
|
+
var _countSource$textCont2, _this$originalModel2, _this$modifiedModel3, _this$diffEditorView14, _this$diffEditorView15, _secondaryNode$closes;
|
|
3438
3822
|
if (!this.lastContainer) return null;
|
|
3439
3823
|
const overlay = this.ensureDiffUnchangedBridgeOverlay();
|
|
3440
3824
|
if (!overlay) return null;
|
|
@@ -3443,9 +3827,19 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
3443
3827
|
const primaryRect = primaryNode.getBoundingClientRect();
|
|
3444
3828
|
const primaryStyle = globalThis.getComputedStyle(primaryNode);
|
|
3445
3829
|
const countSource = primaryNode.querySelector(".stream-monaco-unchanged-count") ?? secondaryNode.querySelector(".stream-monaco-unchanged-count");
|
|
3446
|
-
const countText =
|
|
3830
|
+
const countText = formatDiffUnchangedCountLabel((countSource === null || countSource === void 0 || (_countSource$textCont2 = countSource.textContent) === null || _countSource$textCont2 === void 0 ? void 0 : _countSource$textCont2.trim()) || "Unmodified lines");
|
|
3447
3831
|
const unchangedRegionStyle = this.resolveDiffUnchangedRegionStyleOption();
|
|
3448
|
-
const
|
|
3832
|
+
const contextLineCount = this.resolveDiffHideUnchangedRegionsOption().contextLineCount ?? 3;
|
|
3833
|
+
const summaryLabel = resolveDiffUnchangedSummaryLabel({
|
|
3834
|
+
countText,
|
|
3835
|
+
unchangedRegionStyle,
|
|
3836
|
+
lineChanges: this.getEffectiveLineChanges(),
|
|
3837
|
+
pairIndex,
|
|
3838
|
+
primaryNode,
|
|
3839
|
+
contextLineCount,
|
|
3840
|
+
originalTotalLines: ((_this$originalModel2 = this.originalModel) === null || _this$originalModel2 === void 0 ? void 0 : _this$originalModel2.getLineCount()) ?? 0,
|
|
3841
|
+
modifiedTotalLines: ((_this$modifiedModel3 = this.modifiedModel) === null || _this$modifiedModel3 === void 0 ? void 0 : _this$modifiedModel3.getLineCount()) ?? 0
|
|
3842
|
+
});
|
|
3449
3843
|
const editorSurface = primaryNode.closest(".monaco-editor") ?? primaryNode;
|
|
3450
3844
|
const editorSurfaceStyle = globalThis.getComputedStyle(editorSurface);
|
|
3451
3845
|
const primaryHidden = primaryNode.parentElement;
|
|
@@ -3454,7 +3848,13 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
3454
3848
|
const secondaryWidget = secondaryHidden === null || secondaryHidden === void 0 ? void 0 : secondaryHidden.parentElement;
|
|
3455
3849
|
const topHandle = (primaryHidden === null || primaryHidden === void 0 ? void 0 : primaryHidden.querySelector(".top")) ?? (secondaryHidden === null || secondaryHidden === void 0 ? void 0 : secondaryHidden.querySelector(".top"));
|
|
3456
3850
|
const bottomHandle = (primaryHidden === null || primaryHidden === void 0 ? void 0 : primaryHidden.querySelector(".bottom")) ?? (secondaryHidden === null || secondaryHidden === void 0 ? void 0 : secondaryHidden.querySelector(".bottom"));
|
|
3457
|
-
const { showTopHandle, showBottomHandle } =
|
|
3851
|
+
const { showTopHandle, showBottomHandle } = resolveDiffUnchangedRevealLayout({
|
|
3852
|
+
primaryNode,
|
|
3853
|
+
countText,
|
|
3854
|
+
pairIndex,
|
|
3855
|
+
pairCount,
|
|
3856
|
+
modelLineCount: ((_this$diffEditorView14 = this.diffEditorView) === null || _this$diffEditorView14 === void 0 || (_this$diffEditorView14 = _this$diffEditorView14.getModifiedEditor().getModel()) === null || _this$diffEditorView14 === void 0 || (_this$diffEditorView15 = _this$diffEditorView14.getLineCount) === null || _this$diffEditorView15 === void 0 ? void 0 : _this$diffEditorView15.call(_this$diffEditorView14)) ?? null
|
|
3857
|
+
});
|
|
3458
3858
|
const key = this.getDiffUnchangedBridgeKey(secondaryNode, primaryNode);
|
|
3459
3859
|
secondaryNode.classList.add("stream-monaco-unchanged-bridge-source");
|
|
3460
3860
|
primaryNode.classList.add("stream-monaco-unchanged-bridge-source");
|
|
@@ -3466,42 +3866,24 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
3466
3866
|
const primaryAnchorRect = (primaryWidget === null || primaryWidget === void 0 ? void 0 : primaryWidget.getBoundingClientRect()) ?? primaryRect;
|
|
3467
3867
|
const secondaryMargin = (_secondaryNode$closes = secondaryNode.closest(".monaco-editor")) === null || _secondaryNode$closes === void 0 ? void 0 : _secondaryNode$closes.querySelector(".margin");
|
|
3468
3868
|
const secondaryMarginRect = secondaryMargin === null || secondaryMargin === void 0 ? void 0 : secondaryMargin.getBoundingClientRect();
|
|
3469
|
-
const lineInfoRailMetrics = unchangedRegionStyle === "line-info" ?
|
|
3869
|
+
const lineInfoRailMetrics = unchangedRegionStyle === "line-info" ? resolveDiffUnchangedLineInfoRailMetrics(secondaryNode) : null;
|
|
3470
3870
|
const bridgeLeftInset = (lineInfoRailMetrics === null || lineInfoRailMetrics === void 0 ? void 0 : lineInfoRailMetrics.leftInset) ?? 0;
|
|
3471
3871
|
const bridgeRailWidth = (lineInfoRailMetrics === null || lineInfoRailMetrics === void 0 ? void 0 : lineInfoRailMetrics.width) ?? (secondaryMarginRect === null || secondaryMarginRect === void 0 ? void 0 : secondaryMarginRect.width) ?? null;
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
const summaryLabel = metadataLabel || countText;
|
|
3488
|
-
const summaryInteractive = unchangedRegionStyle === "line-info" || unchangedRegionStyle === "line-info-basic";
|
|
3489
|
-
summary.disabled = !summaryInteractive;
|
|
3490
|
-
summary.tabIndex = summaryInteractive ? 0 : -1;
|
|
3491
|
-
if (summaryInteractive) {
|
|
3492
|
-
summary.removeAttribute("aria-hidden");
|
|
3493
|
-
summary.setAttribute("aria-label", `${summaryLabel}. Expand all unmodified lines`);
|
|
3494
|
-
summary.title = "Expand all unmodified lines";
|
|
3495
|
-
} else if (unchangedRegionStyle === "simple") {
|
|
3496
|
-
summary.setAttribute("aria-hidden", "true");
|
|
3497
|
-
summary.removeAttribute("aria-label");
|
|
3498
|
-
summary.title = "";
|
|
3499
|
-
} else {
|
|
3500
|
-
summary.removeAttribute("aria-hidden");
|
|
3501
|
-
summary.removeAttribute("aria-label");
|
|
3502
|
-
summary.title = "";
|
|
3503
|
-
}
|
|
3504
|
-
this.updateDiffUnchangedBridgeMeta(entry, unchangedRegionStyle, summaryLabel);
|
|
3872
|
+
syncDiffUnchangedBridgeNode({
|
|
3873
|
+
bridge,
|
|
3874
|
+
unchangedRegionStyle,
|
|
3875
|
+
containerRect,
|
|
3876
|
+
containerScrollLeft: this.lastContainer.scrollLeft,
|
|
3877
|
+
containerScrollTop: this.lastContainer.scrollTop,
|
|
3878
|
+
secondaryAnchorRect,
|
|
3879
|
+
primaryAnchorRect,
|
|
3880
|
+
bridgeLeftInset,
|
|
3881
|
+
bridgeRailWidth,
|
|
3882
|
+
primaryStyle,
|
|
3883
|
+
editorBackgroundColor: editorSurfaceStyle.backgroundColor
|
|
3884
|
+
});
|
|
3885
|
+
syncDiffUnchangedSummaryButton(summary, unchangedRegionStyle, summaryLabel);
|
|
3886
|
+
syncDiffUnchangedMetaNode(entry.visualMeta, unchangedRegionStyle, summaryLabel);
|
|
3505
3887
|
if (unchangedRegionStyle === "line-info" || unchangedRegionStyle === "line-info-basic") {
|
|
3506
3888
|
this.syncDiffUnchangedBridgeRail(entry, showTopHandle, topHandle ?? null, showBottomHandle, bottomHandle ?? null);
|
|
3507
3889
|
if (entry.rail && entry.rail.parentElement !== bridge) bridge.prepend(entry.rail);
|
|
@@ -3510,7 +3892,7 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
3510
3892
|
entry.rail.setAttribute("aria-hidden", "true");
|
|
3511
3893
|
}
|
|
3512
3894
|
entry.activate = () => {
|
|
3513
|
-
const action = primaryNode
|
|
3895
|
+
const action = findDiffUnchangedActivationAction(primaryNode, secondaryNode);
|
|
3514
3896
|
if (action instanceof HTMLElement) {
|
|
3515
3897
|
this.capturePreviousDiffUnchangedState();
|
|
3516
3898
|
action.click();
|
|
@@ -3547,7 +3929,7 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
3547
3929
|
this.schedulePatchDiffUnchangedRegionsAfterInteraction();
|
|
3548
3930
|
return;
|
|
3549
3931
|
}
|
|
3550
|
-
|
|
3932
|
+
dispatchSyntheticPrimaryMouseDown(node);
|
|
3551
3933
|
this.scheduleCapturePersistedDiffUnchangedState(1);
|
|
3552
3934
|
});
|
|
3553
3935
|
}
|
|
@@ -3676,8 +4058,12 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
3676
4058
|
overlay.className = "stream-monaco-diff-hunk-overlay";
|
|
3677
4059
|
this.diffHunkOverlay = overlay;
|
|
3678
4060
|
this.lastContainer.append(overlay);
|
|
3679
|
-
this.diffHunkUpperNode =
|
|
3680
|
-
this.diffHunkLowerNode =
|
|
4061
|
+
this.diffHunkUpperNode = createDiffHunkActionNode("upper", (side, action) => this.applyDiffHunkAction(side, action));
|
|
4062
|
+
this.diffHunkLowerNode = createDiffHunkActionNode("lower", (side, action) => this.applyDiffHunkAction(side, action));
|
|
4063
|
+
this.createDomDisposable(this.diffHunkDisposables, this.diffHunkUpperNode, "mouseenter", () => this.cancelScheduledHideDiffHunkActions());
|
|
4064
|
+
this.createDomDisposable(this.diffHunkDisposables, this.diffHunkUpperNode, "mouseleave", () => this.scheduleHideDiffHunkActions());
|
|
4065
|
+
this.createDomDisposable(this.diffHunkDisposables, this.diffHunkLowerNode, "mouseenter", () => this.cancelScheduledHideDiffHunkActions());
|
|
4066
|
+
this.createDomDisposable(this.diffHunkDisposables, this.diffHunkLowerNode, "mouseleave", () => this.scheduleHideDiffHunkActions());
|
|
3681
4067
|
overlay.append(this.diffHunkUpperNode, this.diffHunkLowerNode);
|
|
3682
4068
|
const originalEditor = this.diffEditorView.getOriginalEditor();
|
|
3683
4069
|
const modifiedEditor = this.diffEditorView.getModifiedEditor();
|
|
@@ -3720,71 +4106,27 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
3720
4106
|
if (this.diffHunkUpperNode) this.diffHunkUpperNode.style.display = "none";
|
|
3721
4107
|
if (this.diffHunkLowerNode) this.diffHunkLowerNode.style.display = "none";
|
|
3722
4108
|
}
|
|
3723
|
-
inferInlineDiffHunkHoverSide(change, event) {
|
|
3724
|
-
var _event$target$positio;
|
|
3725
|
-
const targetElement = event.target.element instanceof HTMLElement ? event.target.element : null;
|
|
3726
|
-
if (targetElement === null || targetElement === void 0 ? void 0 : targetElement.closest(".line-delete, .char-delete, .inline-deleted-text, .inline-deleted-margin-view-zone")) return "upper";
|
|
3727
|
-
if (targetElement === null || targetElement === void 0 ? void 0 : targetElement.closest(".line-insert, .char-insert, .gutter-insert, .view-line")) return "lower";
|
|
3728
|
-
if (!this.hasModifiedLines(change)) return "upper";
|
|
3729
|
-
if (!this.hasOriginalLines(change)) return "lower";
|
|
3730
|
-
const hoverLine = ((_event$target$positio = event.target.position) === null || _event$target$positio === void 0 ? void 0 : _event$target$positio.lineNumber) ?? 0;
|
|
3731
|
-
const modifiedAnchor = Math.max(1, change.modifiedStartLineNumber || change.modifiedEndLineNumber || 1);
|
|
3732
|
-
return hoverLine < modifiedAnchor ? "upper" : "lower";
|
|
3733
|
-
}
|
|
3734
|
-
hasOriginalLines(change) {
|
|
3735
|
-
return change.originalStartLineNumber > 0 && change.originalEndLineNumber >= change.originalStartLineNumber;
|
|
3736
|
-
}
|
|
3737
|
-
hasModifiedLines(change) {
|
|
3738
|
-
return change.modifiedStartLineNumber > 0 && change.modifiedEndLineNumber >= change.modifiedStartLineNumber;
|
|
3739
|
-
}
|
|
3740
|
-
distanceToLineChange(side, change, line) {
|
|
3741
|
-
const hasRange = side === "original" ? this.hasOriginalLines(change) : this.hasModifiedLines(change);
|
|
3742
|
-
const start = side === "original" ? change.originalStartLineNumber : change.modifiedStartLineNumber;
|
|
3743
|
-
const end = side === "original" ? change.originalEndLineNumber : change.modifiedEndLineNumber;
|
|
3744
|
-
if (hasRange) {
|
|
3745
|
-
if (line < start) return start - line;
|
|
3746
|
-
if (line > end) return line - end;
|
|
3747
|
-
return 0;
|
|
3748
|
-
}
|
|
3749
|
-
const fallbackAnchor = Math.max(1, start || end || 1);
|
|
3750
|
-
return Math.abs(line - fallbackAnchor);
|
|
3751
|
-
}
|
|
3752
|
-
findLineChangeByHoverLine(side, line) {
|
|
3753
|
-
if (this.diffHunkLineChanges.length === 0) return null;
|
|
3754
|
-
let best = null;
|
|
3755
|
-
let bestDistance = Number.POSITIVE_INFINITY;
|
|
3756
|
-
for (const change of this.diffHunkLineChanges) {
|
|
3757
|
-
const distance = this.distanceToLineChange(side, change, line);
|
|
3758
|
-
if (distance < bestDistance) {
|
|
3759
|
-
bestDistance = distance;
|
|
3760
|
-
best = change;
|
|
3761
|
-
if (distance === 0) break;
|
|
3762
|
-
}
|
|
3763
|
-
}
|
|
3764
|
-
if (bestDistance > 2) return null;
|
|
3765
|
-
return best;
|
|
3766
|
-
}
|
|
3767
4109
|
handleDiffHunkMouseMove(side, event) {
|
|
3768
|
-
var _event$target$positio2;
|
|
3769
|
-
const line = (_event$target$
|
|
4110
|
+
var _event$target$positio, _event$target$positio2;
|
|
4111
|
+
const line = (_event$target$positio = event.target.position) === null || _event$target$positio === void 0 ? void 0 : _event$target$positio.lineNumber;
|
|
3770
4112
|
if (!line) {
|
|
3771
4113
|
this.scheduleHideDiffHunkActions(120);
|
|
3772
4114
|
return;
|
|
3773
4115
|
}
|
|
3774
|
-
const change = this.
|
|
4116
|
+
const change = findLineChangeByHoverLine(this.diffHunkLineChanges, side, line);
|
|
3775
4117
|
if (!change) {
|
|
3776
4118
|
this.scheduleHideDiffHunkActions(120);
|
|
3777
4119
|
return;
|
|
3778
4120
|
}
|
|
3779
4121
|
this.cancelScheduledHideDiffHunkActions();
|
|
3780
4122
|
this.diffHunkActiveChange = change;
|
|
3781
|
-
this.diffHunkActiveHoverSide = this.isDiffInlineMode() ?
|
|
4123
|
+
this.diffHunkActiveHoverSide = this.isDiffInlineMode() ? inferInlineDiffHunkHoverSide(change, ((_event$target$positio2 = event.target.position) === null || _event$target$positio2 === void 0 ? void 0 : _event$target$positio2.lineNumber) ?? 0, event.target.element instanceof HTMLElement ? event.target.element : null) : null;
|
|
3782
4124
|
this.repositionDiffHunkNodes();
|
|
3783
4125
|
}
|
|
3784
4126
|
isOriginalEditorCollapsed() {
|
|
3785
|
-
var _this$diffEditorView$
|
|
4127
|
+
var _this$diffEditorView$2, _this$diffEditorView$3;
|
|
3786
4128
|
if (!this.diffEditorView) return true;
|
|
3787
|
-
const info = (_this$diffEditorView$
|
|
4129
|
+
const info = (_this$diffEditorView$2 = (_this$diffEditorView$3 = this.diffEditorView.getOriginalEditor()).getLayoutInfo) === null || _this$diffEditorView$2 === void 0 ? void 0 : _this$diffEditorView$2.call(_this$diffEditorView$3);
|
|
3788
4130
|
return !info || info.width < 24;
|
|
3789
4131
|
}
|
|
3790
4132
|
isDiffInlineMode() {
|
|
@@ -3793,40 +4135,6 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
3793
4135
|
if (typeof HTMLElement !== "undefined" && diffRoot instanceof HTMLElement) return !diffRoot.classList.contains("side-by-side");
|
|
3794
4136
|
return this.isOriginalEditorCollapsed();
|
|
3795
4137
|
}
|
|
3796
|
-
getEditorBySide(side) {
|
|
3797
|
-
if (!this.diffEditorView) return null;
|
|
3798
|
-
return side === "original" ? this.diffEditorView.getOriginalEditor() : this.diffEditorView.getModifiedEditor();
|
|
3799
|
-
}
|
|
3800
|
-
getFullLineRange(model, startLine, endLine) {
|
|
3801
|
-
if (endLine < startLine) return null;
|
|
3802
|
-
const lineCount = model.getLineCount();
|
|
3803
|
-
if (lineCount < 1) return null;
|
|
3804
|
-
const start = Math.max(1, Math.min(startLine, lineCount));
|
|
3805
|
-
const end = Math.max(start, Math.min(endLine, lineCount));
|
|
3806
|
-
if (end < lineCount) return new monaco_shim_exports.Range(start, 1, end + 1, 1);
|
|
3807
|
-
return new monaco_shim_exports.Range(start, 1, end, model.getLineMaxColumn(end));
|
|
3808
|
-
}
|
|
3809
|
-
getLinesText(model, startLine, endLine) {
|
|
3810
|
-
const range = this.getFullLineRange(model, startLine, endLine);
|
|
3811
|
-
if (!range) return "";
|
|
3812
|
-
return model.getValueInRange(range);
|
|
3813
|
-
}
|
|
3814
|
-
getInsertRangeBeforeLine(model, lineNumber) {
|
|
3815
|
-
const lineCount = model.getLineCount();
|
|
3816
|
-
if (lineNumber <= 1) return new monaco_shim_exports.Range(1, 1, 1, 1);
|
|
3817
|
-
if (lineNumber <= lineCount) return new monaco_shim_exports.Range(lineNumber, 1, lineNumber, 1);
|
|
3818
|
-
const lastLine = lineCount;
|
|
3819
|
-
const lastColumn = model.getLineMaxColumn(lastLine);
|
|
3820
|
-
return new monaco_shim_exports.Range(lastLine, lastColumn, lastLine, lastColumn);
|
|
3821
|
-
}
|
|
3822
|
-
getInsertRangeAfterLine(model, lineNumber) {
|
|
3823
|
-
const lineCount = model.getLineCount();
|
|
3824
|
-
if (lineNumber < 1) return new monaco_shim_exports.Range(1, 1, 1, 1);
|
|
3825
|
-
if (lineNumber < lineCount) return new monaco_shim_exports.Range(lineNumber + 1, 1, lineNumber + 1, 1);
|
|
3826
|
-
const lastLine = lineCount;
|
|
3827
|
-
const lastColumn = model.getLineMaxColumn(lastLine);
|
|
3828
|
-
return new monaco_shim_exports.Range(lastLine, lastColumn, lastLine, lastColumn);
|
|
3829
|
-
}
|
|
3830
4138
|
applyDiffModelLanguage(models, codeLanguage) {
|
|
3831
4139
|
if (!codeLanguage) return;
|
|
3832
4140
|
const lang = processedLanguage(codeLanguage);
|
|
@@ -3838,8 +4146,8 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
3838
4146
|
if (!this.diffEditorView || !viewState) return;
|
|
3839
4147
|
const restore = () => {
|
|
3840
4148
|
try {
|
|
3841
|
-
var _this$
|
|
3842
|
-
(_this$
|
|
4149
|
+
var _this$diffEditorView16;
|
|
4150
|
+
(_this$diffEditorView16 = this.diffEditorView) === null || _this$diffEditorView16 === void 0 || _this$diffEditorView16.restoreViewState(viewState);
|
|
3843
4151
|
} catch {}
|
|
3844
4152
|
};
|
|
3845
4153
|
restore();
|
|
@@ -3857,7 +4165,7 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
3857
4165
|
this.pendingPreparedDiffViewModel = null;
|
|
3858
4166
|
}
|
|
3859
4167
|
syncDiffKnownValues() {
|
|
3860
|
-
var _this$
|
|
4168
|
+
var _this$diffEditorView17, _this$diffEditorView18, _this$diffEditorView19, _this$diffHeightManag4;
|
|
3861
4169
|
if (this.originalModel) this.lastKnownOriginalCode = this.originalModel.getValue();
|
|
3862
4170
|
if (this.modifiedModel) {
|
|
3863
4171
|
this.lastKnownModifiedCode = this.modifiedModel.getValue();
|
|
@@ -3866,67 +4174,15 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
3866
4174
|
this.lastKnownModifiedDirty = false;
|
|
3867
4175
|
this._hasScrollBar = false;
|
|
3868
4176
|
this.cachedComputedHeightDiff = this.computedHeight();
|
|
3869
|
-
this.cachedScrollHeightDiff = ((_this$
|
|
4177
|
+
this.cachedScrollHeightDiff = ((_this$diffEditorView17 = this.diffEditorView) === null || _this$diffEditorView17 === void 0 || (_this$diffEditorView19 = (_this$diffEditorView18 = _this$diffEditorView17.getModifiedEditor()).getScrollHeight) === null || _this$diffEditorView19 === void 0 ? void 0 : _this$diffEditorView19.call(_this$diffEditorView18)) ?? this.cachedScrollHeightDiff;
|
|
3870
4178
|
(_this$diffHeightManag4 = this.diffHeightManager) === null || _this$diffHeightManag4 === void 0 || _this$diffHeightManag4.update();
|
|
3871
4179
|
}
|
|
3872
|
-
applyDefaultDiffHunkAction(context) {
|
|
3873
|
-
const { action, side, lineChange } = context;
|
|
3874
|
-
if (!this.originalModel || !this.modifiedModel) return;
|
|
3875
|
-
const hasOriginal = this.hasOriginalLines(lineChange);
|
|
3876
|
-
const hasModified = this.hasModifiedLines(lineChange);
|
|
3877
|
-
if (action === "revert" && side === "upper") {
|
|
3878
|
-
if (!hasOriginal) return;
|
|
3879
|
-
const text = this.getLinesText(this.originalModel, lineChange.originalStartLineNumber, lineChange.originalEndLineNumber);
|
|
3880
|
-
if (!text) return;
|
|
3881
|
-
const range = hasModified ? this.getInsertRangeBeforeLine(this.modifiedModel, lineChange.modifiedStartLineNumber) : this.getInsertRangeAfterLine(this.modifiedModel, Math.max(0, lineChange.modifiedStartLineNumber || lineChange.modifiedEndLineNumber));
|
|
3882
|
-
this.modifiedModel.applyEdits([{
|
|
3883
|
-
range,
|
|
3884
|
-
text,
|
|
3885
|
-
forceMoveMarkers: true
|
|
3886
|
-
}]);
|
|
3887
|
-
return;
|
|
3888
|
-
}
|
|
3889
|
-
if (action === "revert" && side === "lower") {
|
|
3890
|
-
if (!hasModified) return;
|
|
3891
|
-
const range = this.getFullLineRange(this.modifiedModel, lineChange.modifiedStartLineNumber, lineChange.modifiedEndLineNumber);
|
|
3892
|
-
if (!range) return;
|
|
3893
|
-
this.modifiedModel.applyEdits([{
|
|
3894
|
-
range,
|
|
3895
|
-
text: "",
|
|
3896
|
-
forceMoveMarkers: true
|
|
3897
|
-
}]);
|
|
3898
|
-
return;
|
|
3899
|
-
}
|
|
3900
|
-
if (action === "stage" && side === "upper") {
|
|
3901
|
-
if (!hasOriginal) return;
|
|
3902
|
-
const range = this.getFullLineRange(this.originalModel, lineChange.originalStartLineNumber, lineChange.originalEndLineNumber);
|
|
3903
|
-
if (!range) return;
|
|
3904
|
-
this.originalModel.applyEdits([{
|
|
3905
|
-
range,
|
|
3906
|
-
text: "",
|
|
3907
|
-
forceMoveMarkers: true
|
|
3908
|
-
}]);
|
|
3909
|
-
return;
|
|
3910
|
-
}
|
|
3911
|
-
if (action === "stage" && side === "lower") {
|
|
3912
|
-
if (!hasModified) return;
|
|
3913
|
-
const text = this.getLinesText(this.modifiedModel, lineChange.modifiedStartLineNumber, lineChange.modifiedEndLineNumber);
|
|
3914
|
-
if (!text) return;
|
|
3915
|
-
const anchor = hasOriginal ? lineChange.originalEndLineNumber : Math.max(0, lineChange.originalStartLineNumber);
|
|
3916
|
-
const range = this.getInsertRangeAfterLine(this.originalModel, anchor);
|
|
3917
|
-
this.originalModel.applyEdits([{
|
|
3918
|
-
range,
|
|
3919
|
-
text,
|
|
3920
|
-
forceMoveMarkers: true
|
|
3921
|
-
}]);
|
|
3922
|
-
}
|
|
3923
|
-
}
|
|
3924
4180
|
async applyDiffHunkAction(side, action) {
|
|
3925
4181
|
if (!this.diffHunkActiveChange || !this.originalModel || !this.modifiedModel) return;
|
|
3926
4182
|
if (this.diffHunkActionInFlight) return;
|
|
3927
4183
|
this.diffHunkActionInFlight = true;
|
|
3928
|
-
|
|
3929
|
-
|
|
4184
|
+
setDiffHunkNodeEnabled(this.diffHunkUpperNode, false);
|
|
4185
|
+
setDiffHunkNodeEnabled(this.diffHunkLowerNode, false);
|
|
3930
4186
|
try {
|
|
3931
4187
|
this.flushOriginalAppendBufferSync();
|
|
3932
4188
|
this.flushModifiedAppendBufferSync();
|
|
@@ -3943,39 +4199,13 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
3943
4199
|
} catch (error$1) {
|
|
3944
4200
|
console.warn("onDiffHunkAction callback threw an error:", error$1);
|
|
3945
4201
|
}
|
|
3946
|
-
if (allowDefault)
|
|
4202
|
+
if (allowDefault) applyDefaultDiffHunkAction(context);
|
|
3947
4203
|
this.syncDiffKnownValues();
|
|
3948
4204
|
this.hideDiffHunkActions();
|
|
3949
4205
|
} finally {
|
|
3950
4206
|
this.diffHunkActionInFlight = false;
|
|
3951
4207
|
}
|
|
3952
4208
|
}
|
|
3953
|
-
setDiffHunkNodeEnabled(node, enabled) {
|
|
3954
|
-
if (!node) return;
|
|
3955
|
-
const buttons = node.querySelectorAll("button");
|
|
3956
|
-
buttons.forEach((button) => {
|
|
3957
|
-
button.disabled = !enabled;
|
|
3958
|
-
});
|
|
3959
|
-
}
|
|
3960
|
-
positionDiffHunkNode(node, side, anchorLine, extraOffsetY = 0) {
|
|
3961
|
-
var _editor$getScrollTop2;
|
|
3962
|
-
if (!this.diffHunkOverlay) return;
|
|
3963
|
-
const editor = this.getEditorBySide(side);
|
|
3964
|
-
if (!editor) return;
|
|
3965
|
-
const host = editor.getContainerDomNode();
|
|
3966
|
-
const line = Math.max(1, anchorLine);
|
|
3967
|
-
const rawTop = editor.getTopForLineNumber(line) - (((_editor$getScrollTop2 = editor.getScrollTop) === null || _editor$getScrollTop2 === void 0 ? void 0 : _editor$getScrollTop2.call(editor)) ?? 0);
|
|
3968
|
-
const lineHeight = editor.getOption(monaco_shim_exports.editor.EditorOption.lineHeight);
|
|
3969
|
-
const nodeWidth = node.offsetWidth || 130;
|
|
3970
|
-
const nodeHeight = node.offsetHeight || 30;
|
|
3971
|
-
const left = host.offsetLeft + Math.max(6, host.clientWidth - nodeWidth - 10);
|
|
3972
|
-
const hostTop = host.offsetTop;
|
|
3973
|
-
const minTop = hostTop + 4;
|
|
3974
|
-
const maxTop = hostTop + Math.max(4, host.clientHeight - nodeHeight - 4);
|
|
3975
|
-
const top = Math.min(maxTop, Math.max(minTop, hostTop + rawTop + Math.round(lineHeight * .2) + extraOffsetY));
|
|
3976
|
-
node.style.transform = `translate(${Math.round(left)}px, ${Math.round(top)}px)`;
|
|
3977
|
-
node.style.display = "flex";
|
|
3978
|
-
}
|
|
3979
4209
|
repositionDiffHunkNodes() {
|
|
3980
4210
|
if (!this.diffHunkActiveChange) {
|
|
3981
4211
|
this.hideDiffHunkActions();
|
|
@@ -3984,22 +4214,22 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
3984
4214
|
if (!this.diffHunkUpperNode || !this.diffHunkLowerNode) return;
|
|
3985
4215
|
if (!this.diffEditorView) return;
|
|
3986
4216
|
const change = this.diffHunkActiveChange;
|
|
3987
|
-
const hasOriginal =
|
|
3988
|
-
const hasModified =
|
|
3989
|
-
|
|
3990
|
-
|
|
4217
|
+
const hasOriginal = hasOriginalLines(change);
|
|
4218
|
+
const hasModified = hasModifiedLines(change);
|
|
4219
|
+
setDiffHunkNodeEnabled(this.diffHunkUpperNode, hasOriginal);
|
|
4220
|
+
setDiffHunkNodeEnabled(this.diffHunkLowerNode, hasModified);
|
|
3991
4221
|
const inlineMode = this.isDiffInlineMode();
|
|
3992
4222
|
if (inlineMode) {
|
|
3993
4223
|
const inlineHoverSide = this.diffHunkActiveHoverSide ?? (hasOriginal && !hasModified ? "upper" : "lower");
|
|
3994
4224
|
if (inlineHoverSide === "upper" && hasOriginal) {
|
|
3995
4225
|
const upperAnchor = Math.max(1, change.modifiedStartLineNumber - 1 || change.modifiedEndLineNumber || 1);
|
|
3996
|
-
|
|
4226
|
+
positionDiffHunkNode(this.diffHunkUpperNode, this.diffEditorView.getModifiedEditor(), upperAnchor);
|
|
3997
4227
|
this.diffHunkLowerNode.style.display = "none";
|
|
3998
4228
|
return;
|
|
3999
4229
|
}
|
|
4000
4230
|
if (hasModified) {
|
|
4001
4231
|
const lowerAnchor = Math.max(1, change.modifiedStartLineNumber || change.modifiedEndLineNumber || 1);
|
|
4002
|
-
|
|
4232
|
+
positionDiffHunkNode(this.diffHunkLowerNode, this.diffEditorView.getModifiedEditor(), lowerAnchor);
|
|
4003
4233
|
this.diffHunkUpperNode.style.display = "none";
|
|
4004
4234
|
return;
|
|
4005
4235
|
}
|
|
@@ -4007,13 +4237,12 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
4007
4237
|
return;
|
|
4008
4238
|
}
|
|
4009
4239
|
if (hasOriginal) {
|
|
4010
|
-
const upperSide = "original";
|
|
4011
4240
|
const upperAnchor = change.originalStartLineNumber;
|
|
4012
|
-
|
|
4241
|
+
positionDiffHunkNode(this.diffHunkUpperNode, this.diffEditorView.getOriginalEditor(), upperAnchor);
|
|
4013
4242
|
} else this.diffHunkUpperNode.style.display = "none";
|
|
4014
4243
|
if (hasModified) {
|
|
4015
4244
|
const lowerAnchor = change.modifiedStartLineNumber;
|
|
4016
|
-
|
|
4245
|
+
positionDiffHunkNode(this.diffHunkLowerNode, this.diffEditorView.getModifiedEditor(), lowerAnchor);
|
|
4017
4246
|
} else this.diffHunkLowerNode.style.display = "none";
|
|
4018
4247
|
}
|
|
4019
4248
|
scheduleFlushAppendBufferDiff() {
|
|
@@ -4052,26 +4281,20 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
4052
4281
|
this.appendToModel(this.originalModel, text);
|
|
4053
4282
|
}
|
|
4054
4283
|
computeRawHeight() {
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
const lineHeight = modifiedEditor.getOption(monaco_shim_exports.editor.EditorOption.lineHeight);
|
|
4060
|
-
const oCount = ((_originalEditor$getMo = originalEditor.getModel()) === null || _originalEditor$getMo === void 0 ? void 0 : _originalEditor$getMo.getLineCount()) ?? 1;
|
|
4061
|
-
const mCount = ((_modifiedEditor$getMo2 = modifiedEditor.getModel()) === null || _modifiedEditor$getMo2 === void 0 ? void 0 : _modifiedEditor$getMo2.getLineCount()) ?? 1;
|
|
4062
|
-
const lineCount = Math.max(oCount, mCount);
|
|
4063
|
-
const fromLines = lineCount * lineHeight + padding;
|
|
4064
|
-
const scrollH = Math.max(((_originalEditor$getSc5 = originalEditor.getScrollHeight) === null || _originalEditor$getSc5 === void 0 ? void 0 : _originalEditor$getSc5.call(originalEditor)) ?? 0, ((_modifiedEditor$getSc10 = modifiedEditor.getScrollHeight) === null || _modifiedEditor$getSc10 === void 0 ? void 0 : _modifiedEditor$getSc10.call(modifiedEditor)) ?? 0);
|
|
4065
|
-
const desired = Math.max(fromLines, scrollH);
|
|
4066
|
-
return Math.min(desired, this.maxHeightValue);
|
|
4284
|
+
return computeDiffRawHeight({
|
|
4285
|
+
diffEditorView: this.diffEditorView,
|
|
4286
|
+
maxHeightValue: this.maxHeightValue
|
|
4287
|
+
});
|
|
4067
4288
|
}
|
|
4068
4289
|
computedHeight() {
|
|
4069
|
-
const
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
|
|
4290
|
+
const { height, nextInlineDiffStreamingHeightFloor } = computeDiffHeight({
|
|
4291
|
+
rawHeight: this.computeRawHeight(),
|
|
4292
|
+
isInlineMode: this.isDiffInlineMode(),
|
|
4293
|
+
inlineDiffStreamingPresentationActive: this.inlineDiffStreamingPresentationActive,
|
|
4294
|
+
inlineDiffStreamingHeightFloor: this.inlineDiffStreamingHeightFloor
|
|
4295
|
+
});
|
|
4296
|
+
this.inlineDiffStreamingHeightFloor = nextInlineDiffStreamingHeightFloor;
|
|
4297
|
+
return height;
|
|
4075
4298
|
}
|
|
4076
4299
|
eagerlyGrowDiffContainerHeight() {
|
|
4077
4300
|
var _this$lastContainer$g, _this$lastContainer10;
|
|
@@ -4116,17 +4339,22 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
4116
4339
|
if (this._hasScrollBar) return true;
|
|
4117
4340
|
const m = this.measureViewportDiff();
|
|
4118
4341
|
if (!m) return false;
|
|
4119
|
-
|
|
4120
|
-
return this._hasScrollBar = m.scrollHeight > m.computedHeight + Math.max(padding / 2, epsilon);
|
|
4342
|
+
return this._hasScrollBar = hasVerticalScrollbar(m);
|
|
4121
4343
|
}
|
|
4122
4344
|
userIsNearBottomDiff() {
|
|
4123
4345
|
if (!this.diffEditorView) return true;
|
|
4124
4346
|
const m = this.measureViewportDiff();
|
|
4125
4347
|
if (!m || !m.li) return true;
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4348
|
+
return isUserNearBottom({
|
|
4349
|
+
computedHeight: m.computedHeight,
|
|
4350
|
+
lineHeight: m.lineHeight,
|
|
4351
|
+
scrollHeight: m.scrollHeight,
|
|
4352
|
+
scrollTop: m.scrollTop,
|
|
4353
|
+
viewportHeight: m.li.height
|
|
4354
|
+
}, {
|
|
4355
|
+
autoScrollThresholdLines: this.autoScrollThresholdLines ?? 0,
|
|
4356
|
+
autoScrollThresholdPx: this.autoScrollThresholdPx || 0
|
|
4357
|
+
});
|
|
4130
4358
|
}
|
|
4131
4359
|
maybeScrollDiffToBottom(targetLine, prevLineOverride) {
|
|
4132
4360
|
this.rafScheduler.schedule("maybe-scroll-diff", () => {
|
|
@@ -4202,7 +4430,7 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
4202
4430
|
}
|
|
4203
4431
|
performRevealDiffTicketed(line, ticket) {
|
|
4204
4432
|
this.rafScheduler.schedule("revealDiff", () => {
|
|
4205
|
-
var _editor;
|
|
4433
|
+
var _editor$1;
|
|
4206
4434
|
if (this.diffScrollWatcher) {
|
|
4207
4435
|
log("diff", "performRevealDiffTicketed - suppressing watcher", {
|
|
4208
4436
|
ticket,
|
|
@@ -4217,16 +4445,11 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
4217
4445
|
line
|
|
4218
4446
|
});
|
|
4219
4447
|
const strategy = this.diffHideUnchangedRegionsDeferred ? "bottom" : this.revealStrategyOption ?? this.options.revealStrategy ?? "centerIfOutside";
|
|
4220
|
-
const ScrollType =
|
|
4221
|
-
const smooth = !this.diffHideUnchangedRegionsDeferred && ScrollType && typeof ScrollType.Smooth !== "undefined" ? ScrollType.Smooth : void 0;
|
|
4448
|
+
const ScrollType$1 = ScrollType || ((_editor$1 = monaco_shim_exports.editor) === null || _editor$1 === void 0 ? void 0 : _editor$1.ScrollType);
|
|
4449
|
+
const smooth = !this.diffHideUnchangedRegionsDeferred && ScrollType$1 && typeof ScrollType$1.Smooth !== "undefined" ? ScrollType$1.Smooth : void 0;
|
|
4222
4450
|
try {
|
|
4223
4451
|
const me = this.diffEditorView.getModifiedEditor();
|
|
4224
|
-
|
|
4225
|
-
else me.revealLine(line);
|
|
4226
|
-
else if (strategy === "center") if (typeof smooth !== "undefined") me.revealLineInCenter(line, smooth);
|
|
4227
|
-
else me.revealLineInCenter(line);
|
|
4228
|
-
else if (typeof smooth !== "undefined") me.revealLineInCenterIfOutsideViewport(line, smooth);
|
|
4229
|
-
else me.revealLineInCenterIfOutsideViewport(line);
|
|
4452
|
+
revealEditorLine(me, line, strategy, smooth);
|
|
4230
4453
|
} catch {
|
|
4231
4454
|
try {
|
|
4232
4455
|
this.diffEditorView.getModifiedEditor().revealLine(line);
|
|
@@ -4238,8 +4461,8 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
4238
4461
|
lastRevealLineDiff: this.lastRevealLineDiff
|
|
4239
4462
|
});
|
|
4240
4463
|
try {
|
|
4241
|
-
var _this$
|
|
4242
|
-
this.lastScrollTopDiff = ((_this$
|
|
4464
|
+
var _this$diffEditorView20, _this$diffEditorView21, _this$diffEditorView22;
|
|
4465
|
+
this.lastScrollTopDiff = ((_this$diffEditorView20 = this.diffEditorView) === null || _this$diffEditorView20 === void 0 || (_this$diffEditorView22 = (_this$diffEditorView21 = _this$diffEditorView20.getModifiedEditor()).getScrollTop) === null || _this$diffEditorView22 === void 0 ? void 0 : _this$diffEditorView22.call(_this$diffEditorView21)) ?? this.lastScrollTopDiff;
|
|
4243
4466
|
} catch {}
|
|
4244
4467
|
});
|
|
4245
4468
|
}
|
|
@@ -4247,11 +4470,10 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
4247
4470
|
var _editor2;
|
|
4248
4471
|
if (!this.diffEditorView) return;
|
|
4249
4472
|
if (ticket !== this.revealTicketDiff) return;
|
|
4250
|
-
const ScrollType =
|
|
4251
|
-
const immediate = ScrollType && typeof ScrollType.Immediate !== "undefined" ? ScrollType.Immediate : void 0;
|
|
4473
|
+
const ScrollType$1 = ScrollType || ((_editor2 = monaco_shim_exports.editor) === null || _editor2 === void 0 ? void 0 : _editor2.ScrollType);
|
|
4474
|
+
const immediate = ScrollType$1 && typeof ScrollType$1.Immediate !== "undefined" ? ScrollType$1.Immediate : void 0;
|
|
4252
4475
|
const me = this.diffEditorView.getModifiedEditor();
|
|
4253
|
-
|
|
4254
|
-
else me.revealLine(line);
|
|
4476
|
+
revealEditorLine(me, line, "bottom", immediate);
|
|
4255
4477
|
this.measureViewportDiff();
|
|
4256
4478
|
log("diff", "performImmediateRevealDiff", {
|
|
4257
4479
|
line,
|
|
@@ -4271,22 +4493,7 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
4271
4493
|
});
|
|
4272
4494
|
}
|
|
4273
4495
|
waitForHeightAppliedDiff(target, timeoutMs = 500) {
|
|
4274
|
-
return
|
|
4275
|
-
const start = typeof performance !== "undefined" && performance.now ? performance.now() : Date.now();
|
|
4276
|
-
const check = () => {
|
|
4277
|
-
const applied = this.lastContainer ? Number.parseFloat((this.lastContainer.style.height || "").replace("px", "")) || 0 : -1;
|
|
4278
|
-
if (applied >= target - 1) {
|
|
4279
|
-
resolve();
|
|
4280
|
-
return;
|
|
4281
|
-
}
|
|
4282
|
-
if ((typeof performance !== "undefined" && performance.now ? performance.now() : Date.now()) - start > timeoutMs) {
|
|
4283
|
-
resolve();
|
|
4284
|
-
return;
|
|
4285
|
-
}
|
|
4286
|
-
requestAnimationFrame(check);
|
|
4287
|
-
};
|
|
4288
|
-
check();
|
|
4289
|
-
});
|
|
4496
|
+
return waitForElementHeightApplied(this.lastContainer, target, timeoutMs);
|
|
4290
4497
|
}
|
|
4291
4498
|
async createDiffEditor(container, originalCode, modifiedCode, language, currentTheme) {
|
|
4292
4499
|
var _me$getScrollHeight2, _me$getOption, _oEditor$onDidLayoutC, _mEditor$onDidLayoutC, _oEditor$onDidContent, _mEditor$onDidContent;
|
|
@@ -4435,8 +4642,8 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
4435
4642
|
if (this.lastContainer) {
|
|
4436
4643
|
this.lastContainer.style.overflow = "hidden";
|
|
4437
4644
|
if (computed$1 >= this.maxHeightValue - 1 && this.shouldAutoScrollDiff && !this.diffHideUnchangedRegionsDeferred) {
|
|
4438
|
-
var _this$
|
|
4439
|
-
this.maybeScrollDiffToBottom((_this$
|
|
4645
|
+
var _this$modifiedModel4;
|
|
4646
|
+
this.maybeScrollDiffToBottom((_this$modifiedModel4 = this.modifiedModel) === null || _this$modifiedModel4 === void 0 ? void 0 : _this$modifiedModel4.getLineCount());
|
|
4440
4647
|
}
|
|
4441
4648
|
}
|
|
4442
4649
|
});
|
|
@@ -4459,13 +4666,14 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
4459
4666
|
if (this.lastContainer) {
|
|
4460
4667
|
this.lastContainer.style.overflow = "hidden";
|
|
4461
4668
|
if (computed$1 >= this.maxHeightValue - 1 && this.shouldAutoScrollDiff && !this.diffHideUnchangedRegionsDeferred) {
|
|
4462
|
-
var _this$
|
|
4463
|
-
this.maybeScrollDiffToBottom((_this$
|
|
4669
|
+
var _this$modifiedModel5;
|
|
4670
|
+
this.maybeScrollDiffToBottom((_this$modifiedModel5 = this.modifiedModel) === null || _this$modifiedModel5 === void 0 ? void 0 : _this$modifiedModel5.getLineCount());
|
|
4464
4671
|
}
|
|
4465
4672
|
}
|
|
4466
4673
|
});
|
|
4467
4674
|
});
|
|
4468
4675
|
mEditor.onDidChangeModelContent(() => {
|
|
4676
|
+
if (this.programmaticModifiedContentChangeDepth > 0) return;
|
|
4469
4677
|
this.lastKnownModifiedDirty = true;
|
|
4470
4678
|
this.rafScheduler.schedule("sync-last-known-modified", () => this.syncLastKnownModified());
|
|
4471
4679
|
});
|
|
@@ -4609,7 +4817,7 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
4609
4817
|
if (this.modifiedModel && this.modifiedModel.getLanguageId() !== language) monaco_shim_exports.editor.setModelLanguage(this.modifiedModel, language);
|
|
4610
4818
|
}
|
|
4611
4819
|
async setDiffModels(models, options = {}) {
|
|
4612
|
-
var _this$
|
|
4820
|
+
var _this$originalModel3, _this$modifiedModel6, _this$diffEditorView$4, _this$diffEditorView$5, _this$diffEditorView$6, _this$diffEditorView$7;
|
|
4613
4821
|
if (!this.diffEditorView) return;
|
|
4614
4822
|
const transitionRequestId = ++this.diffModelTransitionRequestId;
|
|
4615
4823
|
this.preserveNativeDiffDecorationsOnStaleAppend = false;
|
|
@@ -4617,8 +4825,8 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
4617
4825
|
const nextOriginal = models.original;
|
|
4618
4826
|
const nextModified = models.modified;
|
|
4619
4827
|
this.applyDiffModelLanguage(models, options.codeLanguage);
|
|
4620
|
-
const currentOriginalValue = this.lastKnownOriginalCode ?? ((_this$
|
|
4621
|
-
const currentModifiedValue = this.lastKnownModifiedCode ?? ((_this$
|
|
4828
|
+
const currentOriginalValue = this.lastKnownOriginalCode ?? ((_this$originalModel3 = this.originalModel) === null || _this$originalModel3 === void 0 ? void 0 : _this$originalModel3.getValue()) ?? null;
|
|
4829
|
+
const currentModifiedValue = this.lastKnownModifiedCode ?? ((_this$modifiedModel6 = this.modifiedModel) === null || _this$modifiedModel6 === void 0 ? void 0 : _this$modifiedModel6.getValue()) ?? null;
|
|
4622
4830
|
const nextOriginalValue = nextOriginal.getValue();
|
|
4623
4831
|
const nextModifiedValue = nextModified.getValue();
|
|
4624
4832
|
const sameContent = currentOriginalValue === nextOriginalValue && currentModifiedValue === nextModifiedValue;
|
|
@@ -4674,8 +4882,8 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
4674
4882
|
this.queuePendingDiffScrollRestore(preservedScrollPosition, shouldRestorePersistedUnchangedState ? 2 : 0);
|
|
4675
4883
|
if (shouldRestorePersistedUnchangedState) this.capturePersistedDiffUnchangedState();
|
|
4676
4884
|
const applyModelSwap = () => {
|
|
4677
|
-
var _this$
|
|
4678
|
-
(_this$
|
|
4885
|
+
var _this$diffEditorView23;
|
|
4886
|
+
(_this$diffEditorView23 = this.diffEditorView) === null || _this$diffEditorView23 === void 0 || _this$diffEditorView23.setModel(nextModelTarget);
|
|
4679
4887
|
};
|
|
4680
4888
|
if (preserveViewState) this.withLockedDiffScrollPosition(applyModelSwap);
|
|
4681
4889
|
else applyModelSwap();
|
|
@@ -4690,8 +4898,8 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
4690
4898
|
this.lastKnownModifiedLineCount = nextModified.getLineCount();
|
|
4691
4899
|
this.lastKnownModifiedDirty = false;
|
|
4692
4900
|
this._hasScrollBar = false;
|
|
4693
|
-
this.cachedScrollHeightDiff = ((_this$diffEditorView$
|
|
4694
|
-
this.cachedLineHeightDiff = ((_this$diffEditorView$
|
|
4901
|
+
this.cachedScrollHeightDiff = ((_this$diffEditorView$4 = (_this$diffEditorView$5 = this.diffEditorView.getModifiedEditor()).getScrollHeight) === null || _this$diffEditorView$4 === void 0 ? void 0 : _this$diffEditorView$4.call(_this$diffEditorView$5)) ?? null;
|
|
4902
|
+
this.cachedLineHeightDiff = ((_this$diffEditorView$6 = (_this$diffEditorView$7 = this.diffEditorView.getModifiedEditor()).getOption) === null || _this$diffEditorView$6 === void 0 ? void 0 : _this$diffEditorView$6.call(_this$diffEditorView$7, monaco_shim_exports.editor.EditorOption.lineHeight)) ?? null;
|
|
4695
4903
|
this.cachedComputedHeightDiff = this.computedHeight();
|
|
4696
4904
|
this.diffHunkLineChanges = this.getEffectiveLineChanges();
|
|
4697
4905
|
this.hideDiffHunkActions();
|
|
@@ -4927,11 +5135,13 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
4927
5135
|
const lastColumn$1 = model.getLineMaxColumn(prevLine);
|
|
4928
5136
|
const range$1 = new monaco_shim_exports.Range(prevLine, lastColumn$1, prevLine, lastColumn$1);
|
|
4929
5137
|
this.preserveNativeDiffDecorationsOnStaleAppend = true;
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
|
|
4933
|
-
|
|
4934
|
-
|
|
5138
|
+
this.runAsProgrammaticModifiedContentChange(() => {
|
|
5139
|
+
model.applyEdits([{
|
|
5140
|
+
range: range$1,
|
|
5141
|
+
text: part,
|
|
5142
|
+
forceMoveMarkers: true
|
|
5143
|
+
}]);
|
|
5144
|
+
});
|
|
4935
5145
|
this.lastKnownModifiedCode = model.getValue();
|
|
4936
5146
|
const newLine$1 = model.getLineCount();
|
|
4937
5147
|
this.lastKnownModifiedLineCount = newLine$1;
|
|
@@ -4967,11 +5177,13 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
4967
5177
|
const lastColumn = model.getLineMaxColumn(prevLine);
|
|
4968
5178
|
const range = new monaco_shim_exports.Range(prevLine, lastColumn, prevLine, lastColumn);
|
|
4969
5179
|
this.preserveNativeDiffDecorationsOnStaleAppend = true;
|
|
4970
|
-
|
|
4971
|
-
|
|
4972
|
-
|
|
4973
|
-
|
|
4974
|
-
|
|
5180
|
+
this.runAsProgrammaticModifiedContentChange(() => {
|
|
5181
|
+
model.applyEdits([{
|
|
5182
|
+
range,
|
|
5183
|
+
text,
|
|
5184
|
+
forceMoveMarkers: true
|
|
5185
|
+
}]);
|
|
5186
|
+
});
|
|
4975
5187
|
this.lastKnownModifiedCode = model.getValue();
|
|
4976
5188
|
const newLine = model.getLineCount();
|
|
4977
5189
|
this.lastKnownModifiedLineCount = newLine;
|
|
@@ -4984,17 +5196,19 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
4984
5196
|
else this.maybeScrollDiffToBottom(newLine, prevLine);
|
|
4985
5197
|
if (suppressedByFlush) watcherApi.setSuppressed(false);
|
|
4986
5198
|
try {
|
|
4987
|
-
var _this$
|
|
4988
|
-
this.lastScrollTopDiff = ((_this$
|
|
5199
|
+
var _this$diffEditorView24, _this$diffEditorView25, _this$diffEditorView26;
|
|
5200
|
+
this.lastScrollTopDiff = ((_this$diffEditorView24 = this.diffEditorView) === null || _this$diffEditorView24 === void 0 || (_this$diffEditorView26 = (_this$diffEditorView25 = _this$diffEditorView24.getModifiedEditor()).getScrollTop) === null || _this$diffEditorView26 === void 0 ? void 0 : _this$diffEditorView26.call(_this$diffEditorView25)) ?? this.lastScrollTopDiff;
|
|
4989
5201
|
} catch {}
|
|
4990
5202
|
}
|
|
4991
5203
|
applyMinimalEditToModel(model, prev, next) {
|
|
4992
|
-
const maxChars =
|
|
4993
|
-
const ratio =
|
|
5204
|
+
const maxChars = this.minimalEditMaxCharsValue;
|
|
5205
|
+
const ratio = this.minimalEditMaxChangeRatioValue;
|
|
4994
5206
|
const maxLen = Math.max(prev.length, next.length);
|
|
4995
5207
|
const changeRatio = maxLen > 0 ? Math.abs(next.length - prev.length) / maxLen : 0;
|
|
4996
5208
|
if (prev.length + next.length > maxChars || changeRatio > ratio) {
|
|
4997
|
-
|
|
5209
|
+
this.applyModelEdit(model, () => {
|
|
5210
|
+
model.setValue(next);
|
|
5211
|
+
});
|
|
4998
5212
|
if (model === this.modifiedModel) this.lastKnownModifiedLineCount = model.getLineCount();
|
|
4999
5213
|
return;
|
|
5000
5214
|
}
|
|
@@ -5004,11 +5218,13 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
5004
5218
|
const rangeStart = model.getPositionAt(start);
|
|
5005
5219
|
const rangeEnd = model.getPositionAt(endPrevIncl + 1);
|
|
5006
5220
|
const range = new monaco_shim_exports.Range(rangeStart.lineNumber, rangeStart.column, rangeEnd.lineNumber, rangeEnd.column);
|
|
5007
|
-
|
|
5008
|
-
|
|
5009
|
-
|
|
5010
|
-
|
|
5011
|
-
|
|
5221
|
+
this.applyModelEdit(model, () => {
|
|
5222
|
+
model.applyEdits([{
|
|
5223
|
+
range,
|
|
5224
|
+
text: replaceText,
|
|
5225
|
+
forceMoveMarkers: true
|
|
5226
|
+
}]);
|
|
5227
|
+
});
|
|
5012
5228
|
if (model === this.modifiedModel) this.lastKnownModifiedLineCount = model.getLineCount();
|
|
5013
5229
|
}
|
|
5014
5230
|
appendToModel(model, appendText) {
|
|
@@ -5016,13 +5232,30 @@ var DiffEditorManager = class DiffEditorManager {
|
|
|
5016
5232
|
const lastLine = model.getLineCount();
|
|
5017
5233
|
const lastColumn = model.getLineMaxColumn(lastLine);
|
|
5018
5234
|
const range = new monaco_shim_exports.Range(lastLine, lastColumn, lastLine, lastColumn);
|
|
5019
|
-
|
|
5020
|
-
|
|
5021
|
-
|
|
5022
|
-
|
|
5023
|
-
|
|
5235
|
+
this.applyModelEdit(model, () => {
|
|
5236
|
+
model.applyEdits([{
|
|
5237
|
+
range,
|
|
5238
|
+
text: appendText,
|
|
5239
|
+
forceMoveMarkers: true
|
|
5240
|
+
}]);
|
|
5241
|
+
});
|
|
5024
5242
|
if (model === this.modifiedModel) this.lastKnownModifiedLineCount = model.getLineCount();
|
|
5025
5243
|
}
|
|
5244
|
+
applyModelEdit(model, fn) {
|
|
5245
|
+
if (model === this.modifiedModel) {
|
|
5246
|
+
this.runAsProgrammaticModifiedContentChange(fn);
|
|
5247
|
+
return;
|
|
5248
|
+
}
|
|
5249
|
+
fn();
|
|
5250
|
+
}
|
|
5251
|
+
runAsProgrammaticModifiedContentChange(fn) {
|
|
5252
|
+
this.programmaticModifiedContentChangeDepth += 1;
|
|
5253
|
+
try {
|
|
5254
|
+
fn();
|
|
5255
|
+
} finally {
|
|
5256
|
+
this.programmaticModifiedContentChangeDepth -= 1;
|
|
5257
|
+
}
|
|
5258
|
+
}
|
|
5026
5259
|
};
|
|
5027
5260
|
|
|
5028
5261
|
//#endregion
|
|
@@ -5034,6 +5267,8 @@ var EditorManager = class {
|
|
|
5034
5267
|
pendingUpdate = null;
|
|
5035
5268
|
_hasScrollBar = false;
|
|
5036
5269
|
updateThrottleMs = 50;
|
|
5270
|
+
minimalEditMaxCharsValue = minimalEditMaxChars;
|
|
5271
|
+
minimalEditMaxChangeRatioValue = minimalEditMaxChangeRatio;
|
|
5037
5272
|
lastUpdateFlushTime = 0;
|
|
5038
5273
|
updateThrottleTimer = null;
|
|
5039
5274
|
shouldAutoScroll = true;
|
|
@@ -5089,6 +5324,8 @@ var EditorManager = class {
|
|
|
5089
5324
|
this.revealDebounceMsOption = revealDebounceMsOption;
|
|
5090
5325
|
this.updateThrottleMsOption = updateThrottleMsOption;
|
|
5091
5326
|
this.updateThrottleMs = this.updateThrottleMsOption ?? this.options.updateThrottleMs ?? 50;
|
|
5327
|
+
this.minimalEditMaxCharsValue = this.options.minimalEditMaxChars ?? minimalEditMaxChars;
|
|
5328
|
+
this.minimalEditMaxChangeRatioValue = this.options.minimalEditMaxChangeRatio ?? minimalEditMaxChangeRatio;
|
|
5092
5329
|
}
|
|
5093
5330
|
cancelRafs() {
|
|
5094
5331
|
this.rafScheduler.cancel("update");
|
|
@@ -5223,7 +5460,7 @@ var EditorManager = class {
|
|
|
5223
5460
|
}
|
|
5224
5461
|
performReveal(line, ticket) {
|
|
5225
5462
|
this.rafScheduler.schedule("reveal", () => {
|
|
5226
|
-
var _editor;
|
|
5463
|
+
var _editor$1;
|
|
5227
5464
|
if (ticket !== this.revealTicket) {
|
|
5228
5465
|
this.dlog("performReveal skipped, stale ticket", ticket, "current", this.revealTicket);
|
|
5229
5466
|
return;
|
|
@@ -5231,8 +5468,8 @@ var EditorManager = class {
|
|
|
5231
5468
|
this.dlog("performReveal executing, ticket=", ticket, "line=", line);
|
|
5232
5469
|
const strategy = this.revealStrategyOption ?? this.options.revealStrategy ?? "centerIfOutside";
|
|
5233
5470
|
this.dlog("performReveal strategy=", strategy);
|
|
5234
|
-
const ScrollType =
|
|
5235
|
-
const smooth = ScrollType && typeof ScrollType.Smooth !== "undefined" ? ScrollType.Smooth : void 0;
|
|
5471
|
+
const ScrollType$1 = ScrollType || ((_editor$1 = monaco_shim_exports.editor) === null || _editor$1 === void 0 ? void 0 : _editor$1.ScrollType);
|
|
5472
|
+
const smooth = ScrollType$1 && typeof ScrollType$1.Smooth !== "undefined" ? ScrollType$1.Smooth : void 0;
|
|
5236
5473
|
try {
|
|
5237
5474
|
if (strategy === "bottom") if (typeof smooth !== "undefined") this.editorView.revealLine(line, smooth);
|
|
5238
5475
|
else this.editorView.revealLine(line);
|
|
@@ -5256,8 +5493,8 @@ var EditorManager = class {
|
|
|
5256
5493
|
this.dlog("performImmediateReveal skipped, stale ticket", ticket, "current", this.revealTicket);
|
|
5257
5494
|
return;
|
|
5258
5495
|
}
|
|
5259
|
-
const ScrollType =
|
|
5260
|
-
const immediate = ScrollType && typeof ScrollType.Immediate !== "undefined" ? ScrollType.Immediate : void 0;
|
|
5496
|
+
const ScrollType$1 = ScrollType || ((_editor2 = monaco_shim_exports.editor) === null || _editor2 === void 0 ? void 0 : _editor2.ScrollType);
|
|
5497
|
+
const immediate = ScrollType$1 && typeof ScrollType$1.Immediate !== "undefined" ? ScrollType$1.Immediate : void 0;
|
|
5261
5498
|
if (typeof immediate !== "undefined") this.editorView.revealLine(line, immediate);
|
|
5262
5499
|
else this.editorView.revealLine(line);
|
|
5263
5500
|
} catch {}
|
|
@@ -5269,8 +5506,8 @@ var EditorManager = class {
|
|
|
5269
5506
|
try {
|
|
5270
5507
|
var _editor3;
|
|
5271
5508
|
if (!this.editorView) return;
|
|
5272
|
-
const ScrollType =
|
|
5273
|
-
const immediate = ScrollType && typeof ScrollType.Immediate !== "undefined" ? ScrollType.Immediate : void 0;
|
|
5509
|
+
const ScrollType$1 = ScrollType || ((_editor3 = monaco_shim_exports.editor) === null || _editor3 === void 0 ? void 0 : _editor3.ScrollType);
|
|
5510
|
+
const immediate = ScrollType$1 && typeof ScrollType$1.Immediate !== "undefined" ? ScrollType$1.Immediate : void 0;
|
|
5274
5511
|
if (typeof immediate !== "undefined") this.editorView.revealLine(line, immediate);
|
|
5275
5512
|
else this.editorView.revealLine(line);
|
|
5276
5513
|
} catch {}
|
|
@@ -5538,7 +5775,6 @@ var EditorManager = class {
|
|
|
5538
5775
|
if (newCode.startsWith(prevCode) && prevCode.length < newCode.length) {
|
|
5539
5776
|
const suffix = newCode.slice(prevCode.length);
|
|
5540
5777
|
if (suffix) this.appendCode(suffix, codeLanguage);
|
|
5541
|
-
this.lastKnownCode = newCode;
|
|
5542
5778
|
return;
|
|
5543
5779
|
}
|
|
5544
5780
|
const prevLineCount = model.getLineCount();
|
|
@@ -5571,8 +5807,8 @@ var EditorManager = class {
|
|
|
5571
5807
|
if (!this.editorView) return;
|
|
5572
5808
|
const model = this.editorView.getModel();
|
|
5573
5809
|
if (!model) return;
|
|
5574
|
-
const maxChars =
|
|
5575
|
-
const ratio =
|
|
5810
|
+
const maxChars = this.minimalEditMaxCharsValue;
|
|
5811
|
+
const ratio = this.minimalEditMaxChangeRatioValue;
|
|
5576
5812
|
const maxLen = Math.max(prev.length, next.length);
|
|
5577
5813
|
const changeRatio = maxLen > 0 ? Math.abs(next.length - prev.length) / maxLen : 0;
|
|
5578
5814
|
if (prev.length + next.length > maxChars || changeRatio > ratio) {
|
|
@@ -5656,6 +5892,10 @@ var EditorManager = class {
|
|
|
5656
5892
|
getEditorView() {
|
|
5657
5893
|
return this.editorView;
|
|
5658
5894
|
}
|
|
5895
|
+
getCode() {
|
|
5896
|
+
var _this$editorView9;
|
|
5897
|
+
return ((_this$editorView9 = this.editorView) === null || _this$editorView9 === void 0 || (_this$editorView9 = _this$editorView9.getModel()) === null || _this$editorView9 === void 0 ? void 0 : _this$editorView9.getValue()) ?? null;
|
|
5898
|
+
}
|
|
5659
5899
|
setUpdateThrottleMs(ms) {
|
|
5660
5900
|
this.updateThrottleMs = ms;
|
|
5661
5901
|
if (!this.updateThrottleMs && this.updateThrottleTimer != null) {
|
|
@@ -5838,6 +6078,14 @@ async function ensureMonacoHighlighter(themes, languages$1) {
|
|
|
5838
6078
|
*/
|
|
5839
6079
|
function clearHighlighterCache() {
|
|
5840
6080
|
highlighterCache.clear();
|
|
6081
|
+
monacoHighlighterPromise = null;
|
|
6082
|
+
lastPatchedHighlighter = null;
|
|
6083
|
+
lastPatchedLanguages = /* @__PURE__ */ new Set();
|
|
6084
|
+
monacoThemeByKey.clear();
|
|
6085
|
+
monacoLanguageSet.clear();
|
|
6086
|
+
themeRegisterPromise = null;
|
|
6087
|
+
languagesRegistered = false;
|
|
6088
|
+
currentLanguages = [];
|
|
5841
6089
|
}
|
|
5842
6090
|
function serializeThemes(themes) {
|
|
5843
6091
|
return JSON.stringify(themes.map((t) => typeof t === "string" ? t : t.name ?? JSON.stringify(t)).sort());
|
|
@@ -6077,15 +6325,13 @@ let globalAppliedThemeName = null;
|
|
|
6077
6325
|
function useMonaco(monacoOptions = {}) {
|
|
6078
6326
|
var _monacoOptions$themes;
|
|
6079
6327
|
const disposals = [];
|
|
6080
|
-
|
|
6081
|
-
if (monacoOptions.isCleanOnBeforeCreate ?? true) disposals.length = 0;
|
|
6328
|
+
const pendingCreateDisposables = /* @__PURE__ */ new Map();
|
|
6082
6329
|
let editorView = null;
|
|
6083
6330
|
let editorMgr = null;
|
|
6084
6331
|
let diffEditorView = null;
|
|
6085
6332
|
let diffMgr = null;
|
|
6086
6333
|
let originalModel = null;
|
|
6087
6334
|
let modifiedModel = null;
|
|
6088
|
-
let _hasScrollBar = false;
|
|
6089
6335
|
const themes = monacoOptions.themes && ((_monacoOptions$themes = monacoOptions.themes) === null || _monacoOptions$themes === void 0 ? void 0 : _monacoOptions$themes.length) ? monacoOptions.themes : defaultThemes;
|
|
6090
6336
|
if (!Array.isArray(themes) || themes.length < 2) throw new Error("Monaco themes must be an array with at least two themes: [darkTheme, lightTheme]");
|
|
6091
6337
|
const languages$1 = monacoOptions.languages ?? defaultLanguages;
|
|
@@ -6106,22 +6352,12 @@ function useMonaco(monacoOptions = {}) {
|
|
|
6106
6352
|
};
|
|
6107
6353
|
const maxHeightValue = getMaxHeightValue();
|
|
6108
6354
|
const maxHeightCSS = getMaxHeightCSS();
|
|
6109
|
-
let
|
|
6110
|
-
let
|
|
6111
|
-
|
|
6112
|
-
|
|
6113
|
-
let updateThrottleMs = monacoOptions.updateThrottleMs ?? 50;
|
|
6114
|
-
let lastFlushTime = 0;
|
|
6115
|
-
let updateThrottleTimer = null;
|
|
6116
|
-
let pendingUpdate = null;
|
|
6117
|
-
let shouldAutoScroll = true;
|
|
6118
|
-
const cachedComputedHeight = null;
|
|
6119
|
-
const appendBuffer = [];
|
|
6120
|
-
let appendBufferScheduled = false;
|
|
6355
|
+
let createRequestSeq = 0;
|
|
6356
|
+
let activeCreateRequestId = null;
|
|
6357
|
+
let activeCreateKind = null;
|
|
6358
|
+
let queuedEditorUpdateDuringCreate = null;
|
|
6121
6359
|
const currentTheme = computed(() => monacoOptions.theme ?? (typeof themes[0] === "string" ? themes[0] : themes[0].name));
|
|
6122
6360
|
let requestedThemeName = monacoOptions.theme ?? globalRequestedThemeName ?? currentTheme.value;
|
|
6123
|
-
let themeWatcher = null;
|
|
6124
|
-
const rafScheduler = createRafScheduler();
|
|
6125
6361
|
async function tryLoadAndSetShikiTheme(highlighter, themeName) {
|
|
6126
6362
|
if (!highlighter || typeof highlighter.setTheme !== "function") return;
|
|
6127
6363
|
try {
|
|
@@ -6192,326 +6428,206 @@ function useMonaco(monacoOptions = {}) {
|
|
|
6192
6428
|
const list = availableNames.includes(themeName) ? themes : themes.concat(themeName);
|
|
6193
6429
|
await registerMonacoThemes(list, languages$1);
|
|
6194
6430
|
}
|
|
6195
|
-
function
|
|
6196
|
-
|
|
6197
|
-
if (_hasScrollBar) return true;
|
|
6198
|
-
const ch = cachedComputedHeight ?? computedHeight(editorView);
|
|
6199
|
-
return _hasScrollBar = editorView.getScrollHeight() > ch + padding / 2;
|
|
6200
|
-
}
|
|
6201
|
-
let revealDebounceId = null;
|
|
6202
|
-
const revealDebounceMs = 75;
|
|
6203
|
-
function maybeScrollToBottom(targetLine) {
|
|
6204
|
-
if (autoScrollOnUpdate && shouldAutoScroll && hasVerticalScrollbar()) {
|
|
6205
|
-
const model = editorView.getModel();
|
|
6206
|
-
const line = targetLine ?? (model === null || model === void 0 ? void 0 : model.getLineCount()) ?? 1;
|
|
6207
|
-
if (revealDebounceId != null) {
|
|
6208
|
-
clearTimeout(revealDebounceId);
|
|
6209
|
-
revealDebounceId = null;
|
|
6210
|
-
}
|
|
6211
|
-
revealDebounceId = setTimeout(() => {
|
|
6212
|
-
revealDebounceId = null;
|
|
6213
|
-
rafScheduler.schedule("reveal", () => {
|
|
6214
|
-
try {
|
|
6215
|
-
var _editor;
|
|
6216
|
-
const ScrollType = monaco_shim_exports.ScrollType || ((_editor = monaco_shim_exports.editor) === null || _editor === void 0 ? void 0 : _editor.ScrollType);
|
|
6217
|
-
if (ScrollType && typeof ScrollType.Smooth !== "undefined") editorView.revealLineInCenterIfOutsideViewport(line, ScrollType.Smooth);
|
|
6218
|
-
else editorView.revealLineInCenterIfOutsideViewport(line);
|
|
6219
|
-
} catch {}
|
|
6220
|
-
});
|
|
6221
|
-
}, revealDebounceMs);
|
|
6222
|
-
}
|
|
6431
|
+
function resolveRequestedThemeName() {
|
|
6432
|
+
return requestedThemeName ?? globalRequestedThemeName ?? monacoOptions.theme ?? currentTheme.value;
|
|
6223
6433
|
}
|
|
6224
|
-
|
|
6225
|
-
|
|
6226
|
-
|
|
6227
|
-
|
|
6228
|
-
|
|
6229
|
-
disposals.length = 0;
|
|
6230
|
-
}
|
|
6231
|
-
if (monacoOptions.onBeforeCreate) {
|
|
6232
|
-
const ds = monacoOptions.onBeforeCreate(monaco_shim_exports);
|
|
6233
|
-
if (ds) disposals.push(...ds);
|
|
6234
|
-
}
|
|
6235
|
-
const initialThemeName = monacoOptions.theme ?? requestedThemeName ?? globalRequestedThemeName ?? currentTheme.value;
|
|
6236
|
-
await ensureThemeRegistered(initialThemeName);
|
|
6237
|
-
editorMgr = new EditorManager(monacoOptions, maxHeightValue, maxHeightCSS, autoScrollOnUpdate, autoScrollInitial, autoScrollThresholdPx, autoScrollThresholdLines, monacoOptions.revealDebounceMs, updateThrottleMs);
|
|
6238
|
-
editorView = await editorMgr.createEditor(container, code, language, initialThemeName);
|
|
6239
|
-
if (pendingUpdate && editorMgr) {
|
|
6240
|
-
const { code: queuedCode, lang: queuedLang } = pendingUpdate;
|
|
6241
|
-
pendingUpdate = null;
|
|
6242
|
-
editorMgr.updateCode(queuedCode, queuedLang);
|
|
6243
|
-
}
|
|
6244
|
-
if (typeof monacoOptions.onThemeChange === "function") monacoOptions.onThemeChange(initialThemeName);
|
|
6245
|
-
if (editorView) lastKnownCode = editorView.getValue();
|
|
6246
|
-
return editorView;
|
|
6247
|
-
}
|
|
6248
|
-
function computedHeight(editorView$1) {
|
|
6249
|
-
var _getModel;
|
|
6250
|
-
const lineCount = ((_getModel = editorView$1.getModel()) === null || _getModel === void 0 ? void 0 : _getModel.getLineCount()) ?? 1;
|
|
6251
|
-
const lineHeight = editorView$1.getOption(monaco_shim_exports.editor.EditorOption.lineHeight);
|
|
6252
|
-
const height = Math.min(lineCount * lineHeight + padding, maxHeightValue);
|
|
6253
|
-
return height;
|
|
6434
|
+
function commitAppliedTheme(themeName) {
|
|
6435
|
+
requestedThemeName = themeName;
|
|
6436
|
+
globalRequestedThemeName = themeName;
|
|
6437
|
+
globalAppliedThemeName = themeName;
|
|
6438
|
+
monacoOptions.theme = themeName;
|
|
6254
6439
|
}
|
|
6255
|
-
async function
|
|
6256
|
-
|
|
6257
|
-
lastContainer = container;
|
|
6258
|
-
if (monacoOptions.isCleanOnBeforeCreate ?? true) {
|
|
6259
|
-
disposals.forEach((d) => d.dispose());
|
|
6260
|
-
disposals.length = 0;
|
|
6261
|
-
}
|
|
6262
|
-
if (monacoOptions.onBeforeCreate) {
|
|
6263
|
-
const ds = monacoOptions.onBeforeCreate(monaco_shim_exports);
|
|
6264
|
-
if (ds) disposals.push(...ds);
|
|
6265
|
-
}
|
|
6266
|
-
const initialThemeName = monacoOptions.theme ?? requestedThemeName ?? globalRequestedThemeName ?? currentTheme.value;
|
|
6267
|
-
await ensureThemeRegistered(initialThemeName);
|
|
6440
|
+
async function notifyThemeApplied(themeName) {
|
|
6441
|
+
if (typeof monacoOptions.onThemeChange !== "function") return;
|
|
6268
6442
|
try {
|
|
6269
|
-
|
|
6443
|
+
await monacoOptions.onThemeChange(themeName);
|
|
6444
|
+
} catch (err) {
|
|
6445
|
+
console.warn("onThemeChange callback threw an error:", err);
|
|
6446
|
+
}
|
|
6447
|
+
}
|
|
6448
|
+
function disposeDisposables(items) {
|
|
6449
|
+
if (!(items === null || items === void 0 ? void 0 : items.length)) return;
|
|
6450
|
+
for (const item of items) try {
|
|
6451
|
+
item.dispose();
|
|
6270
6452
|
} catch {}
|
|
6271
|
-
diffMgr = new DiffEditorManager(monacoOptions, maxHeightValue, maxHeightCSS, autoScrollOnUpdate, autoScrollInitial, autoScrollThresholdPx, autoScrollThresholdLines, diffAutoScroll, monacoOptions.revealDebounceMs, monacoOptions.diffUpdateThrottleMs);
|
|
6272
|
-
diffEditorView = await diffMgr.createDiffEditor(container, originalCode, modifiedCode, language, initialThemeName);
|
|
6273
|
-
if (typeof monacoOptions.onThemeChange === "function") monacoOptions.onThemeChange(initialThemeName);
|
|
6274
|
-
const models = diffMgr.getDiffModels();
|
|
6275
|
-
originalModel = models.original;
|
|
6276
|
-
modifiedModel = models.modified;
|
|
6277
|
-
return diffEditorView;
|
|
6278
|
-
}
|
|
6279
|
-
function clearFallbackAsyncWork() {
|
|
6280
|
-
rafScheduler.cancel("update");
|
|
6281
|
-
rafScheduler.cancel("append");
|
|
6282
|
-
rafScheduler.cancel("reveal");
|
|
6283
|
-
pendingUpdate = null;
|
|
6284
|
-
appendBufferScheduled = false;
|
|
6285
|
-
appendBuffer.length = 0;
|
|
6286
|
-
if (revealDebounceId != null) {
|
|
6287
|
-
clearTimeout(revealDebounceId);
|
|
6288
|
-
revealDebounceId = null;
|
|
6289
|
-
}
|
|
6290
|
-
if (updateThrottleTimer != null) {
|
|
6291
|
-
clearTimeout(updateThrottleTimer);
|
|
6292
|
-
updateThrottleTimer = null;
|
|
6293
|
-
}
|
|
6294
|
-
lastFlushTime = 0;
|
|
6295
6453
|
}
|
|
6296
|
-
function
|
|
6454
|
+
function takePendingCreateDisposables(requestId) {
|
|
6455
|
+
const items = pendingCreateDisposables.get(requestId) ?? [];
|
|
6456
|
+
pendingCreateDisposables.delete(requestId);
|
|
6457
|
+
return items;
|
|
6458
|
+
}
|
|
6459
|
+
function disposeAllPendingCreateDisposables() {
|
|
6460
|
+
for (const requestId of Array.from(pendingCreateDisposables.keys())) disposeDisposables(takePendingCreateDisposables(requestId));
|
|
6461
|
+
}
|
|
6462
|
+
function cleanupInstances() {
|
|
6297
6463
|
if (editorMgr) {
|
|
6298
6464
|
editorMgr.cleanup();
|
|
6299
6465
|
editorMgr = null;
|
|
6300
|
-
}
|
|
6466
|
+
} else if (editorView) try {
|
|
6467
|
+
editorView.dispose();
|
|
6468
|
+
} catch {}
|
|
6301
6469
|
if (diffMgr) {
|
|
6302
6470
|
diffMgr.cleanup();
|
|
6303
6471
|
diffMgr = null;
|
|
6472
|
+
} else {
|
|
6473
|
+
try {
|
|
6474
|
+
diffEditorView === null || diffEditorView === void 0 || diffEditorView.dispose();
|
|
6475
|
+
} catch {}
|
|
6476
|
+
try {
|
|
6477
|
+
originalModel === null || originalModel === void 0 || originalModel.dispose();
|
|
6478
|
+
} catch {}
|
|
6479
|
+
try {
|
|
6480
|
+
modifiedModel === null || modifiedModel === void 0 || modifiedModel.dispose();
|
|
6481
|
+
} catch {}
|
|
6304
6482
|
}
|
|
6305
|
-
|
|
6306
|
-
if (!editorMgr && editorView) {
|
|
6307
|
-
editorView.dispose();
|
|
6308
|
-
editorView = null;
|
|
6309
|
-
}
|
|
6310
|
-
lastKnownCode = null;
|
|
6311
|
-
if (lastContainer) {
|
|
6312
|
-
lastContainer.innerHTML = "";
|
|
6313
|
-
lastContainer = null;
|
|
6314
|
-
}
|
|
6315
|
-
if (themeWatcher) {
|
|
6316
|
-
themeWatcher();
|
|
6317
|
-
themeWatcher = null;
|
|
6318
|
-
}
|
|
6483
|
+
editorView = null;
|
|
6319
6484
|
diffEditorView = null;
|
|
6320
6485
|
originalModel = null;
|
|
6321
6486
|
modifiedModel = null;
|
|
6322
6487
|
}
|
|
6323
|
-
function
|
|
6324
|
-
|
|
6325
|
-
|
|
6326
|
-
|
|
6327
|
-
|
|
6328
|
-
|
|
6329
|
-
|
|
6330
|
-
|
|
6331
|
-
|
|
6332
|
-
|
|
6333
|
-
|
|
6334
|
-
|
|
6335
|
-
|
|
6336
|
-
|
|
6337
|
-
|
|
6338
|
-
|
|
6488
|
+
function createSupersededError() {
|
|
6489
|
+
const err = new Error("Editor creation was superseded");
|
|
6490
|
+
err.name = "AbortError";
|
|
6491
|
+
err.code = "STREAM_MONACO_CREATE_SUPERSEDED";
|
|
6492
|
+
return err;
|
|
6493
|
+
}
|
|
6494
|
+
function isCreateActive(requestId, kind) {
|
|
6495
|
+
return activeCreateRequestId === requestId && activeCreateKind === kind;
|
|
6496
|
+
}
|
|
6497
|
+
function assertCreateStillActive(requestId, kind) {
|
|
6498
|
+
if (!isCreateActive(requestId, kind)) throw createSupersededError();
|
|
6499
|
+
}
|
|
6500
|
+
function cancelPendingCreates() {
|
|
6501
|
+
activeCreateRequestId = null;
|
|
6502
|
+
activeCreateKind = null;
|
|
6503
|
+
queuedEditorUpdateDuringCreate = null;
|
|
6504
|
+
disposeAllPendingCreateDisposables();
|
|
6505
|
+
}
|
|
6506
|
+
async function resolveCreateThemeName(requestId, kind) {
|
|
6507
|
+
let themeName = resolveRequestedThemeName();
|
|
6508
|
+
while (true) {
|
|
6509
|
+
assertCreateStillActive(requestId, kind);
|
|
6510
|
+
await ensureThemeRegistered(themeName);
|
|
6511
|
+
assertCreateStillActive(requestId, kind);
|
|
6512
|
+
const latestThemeName = resolveRequestedThemeName();
|
|
6513
|
+
if (latestThemeName === themeName) return themeName;
|
|
6514
|
+
themeName = latestThemeName;
|
|
6339
6515
|
}
|
|
6340
6516
|
}
|
|
6341
|
-
function
|
|
6342
|
-
|
|
6343
|
-
|
|
6344
|
-
|
|
6517
|
+
async function createEditor(container, code, language) {
|
|
6518
|
+
var _monacoOptions$onBefo;
|
|
6519
|
+
cancelPendingCreates();
|
|
6520
|
+
cleanupInstances();
|
|
6521
|
+
const requestId = ++createRequestSeq;
|
|
6522
|
+
activeCreateRequestId = requestId;
|
|
6523
|
+
activeCreateKind = "editor";
|
|
6524
|
+
if (monacoOptions.isCleanOnBeforeCreate ?? true) disposeDisposables(disposals.splice(0));
|
|
6525
|
+
const requestDisposables = ((_monacoOptions$onBefo = monacoOptions.onBeforeCreate) === null || _monacoOptions$onBefo === void 0 ? void 0 : _monacoOptions$onBefo.call(monacoOptions, monaco_shim_exports)) ?? [];
|
|
6526
|
+
if (requestDisposables.length) pendingCreateDisposables.set(requestId, requestDisposables);
|
|
6527
|
+
let nextEditorMgr = null;
|
|
6345
6528
|
try {
|
|
6346
|
-
const
|
|
6347
|
-
|
|
6348
|
-
const
|
|
6349
|
-
|
|
6350
|
-
|
|
6351
|
-
|
|
6352
|
-
|
|
6353
|
-
|
|
6354
|
-
|
|
6355
|
-
|
|
6356
|
-
|
|
6357
|
-
|
|
6358
|
-
|
|
6359
|
-
|
|
6360
|
-
|
|
6361
|
-
|
|
6362
|
-
|
|
6363
|
-
|
|
6364
|
-
|
|
6365
|
-
const isReadOnly = editorView.getOption(monaco_shim_exports.editor.EditorOption.readOnly);
|
|
6366
|
-
const edit = [{
|
|
6367
|
-
range,
|
|
6368
|
-
text: replaceText,
|
|
6369
|
-
forceMoveMarkers: true
|
|
6370
|
-
}];
|
|
6371
|
-
if (isReadOnly) model.applyEdits(edit);
|
|
6372
|
-
else editorView.executeEdits("minimal-replace", edit);
|
|
6373
|
-
}
|
|
6374
|
-
function flushPendingUpdate() {
|
|
6375
|
-
if (!pendingUpdate) return;
|
|
6376
|
-
lastFlushTime = Date.now();
|
|
6377
|
-
if (!editorView) return;
|
|
6378
|
-
const model = editorView.getModel();
|
|
6379
|
-
if (!model) return;
|
|
6380
|
-
const { code: newCode, lang: codeLanguage } = pendingUpdate;
|
|
6381
|
-
pendingUpdate = null;
|
|
6382
|
-
const processedCodeLanguage = processedLanguage(codeLanguage);
|
|
6383
|
-
let prevCode = null;
|
|
6384
|
-
if (appendBuffer.length > 0) {
|
|
6385
|
-
appendBuffer.length = 0;
|
|
6386
|
-
appendBufferScheduled = false;
|
|
6387
|
-
rafScheduler.cancel("append");
|
|
6388
|
-
try {
|
|
6389
|
-
prevCode = model.getValue();
|
|
6390
|
-
lastKnownCode = prevCode;
|
|
6391
|
-
} catch {
|
|
6392
|
-
prevCode = lastKnownCode ?? "";
|
|
6529
|
+
const initialThemeName = await resolveCreateThemeName(requestId, "editor");
|
|
6530
|
+
nextEditorMgr = new EditorManager(monacoOptions, maxHeightValue, maxHeightCSS, autoScrollOnUpdate, autoScrollInitial, autoScrollThresholdPx, autoScrollThresholdLines, monacoOptions.revealDebounceMs, monacoOptions.updateThrottleMs);
|
|
6531
|
+
const nextEditorView = await nextEditorMgr.createEditor(container, code, language, initialThemeName);
|
|
6532
|
+
assertCreateStillActive(requestId, "editor");
|
|
6533
|
+
editorMgr = nextEditorMgr;
|
|
6534
|
+
editorView = nextEditorView;
|
|
6535
|
+
diffMgr = null;
|
|
6536
|
+
diffEditorView = null;
|
|
6537
|
+
originalModel = null;
|
|
6538
|
+
modifiedModel = null;
|
|
6539
|
+
commitAppliedTheme(initialThemeName);
|
|
6540
|
+
const committedDisposables = takePendingCreateDisposables(requestId);
|
|
6541
|
+
if (committedDisposables.length) disposals.push(...committedDisposables);
|
|
6542
|
+
activeCreateRequestId = null;
|
|
6543
|
+
activeCreateKind = null;
|
|
6544
|
+
const queuedUpdate = queuedEditorUpdateDuringCreate;
|
|
6545
|
+
if ((queuedUpdate === null || queuedUpdate === void 0 ? void 0 : queuedUpdate.requestId) === requestId) {
|
|
6546
|
+
queuedEditorUpdateDuringCreate = null;
|
|
6547
|
+
editorMgr.updateCode(queuedUpdate.code, queuedUpdate.lang);
|
|
6393
6548
|
}
|
|
6394
|
-
|
|
6395
|
-
|
|
6396
|
-
|
|
6397
|
-
|
|
6398
|
-
|
|
6399
|
-
} catch {
|
|
6400
|
-
|
|
6549
|
+
await notifyThemeApplied(initialThemeName);
|
|
6550
|
+
return nextEditorView;
|
|
6551
|
+
} catch (error$1) {
|
|
6552
|
+
if (nextEditorMgr) try {
|
|
6553
|
+
nextEditorMgr.cleanup();
|
|
6554
|
+
} catch {}
|
|
6555
|
+
disposeDisposables(takePendingCreateDisposables(requestId));
|
|
6556
|
+
if (activeCreateRequestId === requestId) {
|
|
6557
|
+
activeCreateRequestId = null;
|
|
6558
|
+
activeCreateKind = null;
|
|
6559
|
+
queuedEditorUpdateDuringCreate = null;
|
|
6401
6560
|
}
|
|
6561
|
+
throw error$1;
|
|
6402
6562
|
}
|
|
6403
|
-
|
|
6404
|
-
|
|
6405
|
-
|
|
6406
|
-
|
|
6407
|
-
|
|
6408
|
-
|
|
6409
|
-
|
|
6410
|
-
|
|
6411
|
-
|
|
6412
|
-
|
|
6413
|
-
|
|
6414
|
-
|
|
6415
|
-
const suffix = newCode.slice(prevCode.length);
|
|
6416
|
-
if (suffix) appendCode(suffix, codeLanguage);
|
|
6417
|
-
lastKnownCode = newCode;
|
|
6418
|
-
return;
|
|
6419
|
-
}
|
|
6420
|
-
try {
|
|
6421
|
-
const maxChars = minimalEditMaxCharsLocal;
|
|
6422
|
-
const ratio = minimalEditMaxChangeRatioLocal;
|
|
6423
|
-
const maxLen = Math.max(prevCode.length, newCode.length);
|
|
6424
|
-
const changeRatio = maxLen > 0 ? Math.abs(newCode.length - prevCode.length) / maxLen : 0;
|
|
6425
|
-
if (prevCode.length + newCode.length > maxChars || changeRatio > ratio) {
|
|
6426
|
-
const prevLineCount = model.getLineCount();
|
|
6427
|
-
model.setValue(newCode);
|
|
6428
|
-
lastKnownCode = newCode;
|
|
6429
|
-
const newLineCount = model.getLineCount();
|
|
6430
|
-
if (newLineCount !== prevLineCount) maybeScrollToBottom(newLineCount);
|
|
6431
|
-
return;
|
|
6432
|
-
}
|
|
6433
|
-
} catch {}
|
|
6563
|
+
}
|
|
6564
|
+
async function createDiffEditor(container, originalCode, modifiedCode, language) {
|
|
6565
|
+
var _monacoOptions$onBefo2;
|
|
6566
|
+
cancelPendingCreates();
|
|
6567
|
+
cleanupInstances();
|
|
6568
|
+
const requestId = ++createRequestSeq;
|
|
6569
|
+
activeCreateRequestId = requestId;
|
|
6570
|
+
activeCreateKind = "diff";
|
|
6571
|
+
if (monacoOptions.isCleanOnBeforeCreate ?? true) disposeDisposables(disposals.splice(0));
|
|
6572
|
+
const requestDisposables = ((_monacoOptions$onBefo2 = monacoOptions.onBeforeCreate) === null || _monacoOptions$onBefo2 === void 0 ? void 0 : _monacoOptions$onBefo2.call(monacoOptions, monaco_shim_exports)) ?? [];
|
|
6573
|
+
if (requestDisposables.length) pendingCreateDisposables.set(requestId, requestDisposables);
|
|
6574
|
+
let nextDiffMgr = null;
|
|
6434
6575
|
try {
|
|
6435
|
-
|
|
6436
|
-
|
|
6437
|
-
const
|
|
6438
|
-
|
|
6439
|
-
|
|
6440
|
-
|
|
6441
|
-
|
|
6442
|
-
|
|
6443
|
-
|
|
6444
|
-
|
|
6445
|
-
|
|
6446
|
-
|
|
6576
|
+
const initialThemeName = await resolveCreateThemeName(requestId, "diff");
|
|
6577
|
+
nextDiffMgr = new DiffEditorManager(monacoOptions, maxHeightValue, maxHeightCSS, autoScrollOnUpdate, autoScrollInitial, autoScrollThresholdPx, autoScrollThresholdLines, diffAutoScroll, monacoOptions.revealDebounceMs, monacoOptions.diffUpdateThrottleMs);
|
|
6578
|
+
const nextDiffEditorView = await nextDiffMgr.createDiffEditor(container, originalCode, modifiedCode, language, initialThemeName);
|
|
6579
|
+
assertCreateStillActive(requestId, "diff");
|
|
6580
|
+
diffMgr = nextDiffMgr;
|
|
6581
|
+
diffEditorView = nextDiffEditorView;
|
|
6582
|
+
editorMgr = null;
|
|
6583
|
+
editorView = null;
|
|
6584
|
+
const models = diffMgr.getDiffModels();
|
|
6585
|
+
originalModel = models.original;
|
|
6586
|
+
modifiedModel = models.modified;
|
|
6587
|
+
commitAppliedTheme(initialThemeName);
|
|
6588
|
+
const committedDisposables = takePendingCreateDisposables(requestId);
|
|
6589
|
+
if (committedDisposables.length) disposals.push(...committedDisposables);
|
|
6590
|
+
activeCreateRequestId = null;
|
|
6591
|
+
activeCreateKind = null;
|
|
6592
|
+
await notifyThemeApplied(initialThemeName);
|
|
6593
|
+
return nextDiffEditorView;
|
|
6594
|
+
} catch (error$1) {
|
|
6595
|
+
if (nextDiffMgr) try {
|
|
6596
|
+
nextDiffMgr.cleanup();
|
|
6447
6597
|
} catch {}
|
|
6598
|
+
disposeDisposables(takePendingCreateDisposables(requestId));
|
|
6599
|
+
if (activeCreateRequestId === requestId) {
|
|
6600
|
+
activeCreateRequestId = null;
|
|
6601
|
+
activeCreateKind = null;
|
|
6602
|
+
}
|
|
6603
|
+
throw error$1;
|
|
6448
6604
|
}
|
|
6449
6605
|
}
|
|
6450
|
-
function
|
|
6451
|
-
|
|
6452
|
-
|
|
6453
|
-
|
|
6454
|
-
|
|
6455
|
-
|
|
6456
|
-
|
|
6457
|
-
return;
|
|
6458
|
-
}
|
|
6459
|
-
const text = appendBuffer.join("");
|
|
6460
|
-
appendBuffer.length = 0;
|
|
6461
|
-
try {
|
|
6462
|
-
const lastLine = model.getLineCount();
|
|
6463
|
-
const lastColumn = model.getLineMaxColumn(lastLine);
|
|
6464
|
-
const range = new monaco_shim_exports.Range(lastLine, lastColumn, lastLine, lastColumn);
|
|
6465
|
-
const isReadOnly = editorView.getOption(monaco_shim_exports.editor.EditorOption.readOnly);
|
|
6466
|
-
if (isReadOnly) model.applyEdits([{
|
|
6467
|
-
range,
|
|
6468
|
-
text,
|
|
6469
|
-
forceMoveMarkers: true
|
|
6470
|
-
}]);
|
|
6471
|
-
else editorView.executeEdits("append", [{
|
|
6472
|
-
range,
|
|
6473
|
-
text,
|
|
6474
|
-
forceMoveMarkers: true
|
|
6475
|
-
}]);
|
|
6476
|
-
if (lastKnownCode != null) lastKnownCode = lastKnownCode + text;
|
|
6477
|
-
try {
|
|
6478
|
-
if (lastLine !== model.getLineCount()) maybeScrollToBottom(model.getLineCount());
|
|
6479
|
-
} catch {}
|
|
6480
|
-
} catch {}
|
|
6606
|
+
function cleanupEditor() {
|
|
6607
|
+
cancelPendingCreates();
|
|
6608
|
+
cleanupInstances();
|
|
6609
|
+
disposeDisposables(disposals.splice(0));
|
|
6610
|
+
}
|
|
6611
|
+
function appendCode(appendText, codeLanguage) {
|
|
6612
|
+
if (editorMgr) editorMgr.appendCode(appendText, codeLanguage);
|
|
6481
6613
|
}
|
|
6482
6614
|
function updateCode(newCode, codeLanguage) {
|
|
6483
|
-
if (editorMgr)
|
|
6484
|
-
|
|
6485
|
-
|
|
6486
|
-
code: newCode,
|
|
6487
|
-
lang: codeLanguage
|
|
6488
|
-
};
|
|
6489
|
-
rafScheduler.schedule("update", () => {
|
|
6490
|
-
if (!updateThrottleMs) {
|
|
6491
|
-
flushPendingUpdate();
|
|
6492
|
-
return;
|
|
6493
|
-
}
|
|
6494
|
-
const now = Date.now();
|
|
6495
|
-
const since = now - lastFlushTime;
|
|
6496
|
-
if (since >= updateThrottleMs) {
|
|
6497
|
-
flushPendingUpdate();
|
|
6498
|
-
return;
|
|
6499
|
-
}
|
|
6500
|
-
if (updateThrottleTimer != null) return;
|
|
6501
|
-
const wait = updateThrottleMs - since;
|
|
6502
|
-
updateThrottleTimer = setTimeout(() => {
|
|
6503
|
-
updateThrottleTimer = null;
|
|
6504
|
-
rafScheduler.schedule("update", () => flushPendingUpdate());
|
|
6505
|
-
}, wait);
|
|
6506
|
-
});
|
|
6615
|
+
if (editorMgr) {
|
|
6616
|
+
editorMgr.updateCode(newCode, codeLanguage);
|
|
6617
|
+
return;
|
|
6507
6618
|
}
|
|
6619
|
+
if (activeCreateRequestId != null && activeCreateKind === "editor") queuedEditorUpdateDuringCreate = {
|
|
6620
|
+
requestId: activeCreateRequestId,
|
|
6621
|
+
code: newCode,
|
|
6622
|
+
lang: codeLanguage
|
|
6623
|
+
};
|
|
6508
6624
|
}
|
|
6509
6625
|
function setUpdateThrottleMs(ms) {
|
|
6510
|
-
updateThrottleMs = ms;
|
|
6626
|
+
monacoOptions.updateThrottleMs = ms;
|
|
6511
6627
|
editorMgr === null || editorMgr === void 0 || editorMgr.setUpdateThrottleMs(ms);
|
|
6512
6628
|
}
|
|
6513
6629
|
function getUpdateThrottleMs() {
|
|
6514
|
-
return (editorMgr === null || editorMgr === void 0 ? void 0 : editorMgr.getUpdateThrottleMs()) ?? updateThrottleMs;
|
|
6630
|
+
return (editorMgr === null || editorMgr === void 0 ? void 0 : editorMgr.getUpdateThrottleMs()) ?? monacoOptions.updateThrottleMs ?? 50;
|
|
6515
6631
|
}
|
|
6516
6632
|
function updateDiff(originalCode, modifiedCode, codeLanguage) {
|
|
6517
6633
|
if (diffMgr) diffMgr.updateDiff(originalCode, modifiedCode, codeLanguage);
|
|
@@ -6543,15 +6659,12 @@ function useMonaco(monacoOptions = {}) {
|
|
|
6543
6659
|
createDiffEditor,
|
|
6544
6660
|
cleanupEditor,
|
|
6545
6661
|
safeClean() {
|
|
6546
|
-
clearFallbackAsyncWork();
|
|
6547
6662
|
if (editorMgr) try {
|
|
6548
6663
|
editorMgr.safeClean();
|
|
6549
6664
|
} catch {}
|
|
6550
6665
|
if (diffMgr) try {
|
|
6551
6666
|
diffMgr.safeClean();
|
|
6552
6667
|
} catch {}
|
|
6553
|
-
_hasScrollBar = false;
|
|
6554
|
-
shouldAutoScroll = !!autoScrollInitial;
|
|
6555
6668
|
},
|
|
6556
6669
|
updateCode,
|
|
6557
6670
|
appendCode,
|
|
@@ -6588,10 +6701,10 @@ function useMonaco(monacoOptions = {}) {
|
|
|
6588
6701
|
return monaco_shim_exports.editor;
|
|
6589
6702
|
},
|
|
6590
6703
|
getEditorView() {
|
|
6591
|
-
return editorView;
|
|
6704
|
+
return (editorMgr === null || editorMgr === void 0 ? void 0 : editorMgr.getEditorView()) ?? editorView;
|
|
6592
6705
|
},
|
|
6593
6706
|
getDiffEditorView() {
|
|
6594
|
-
return diffEditorView;
|
|
6707
|
+
return (diffMgr === null || diffMgr === void 0 ? void 0 : diffMgr.getDiffEditorView()) ?? diffEditorView;
|
|
6595
6708
|
},
|
|
6596
6709
|
getDiffModels() {
|
|
6597
6710
|
if (diffMgr) return diffMgr.getDiffModels();
|
|
@@ -6606,18 +6719,22 @@ function useMonaco(monacoOptions = {}) {
|
|
|
6606
6719
|
setUpdateThrottleMs,
|
|
6607
6720
|
getUpdateThrottleMs,
|
|
6608
6721
|
getCode() {
|
|
6722
|
+
if (editorMgr) return editorMgr.getCode();
|
|
6609
6723
|
if (editorView) try {
|
|
6610
6724
|
var _editorView$getModel;
|
|
6611
6725
|
return ((_editorView$getModel = editorView.getModel()) === null || _editorView$getModel === void 0 ? void 0 : _editorView$getModel.getValue()) ?? null;
|
|
6612
6726
|
} catch {
|
|
6613
6727
|
return null;
|
|
6614
6728
|
}
|
|
6615
|
-
|
|
6616
|
-
|
|
6617
|
-
|
|
6729
|
+
const diffModels = (diffMgr === null || diffMgr === void 0 ? void 0 : diffMgr.getDiffModels()) ?? {
|
|
6730
|
+
original: originalModel,
|
|
6731
|
+
modified: modifiedModel
|
|
6732
|
+
};
|
|
6733
|
+
if (diffEditorView || diffModels.original && diffModels.modified) try {
|
|
6734
|
+
var _diffModels$original, _diffModels$modified;
|
|
6618
6735
|
return {
|
|
6619
|
-
original,
|
|
6620
|
-
modified
|
|
6736
|
+
original: ((_diffModels$original = diffModels.original) === null || _diffModels$original === void 0 ? void 0 : _diffModels$original.getValue()) ?? "",
|
|
6737
|
+
modified: ((_diffModels$modified = diffModels.modified) === null || _diffModels$modified === void 0 ? void 0 : _diffModels$modified.getValue()) ?? ""
|
|
6621
6738
|
};
|
|
6622
6739
|
} catch {
|
|
6623
6740
|
return null;
|