@singapore-editor/diff 0.2.0 → 0.2.11
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/LICENSE +22 -0
- package/README.md +20 -134
- package/dist/diffGutter.js +2 -3
- package/dist/diffGutter.js.map +1 -1
- package/dist/diffRows.js +1 -2
- package/dist/diffSyntax.d.ts +17 -13
- package/dist/diffSyntax.d.ts.map +1 -1
- package/dist/diffSyntax.js +88 -59
- package/dist/diffSyntax.js.map +1 -1
- package/dist/editorDiffPlugin.d.ts +5 -4
- package/dist/editorDiffPlugin.d.ts.map +1 -1
- package/dist/editorDiffPlugin.js +9 -7
- package/dist/editorDiffPlugin.js.map +1 -1
- package/dist/editorOptions.d.ts +2 -2
- package/dist/editorOptions.d.ts.map +1 -1
- package/dist/editorOptions.js +5 -10
- package/dist/editorOptions.js.map +1 -1
- package/dist/gutters.js +1 -2
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -3
- package/dist/inline.js +1 -2
- package/dist/lines.d.ts +16 -0
- package/dist/lines.d.ts.map +1 -1
- package/dist/lines.js +31 -5
- package/dist/lines.js.map +1 -1
- package/dist/liveProjection.js +1 -2
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +14 -12
- package/dist/model.js.map +1 -1
- package/dist/projection.js +2 -3
- package/dist/projection.js.map +1 -1
- package/dist/regions.d.ts.map +1 -1
- package/dist/regions.js +0 -0
- package/dist/regions.js.map +1 -1
- package/dist/theme.js +4 -5
- package/dist/theme.js.map +1 -1
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +24 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Shaul Lavo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# @singapore-editor/diff
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Stacked and split diffs with inline changes for the Singapore editor.
|
|
4
|
+
|
|
5
|
+
Part of [Singapore](https://singapore.shaulavo.dev/). A code editor for the browser that keeps every version.
|
|
4
6
|
|
|
5
7
|
## Install
|
|
6
8
|
|
|
@@ -10,149 +12,33 @@ npm install @singapore-editor/core @singapore-editor/diff
|
|
|
10
12
|
|
|
11
13
|
## Usage
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
expansion state and the gutter; the **host owns the editor's document**, because no plugin context
|
|
15
|
-
can mutate document text. So the host pushes the plugin's rows in and re-applies its tokens:
|
|
15
|
+
Compare two versions and project the changed rows. Use `createDiffPlugin()` to render them in an editor.
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
|
-
import {
|
|
19
|
-
createDiffEditorOptions,
|
|
20
|
-
createDiffPlugin,
|
|
21
|
-
joinRenderLines,
|
|
22
|
-
parseGitPatch,
|
|
23
|
-
} from '@singapore-editor/diff'
|
|
24
|
-
import { Editor } from '@singapore-editor/core/editor'
|
|
25
|
-
import '@singapore-editor/core/style.css'
|
|
26
|
-
import '@singapore-editor/diff/style.css'
|
|
27
|
-
|
|
28
|
-
const plugin = createDiffPlugin({ mode: 'document', side: 'stacked' })
|
|
29
|
-
const editor = new Editor(host, {
|
|
30
|
-
...createDiffEditorOptions(),
|
|
31
|
-
plugins: [plugin],
|
|
32
|
-
tabSize: 4,
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
const push = () => {
|
|
36
|
-
// The tokens travel with the text: `setText` replaces the document, and a toggle without them
|
|
37
|
-
// would repaint uncoloured until the next parse.
|
|
38
|
-
//
|
|
39
|
-
// `Editor.syncText` is the cheaper alternative — it computes the minimal prefix/suffix edit
|
|
40
|
-
// rather than tearing the document down, and for an expansion that edit is exactly the inserted
|
|
41
|
-
// lines. It is not the default here because it also preserves caret and selection across rows
|
|
42
|
-
// that have moved, and an expansion moves every row below the region: a reader holding a
|
|
43
|
-
// selection would find it pointing at different text. Worth taking if your host has no selection
|
|
44
|
-
// to lose.
|
|
45
|
-
editor.setText(joinRenderLines(plugin.getRows()), { tokens: plugin.getTokens() })
|
|
46
|
-
}
|
|
47
|
-
plugin.onDidChangeRows(push)
|
|
48
|
-
plugin.onDidChangeTokens(() => editor.setTokens(plugin.getTokens()))
|
|
49
|
-
|
|
50
|
-
plugin.setFile(parseGitPatch(patchText)[0])
|
|
51
|
-
```
|
|
18
|
+
import { createStackedProjection, createTextDiff, joinRenderLines } from '@singapore-editor/diff'
|
|
52
19
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
Spread it and add your own options: plugins, typography, theme. The pushed text carries no
|
|
57
|
-
`languageId`, because the language belongs to the plugin's per-side syntax documents.
|
|
58
|
-
|
|
59
|
-
`keymap` and `cursorLineHighlight` are whole objects, and a field an override leaves out takes the
|
|
60
|
-
editor default: every key pack and a painted cursor line. Extend them:
|
|
61
|
-
|
|
62
|
-
```ts
|
|
63
|
-
const preset = createDiffEditorOptions()
|
|
64
|
-
const editor = new Editor(host, {
|
|
65
|
-
...preset,
|
|
66
|
-
cursorLineHighlight: { ...preset.cursorLineHighlight, gutterNumber: true },
|
|
67
|
-
keymap: { ...preset.keymap, layers: [...preset.keymap.layers, hostLayer] },
|
|
68
|
-
plugins: [plugin],
|
|
20
|
+
const file = createTextDiff({
|
|
21
|
+
oldFile: { path: 'note.ts', text: 'const value = 1\n' },
|
|
22
|
+
newFile: { path: 'note.ts', text: 'const value = 2\n' },
|
|
69
23
|
})
|
|
24
|
+
const projection = createStackedProjection(file)
|
|
25
|
+
console.log(joinRenderLines(projection.rows))
|
|
70
26
|
```
|
|
71
27
|
|
|
72
|
-
|
|
73
|
-
**Give both plugins the same region store**, or expanding a collapsed region on one side leaves the
|
|
74
|
-
other where it was and every row below it misaligns:
|
|
28
|
+
## API highlights
|
|
75
29
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const right = createDiffPlugin({ mode: 'document', side: 'new', regions })
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
This is not the mirroring the design forbids — there is one store, and both sides read it, rather
|
|
83
|
-
than two sets kept in step. The panes stay aligned only while word wrap is off and no fold map is
|
|
84
|
-
set.
|
|
85
|
-
|
|
86
|
-
A host that needs the diff row under a pointer calls `diffRowAtEvent(event)`. It answers with the
|
|
87
|
-
pane's side, its rows and the index into them, resolved through the editor's own row geometry,
|
|
88
|
-
so a host never reads `data-editor-virtual-row` or a pane class to find out where a press landed.
|
|
89
|
-
|
|
90
|
-
Expansion is per _diff_, not per path: pushing the same path with different content resets it,
|
|
91
|
-
because region keys are absolute line numbers and any edit above a region renumbers it. Pushing an
|
|
92
|
-
identical file again keeps it.
|
|
30
|
+
- `createTextDiff()` compares two file versions.
|
|
31
|
+
- `createDiffPlugin()` projects stacked or split rows.
|
|
32
|
+
- `parseGitPatch()` reads a Git patch.
|
|
93
33
|
|
|
94
|
-
|
|
34
|
+
[Generated API reference](https://singapore.shaulavo.dev/docs/reference/api/diff/overview/)
|
|
95
35
|
|
|
96
|
-
|
|
36
|
+
## In the Singapore family
|
|
97
37
|
|
|
98
|
-
|
|
99
|
-
| --------------------------------- | ----------------------- |
|
|
100
|
-
| `--editor-diff-background` | `backgroundColor` |
|
|
101
|
-
| `--editor-diff-foreground` | `foregroundColor` |
|
|
102
|
-
| `--editor-diff-gutter-background` | `gutterBackgroundColor` |
|
|
38
|
+
`@singapore-editor/core` owns the editor view. Add this plugin to display changes between two file versions.
|
|
103
39
|
|
|
104
|
-
|
|
105
|
-
inherit the values, and `editor.setTheme(theme)` updates them without remounting.
|
|
40
|
+
[Singapore README](https://github.com/ShaulLavo/singapore/blob/main/README.md) · [Documentation](https://singapore.shaulavo.dev/docs/start-here/introduction/)
|
|
106
41
|
|
|
107
|
-
|
|
108
|
-
editor.setTheme({
|
|
109
|
-
type: 'light',
|
|
110
|
-
backgroundColor: '#ffffff',
|
|
111
|
-
foregroundColor: '#18181b',
|
|
112
|
-
gutterBackgroundColor: '#f4f4f5',
|
|
113
|
-
colors: { 'diff.added.bg': '#dcfce7' },
|
|
114
|
-
})
|
|
115
|
-
```
|
|
42
|
+
## License
|
|
116
43
|
|
|
117
|
-
|
|
118
|
-
`type`; explicit colors override those defaults. A light theme should also supply its base colors.
|
|
119
|
-
|
|
120
|
-
| Color id | Paint |
|
|
121
|
-
| -------------------------------------- | ----------------------------------------------- |
|
|
122
|
-
| `diff.added`, `diff.deleted` | Added and deleted gutter numbers and indicators |
|
|
123
|
-
| `diff.modified` | Input to the default hunk background mix |
|
|
124
|
-
| `diff.added.bg`, `diff.deleted.bg` | Changed rows and their gutter rows |
|
|
125
|
-
| `diff.hunk.bg`, `diff.hunk.foreground` | Hunk separators and their gutter rows |
|
|
126
|
-
| `diff.placeholder.bg` | Empty cells on one side of a split diff |
|
|
127
|
-
| `diff.muted` | Empty diff message |
|
|
128
|
-
| `diff.border`, `diff.split.handle` | Host diff borders and split handles |
|
|
129
|
-
|
|
130
|
-
## Stacked rows
|
|
131
|
-
|
|
132
|
-
`plugin.getStackedRows()` returns both sides in row order, including the plugin's current region
|
|
133
|
-
expansions. For a stacked plugin it returns the same readonly array as `getRows()`. For a split
|
|
134
|
-
plugin the result is cached until its file or expansion state changes. Private region stores keep
|
|
135
|
-
views independent; plugins given the same store observe each other's toggles. Overlay mode returns
|
|
136
|
-
its live projection rows, as `getRows()` does.
|
|
137
|
-
|
|
138
|
-
## Modes
|
|
139
|
-
|
|
140
|
-
- **`document`** (default) — the editor holds a synthetic buffer of the projected rows. Deletion rows
|
|
141
|
-
are real document lines, so they highlight, select and copy like any other text. This is the
|
|
142
|
-
parity path.
|
|
143
|
-
- **`overlay`** — the editor holds the host's live, editable buffer and deletions arrive as injected
|
|
144
|
-
rows. Injected rows have no offset space (`startOffset === endOffset`), which means no selection,
|
|
145
|
-
no copy, no inline word-diff, and syntax colouring borrowed from whatever document text sits at
|
|
146
|
-
the anchor offset. Non-parity by construction — see `test/overlayModeLimits.test.ts`. Use it for a
|
|
147
|
-
live dirty-diff against an editable document, not for a diff view.
|
|
148
|
-
|
|
149
|
-
## Exports
|
|
150
|
-
|
|
151
|
-
- `createDiffPlugin` — the one plugin factory, carrying both modes. `mode` is required.
|
|
152
|
-
- `createDiffEditorOptions` — the editor options a document-mode diff needs.
|
|
153
|
-
- `createDiffRegionStore` — shared expansion state for the two sides of a split view.
|
|
154
|
-
- `parseGitPatch` and `createTextDiff` build diff models.
|
|
155
|
-
- `createSplitProjection`, `createStackedProjection`, and `createLiveDiffProjection` expose render
|
|
156
|
-
projections.
|
|
157
|
-
- `joinRenderLines` turns projected rows into the buffer text the host pushes in.
|
|
158
|
-
- `projectDiffSyntaxTokens` maps full-file token streams onto projected rows.
|
|
44
|
+
MIT. [License](https://github.com/ShaulLavo/singapore/blob/main/LICENSE)
|
package/dist/diffGutter.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { diffGutterIndicatorText, diffGutterLaneTone, diffGutterLayout, diffGutterNumberText, diffGutterRowTone } from "./gutters.js";
|
|
2
|
-
|
|
2
|
+
// src/diffGutter.ts
|
|
3
3
|
/**
|
|
4
4
|
* Lane elements are resolved once, when the cell is created, and never looked up again.
|
|
5
5
|
*
|
|
@@ -45,7 +45,7 @@ function createDiffGutterContribution(options) {
|
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
function gutterLaneKinds(side) {
|
|
48
|
-
if (side === "stacked") return [
|
|
48
|
+
if (side === "stacked") return NUMBER_LANES.concat(["indicator"]);
|
|
49
49
|
return [side, "indicator"];
|
|
50
50
|
}
|
|
51
51
|
/** Everything `onLayout` publishes, so the memo cannot miss a change the payload carries. */
|
|
@@ -183,7 +183,6 @@ function validLane(value) {
|
|
|
183
183
|
if (!("tone" in value) || !validTone(value.tone)) return false;
|
|
184
184
|
return "width" in value && typeof value.width === "number" && Number.isFinite(value.width) && value.width >= 0 && value.width <= 1e4;
|
|
185
185
|
}
|
|
186
|
-
//#endregion
|
|
187
186
|
export { createDiffGutterContribution };
|
|
188
187
|
|
|
189
188
|
//# sourceMappingURL=diffGutter.js.map
|
package/dist/diffGutter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diffGutter.js","names":[],"sources":["../src/diffGutter.ts"],"sourcesContent":["import type {\n EditorGutterContribution,\n EditorGutterRowContext,\n} from '@singapore-editor/core/extensions'\nimport {\n diffGutterIndicatorText,\n diffGutterLaneTone,\n diffGutterLayout,\n diffGutterNumberText,\n diffGutterRowTone,\n type DiffGutterDigits,\n type DiffGutterLaneKind,\n type DiffGutterLayout,\n type DiffGutterSide,\n} from './gutters'\nimport type { DiffRenderRow } from './types'\n\nexport type DiffGutterOptions = {\n readonly side: DiffGutterSide\n /**\n * Where a changed row's gutter tint is painted. `row`: this gutter is the pane's whole gutter\n * (document mode), so the row decoration tints the gutter row, leading inset included, and the\n * cell stays clear. `cell`: the gutter is shared with the host's lanes (overlay mode), so only\n * this cell is tinted.\n */\n readonly tint: 'cell' | 'row'\n /**\n * The widest line number each lane must fit, computed once when the projection is built. Passing\n * rows here instead would make `width()` re-scan every projected row on every width\n * invalidation — which in overlay mode is every line of the file.\n */\n readonly getDigits: () => DiffGutterDigits\n /**\n * Which diff row a rendered gutter row is showing. The two modes answer this differently and the\n * gutter must not guess: in `document` mode the projection array index *is* the buffer row (§C4),\n * but in `overlay` mode the array interleaves injected deletion rows, so position and buffer row\n * diverge after the first deletion and the lookup has to go through `rowsByBufferRow`.\n *\n * Indexing a projection array positionally here is what broke overlay numbering once already.\n */\n readonly resolveRow: (row: EditorGutterRowContext) => DiffRenderRow | null\n readonly isEnabled?: () => boolean\n /**\n * Called whenever the lane geometry is recomputed, so the host can publish it as CSS custom\n * properties. The canvas gutter derived lane widths arithmetically; a DOM gutter has to hand the\n * same numbers to CSS or the columns drift (§3.3, trap 1).\n */\n readonly onLayout?: (layout: DiffGutterLayout) => void\n}\n\ntype DiffGutterLanes = {\n readonly cell: HTMLElement\n readonly lanes: ReadonlyMap<DiffGutterLaneKind, HTMLElement>\n}\n\n/**\n * Lane elements are resolved once, when the cell is created, and never looked up again.\n *\n * The previous live-diff gutter ran three `querySelector` calls per row per update\n * (editorDiffPlugin.ts:246-255 before this change) — ~132 lookups per repaint at 44 mounted rows,\n * on the exact path the Aug-2026 scroll work fixed. Cells are created once and recycled by the\n * core (virtualizedTextViewRows.ts:308-330), so caching here costs one WeakMap entry per mounted\n * row and removes the lookups entirely (§3.3, trap 3).\n */\nconst lanesByCell = new WeakMap<HTMLElement, DiffGutterLanes>()\n\nconst NUMBER_LANES: readonly DiffGutterLaneKind[] = ['old', 'new']\n\nexport function createDiffGutterContribution(options: DiffGutterOptions): EditorGutterContribution {\n const laneKinds = gutterLaneKinds(options.side)\n let lastLayoutKey: string | null = null\n let laneWidths: readonly number[] = []\n\n return {\n id: `editor-diff-gutter-${options.side}`,\n className: 'editor-diff-gutter-cell',\n snapshotRenderer: {\n key: `diff-gutter-v1:${options.side}`,\n capture: (cell) => captureGutter(cell, laneKinds, laneWidths),\n restore: (cell, paint) => restoreGutter(cell, paint, laneKinds),\n },\n createCell(document) {\n const cell = createDiffGutterCell(document, laneKinds)\n if (options.tint === 'cell') cell.classList.add('editor-diff-gutter-tinted')\n return cell\n },\n width(context) {\n if (options.isEnabled && !options.isEnabled()) return 0\n\n const layout = diffGutterLayout(\n options.side,\n options.getDigits(),\n context.lineCount,\n context.metrics.characterWidth,\n )\n // Only on an actual change: `width` runs inside the core's layout pass, and writing custom\n // properties unconditionally would dirty style for the whole subtree on every recompute.\n //\n // Keyed on the whole lane split, not on the total. The stacked total is\n // `ceil(old*cw + 6) + ceil(new*cw + 6) + 12`, which is symmetric in the two lane character\n // counts — so swapping to a file whose old/new digit widths are transposed leaves the total\n // identical while the split needs to change, and a total-keyed memo would silently keep\n // publishing the previous columns. Lanes are `overflow: hidden`, so the under-sized one\n // clips its leading digit.\n laneWidths = layout.lanes.map((lane) => lane.width)\n const layoutKey = gutterLayoutKey(layout)\n if (layoutKey !== lastLayoutKey) {\n lastLayoutKey = layoutKey\n options.onLayout?.(layout)\n }\n return layout.width\n },\n updateCell(element, row) {\n updateDiffGutterCell(element, row, options)\n },\n }\n}\n\nfunction gutterLaneKinds(side: DiffGutterSide): readonly DiffGutterLaneKind[] {\n if (side === 'stacked') return [...NUMBER_LANES, 'indicator']\n return [side, 'indicator']\n}\n\n/** Everything `onLayout` publishes, so the memo cannot miss a change the payload carries. */\nfunction gutterLayoutKey(layout: DiffGutterLayout): string {\n return `${layout.width}:${layout.lanes.map((lane) => `${lane.kind}=${lane.width}`).join(',')}`\n}\n\nfunction createDiffGutterCell(\n document: Document,\n laneKinds: readonly DiffGutterLaneKind[],\n): HTMLElement {\n const cell = document.createElement('span')\n cell.className = 'editor-diff-gutter'\n cell.setAttribute('aria-hidden', 'true')\n\n const lanes = new Map<DiffGutterLaneKind, HTMLElement>()\n for (const kind of laneKinds) {\n const lane = document.createElement('span')\n lane.className = `editor-diff-gutter-lane editor-diff-gutter-lane-${kind}`\n cell.appendChild(lane)\n lanes.set(kind, lane)\n }\n\n lanesByCell.set(cell, { cell, lanes })\n return cell\n}\n\nfunction updateDiffGutterCell(\n element: HTMLElement,\n row: EditorGutterRowContext,\n options: DiffGutterOptions,\n): void {\n const cached = lanesByCell.get(element)\n if (!cached) return\n element.style.removeProperty('grid-template-columns')\n\n const diffRow = diffRowForGutterRow(row, options)\n element.hidden = !diffRow\n if (!diffRow) {\n for (const lane of cached.lanes.values()) clearLane(lane)\n if (element.dataset.diffRowType !== undefined) delete element.dataset.diffRowType\n if (element.dataset.diffRowTone !== undefined) delete element.dataset.diffRowTone\n return\n }\n\n for (const [kind, lane] of cached.lanes) {\n setLaneText(lane, laneText(diffRow, kind))\n setLaneTone(lane, diffGutterLaneTone(diffRow, kind))\n }\n setDataset(element, 'diffRowType', diffRow.type)\n setDataset(element, 'diffRowTone', diffGutterRowTone(diffRow, options.side))\n}\n\nfunction diffRowForGutterRow(\n row: EditorGutterRowContext,\n options: DiffGutterOptions,\n): DiffRenderRow | null {\n if (options.isEnabled && !options.isEnabled()) return null\n return options.resolveRow(row)\n}\n\nfunction laneText(row: DiffRenderRow, kind: DiffGutterLaneKind): string {\n if (kind === 'indicator') return diffGutterIndicatorText(row)\n return diffGutterNumberText(row, kind)\n}\n\nfunction clearLane(lane: HTMLElement): void {\n setLaneText(lane, '')\n setLaneTone(lane, 'default')\n}\n\nfunction setLaneText(lane: HTMLElement, text: string): void {\n if (lane.textContent === text) return\n lane.textContent = text\n}\n\nfunction setLaneTone(lane: HTMLElement, tone: string): void {\n setDataset(lane, 'diffTone', tone)\n}\n\nfunction setDataset(element: HTMLElement, key: string, value: string): void {\n if (element.dataset[key] === value) return\n element.dataset[key] = value\n}\n\ntype GutterPaint = {\n hidden: boolean\n type: string\n tone: string\n lanes: { text: string; tone: string; width: number }[]\n}\n\nfunction captureGutter(\n cell: HTMLElement,\n kinds: readonly DiffGutterLaneKind[],\n widths: readonly number[],\n): string | null {\n const cached = lanesByCell.get(cell)\n if (!cached || widths.length !== kinds.length) return null\n const lanes = kinds.map((kind, index) => {\n const lane = cached.lanes.get(kind)\n return {\n text: lane?.textContent ?? '',\n tone: lane?.dataset.diffTone ?? 'default',\n width: widths[index]!,\n }\n })\n return JSON.stringify({\n hidden: cell.hidden,\n type: cell.dataset.diffRowType ?? '',\n tone: cell.dataset.diffRowTone ?? 'default',\n lanes,\n })\n}\n\nfunction restoreGutter(\n cell: HTMLElement,\n paint: string,\n kinds: readonly DiffGutterLaneKind[],\n): boolean {\n if (paint.length > 4096) return false\n let value: unknown\n try {\n value = JSON.parse(paint)\n } catch {\n return false\n }\n if (!validGutterPaint(value, kinds.length)) return false\n const cached = lanesByCell.get(cell)\n if (!cached) return false\n cell.hidden = value.hidden\n setDataset(cell, 'diffRowType', value.type)\n setDataset(cell, 'diffRowTone', value.tone)\n cell.style.gridTemplateColumns = value.lanes.map((lane) => `${lane.width}px`).join(' ')\n for (let index = 0; index < kinds.length; index += 1) {\n const lane = cached.lanes.get(kinds[index]!)\n const saved = value.lanes[index]\n if (!lane || !saved) return false\n setLaneText(lane, saved.text)\n setLaneTone(lane, saved.tone)\n }\n return true\n}\n\nfunction validGutterPaint(value: unknown, length: number): value is GutterPaint {\n if (!value || typeof value !== 'object') return false\n if (!('hidden' in value) || typeof value.hidden !== 'boolean') return false\n if (\n !('type' in value) ||\n typeof value.type !== 'string' ||\n !['', 'context', 'addition', 'deletion', 'placeholder', 'hunk', 'empty'].includes(value.type)\n )\n return false\n if (!('tone' in value) || !validTone(value.tone)) return false\n if (!('lanes' in value) || !Array.isArray(value.lanes) || value.lanes.length !== length)\n return false\n return value.lanes.every(validLane)\n}\n\nfunction validTone(value: unknown): value is string {\n return typeof value === 'string' && ['default', 'added', 'deleted', 'hunk'].includes(value)\n}\n\nfunction validLane(value: unknown): boolean {\n if (!value || typeof value !== 'object') return false\n if (!('text' in value) || typeof value.text !== 'string' || value.text.length > 24) return false\n if (!('tone' in value) || !validTone(value.tone)) return false\n return (\n 'width' in value &&\n typeof value.width === 'number' &&\n Number.isFinite(value.width) &&\n value.width >= 0 &&\n value.width <= 10_000\n )\n}\n"],"mappings":";;;;;;;;;;;AAgEA,IAAM,8BAAc,IAAI,QAAsC;AAE9D,IAAM,eAA8C,CAAC,OAAO,KAAK;AAEjE,SAAgB,6BAA6B,SAAsD;CACjG,MAAM,YAAY,gBAAgB,QAAQ,IAAI;CAC9C,IAAI,gBAA+B;CACnC,IAAI,aAAgC,CAAC;CAErC,OAAO;EACL,IAAI,sBAAsB,QAAQ;EAClC,WAAW;EACX,kBAAkB;GAChB,KAAK,kBAAkB,QAAQ;GAC/B,UAAU,SAAS,cAAc,MAAM,WAAW,UAAU;GAC5D,UAAU,MAAM,UAAU,cAAc,MAAM,OAAO,SAAS;EAChE;EACA,WAAW,UAAU;GACnB,MAAM,OAAO,qBAAqB,UAAU,SAAS;GACrD,IAAI,QAAQ,SAAS,QAAQ,KAAK,UAAU,IAAI,2BAA2B;GAC3E,OAAO;EACT;EACA,MAAM,SAAS;GACb,IAAI,QAAQ,aAAa,CAAC,QAAQ,UAAU,GAAG,OAAO;GAEtD,MAAM,SAAS,iBACb,QAAQ,MACR,QAAQ,UAAU,GAClB,QAAQ,WACR,QAAQ,QAAQ,cAClB;GAUA,aAAa,OAAO,MAAM,KAAK,SAAS,KAAK,KAAK;GAClD,MAAM,YAAY,gBAAgB,MAAM;GACxC,IAAI,cAAc,eAAe;IAC/B,gBAAgB;IAChB,QAAQ,WAAW,MAAM;GAC3B;GACA,OAAO,OAAO;EAChB;EACA,WAAW,SAAS,KAAK;GACvB,qBAAqB,SAAS,KAAK,OAAO;EAC5C;CACF;AACF;AAEA,SAAS,g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S,UAAU,OAAyB;CAC1C,IAAI,CAAC,SAAS,OAAO,UAAU,UAAU,OAAO;CAChD,IAAI,EAAE,UAAU,UAAU,OAAO,MAAM,SAAS,YAAY,MAAM,KAAK,SAAS,IAAI,OAAO;CAC3F,IAAI,EAAE,UAAU,UAAU,CAAC,UAAU,MAAM,IAAI,GAAG,OAAO;CACzD,OACE,WAAW,SACX,OAAO,MAAM,UAAU,YACvB,OAAO,SAAS,MAAM,KAAK,KAC3B,MAAM,SAAS,KACf,MAAM,SAAS;AAEnB"}
|
|
1
|
+
{"version":3,"file":"diffGutter.js","names":[],"sources":["../src/diffGutter.ts"],"sourcesContent":["import type {\n EditorGutterContribution,\n EditorGutterRowContext,\n} from '@singapore-editor/core/extensions'\nimport {\n diffGutterIndicatorText,\n diffGutterLaneTone,\n diffGutterLayout,\n diffGutterNumberText,\n diffGutterRowTone,\n type DiffGutterDigits,\n type DiffGutterLaneKind,\n type DiffGutterLayout,\n type DiffGutterSide,\n} from './gutters'\nimport type { DiffRenderRow } from './types'\n\nexport type DiffGutterOptions = {\n readonly side: DiffGutterSide\n /**\n * Where a changed row's gutter tint is painted. `row`: this gutter is the pane's whole gutter\n * (document mode), so the row decoration tints the gutter row, leading inset included, and the\n * cell stays clear. `cell`: the gutter is shared with the host's lanes (overlay mode), so only\n * this cell is tinted.\n */\n readonly tint: 'cell' | 'row'\n /**\n * The widest line number each lane must fit, computed once when the projection is built. Passing\n * rows here instead would make `width()` re-scan every projected row on every width\n * invalidation — which in overlay mode is every line of the file.\n */\n readonly getDigits: () => DiffGutterDigits\n /**\n * Which diff row a rendered gutter row is showing. The two modes answer this differently and the\n * gutter must not guess: in `document` mode the projection array index *is* the buffer row (§C4),\n * but in `overlay` mode the array interleaves injected deletion rows, so position and buffer row\n * diverge after the first deletion and the lookup has to go through `rowsByBufferRow`.\n *\n * Indexing a projection array positionally here is what broke overlay numbering once already.\n */\n readonly resolveRow: (row: EditorGutterRowContext) => DiffRenderRow | null\n readonly isEnabled?: () => boolean\n /**\n * Called whenever the lane geometry is recomputed, so the host can publish it as CSS custom\n * properties. The canvas gutter derived lane widths arithmetically; a DOM gutter has to hand the\n * same numbers to CSS or the columns drift (§3.3, trap 1).\n */\n readonly onLayout?: (layout: DiffGutterLayout) => void\n}\n\ntype DiffGutterLanes = {\n readonly cell: HTMLElement\n readonly lanes: ReadonlyMap<DiffGutterLaneKind, HTMLElement>\n}\n\n/**\n * Lane elements are resolved once, when the cell is created, and never looked up again.\n *\n * The previous live-diff gutter ran three `querySelector` calls per row per update\n * (editorDiffPlugin.ts:246-255 before this change) — ~132 lookups per repaint at 44 mounted rows,\n * on the exact path the Aug-2026 scroll work fixed. Cells are created once and recycled by the\n * core (virtualizedTextViewRows.ts:308-330), so caching here costs one WeakMap entry per mounted\n * row and removes the lookups entirely (§3.3, trap 3).\n */\nconst lanesByCell = new WeakMap<HTMLElement, DiffGutterLanes>()\n\nconst NUMBER_LANES: readonly DiffGutterLaneKind[] = ['old', 'new']\n\nexport function createDiffGutterContribution(options: DiffGutterOptions): EditorGutterContribution {\n const laneKinds = gutterLaneKinds(options.side)\n let lastLayoutKey: string | null = null\n let laneWidths: readonly number[] = []\n\n return {\n id: `editor-diff-gutter-${options.side}`,\n className: 'editor-diff-gutter-cell',\n snapshotRenderer: {\n key: `diff-gutter-v1:${options.side}`,\n capture: (cell) => captureGutter(cell, laneKinds, laneWidths),\n restore: (cell, paint) => restoreGutter(cell, paint, laneKinds),\n },\n createCell(document) {\n const cell = createDiffGutterCell(document, laneKinds)\n if (options.tint === 'cell') cell.classList.add('editor-diff-gutter-tinted')\n return cell\n },\n width(context) {\n if (options.isEnabled && !options.isEnabled()) return 0\n\n const layout = diffGutterLayout(\n options.side,\n options.getDigits(),\n context.lineCount,\n context.metrics.characterWidth,\n )\n // Only on an actual change: `width` runs inside the core's layout pass, and writing custom\n // properties unconditionally would dirty style for the whole subtree on every recompute.\n //\n // Keyed on the whole lane split, not on the total. The stacked total is\n // `ceil(old*cw + 6) + ceil(new*cw + 6) + 12`, which is symmetric in the two lane character\n // counts — so swapping to a file whose old/new digit widths are transposed leaves the total\n // identical while the split needs to change, and a total-keyed memo would silently keep\n // publishing the previous columns. Lanes are `overflow: hidden`, so the under-sized one\n // clips its leading digit.\n laneWidths = layout.lanes.map((lane) => lane.width)\n const layoutKey = gutterLayoutKey(layout)\n if (layoutKey !== lastLayoutKey) {\n lastLayoutKey = layoutKey\n options.onLayout?.(layout)\n }\n return layout.width\n },\n updateCell(element, row) {\n updateDiffGutterCell(element, row, options)\n },\n }\n}\n\nfunction gutterLaneKinds(side: DiffGutterSide): readonly DiffGutterLaneKind[] {\n if (side === 'stacked') return NUMBER_LANES.concat(['indicator'])\n return [side, 'indicator']\n}\n\n/** Everything `onLayout` publishes, so the memo cannot miss a change the payload carries. */\nfunction gutterLayoutKey(layout: DiffGutterLayout): string {\n return `${layout.width}:${layout.lanes.map((lane) => `${lane.kind}=${lane.width}`).join(',')}`\n}\n\nfunction createDiffGutterCell(\n document: Document,\n laneKinds: readonly DiffGutterLaneKind[],\n): HTMLElement {\n const cell = document.createElement('span')\n cell.className = 'editor-diff-gutter'\n cell.setAttribute('aria-hidden', 'true')\n\n const lanes = new Map<DiffGutterLaneKind, HTMLElement>()\n for (const kind of laneKinds) {\n const lane = document.createElement('span')\n lane.className = `editor-diff-gutter-lane editor-diff-gutter-lane-${kind}`\n cell.appendChild(lane)\n lanes.set(kind, lane)\n }\n\n lanesByCell.set(cell, { cell, lanes })\n return cell\n}\n\nfunction updateDiffGutterCell(\n element: HTMLElement,\n row: EditorGutterRowContext,\n options: DiffGutterOptions,\n): void {\n const cached = lanesByCell.get(element)\n if (!cached) return\n element.style.removeProperty('grid-template-columns')\n\n const diffRow = diffRowForGutterRow(row, options)\n element.hidden = !diffRow\n if (!diffRow) {\n for (const lane of cached.lanes.values()) clearLane(lane)\n if (element.dataset.diffRowType !== undefined) delete element.dataset.diffRowType\n if (element.dataset.diffRowTone !== undefined) delete element.dataset.diffRowTone\n return\n }\n\n for (const [kind, lane] of cached.lanes) {\n setLaneText(lane, laneText(diffRow, kind))\n setLaneTone(lane, diffGutterLaneTone(diffRow, kind))\n }\n setDataset(element, 'diffRowType', diffRow.type)\n setDataset(element, 'diffRowTone', diffGutterRowTone(diffRow, options.side))\n}\n\nfunction diffRowForGutterRow(\n row: EditorGutterRowContext,\n options: DiffGutterOptions,\n): DiffRenderRow | null {\n if (options.isEnabled && !options.isEnabled()) return null\n return options.resolveRow(row)\n}\n\nfunction laneText(row: DiffRenderRow, kind: DiffGutterLaneKind): string {\n if (kind === 'indicator') return diffGutterIndicatorText(row)\n return diffGutterNumberText(row, kind)\n}\n\nfunction clearLane(lane: HTMLElement): void {\n setLaneText(lane, '')\n setLaneTone(lane, 'default')\n}\n\nfunction setLaneText(lane: HTMLElement, text: string): void {\n if (lane.textContent === text) return\n lane.textContent = text\n}\n\nfunction setLaneTone(lane: HTMLElement, tone: string): void {\n setDataset(lane, 'diffTone', tone)\n}\n\nfunction setDataset(element: HTMLElement, key: string, value: string): void {\n if (element.dataset[key] === value) return\n element.dataset[key] = value\n}\n\ntype GutterPaint = {\n hidden: boolean\n type: string\n tone: string\n lanes: { text: string; tone: string; width: number }[]\n}\n\nfunction captureGutter(\n cell: HTMLElement,\n kinds: readonly DiffGutterLaneKind[],\n widths: readonly number[],\n): string | null {\n const cached = lanesByCell.get(cell)\n if (!cached || widths.length !== kinds.length) return null\n const lanes = kinds.map((kind, index) => {\n const lane = cached.lanes.get(kind)\n return {\n text: lane?.textContent ?? '',\n tone: lane?.dataset.diffTone ?? 'default',\n width: widths[index]!,\n }\n })\n return JSON.stringify({\n hidden: cell.hidden,\n type: cell.dataset.diffRowType ?? '',\n tone: cell.dataset.diffRowTone ?? 'default',\n lanes,\n })\n}\n\nfunction restoreGutter(\n cell: HTMLElement,\n paint: string,\n kinds: readonly DiffGutterLaneKind[],\n): boolean {\n if (paint.length > 4096) return false\n let value: unknown\n try {\n value = JSON.parse(paint)\n } catch {\n return false\n }\n if (!validGutterPaint(value, kinds.length)) return false\n const cached = lanesByCell.get(cell)\n if (!cached) return false\n cell.hidden = value.hidden\n setDataset(cell, 'diffRowType', value.type)\n setDataset(cell, 'diffRowTone', value.tone)\n cell.style.gridTemplateColumns = value.lanes.map((lane) => `${lane.width}px`).join(' ')\n for (let index = 0; index < kinds.length; index += 1) {\n const lane = cached.lanes.get(kinds[index]!)\n const saved = value.lanes[index]\n if (!lane || !saved) return false\n setLaneText(lane, saved.text)\n setLaneTone(lane, saved.tone)\n }\n return true\n}\n\nfunction validGutterPaint(value: unknown, length: number): value is GutterPaint {\n if (!value || typeof value !== 'object') return false\n if (!('hidden' in value) || typeof value.hidden !== 'boolean') return false\n if (\n !('type' in value) ||\n typeof value.type !== 'string' ||\n !['', 'context', 'addition', 'deletion', 'placeholder', 'hunk', 'empty'].includes(value.type)\n )\n return false\n if (!('tone' in value) || !validTone(value.tone)) return false\n if (!('lanes' in value) || !Array.isArray(value.lanes) || value.lanes.length !== length)\n return false\n return value.lanes.every(validLane)\n}\n\nfunction validTone(value: unknown): value is string {\n return typeof value === 'string' && ['default', 'added', 'deleted', 'hunk'].includes(value)\n}\n\nfunction validLane(value: unknown): boolean {\n if (!value || typeof value !== 'object') return false\n if (!('text' in value) || typeof value.text !== 'string' || value.text.length > 24) return false\n if (!('tone' in value) || !validTone(value.tone)) return false\n return (\n 'width' in value &&\n typeof value.width === 'number' &&\n Number.isFinite(value.width) &&\n value.width >= 0 &&\n value.width <= 10_000\n )\n}\n"],"mappings":";;;;;;;;;;;AAgEA,IAAM,8BAAc,IAAI,QAAsC;AAE9D,IAAM,eAA8C,CAAC,OAAO,KAAK;AAEjE,SAAgB,6BAA6B,SAAsD;CACjG,MAAM,YAAY,gBAAgB,QAAQ,IAAI;CAC9C,IAAI,gBAA+B;CACnC,IAAI,aAAgC,CAAC;CAErC,OAAO;EACL,IAAI,sBAAsB,QAAQ;EAClC,WAAW;EACX,kBAAkB;GAChB,KAAK,kBAAkB,QAA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MAAM,IAAI;CAC9B;CACA,OAAO;AACT;AAEA,SAAS,iBAAiB,OAAgB,QAAsC;CAC9E,IAAI,CAAC,SAAS,OAAO,UAAU,UAAU,OAAO;CAChD,IAAI,EAAE,YAAY,UAAU,OAAO,MAAM,WAAW,WAAW,OAAO;CACtE,IACE,EAAE,UAAU,UACZ,OAAO,MAAM,SAAS,YACtB,CAAC;EAAC;EAAI;EAAW;EAAY;EAAY;EAAe;EAAQ;CAAO,CAAC,CAAC,SAAS,MAAM,IAAI,GAE5F,OAAO;CACT,IAAI,EAAE,UAAU,UAAU,CAAC,UAAU,MAAM,IAAI,GAAG,OAAO;CACzD,IAAI,EAAE,WAAW,UAAU,CAAC,MAAM,QAAQ,MAAM,KAAK,KAAK,MAAM,MAAM,WAAW,QAC/E,OAAO;CACT,OAAO,MAAM,MAAM,MAAM,SAAS;AACpC;AAEA,SAAS,UAAU,OAAiC;CAClD,OAAO,OAAO,UAAU,YAAY;EAAC;EAAW;EAAS;EAAW;CAAM,CAAC,CAAC,SAAS,KAAK;AAC5F;AAEA,SAAS,UAAU,OAAyB;CAC1C,IAAI,CAAC,SAAS,OAAO,UAAU,UAAU,OAAO;CAChD,IAAI,EAAE,UAAU,UAAU,OAAO,MAAM,SAAS,YAAY,MAAM,KAAK,SAAS,IAAI,OAAO;CAC3F,IAAI,EAAE,UAAU,UAAU,CAAC,UAAU,MAAM,IAAI,GAAG,OAAO;CACzD,OACE,WAAW,SACX,OAAO,MAAM,UAAU,YACvB,OAAO,SAAS,MAAM,KAAK,KAC3B,MAAM,SAAS,KACf,MAAM,SAAS;AAEnB"}
|
package/dist/diffRows.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/diffRows.ts
|
|
2
2
|
function diffRowDecorations(rows) {
|
|
3
3
|
const decorations = /* @__PURE__ */ new Map();
|
|
4
4
|
for (const [index, row] of rows.entries()) {
|
|
@@ -34,7 +34,6 @@ function decorationForRow(row) {
|
|
|
34
34
|
gutterClassName: `editor-diff-gutter-row editor-diff-gutter-band-${row.type}`
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
|
-
//#endregion
|
|
38
37
|
export { diffInlineHighlightRanges, diffRowDecorations };
|
|
39
38
|
|
|
40
39
|
//# sourceMappingURL=diffRows.js.map
|
package/dist/diffSyntax.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { type EditorSyntaxResult, type EditorToken, type EditorTokenInput, type
|
|
|
3
3
|
import type { DiffFile, DiffRenderRow, DiffSyntaxBackend } from './types';
|
|
4
4
|
type DiffSyntaxSide = 'old' | 'new' | 'stacked';
|
|
5
5
|
type DiffSyntaxSourceSide = 'old' | 'new';
|
|
6
|
-
|
|
6
|
+
type DiffSyntaxTokenSource = {
|
|
7
7
|
readonly lineStarts: readonly number[];
|
|
8
8
|
readonly side: DiffSyntaxSourceSide;
|
|
9
9
|
readonly tokens: EditorTokenInput;
|
|
@@ -20,8 +20,16 @@ export type DiffSyntaxControllerOptions = {
|
|
|
20
20
|
/** Fires when a *newly parsed* token stream lands; row-driven re-projection is synchronous. */
|
|
21
21
|
readonly onDidChangeTokens: () => void;
|
|
22
22
|
};
|
|
23
|
-
/**
|
|
24
|
-
export type
|
|
23
|
+
/** A disposable interest in one owned or borrowed immutable source stream. */
|
|
24
|
+
export type DiffSyntaxSourceReader = {
|
|
25
|
+
readonly side: DiffSyntaxSourceSide;
|
|
26
|
+
readonly lineStarts: readonly number[];
|
|
27
|
+
readonly tokens: EditorTokenStore;
|
|
28
|
+
onDidChangeTokens(listener: () => void): () => void;
|
|
29
|
+
dispose(): void;
|
|
30
|
+
};
|
|
31
|
+
/** Owned streams or borrowed readers, including a preparation still running. */
|
|
32
|
+
export type PreparedDiffSyntaxInput = readonly DiffSyntaxSourceReader[] | Promise<readonly DiffSyntaxSourceReader[]>;
|
|
25
33
|
export type PrepareDiffSyntaxOptions = {
|
|
26
34
|
readonly backend?: DiffSyntaxBackend;
|
|
27
35
|
/** Which pane the sources are for. `stacked` prepares both source sides. */
|
|
@@ -30,8 +38,8 @@ export type PrepareDiffSyntaxOptions = {
|
|
|
30
38
|
};
|
|
31
39
|
/**
|
|
32
40
|
* One source side's parsed token stream and the session that recolours it on a theme change.
|
|
33
|
-
*
|
|
34
|
-
*
|
|
41
|
+
* Its creator owns it and disposes it. A shared owner lends separate DiffSyntaxSourceReader
|
|
42
|
+
* interests, whose disposal releases only that interest.
|
|
35
43
|
*/
|
|
36
44
|
export declare class PreparedDiffSyntaxSource {
|
|
37
45
|
readonly side: DiffSyntaxSourceSide;
|
|
@@ -83,6 +91,7 @@ export declare class DiffSyntaxController {
|
|
|
83
91
|
private tokens;
|
|
84
92
|
private disposed;
|
|
85
93
|
private ready;
|
|
94
|
+
private generation;
|
|
86
95
|
constructor(options: DiffSyntaxControllerOptions);
|
|
87
96
|
/** A disposed controller is terminal — its scheduler never runs another task. */
|
|
88
97
|
isDisposed(): boolean;
|
|
@@ -90,20 +99,15 @@ export declare class DiffSyntaxController {
|
|
|
90
99
|
getTokens(): readonly EditorToken[];
|
|
91
100
|
/**
|
|
92
101
|
* New file: drop the cached streams, then adopt `prepared` when it covers this side, or reparse.
|
|
93
|
-
* A preparation still running is awaited instead of parsing the same file twice.
|
|
94
|
-
*
|
|
102
|
+
* A preparation still running is awaited instead of parsing the same file twice. Detachment
|
|
103
|
+
* disposes each reader, releasing borrowed interests or owned sessions.
|
|
95
104
|
*/
|
|
96
105
|
setFile(file: DiffFile | null, rows: readonly DiffRenderRow[], prepared?: PreparedDiffSyntaxInput): void;
|
|
97
106
|
/** Whether `prepared` was adopted; otherwise it is disposed, and a current file reparses. */
|
|
98
107
|
private settlePrepared;
|
|
99
108
|
/** Same file, different rows — an expansion toggle. Re-project what is already parsed. */
|
|
100
109
|
setRows(rows: readonly DiffRenderRow[]): void;
|
|
101
|
-
|
|
102
|
-
* Hands the parsed streams of the current file to the caller, which then owns them; empty while
|
|
103
|
-
* a parse is still running. The controller keeps projecting their current tokens, and stops
|
|
104
|
-
* following their recolouring.
|
|
105
|
-
*/
|
|
106
|
-
release(): readonly PreparedDiffSyntaxSource[];
|
|
110
|
+
release(): void;
|
|
107
111
|
dispose(): void;
|
|
108
112
|
private reproject;
|
|
109
113
|
private load;
|
package/dist/diffSyntax.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diffSyntax.d.ts","sourceRoot":"","sources":["../src/diffSyntax.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"diffSyntax.d.ts","sourceRoot":"","sources":["../src/diffSyntax.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,wBAAwB,EACzB,MAAM,mCAAmC,CAAA;AAC1C,OAAO,EAML,KAAK,kBAAkB,EAEvB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EAEtB,MAAM,+BAA+B,CAAA;AAGtC,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAEzE,KAAK,cAAc,GAAG,KAAK,GAAG,KAAK,GAAG,SAAS,CAAA;AAC/C,KAAK,oBAAoB,GAAG,KAAK,GAAG,KAAK,CAAA;AAKzC,KAAK,qBAAqB,GAAG;IAC3B,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAA;IACtC,QAAQ,CAAC,IAAI,EAAE,oBAAoB,CAAA;IACnC,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAA;CAClC,CAAA;AAED,MAAM,MAAM,8BAA8B,GAAG;IAC3C,QAAQ,CAAC,IAAI,EAAE,SAAS,aAAa,EAAE,CAAA;IACvC,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAA;IAC7B,QAAQ,CAAC,OAAO,EAAE,SAAS,qBAAqB,EAAE,CAAA;CACnD,CAAA;AAED,MAAM,MAAM,2BAA2B,GAAG;IACxC,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAA;IAC7B,QAAQ,CAAC,OAAO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