@noldova/code.editor.diff.angular 0.0.0-stage → 0.0.1
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 +21 -0
- package/README.md +14 -2
- package/api/index.d.ts +17 -0
- package/api/index.js +16 -0
- package/app/components/diff-editor/diff-editor.component.d.ts +165 -0
- package/app/components/diff-editor/diff-editor.component.js +212 -0
- package/app/enums/diff-layout.d.ts +28 -0
- package/app/enums/diff-layout.js +13 -0
- package/app/interfaces/i-diff-navigator.d.ts +32 -0
- package/app/interfaces/i-diff-navigator.js +7 -0
- package/app/models/change-command.d.ts +15 -0
- package/app/models/change-command.js +23 -0
- package/app/models/diff-folds.d.ts +18 -0
- package/app/models/diff-folds.js +32 -0
- package/app/models/diff-layer.d.ts +26 -0
- package/app/models/diff-layer.js +62 -0
- package/app/models/inline-numbering.d.ts +16 -0
- package/app/models/inline-numbering.js +23 -0
- package/app/services/diff-editor-classes.d.ts +36 -0
- package/app/services/diff-editor-classes.js +14 -0
- package/app/services/diff-editor-commands.d.ts +37 -0
- package/app/services/diff-editor-commands.js +15 -0
- package/app/services/diff-editor-contribution.d.ts +44 -0
- package/app/services/diff-editor-contribution.js +28 -0
- package/app/services/diff-editor-features.d.ts +23 -0
- package/app/services/diff-editor-features.js +13 -0
- package/app/services/diff-editor-registries.d.ts +40 -0
- package/app/services/diff-editor-registries.js +25 -0
- package/app/services/diff-editor-settings.d.ts +49 -0
- package/app/services/diff-editor-settings.js +18 -0
- package/app/services/diff-worker.d.ts +42 -0
- package/app/services/diff-worker.js +13 -0
- package/app/workers/diff.worker.d.ts +8 -0
- package/app/workers/diff.worker.js +12 -0
- package/package.json +39 -4
- package/resources.d.ts +60 -0
- package/resources.js +72 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Noldova
|
|
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.
|
package/README.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @noldova/code.editor.diff.angular
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The code editor's diff view in Angular: `DiffEditorComponent`, the `noldova-diff-editor` view of a `@noldova/code.editor.diff` `DocumentDiff`, side by side, inline, or side by side until the view is narrower than its breakpoint.
|
|
4
|
+
It colors both texts by its `language`, an id or a definition, as the code view does, shows the changed lines and characters, folds the unchanged regions, keeps the modified side editable unless it is read-only and the original read-only unless asked, and moves between changes with the `diffEditor.nextChange` and `diffEditor.previousChange` commands, on Alt with Down and Up, or `nextChange` and `previousChange`.
|
|
5
|
+
Its `DiffEditorContribution` adds those commands, their keys, the `inDiffEditor` condition and the `DiffEditorSettings` to the app's `CodeEditorRegistries`: `diff.contextLines`, the unchanged lines kept next to a change; `diff.minimumHiddenLines`, the fewest lines a fold hides; `diff.characterDiffLimit`, the most characters compared by character; and `diff.inlineBreakpoint`, the width in rem below which the automatic layout is inline.
|
|
6
|
+
A host sets them, and rebinds the keys, in `CodeEditorRegistries` like any other setting or key.
|
|
7
|
+
It draws on `@noldova/code.editor.angular`'s code view through its public decorations, and is styled only with the interface kit's tokens.
|
|
8
|
+
|
|
9
|
+
## The worker
|
|
10
|
+
|
|
11
|
+
`DiffWorker.create()` starts a worker that runs the default algorithm's line diff, as a `WorkerRunner` to give to `DocumentDiff`.
|
|
12
|
+
In the browser that worker is the default path, so the page never waits for a diff; the app's build sets `webWorkerTsConfig` to bundle `diff.worker.ts`, as this package's `angular.json` does with `tsconfig.worker.json`.
|
|
13
|
+
Without a worker the diff runs a slice at a time on the page, and its one call to the algorithm holds the page for its whole time, as `@noldova/code.editor.diff`'s README says.
|
|
14
|
+
|
|
15
|
+
[documents/ARCHITECTURE.md](../../documents/ARCHITECTURE.md) says how the view is built.
|
package/api/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
export { DiffEditorComponent } from "../app/components/diff-editor/diff-editor.component.js";
|
|
9
|
+
export { DiffLayout } from "../app/enums/diff-layout.js";
|
|
10
|
+
export type { IDiffNavigator } from "../app/interfaces/i-diff-navigator.js";
|
|
11
|
+
export { DiffEditorClasses } from "../app/services/diff-editor-classes.js";
|
|
12
|
+
export { DiffEditorCommands } from "../app/services/diff-editor-commands.js";
|
|
13
|
+
export { DiffEditorContribution } from "../app/services/diff-editor-contribution.js";
|
|
14
|
+
export { DiffEditorFeatures } from "../app/services/diff-editor-features.js";
|
|
15
|
+
export { DiffEditorRegistries } from "../app/services/diff-editor-registries.js";
|
|
16
|
+
export { DiffEditorSettings } from "../app/services/diff-editor-settings.js";
|
|
17
|
+
export { DiffWorker } from "../app/services/diff-worker.js";
|
package/api/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
export { DiffEditorComponent } from "../app/components/diff-editor/diff-editor.component.js";
|
|
9
|
+
export { DiffLayout } from "../app/enums/diff-layout.js";
|
|
10
|
+
export { DiffEditorClasses } from "../app/services/diff-editor-classes.js";
|
|
11
|
+
export { DiffEditorCommands } from "../app/services/diff-editor-commands.js";
|
|
12
|
+
export { DiffEditorContribution } from "../app/services/diff-editor-contribution.js";
|
|
13
|
+
export { DiffEditorFeatures } from "../app/services/diff-editor-features.js";
|
|
14
|
+
export { DiffEditorRegistries } from "../app/services/diff-editor-registries.js";
|
|
15
|
+
export { DiffEditorSettings } from "../app/services/diff-editor-settings.js";
|
|
16
|
+
export { DiffWorker } from "../app/services/diff-worker.js";
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import "@noldova/context.core";
|
|
9
|
+
import { type InputSignal, type OutputEmitterRef, type Signal, type WritableSignal } from "@angular/core";
|
|
10
|
+
import { type ILanguageDefinition, TextSelection, UndoHistory } from "@noldova/code.editor";
|
|
11
|
+
import { type CodeFold, type ICodeDecorations } from "@noldova/code.editor.angular";
|
|
12
|
+
import { type DocumentDiff } from "@noldova/code.editor.diff";
|
|
13
|
+
import { type IReadOnlyList } from "@noldova/context.collections";
|
|
14
|
+
import { DiffLayout } from "../../enums/diff-layout.js";
|
|
15
|
+
import type { IDiffNavigator } from "../../interfaces/i-diff-navigator.js";
|
|
16
|
+
import { DiffFolds } from "../../models/diff-folds.js";
|
|
17
|
+
import * as i0 from "@angular/core";
|
|
18
|
+
/**
|
|
19
|
+
* The `noldova-diff-editor` component: the diff view, which compares an
|
|
20
|
+
* original and a modified text, side by side or inline, with the modified
|
|
21
|
+
* side editable unless it is read-only, and the original when asked.
|
|
22
|
+
*
|
|
23
|
+
* @remarks
|
|
24
|
+
* It draws on its code views through their decorations. Unchanged regions
|
|
25
|
+
* collapse to a fold row with a toggle that expands them, an expanded region
|
|
26
|
+
* keeps a toggle on its first line that collapses it again, and Alt with
|
|
27
|
+
* Down or Up, like {@link DiffEditorComponent.nextChange} and
|
|
28
|
+
* {@link DiffEditorComponent.previousChange}, moves the caret between
|
|
29
|
+
* changes, naming each one for screen readers. Its settings and keys come
|
|
30
|
+
* from {@link DiffEditorRegistries}: a key the focused code view doesn't
|
|
31
|
+
* handle goes to the diff view's key bindings.
|
|
32
|
+
*/
|
|
33
|
+
export declare class DiffEditorComponent implements IDiffNavigator {
|
|
34
|
+
private readonly registries;
|
|
35
|
+
private readonly conditions;
|
|
36
|
+
private readonly features;
|
|
37
|
+
private readonly keys;
|
|
38
|
+
private readonly settingsVersion;
|
|
39
|
+
private readonly originalView;
|
|
40
|
+
private readonly modifiedView;
|
|
41
|
+
private readonly version;
|
|
42
|
+
private readonly originalCache;
|
|
43
|
+
private readonly opened;
|
|
44
|
+
private readonly width;
|
|
45
|
+
/**
|
|
46
|
+
* The diff of the two documents, which the view follows through every
|
|
47
|
+
* edit; required.
|
|
48
|
+
*/
|
|
49
|
+
readonly diff: InputSignal<DocumentDiff>;
|
|
50
|
+
/**
|
|
51
|
+
* The modified document's undo history; required.
|
|
52
|
+
*/
|
|
53
|
+
readonly history: InputSignal<UndoHistory>;
|
|
54
|
+
/**
|
|
55
|
+
* The original document's undo history, or null, when not bound, for one
|
|
56
|
+
* of the view's own.
|
|
57
|
+
*/
|
|
58
|
+
readonly originalHistory: InputSignal<UndoHistory | null>;
|
|
59
|
+
/**
|
|
60
|
+
* The language that colors both texts: its id in the app's code editor
|
|
61
|
+
* registries, its definition, or null, when not bound, for plain text; the
|
|
62
|
+
* texts show plain until the language's tokenizer is ready.
|
|
63
|
+
*/
|
|
64
|
+
readonly language: InputSignal<string | ILanguageDefinition | null>;
|
|
65
|
+
/**
|
|
66
|
+
* How the view lays out the two texts; {@link DiffLayout.Automatic} when
|
|
67
|
+
* not bound.
|
|
68
|
+
*/
|
|
69
|
+
readonly layout: InputSignal<DiffLayout>;
|
|
70
|
+
/**
|
|
71
|
+
* The original side's accessible name; required.
|
|
72
|
+
*/
|
|
73
|
+
readonly originalLabel: InputSignal<string>;
|
|
74
|
+
/**
|
|
75
|
+
* The modified side's accessible name; required.
|
|
76
|
+
*/
|
|
77
|
+
readonly modifiedLabel: InputSignal<string>;
|
|
78
|
+
/**
|
|
79
|
+
* Whether the modified side refuses edits too; false when not bound.
|
|
80
|
+
*/
|
|
81
|
+
readonly readOnly: InputSignal<boolean>;
|
|
82
|
+
/**
|
|
83
|
+
* Whether the original side refuses edits; true when not bound.
|
|
84
|
+
*/
|
|
85
|
+
readonly originalReadOnly: InputSignal<boolean>;
|
|
86
|
+
/**
|
|
87
|
+
* Emits the chords of a key sequence the view or one of its panes waits to
|
|
88
|
+
* complete, as the platform shows them, and null once it completes or
|
|
89
|
+
* drops; the panes and the view's own keys share one dispatcher.
|
|
90
|
+
*/
|
|
91
|
+
readonly keySequencePending: OutputEmitterRef<string | null>;
|
|
92
|
+
private readonly tokenizer;
|
|
93
|
+
/**
|
|
94
|
+
* Whether the view shows the two texts inline now.
|
|
95
|
+
*/
|
|
96
|
+
readonly inline: Signal<boolean>;
|
|
97
|
+
protected readonly originalUndo: Signal<UndoHistory>;
|
|
98
|
+
protected readonly folds: Signal<DiffFolds>;
|
|
99
|
+
protected readonly originalDecorations: Signal<IReadOnlyList<ICodeDecorations>>;
|
|
100
|
+
protected readonly modifiedDecorations: Signal<IReadOnlyList<ICodeDecorations>>;
|
|
101
|
+
protected readonly inlineDecorations: Signal<IReadOnlyList<ICodeDecorations>>;
|
|
102
|
+
protected readonly announcement: WritableSignal<string>;
|
|
103
|
+
/**
|
|
104
|
+
* Creates the view, which Angular does for each `noldova-diff-editor`
|
|
105
|
+
* element.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* import { Component } from "@angular/core";
|
|
110
|
+
* import { TextDocument, UndoHistory } from "@noldova/code.editor";
|
|
111
|
+
* import { DocumentDiff } from "@noldova/code.editor.diff";
|
|
112
|
+
* import { DiffEditorComponent, DiffWorker } from "@noldova/code.editor.diff.angular";
|
|
113
|
+
*
|
|
114
|
+
* @Component({
|
|
115
|
+
* selector: "app-changes",
|
|
116
|
+
* imports: [DiffEditorComponent],
|
|
117
|
+
* template: "<noldova-diff-editor [diff]=\"diff\" [history]=\"history\" originalLabel=\"main\" modifiedLabel=\"Working tree\" />"
|
|
118
|
+
* })
|
|
119
|
+
* export class ChangesComponent {
|
|
120
|
+
* protected readonly diff: DocumentDiff = new DocumentDiff(TextDocument.fromText("a"), TextDocument.fromText("b"), undefined, DiffWorker.create());
|
|
121
|
+
* protected readonly history: UndoHistory = new UndoHistory(this.diff.modified);
|
|
122
|
+
* }
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
constructor();
|
|
126
|
+
/**
|
|
127
|
+
* Moves the caret of the focused side, or of the modified side, to the
|
|
128
|
+
* next change, wrapping at the end, and names it for screen readers.
|
|
129
|
+
*
|
|
130
|
+
* @returns Whether there was a change to move to.
|
|
131
|
+
* @example
|
|
132
|
+
* ```ts
|
|
133
|
+
* import type { DiffEditorComponent } from "@noldova/code.editor.diff.angular";
|
|
134
|
+
*
|
|
135
|
+
* declare const view: DiffEditorComponent;
|
|
136
|
+
* view.nextChange();
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
nextChange(): boolean;
|
|
140
|
+
/**
|
|
141
|
+
* Moves the caret of the focused side, or of the modified side, to the
|
|
142
|
+
* previous change, wrapping at the start, and names it for screen readers.
|
|
143
|
+
*
|
|
144
|
+
* @returns Whether there was a change to move to.
|
|
145
|
+
* @example
|
|
146
|
+
* ```ts
|
|
147
|
+
* import type { DiffEditorComponent } from "@noldova/code.editor.diff.angular";
|
|
148
|
+
*
|
|
149
|
+
* declare const view: DiffEditorComponent;
|
|
150
|
+
* view.previousChange();
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
previousChange(): boolean;
|
|
154
|
+
protected toggle(fold: CodeFold): void;
|
|
155
|
+
protected reveal(folds: IReadOnlyList<CodeFold>, selections: IReadOnlyList<TextSelection>): void;
|
|
156
|
+
private onOriginalTokens;
|
|
157
|
+
private setting;
|
|
158
|
+
private onKeyDown;
|
|
159
|
+
private contextAt;
|
|
160
|
+
private moveToChange;
|
|
161
|
+
private static toggled;
|
|
162
|
+
private static remPixels;
|
|
163
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<DiffEditorComponent, never>;
|
|
164
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<DiffEditorComponent, "noldova-diff-editor", never, { "diff": { "alias": "diff"; "required": true; "isSignal": true; }; "history": { "alias": "history"; "required": true; "isSignal": true; }; "originalHistory": { "alias": "originalHistory"; "required": false; "isSignal": true; }; "language": { "alias": "language"; "required": false; "isSignal": true; }; "layout": { "alias": "layout"; "required": false; "isSignal": true; }; "originalLabel": { "alias": "originalLabel"; "required": true; "isSignal": true; }; "modifiedLabel": { "alias": "modifiedLabel"; "required": true; "isSignal": true; }; "readOnly": { "alias": "readOnly"; "required": false; "isSignal": true; }; "originalReadOnly": { "alias": "originalReadOnly"; "required": false; "isSignal": true; }; }, { "keySequencePending": "keySequencePending"; }, never, never, true, never>;
|
|
165
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import "@noldova/context.core";
|
|
9
|
+
import { Component, computed, DestroyRef, effect, ElementRef, inject, input, output, signal, viewChild } from "@angular/core";
|
|
10
|
+
import { CommandContext, ConditionValues, EditorFeatureSet, EditorRegistries, KeyDispatchResult, KeyPress, TextPosition, TextSelection, TokenCache, UndoHistory } from "@noldova/code.editor";
|
|
11
|
+
import { BackgroundTicker, CodeEditorComponent, CodeEmbeddedLines, KeyScope, LanguageTokenizer } from "@noldova/code.editor.angular";
|
|
12
|
+
import { DiffSide } from "@noldova/code.editor.diff";
|
|
13
|
+
import { HashSet, List } from "@noldova/context.collections";
|
|
14
|
+
import { Resources } from "../../../resources.js";
|
|
15
|
+
import { DiffLayout } from "../../enums/diff-layout.js";
|
|
16
|
+
import { DiffFolds } from "../../models/diff-folds.js";
|
|
17
|
+
import { DiffLayer } from "../../models/diff-layer.js";
|
|
18
|
+
import { InlineNumbering } from "../../models/inline-numbering.js";
|
|
19
|
+
import { DiffEditorFeatures } from "../../services/diff-editor-features.js";
|
|
20
|
+
import { DiffEditorRegistries } from "../../services/diff-editor-registries.js";
|
|
21
|
+
import { DiffEditorSettings } from "../../services/diff-editor-settings.js";
|
|
22
|
+
import * as i0 from "@angular/core";
|
|
23
|
+
export class DiffEditorComponent {
|
|
24
|
+
registries = new EditorRegistries(inject(DiffEditorRegistries).registries);
|
|
25
|
+
conditions = new ConditionValues(this.registries.conditions);
|
|
26
|
+
features = new EditorFeatureSet();
|
|
27
|
+
keys = inject(KeyScope);
|
|
28
|
+
settingsVersion = signal(0, /* @ts-ignore */
|
|
29
|
+
...(ngDevMode ? [{ debugName: "settingsVersion" }] : /* istanbul ignore next */ []));
|
|
30
|
+
originalView = viewChild("original", /* @ts-ignore */
|
|
31
|
+
...(ngDevMode ? [{ debugName: "originalView" }] : /* istanbul ignore next */ []));
|
|
32
|
+
modifiedView = viewChild.required("modified", /* @ts-ignore */
|
|
33
|
+
...(ngDevMode ? [{ debugName: "modifiedView" }] : /* istanbul ignore next */ []));
|
|
34
|
+
version = signal(0, /* @ts-ignore */
|
|
35
|
+
...(ngDevMode ? [{ debugName: "version" }] : /* istanbul ignore next */ []));
|
|
36
|
+
originalCache = signal(null, /* @ts-ignore */
|
|
37
|
+
...(ngDevMode ? [{ debugName: "originalCache" }] : /* istanbul ignore next */ []));
|
|
38
|
+
opened = signal(new HashSet(), /* @ts-ignore */
|
|
39
|
+
...(ngDevMode ? [{ debugName: "opened" }] : /* istanbul ignore next */ []));
|
|
40
|
+
width = signal(Number.POSITIVE_INFINITY, /* @ts-ignore */
|
|
41
|
+
...(ngDevMode ? [{ debugName: "width" }] : /* istanbul ignore next */ []));
|
|
42
|
+
diff = input.required(/* @ts-ignore */
|
|
43
|
+
...(ngDevMode ? [{ debugName: "diff" }] : /* istanbul ignore next */ []));
|
|
44
|
+
history = input.required(/* @ts-ignore */
|
|
45
|
+
...(ngDevMode ? [{ debugName: "history" }] : /* istanbul ignore next */ []));
|
|
46
|
+
originalHistory = input(null, /* @ts-ignore */
|
|
47
|
+
...(ngDevMode ? [{ debugName: "originalHistory" }] : /* istanbul ignore next */ []));
|
|
48
|
+
language = input(null, /* @ts-ignore */
|
|
49
|
+
...(ngDevMode ? [{ debugName: "language" }] : /* istanbul ignore next */ []));
|
|
50
|
+
layout = input(DiffLayout.Automatic, /* @ts-ignore */
|
|
51
|
+
...(ngDevMode ? [{ debugName: "layout" }] : /* istanbul ignore next */ []));
|
|
52
|
+
originalLabel = input.required(/* @ts-ignore */
|
|
53
|
+
...(ngDevMode ? [{ debugName: "originalLabel" }] : /* istanbul ignore next */ []));
|
|
54
|
+
modifiedLabel = input.required(/* @ts-ignore */
|
|
55
|
+
...(ngDevMode ? [{ debugName: "modifiedLabel" }] : /* istanbul ignore next */ []));
|
|
56
|
+
readOnly = input(false, /* @ts-ignore */
|
|
57
|
+
...(ngDevMode ? [{ debugName: "readOnly" }] : /* istanbul ignore next */ []));
|
|
58
|
+
originalReadOnly = input(true, /* @ts-ignore */
|
|
59
|
+
...(ngDevMode ? [{ debugName: "originalReadOnly" }] : /* istanbul ignore next */ []));
|
|
60
|
+
keySequencePending = output();
|
|
61
|
+
tokenizer = LanguageTokenizer.of(this.language);
|
|
62
|
+
inline = computed(() => this.layout() === DiffLayout.Inline ||
|
|
63
|
+
this.layout() === DiffLayout.Automatic && this.width() < this.setting(DiffEditorSettings.inlineBreakpoint) * DiffEditorComponent.remPixels(), /* @ts-ignore */
|
|
64
|
+
...(ngDevMode ? [{ debugName: "inline" }] : /* istanbul ignore next */ []));
|
|
65
|
+
originalUndo = computed(() => this.originalHistory() ?? new UndoHistory(this.diff().original), /* @ts-ignore */
|
|
66
|
+
...(ngDevMode ? [{ debugName: "originalUndo" }] : /* istanbul ignore next */ []));
|
|
67
|
+
folds = computed(() => {
|
|
68
|
+
this.version();
|
|
69
|
+
const contextLines = this.setting(DiffEditorSettings.contextLines);
|
|
70
|
+
return new DiffFolds(this.diff().unchangedRegions(contextLines, this.setting(DiffEditorSettings.minimumHiddenLines)), this.opened());
|
|
71
|
+
}, /* @ts-ignore */
|
|
72
|
+
...(ngDevMode ? [{ debugName: "folds" }] : /* istanbul ignore next */ []));
|
|
73
|
+
originalDecorations = computed(() => {
|
|
74
|
+
this.version();
|
|
75
|
+
return new List([new DiffLayer(this.diff(), DiffSide.Original)]);
|
|
76
|
+
}, /* @ts-ignore */
|
|
77
|
+
...(ngDevMode ? [{ debugName: "originalDecorations" }] : /* istanbul ignore next */ []));
|
|
78
|
+
modifiedDecorations = computed(() => {
|
|
79
|
+
this.version();
|
|
80
|
+
return new List([new DiffLayer(this.diff(), DiffSide.Modified)]);
|
|
81
|
+
}, /* @ts-ignore */
|
|
82
|
+
...(ngDevMode ? [{ debugName: "modifiedDecorations" }] : /* istanbul ignore next */ []));
|
|
83
|
+
inlineDecorations = computed(() => {
|
|
84
|
+
this.version();
|
|
85
|
+
const diff = this.diff();
|
|
86
|
+
const removed = new DiffLayer(diff, DiffSide.Original, new List());
|
|
87
|
+
const rows = diff.changes
|
|
88
|
+
.where(t => t.originalLength > 0)
|
|
89
|
+
.select((t) => new CodeEmbeddedLines(t.modifiedStart, diff.original, t.originalStart, t.originalLength, this.originalCache(), removed))
|
|
90
|
+
.toList();
|
|
91
|
+
return new List([new DiffLayer(diff, DiffSide.Modified, rows, new InlineNumbering(diff))]);
|
|
92
|
+
}, /* @ts-ignore */
|
|
93
|
+
...(ngDevMode ? [{ debugName: "inlineDecorations" }] : /* istanbul ignore next */ []));
|
|
94
|
+
announcement = signal(Resources.empty, /* @ts-ignore */
|
|
95
|
+
...(ngDevMode ? [{ debugName: "announcement" }] : /* istanbul ignore next */ []));
|
|
96
|
+
constructor() {
|
|
97
|
+
this.conditions.set(DiffEditorFeatures.inDiffEditor, true);
|
|
98
|
+
this.features.provide(DiffEditorFeatures.navigator, this);
|
|
99
|
+
this.keys.attach(t => this.contextAt(t));
|
|
100
|
+
this.keys.listen(t => this.keySequencePending.emit(t));
|
|
101
|
+
const settingsChange = this.registries.settings.onChange(() => this.settingsVersion.update(t => t + 1));
|
|
102
|
+
effect(onCleanup => onCleanup(this.diff().onChange(() => this.version.update(t => t + 1))));
|
|
103
|
+
effect(() => {
|
|
104
|
+
this.diff().characterDiffLimit = this.setting(DiffEditorSettings.characterDiffLimit);
|
|
105
|
+
});
|
|
106
|
+
effect(onCleanup => {
|
|
107
|
+
const tokenizer = this.inline() ? this.tokenizer() : null;
|
|
108
|
+
const original = this.diff().original;
|
|
109
|
+
const cache = Object.isNull(tokenizer) ? null : new TokenCache(original, tokenizer);
|
|
110
|
+
const ticker = Object.isNull(cache) ? null : new BackgroundTicker(original, hasTime => {
|
|
111
|
+
const from = cache.validLineCount;
|
|
112
|
+
const more = cache.advance(hasTime);
|
|
113
|
+
this.onOriginalTokens(from, cache.validLineCount);
|
|
114
|
+
return more;
|
|
115
|
+
});
|
|
116
|
+
this.originalCache.set(cache);
|
|
117
|
+
onCleanup(() => {
|
|
118
|
+
ticker?.[Symbol.dispose]();
|
|
119
|
+
cache?.[Symbol.dispose]();
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
const host = inject(ElementRef).nativeElement;
|
|
123
|
+
const listener = event => this.onKeyDown(event);
|
|
124
|
+
const observer = new ResizeObserver(entries => {
|
|
125
|
+
for (const entry of entries)
|
|
126
|
+
this.width.set(entry.contentRect.width);
|
|
127
|
+
});
|
|
128
|
+
observer.observe(host);
|
|
129
|
+
host.addEventListener(Resources.keyDown, listener);
|
|
130
|
+
inject(DestroyRef).onDestroy(() => {
|
|
131
|
+
observer.disconnect();
|
|
132
|
+
host.removeEventListener(Resources.keyDown, listener);
|
|
133
|
+
settingsChange[Symbol.dispose]();
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
nextChange() {
|
|
137
|
+
return this.moveToChange(true);
|
|
138
|
+
}
|
|
139
|
+
previousChange() {
|
|
140
|
+
return this.moveToChange(false);
|
|
141
|
+
}
|
|
142
|
+
toggle(fold) {
|
|
143
|
+
const key = this.folds().keyOf(fold);
|
|
144
|
+
this.opened.update(t => DiffEditorComponent.toggled(t, key, fold.collapsed));
|
|
145
|
+
}
|
|
146
|
+
reveal(folds, selections) {
|
|
147
|
+
const keys = selections
|
|
148
|
+
.select(t => this.folds().hiding(folds, t.head.line))
|
|
149
|
+
.where((t) => !Object.isNull(t))
|
|
150
|
+
.select(t => this.folds().keyOf(t));
|
|
151
|
+
if (keys.any())
|
|
152
|
+
this.opened.update(t => new HashSet(t.concat(keys)));
|
|
153
|
+
}
|
|
154
|
+
onOriginalTokens(from, to) {
|
|
155
|
+
if (this.diff().changes.any(t => t.originalLength > 0 && t.originalStart < to && from < t.originalEnd))
|
|
156
|
+
this.modifiedView().refreshTokens();
|
|
157
|
+
}
|
|
158
|
+
setting(setting) {
|
|
159
|
+
this.settingsVersion();
|
|
160
|
+
return this.registries.settings.get(setting);
|
|
161
|
+
}
|
|
162
|
+
onKeyDown(event) {
|
|
163
|
+
if (event.defaultPrevented || event.isComposing)
|
|
164
|
+
return;
|
|
165
|
+
const press = new KeyPress(event.key, event.code, event.shiftKey, event.ctrlKey, event.altKey, event.metaKey);
|
|
166
|
+
if (this.keys.dispatch(press, this.contextAt(event.timeStamp)) === KeyDispatchResult.None)
|
|
167
|
+
return;
|
|
168
|
+
event.preventDefault();
|
|
169
|
+
event.stopPropagation();
|
|
170
|
+
}
|
|
171
|
+
contextAt(time) {
|
|
172
|
+
return new CommandContext(this.registries, this.conditions, this.features, null, time, 0);
|
|
173
|
+
}
|
|
174
|
+
moveToChange(next) {
|
|
175
|
+
const original = this.originalView();
|
|
176
|
+
const view = original?.hasFocus() === true ? original : this.modifiedView();
|
|
177
|
+
const side = view === original ? DiffSide.Original : DiffSide.Modified;
|
|
178
|
+
const diff = this.diff();
|
|
179
|
+
const line = view.caret().line;
|
|
180
|
+
const change = next ? diff.changeAfter(line, side) : diff.changeBefore(line, side);
|
|
181
|
+
if (Object.isNull(change)) {
|
|
182
|
+
this.announcement.set(Resources.noChanges);
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
const lineCount = side === DiffSide.Original ? diff.original.lineCount : diff.modified.lineCount;
|
|
186
|
+
const position = new TextPosition(Math.min(change.startOf(side), lineCount - 1), 0);
|
|
187
|
+
view.select(new List([new TextSelection(position, position)]));
|
|
188
|
+
view.focus();
|
|
189
|
+
this.announcement.set(Resources.formatChange(change.index + 1, diff.changes.count(), change.originalLength, change.modifiedLength));
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
static toggled(opened, key, open) {
|
|
193
|
+
const next = new HashSet(opened);
|
|
194
|
+
if (open)
|
|
195
|
+
next.add(key);
|
|
196
|
+
else
|
|
197
|
+
next.remove(key);
|
|
198
|
+
return next;
|
|
199
|
+
}
|
|
200
|
+
static remPixels() {
|
|
201
|
+
return Number.parseFloat(getComputedStyle(document.documentElement).fontSize);
|
|
202
|
+
}
|
|
203
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: DiffEditorComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
204
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.3.0", type: DiffEditorComponent, isStandalone: true, selector: "noldova-diff-editor", inputs: { diff: { classPropertyName: "diff", publicName: "diff", isSignal: true, isRequired: true, transformFunction: null }, history: { classPropertyName: "history", publicName: "history", isSignal: true, isRequired: true, transformFunction: null }, originalHistory: { classPropertyName: "originalHistory", publicName: "originalHistory", isSignal: true, isRequired: false, transformFunction: null }, language: { classPropertyName: "language", publicName: "language", isSignal: true, isRequired: false, transformFunction: null }, layout: { classPropertyName: "layout", publicName: "layout", isSignal: true, isRequired: false, transformFunction: null }, originalLabel: { classPropertyName: "originalLabel", publicName: "originalLabel", isSignal: true, isRequired: true, transformFunction: null }, modifiedLabel: { classPropertyName: "modifiedLabel", publicName: "modifiedLabel", isSignal: true, isRequired: true, transformFunction: null }, readOnly: { classPropertyName: "readOnly", publicName: "readOnly", isSignal: true, isRequired: false, transformFunction: null }, originalReadOnly: { classPropertyName: "originalReadOnly", publicName: "originalReadOnly", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { keySequencePending: "keySequencePending" }, host: { properties: { "class.nol-diff-editor-inline": "inline()" }, classAttribute: "nol-diff-editor" }, providers: [KeyScope], viewQueries: [{ propertyName: "originalView", first: true, predicate: ["original"], descendants: true, isSignal: true }, { propertyName: "modifiedView", first: true, predicate: ["modified"], descendants: true, isSignal: true }], ngImport: i0, template: "<!--\n@license\nCopyright (c) Noldova.\n\nThis source code is licensed under the license found in the\nLICENSE file in the root directory of this source tree.\n-->\n@if (inline()) {\n <noldova-code-editor #modified class=\"nol-diff-editor-pane\" [document]=\"diff().modified\" [history]=\"history()\" [language]=\"language()\"\n [label]=\"modifiedLabel()\" [readOnly]=\"readOnly()\" [decorations]=\"inlineDecorations()\" [folds]=\"folds().modified\"\n (foldToggle)=\"toggle($event)\" (selectionsChange)=\"reveal(folds().modified, $event)\" />\n} @else {\n <noldova-code-editor #original class=\"nol-diff-editor-pane\" [document]=\"diff().original\" [history]=\"originalUndo()\"\n [language]=\"language()\" [label]=\"originalLabel()\" [readOnly]=\"originalReadOnly()\" [decorations]=\"originalDecorations()\" [folds]=\"folds().original\"\n (scrollChange)=\"modified.scrollTo($event)\" (foldToggle)=\"toggle($event)\" (selectionsChange)=\"reveal(folds().original, $event)\" />\n <noldova-code-editor #modified class=\"nol-diff-editor-pane\" [document]=\"diff().modified\" [history]=\"history()\"\n [language]=\"language()\" [label]=\"modifiedLabel()\" [readOnly]=\"readOnly()\" [decorations]=\"modifiedDecorations()\" [folds]=\"folds().modified\"\n (scrollChange)=\"original.scrollTo($event)\" (foldToggle)=\"toggle($event)\" (selectionsChange)=\"reveal(folds().modified, $event)\" />\n}\n<div class=\"nol-diff-editor-status\" role=\"status\">{{ announcement() }}</div>\n", styles: ["/**\n * @license\n * Copyright (c) Noldova.\n *\n * This source code is licensed under the license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n:host {\n display: flex;\n position: relative;\n box-sizing: border-box;\n min-width: 0;\n min-height: 0;\n overflow: hidden;\n background-color: var(--nol-code);\n}\n\n.nol-diff-editor-pane {\n flex: 1 1 0;\n}\n\n.nol-diff-editor-pane + .nol-diff-editor-pane {\n border-inline-start: var(--nol-border-width) solid var(--nol-card-border);\n}\n\n.nol-diff-editor-status {\n position: absolute;\n width: 1px;\n height: 1px;\n overflow: hidden;\n clip-path: inset(50%);\n white-space: nowrap;\n}\n"], dependencies: [{ kind: "component", type: CodeEditorComponent, selector: "noldova-code-editor", inputs: ["document", "history", "language", "label", "readOnly", "tabIndents", "decorations", "folds"], outputs: ["selectionsChange", "scrollChange", "foldToggle", "barAction", "keySequencePending"] }] });
|
|
205
|
+
}
|
|
206
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: DiffEditorComponent, decorators: [{
|
|
207
|
+
type: Component,
|
|
208
|
+
args: [{ selector: "noldova-diff-editor", imports: [CodeEditorComponent], providers: [KeyScope], host: {
|
|
209
|
+
"class": Resources.hostClass,
|
|
210
|
+
[Resources.inlineClassBinding]: "inline()"
|
|
211
|
+
}, template: "<!--\n@license\nCopyright (c) Noldova.\n\nThis source code is licensed under the license found in the\nLICENSE file in the root directory of this source tree.\n-->\n@if (inline()) {\n <noldova-code-editor #modified class=\"nol-diff-editor-pane\" [document]=\"diff().modified\" [history]=\"history()\" [language]=\"language()\"\n [label]=\"modifiedLabel()\" [readOnly]=\"readOnly()\" [decorations]=\"inlineDecorations()\" [folds]=\"folds().modified\"\n (foldToggle)=\"toggle($event)\" (selectionsChange)=\"reveal(folds().modified, $event)\" />\n} @else {\n <noldova-code-editor #original class=\"nol-diff-editor-pane\" [document]=\"diff().original\" [history]=\"originalUndo()\"\n [language]=\"language()\" [label]=\"originalLabel()\" [readOnly]=\"originalReadOnly()\" [decorations]=\"originalDecorations()\" [folds]=\"folds().original\"\n (scrollChange)=\"modified.scrollTo($event)\" (foldToggle)=\"toggle($event)\" (selectionsChange)=\"reveal(folds().original, $event)\" />\n <noldova-code-editor #modified class=\"nol-diff-editor-pane\" [document]=\"diff().modified\" [history]=\"history()\"\n [language]=\"language()\" [label]=\"modifiedLabel()\" [readOnly]=\"readOnly()\" [decorations]=\"modifiedDecorations()\" [folds]=\"folds().modified\"\n (scrollChange)=\"original.scrollTo($event)\" (foldToggle)=\"toggle($event)\" (selectionsChange)=\"reveal(folds().modified, $event)\" />\n}\n<div class=\"nol-diff-editor-status\" role=\"status\">{{ announcement() }}</div>\n", styles: ["/**\n * @license\n * Copyright (c) Noldova.\n *\n * This source code is licensed under the license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n:host {\n display: flex;\n position: relative;\n box-sizing: border-box;\n min-width: 0;\n min-height: 0;\n overflow: hidden;\n background-color: var(--nol-code);\n}\n\n.nol-diff-editor-pane {\n flex: 1 1 0;\n}\n\n.nol-diff-editor-pane + .nol-diff-editor-pane {\n border-inline-start: var(--nol-border-width) solid var(--nol-card-border);\n}\n\n.nol-diff-editor-status {\n position: absolute;\n width: 1px;\n height: 1px;\n overflow: hidden;\n clip-path: inset(50%);\n white-space: nowrap;\n}\n"] }]
|
|
212
|
+
}], ctorParameters: () => [], propDecorators: { originalView: [{ type: i0.ViewChild, args: ["original", { isSignal: true }] }], modifiedView: [{ type: i0.ViewChild, args: ["modified", { isSignal: true }] }], diff: [{ type: i0.Input, args: [{ isSignal: true, alias: "diff", required: true }] }], history: [{ type: i0.Input, args: [{ isSignal: true, alias: "history", required: true }] }], originalHistory: [{ type: i0.Input, args: [{ isSignal: true, alias: "originalHistory", required: false }] }], language: [{ type: i0.Input, args: [{ isSignal: true, alias: "language", required: false }] }], layout: [{ type: i0.Input, args: [{ isSignal: true, alias: "layout", required: false }] }], originalLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "originalLabel", required: true }] }], modifiedLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "modifiedLabel", required: true }] }], readOnly: [{ type: i0.Input, args: [{ isSignal: true, alias: "readOnly", required: false }] }], originalReadOnly: [{ type: i0.Input, args: [{ isSignal: true, alias: "originalReadOnly", required: false }] }], keySequencePending: [{ type: i0.Output, args: ["keySequencePending"] }] } });
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Names how {@link DiffEditorComponent} lays out its two texts.
|
|
10
|
+
*/
|
|
11
|
+
export declare enum DiffLayout {
|
|
12
|
+
/**
|
|
13
|
+
* Side by side while the view is at least as wide as the
|
|
14
|
+
* {@link DiffEditorSettings.inlineBreakpoint} setting, inline while it is
|
|
15
|
+
* narrower.
|
|
16
|
+
*/
|
|
17
|
+
Automatic = "Automatic",
|
|
18
|
+
/**
|
|
19
|
+
* Two code views, the original on the left and the modified on the right,
|
|
20
|
+
* whose scrolling is locked by their unchanged regions.
|
|
21
|
+
*/
|
|
22
|
+
SideBySide = "SideBySide",
|
|
23
|
+
/**
|
|
24
|
+
* One code view of the modified text, with the removed lines as read-only
|
|
25
|
+
* blocks between its lines and both texts' line numbers in the gutter.
|
|
26
|
+
*/
|
|
27
|
+
Inline = "Inline"
|
|
28
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
export var DiffLayout;
|
|
9
|
+
(function (DiffLayout) {
|
|
10
|
+
DiffLayout["Automatic"] = "Automatic";
|
|
11
|
+
DiffLayout["SideBySide"] = "SideBySide";
|
|
12
|
+
DiffLayout["Inline"] = "Inline";
|
|
13
|
+
})(DiffLayout || (DiffLayout = {}));
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* What the diff view's commands move between changes with.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import type { IDiffNavigator } from "@noldova/code.editor.diff.angular";
|
|
14
|
+
*
|
|
15
|
+
* declare const navigator: IDiffNavigator;
|
|
16
|
+
* navigator.nextChange();
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export interface IDiffNavigator {
|
|
20
|
+
/**
|
|
21
|
+
* Moves to the next change.
|
|
22
|
+
*
|
|
23
|
+
* @returns Whether there was a change to move to.
|
|
24
|
+
*/
|
|
25
|
+
nextChange(): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Moves to the previous change.
|
|
28
|
+
*
|
|
29
|
+
* @returns Whether there was a change to move to.
|
|
30
|
+
*/
|
|
31
|
+
previousChange(): boolean;
|
|
32
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import "@noldova/context.core";
|
|
9
|
+
import type { CommandContext, ICommand } from "@noldova/code.editor";
|
|
10
|
+
export declare class ChangeCommand implements ICommand {
|
|
11
|
+
readonly id: string;
|
|
12
|
+
private readonly next;
|
|
13
|
+
constructor(id: string, next: boolean);
|
|
14
|
+
run(context: CommandContext): boolean;
|
|
15
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import "@noldova/context.core";
|
|
9
|
+
import { DiffEditorFeatures } from "../services/diff-editor-features.js";
|
|
10
|
+
export class ChangeCommand {
|
|
11
|
+
id;
|
|
12
|
+
next;
|
|
13
|
+
constructor(id, next) {
|
|
14
|
+
this.id = id;
|
|
15
|
+
this.next = next;
|
|
16
|
+
}
|
|
17
|
+
run(context) {
|
|
18
|
+
const navigator = context.feature(DiffEditorFeatures.navigator);
|
|
19
|
+
if (Object.isNull(navigator))
|
|
20
|
+
return false;
|
|
21
|
+
return this.next ? navigator.nextChange() : navigator.previousChange();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { CodeFold } from "@noldova/code.editor.angular";
|
|
9
|
+
import { type UnchangedRegion } from "@noldova/code.editor.diff";
|
|
10
|
+
import { type IReadOnlyList, type IReadOnlySet } from "@noldova/context.collections";
|
|
11
|
+
export declare class DiffFolds {
|
|
12
|
+
readonly original: IReadOnlyList<CodeFold>;
|
|
13
|
+
readonly modified: IReadOnlyList<CodeFold>;
|
|
14
|
+
private readonly keys;
|
|
15
|
+
constructor(regions: IReadOnlyList<UnchangedRegion>, opened: IReadOnlySet<number>);
|
|
16
|
+
keyOf(fold: CodeFold): number;
|
|
17
|
+
hiding(folds: IReadOnlyList<CodeFold>, line: number): CodeFold | null;
|
|
18
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { CodeFold } from "@noldova/code.editor.angular";
|
|
9
|
+
import { DiffSide } from "@noldova/code.editor.diff";
|
|
10
|
+
import { Dictionary } from "@noldova/context.collections";
|
|
11
|
+
export class DiffFolds {
|
|
12
|
+
original;
|
|
13
|
+
modified;
|
|
14
|
+
keys;
|
|
15
|
+
constructor(regions, opened) {
|
|
16
|
+
const keys = new Dictionary();
|
|
17
|
+
const foldsOf = (side) => regions.select(t => {
|
|
18
|
+
const fold = new CodeFold(side === DiffSide.Original ? t.originalStart : t.modifiedStart, t.length, !opened.contains(t.originalStart));
|
|
19
|
+
keys.set(fold, t.originalStart);
|
|
20
|
+
return fold;
|
|
21
|
+
}).toList();
|
|
22
|
+
this.original = foldsOf(DiffSide.Original);
|
|
23
|
+
this.modified = foldsOf(DiffSide.Modified);
|
|
24
|
+
this.keys = keys;
|
|
25
|
+
}
|
|
26
|
+
keyOf(fold) {
|
|
27
|
+
return this.keys.get(fold);
|
|
28
|
+
}
|
|
29
|
+
hiding(folds, line) {
|
|
30
|
+
return folds.firstOrDefault(t => t.collapsed && line >= t.startLine && line < t.startLine + t.lineCount) ?? null;
|
|
31
|
+
}
|
|
32
|
+
}
|