@adecore/editor 0.54.3 → 0.54.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/engine.js CHANGED
@@ -142,15 +142,15 @@ class SmartEditor {
142
142
  getText() {
143
143
  return this.model.getText();
144
144
  }
145
- setText(text) {
145
+ setText(text, options = {}) {
146
146
  const spans = changedSpans(this.model.getText(), text);
147
- if (spans.length === 0) {
147
+ if (spans.length === 0 && !options.clearHistory) {
148
148
  return;
149
149
  }
150
150
  this.settingText = true;
151
151
  try {
152
- // Edits and not a reset, which would drop the undo history and put the cursor on line one.
153
- this.model.applyEdits(spans.map((span) => ({ from: span.start, to: span.end, text: span.text })), { source: 'external' });
152
+ // Edits and not a reset, which would put the cursor on line one.
153
+ this.model.applyEdits(spans.map((span) => ({ from: span.start, to: span.end, text: span.text })), { source: 'external', clearHistory: options.clearHistory });
154
154
  }
155
155
  finally {
156
156
  this.settingText = false;
package/dist/fake.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { type Listener } from './listeners.ts';
2
- import type { Editor, EditorAttributionHover, EditorAttributionMark, EditorBlock, EditorCodeBlockOptions, EditorLineAction, EditorReplacement, EditorLineHighlight, LineToken, EditorChangeMark, EditorCodeVision, EditorClick, EditorClickHandler, EditorContextMenu, EditorContentChange, EditorEngine, EditorFindQuery, EditorFindState, EditorReplaceOptions, EditorGutterAction, EditorGutterMarker, EditorHighlight, EditorHover, EditorIndentation, EditorGhostText, EditorInlayClick, EditorInlayClickHandler, EditorInlayHint, EditorInlayTarget, EditorKeyHandler, EditorInputPopup, EditorMarker, EditorMessages, EditorOptions, EditorPosition, EditorPostfixOperand, EditorSurroundShape, EditorTextPlace, EditorUnwrapTarget, EditorRemoteCursor, EditorRange, EditorReveal, EditorRect, EditorRunCommand, EditorSelectionRanges, EditorFoldHints, EditorFoldOutline, EditorFolds, EditorSemanticToken, EditorSmartKeys, EditorApplyEditsOptions, EditorCopy, EditorPasteOptions, EditorTextChange, EditorTrackedRange, EditorTheme, EditorWhitespaceCleanup, EditorWidget } from './types.ts';
2
+ import type { Editor, EditorAttributionHover, EditorAttributionMark, EditorBlock, EditorCodeBlockOptions, EditorLineAction, EditorReplacement, EditorLineHighlight, LineToken, EditorChangeMark, EditorCodeVision, EditorClick, EditorClickHandler, EditorContextMenu, EditorContentChange, EditorEngine, EditorFindQuery, EditorFindState, EditorReplaceOptions, EditorGutterAction, EditorGutterMarker, EditorHighlight, EditorHover, EditorIndentation, EditorGhostText, EditorInlayClick, EditorInlayClickHandler, EditorInlayHint, EditorInlayTarget, EditorKeyHandler, EditorInputPopup, EditorMarker, EditorMessages, EditorOptions, EditorPosition, EditorPostfixOperand, EditorSurroundShape, EditorTextPlace, EditorUnwrapTarget, EditorRemoteCursor, EditorRange, EditorReveal, EditorRect, EditorRunCommand, EditorSelectionRanges, EditorFoldHints, EditorFoldOutline, EditorFolds, EditorSemanticToken, EditorSmartKeys, EditorApplyEditsOptions, EditorSetTextOptions, EditorCopy, EditorPasteOptions, EditorTextChange, EditorTrackedRange, EditorTheme, EditorWhitespaceCleanup, EditorWidget } from './types.ts';
3
3
  export declare class FakeEditor implements Editor {
4
4
  readonly element: HTMLElement;
5
5
  readonly language: string | undefined;
@@ -32,7 +32,7 @@ export declare class FakeEditor implements Editor {
32
32
  save(): void;
33
33
  blur(): void;
34
34
  getText(): string;
35
- setText(text: string): void;
35
+ setText(text: string, options?: EditorSetTextOptions): void;
36
36
  private edit;
37
37
  private rewrite;
38
38
  private state;
package/dist/fake.js CHANGED
@@ -185,10 +185,14 @@ export class FakeEditor {
185
185
  return this.text;
186
186
  }
187
187
  /* Split into the stretches the real editor splits it into, so the carets and tracked ranges follow it alike. */
188
- setText(text) {
188
+ setText(text, options = {}) {
189
189
  this.assertLive();
190
190
  const spans = changedSpans(this.text, text).map((span) => ({ from: span.start, to: span.end, text: span.text }));
191
191
  this.edit(orderedEdits(spans) ?? [], 'external', false);
192
+ if (options.clearHistory) {
193
+ this.undoStack = [];
194
+ this.redoStack = [];
195
+ }
192
196
  }
193
197
  /*
194
198
  * Ordered edits as one step of the history, and the listeners told in the real editor's order: the caret's,
package/dist/index.d.ts CHANGED
@@ -8,4 +8,4 @@ export { createSmartEditorEngine } from './engine.ts';
8
8
  export { rememberCopy } from './controller.ts';
9
9
  export { DEFAULT_SMART_KEYS } from './smart-keys.ts';
10
10
  export { shikiScopeColors, shikiTokenizers } from './shiki.ts';
11
- export type { Editor, EditorAttributionHover, EditorAttributionMark, EditorMarkColor, EditorBlock, EditorChangeKind, EditorChangeMark, EditorCodeVision, EditorCodeVisionEntry, EditorClick, EditorCodeBlockOptions, EditorClickHandler, EditorCommand, EditorContextMenu, EditorEngine, EditorFindQuery, EditorFoldHints, EditorFoldRangeHint, EditorFoldOutline, EditorFoldRange, EditorFoldSymbol, EditorFolds, EditorFindState, EditorReplaceOptions, EditorGutterAction, EditorGutterIcon, EditorGutterMarker, EditorReplacement, EditorIndentation, EditorContentChange, EditorHighlight, EditorHighlightKind, EditorHover, EditorGhostText, EditorInlayClick, EditorInlayClickHandler, EditorInlayHint, EditorInlayTarget, EditorKeyHandler, EditorLineAction, EditorLineHighlight, EditorMarker, EditorInputPopup, EditorMessages, EditorMarkerSeverity, EditorReveal, EditorRect, EditorSmartKeys, EditorOptions, EditorPosition, EditorRemoteCursor, EditorRange, EditorApplyEditsOptions, EditorCopy, EditorPasteOptions, EditorPostfixOperand, EditorSurroundShape, EditorTextPlace, EditorUnwrapTarget, EditorTextChange, EditorTrackedRange, EditorRunCommand, EditorSelectionRanges, EditorTheme, EditorViewCommand, EditorWhitespaceCleanup, EditorWidget, EditorZoom, FoldRole, KeyChord, LineToken, LineTokenKind, ScopeColorSource, ScopeColors, ScopeStyle, EditorSemanticToken, LineTokenizer, SmartEditorEngineOptions, TokenizedLine, TokenizerSource } from './types.ts';
11
+ export type { Editor, EditorAttributionHover, EditorAttributionMark, EditorMarkColor, EditorBlock, EditorChangeKind, EditorChangeMark, EditorCodeVision, EditorCodeVisionEntry, EditorClick, EditorCodeBlockOptions, EditorClickHandler, EditorCommand, EditorContextMenu, EditorEngine, EditorFindQuery, EditorFoldHints, EditorFoldRangeHint, EditorFoldOutline, EditorFoldRange, EditorFoldSymbol, EditorFolds, EditorFindState, EditorReplaceOptions, EditorGutterAction, EditorGutterIcon, EditorGutterMarker, EditorReplacement, EditorIndentation, EditorContentChange, EditorHighlight, EditorHighlightKind, EditorHover, EditorGhostText, EditorInlayClick, EditorInlayClickHandler, EditorInlayHint, EditorInlayTarget, EditorKeyHandler, EditorLineAction, EditorLineHighlight, EditorMarker, EditorInputPopup, EditorMessages, EditorMarkerSeverity, EditorReveal, EditorRect, EditorSmartKeys, EditorOptions, EditorPosition, EditorRemoteCursor, EditorRange, EditorApplyEditsOptions, EditorSetTextOptions, EditorCopy, EditorPasteOptions, EditorPostfixOperand, EditorSurroundShape, EditorTextPlace, EditorUnwrapTarget, EditorTextChange, EditorTrackedRange, EditorRunCommand, EditorSelectionRanges, EditorTheme, EditorViewCommand, EditorWhitespaceCleanup, EditorWidget, EditorZoom, FoldRole, KeyChord, LineToken, LineTokenKind, ScopeColorSource, ScopeColors, ScopeStyle, EditorSemanticToken, LineTokenizer, SmartEditorEngineOptions, TokenizedLine, TokenizerSource } from './types.ts';
package/dist/types.d.ts CHANGED
@@ -167,6 +167,9 @@ export interface EditorPasteOptions {
167
167
  readonly wholeLines?: boolean;
168
168
  readonly reindent?: boolean;
169
169
  }
170
+ export interface EditorSetTextOptions {
171
+ readonly clearHistory?: boolean;
172
+ }
170
173
  export interface EditorApplyEditsOptions {
171
174
  readonly mapSelections?: (range: EditorRange) => EditorRange;
172
175
  readonly mergeUndo?: boolean;
@@ -335,7 +338,7 @@ export interface EditorTrackedRange {
335
338
  }
336
339
  export interface Editor {
337
340
  getText(): string;
338
- setText(text: string): void;
341
+ setText(text: string, options?: EditorSetTextOptions): void;
339
342
  onChange(listener: () => void): () => void;
340
343
  onTextChange(listener: (change: EditorTextChange) => void): () => void;
341
344
  positionAt(offset: number): EditorPosition;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adecore/editor",
3
- "version": "0.54.3",
3
+ "version": "0.54.5",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -54,8 +54,8 @@
54
54
  "test": "bun test --conditions=source"
55
55
  },
56
56
  "dependencies": {
57
- "@adecore/editor-core": "0.54.3",
58
- "@adecore/utils": "0.54.3",
57
+ "@adecore/editor-core": "0.54.5",
58
+ "@adecore/utils": "0.54.5",
59
59
  "linkedom": "^0.18.14",
60
60
  "shiki": "^4.5.0"
61
61
  },
package/src/engine.ts CHANGED
@@ -58,6 +58,7 @@ import type {
58
58
  EditorSemanticToken,
59
59
  EditorSmartKeys,
60
60
  EditorApplyEditsOptions,
61
+ EditorSetTextOptions,
61
62
  EditorTextChange,
62
63
  EditorTrackedRange,
63
64
  EditorTheme,
@@ -225,20 +226,20 @@ class SmartEditor implements Editor {
225
226
  return this.model.getText();
226
227
  }
227
228
 
228
- setText(text: string): void {
229
+ setText(text: string, options: EditorSetTextOptions = {}): void {
229
230
  const spans = changedSpans(this.model.getText(), text);
230
231
 
231
- if (spans.length === 0) {
232
+ if (spans.length === 0 && !options.clearHistory) {
232
233
  return;
233
234
  }
234
235
 
235
236
  this.settingText = true;
236
237
 
237
238
  try {
238
- // Edits and not a reset, which would drop the undo history and put the cursor on line one.
239
+ // Edits and not a reset, which would put the cursor on line one.
239
240
  this.model.applyEdits(
240
241
  spans.map((span) => ({ from: span.start, to: span.end, text: span.text })),
241
- { source: 'external' }
242
+ { source: 'external', clearHistory: options.clearHistory }
242
243
  );
243
244
  } finally {
244
245
  this.settingText = false;
package/src/fake.ts CHANGED
@@ -55,6 +55,7 @@ import type {
55
55
  EditorSemanticToken,
56
56
  EditorSmartKeys,
57
57
  EditorApplyEditsOptions,
58
+ EditorSetTextOptions,
58
59
  EditorCopy,
59
60
  EditorPasteOptions,
60
61
  EditorTextChange,
@@ -306,10 +307,15 @@ export class FakeEditor implements Editor {
306
307
  }
307
308
 
308
309
  /* Split into the stretches the real editor splits it into, so the carets and tracked ranges follow it alike. */
309
- setText(text: string): void {
310
+ setText(text: string, options: EditorSetTextOptions = {}): void {
310
311
  this.assertLive();
311
312
  const spans = changedSpans(this.text, text).map((span) => ({ from: span.start, to: span.end, text: span.text }));
312
313
  this.edit(orderedEdits(spans) ?? [], 'external', false);
314
+
315
+ if (options.clearHistory) {
316
+ this.undoStack = [];
317
+ this.redoStack = [];
318
+ }
313
319
  }
314
320
 
315
321
  /*
package/src/index.ts CHANGED
@@ -63,6 +63,7 @@ export type {
63
63
  EditorRemoteCursor,
64
64
  EditorRange,
65
65
  EditorApplyEditsOptions,
66
+ EditorSetTextOptions,
66
67
  EditorCopy,
67
68
  EditorPasteOptions,
68
69
  EditorPostfixOperand,
package/src/types.ts CHANGED
@@ -336,6 +336,14 @@ export interface EditorPasteOptions {
336
336
  readonly reindent?: boolean;
337
337
  }
338
338
 
339
+ export interface EditorSetTextOptions {
340
+ /*
341
+ * Takes no undo step and drops the history, so undo never goes back past this text, for a text read
342
+ * from disk. Otherwise the text is one undo step, as for a change made elsewhere to the same text.
343
+ */
344
+ readonly clearHistory?: boolean;
345
+ }
346
+
339
347
  export interface EditorApplyEditsOptions {
340
348
  readonly mapSelections?: (range: EditorRange) => EditorRange;
341
349
  readonly mergeUndo?: boolean;
@@ -652,7 +660,7 @@ export interface Editor {
652
660
  * A change from outside, such as a reload after the file changed on disk. It is never reported as a
653
661
  * change, and the cursor and the scroll stay put wherever the text around them did.
654
662
  */
655
- setText(text: string): void;
663
+ setText(text: string, options?: EditorSetTextOptions): void;
656
664
  onChange(listener: () => void): () => void;
657
665
  /* Every change of the text, `setText` and undo included, with what changed in the positions a language server expects. */
658
666
  onTextChange(listener: (change: EditorTextChange) => void): () => void;