@adecore/editor 0.62.0 → 0.63.0-untangle.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.
Files changed (95) hide show
  1. package/dist/attribution.js +0 -1
  2. package/dist/bidi.js +0 -1
  3. package/dist/column-selection.d.ts +0 -1
  4. package/dist/column-selection.js +1 -1
  5. package/dist/controller.d.ts +4 -2
  6. package/dist/controller.js +0 -5
  7. package/dist/engine.js +0 -3
  8. package/dist/fake.d.ts +3 -0
  9. package/dist/fake.js +29 -24
  10. package/dist/find.d.ts +3 -2
  11. package/dist/find.js +0 -2
  12. package/dist/geometry-stops.d.ts +1 -1
  13. package/dist/index.d.ts +3 -2
  14. package/dist/index.js +1 -1
  15. package/dist/keymap-table.d.ts +8 -1
  16. package/dist/keymap-table.js +0 -1
  17. package/dist/keymap.d.ts +2 -1
  18. package/dist/layout-changes.d.ts +2 -1
  19. package/dist/layout.d.ts +3 -57
  20. package/dist/layout.js +1 -6
  21. package/dist/line-geometry.d.ts +55 -0
  22. package/dist/line-geometry.js +1 -0
  23. package/dist/metrics.d.ts +1 -1
  24. package/dist/modifier-gesture.d.ts +2 -1
  25. package/dist/modifier-gesture.js +0 -1
  26. package/dist/native-input.d.ts +2 -1
  27. package/dist/outline.d.ts +3 -3
  28. package/dist/outline.js +0 -1
  29. package/dist/overview.d.ts +3 -2
  30. package/dist/paint.d.ts +5 -5
  31. package/dist/paint.js +3 -4
  32. package/dist/php-html.d.ts +0 -6
  33. package/dist/php-html.js +2 -2
  34. package/dist/pointer.d.ts +2 -1
  35. package/dist/scroll-animation.d.ts +0 -1
  36. package/dist/scroll-animation.js +1 -1
  37. package/dist/scroll.js +0 -1
  38. package/dist/search-client.d.ts +2 -2
  39. package/dist/shiki-document.js +1 -1
  40. package/dist/shiki-grammar.d.ts +7 -0
  41. package/dist/shiki-grammar.js +168 -0
  42. package/dist/shiki-worker.js +1 -1
  43. package/dist/shiki.d.ts +1 -7
  44. package/dist/shiki.js +1 -168
  45. package/dist/smart-keys.js +0 -1
  46. package/dist/testing.js +0 -2
  47. package/dist/todos.d.ts +2 -1
  48. package/dist/tokens.d.ts +2 -1
  49. package/dist/tokens.js +0 -1
  50. package/dist/touch.d.ts +2 -1
  51. package/dist/types.d.ts +5 -13
  52. package/dist/uniform-geometry.d.ts +1 -1
  53. package/dist/view.d.ts +12 -10
  54. package/dist/view.js +61 -38
  55. package/dist/zoom.d.ts +0 -2
  56. package/dist/zoom.js +2 -2
  57. package/package.json +8 -3
  58. package/src/attribution.ts +0 -1
  59. package/src/bidi.ts +0 -1
  60. package/src/column-selection.ts +1 -1
  61. package/src/controller.ts +3 -9
  62. package/src/engine.ts +0 -3
  63. package/src/fake.ts +38 -24
  64. package/src/find.ts +2 -4
  65. package/src/geometry-stops.ts +1 -1
  66. package/src/index.ts +2 -2
  67. package/src/keymap-table.ts +10 -3
  68. package/src/keymap.ts +2 -1
  69. package/src/layout-changes.ts +1 -1
  70. package/src/layout.ts +4 -81
  71. package/src/line-geometry.ts +69 -0
  72. package/src/metrics.ts +1 -1
  73. package/src/modifier-gesture.ts +1 -2
  74. package/src/native-input.ts +1 -1
  75. package/src/outline.ts +3 -5
  76. package/src/overview.ts +2 -2
  77. package/src/paint.ts +5 -11
  78. package/src/php-html.ts +2 -2
  79. package/src/pointer.ts +1 -4
  80. package/src/scroll-animation.ts +1 -1
  81. package/src/scroll.ts +0 -2
  82. package/src/search-client.ts +2 -2
  83. package/src/shiki-document.ts +1 -1
  84. package/src/shiki-grammar.ts +223 -0
  85. package/src/shiki-worker.ts +1 -1
  86. package/src/shiki.ts +1 -224
  87. package/src/smart-keys.ts +0 -1
  88. package/src/testing.ts +0 -2
  89. package/src/todos.ts +1 -1
  90. package/src/tokens.ts +1 -2
  91. package/src/touch.ts +1 -1
  92. package/src/types.ts +9 -22
  93. package/src/uniform-geometry.ts +1 -1
  94. package/src/view.ts +89 -56
  95. package/src/zoom.ts +2 -2
package/src/fake.ts CHANGED
@@ -296,7 +296,6 @@ export class FakeEditor implements Editor {
296
296
  emit(this.saves);
297
297
  }
298
298
 
299
- /* The focus leaving the editor. */
300
299
  blur(): void {
301
300
  this.assertLive();
302
301
  this.focused = false;
@@ -375,7 +374,7 @@ export class FakeEditor implements Editor {
375
374
  );
376
375
 
377
376
  this.followTracked(changed);
378
- this.ghost = null;
377
+ this.dropGhost();
379
378
  this.announceCaret();
380
379
 
381
380
  // Last to first, so each change's range is also where it stands once the ones after it are applied, as the real editor reports them.
@@ -419,7 +418,6 @@ export class FakeEditor implements Editor {
419
418
  return true;
420
419
  }
421
420
 
422
- /* Tells the caret listeners where the primary caret is, when it moved since they last heard. */
423
421
  private announceCaret(): void {
424
422
  const head = this.selections.at(-1)!.head;
425
423
 
@@ -591,7 +589,6 @@ export class FakeEditor implements Editor {
591
589
  }
592
590
  }
593
591
 
594
- /* The tinted lines the host set last. */
595
592
  lineHighlights: readonly EditorLineHighlight[] = [];
596
593
 
597
594
  setLineHighlights(highlights: readonly EditorLineHighlight[]): void {
@@ -614,7 +611,6 @@ export class FakeEditor implements Editor {
614
611
  this.lineLabels = labels;
615
612
  }
616
613
 
617
- /* What the input points at, as the last call left it. */
618
614
  inputPopup: EditorInputPopup | null = null;
619
615
 
620
616
  setInputPopup(popup: EditorInputPopup | null): void {
@@ -642,14 +638,12 @@ export class FakeEditor implements Editor {
642
638
  this.codeBlocks.push({ container, text, options });
643
639
  }
644
640
 
645
- /* The cursors of agents the host set last. */
646
641
  remoteCursors: readonly EditorRemoteCursor[] = [];
647
642
 
648
643
  setRemoteCursors(cursors: readonly EditorRemoteCursor[]): void {
649
644
  this.remoteCursors = cursors;
650
645
  }
651
646
 
652
- /* What the host marked as written by an agent last. */
653
647
  attributionMarks: readonly EditorAttributionMark[] = [];
654
648
  private readonly attributionHovers = new Set<(hover: EditorAttributionHover | null) => void>();
655
649
 
@@ -685,7 +679,6 @@ export class FakeEditor implements Editor {
685
679
  emit(this.attributionHovers, hover);
686
680
  }
687
681
 
688
- /* What each owner put next to lines of the text last. */
689
682
  readonly widgetsByOwner = new Map<string, readonly EditorWidget[]>();
690
683
 
691
684
  /* The default owner's rows. */
@@ -736,14 +729,12 @@ export class FakeEditor implements Editor {
736
729
  }
737
730
  }
738
731
 
739
- /* The code vision rows the host set last. */
740
732
  codeVision: readonly EditorCodeVision[] = [];
741
733
 
742
734
  setCodeVision(rows: readonly EditorCodeVision[]): void {
743
735
  this.codeVision = rows;
744
736
  }
745
737
 
746
- /* The button the host set in the gutter last. */
747
738
  gutterAction: EditorGutterAction | null = null;
748
739
  private readonly gutterActionListeners = new Set<(line: number) => void>();
749
740
 
@@ -755,7 +746,6 @@ export class FakeEditor implements Editor {
755
746
  return subscribe(this.gutterActionListeners, listener);
756
747
  }
757
748
 
758
- /* What each owner put in the gutter last. */
759
749
  readonly gutterMarkersByOwner = new Map<string, readonly EditorGutterMarker[]>();
760
750
  private readonly gutterMarkerListeners = new Set<(id: string) => void>();
761
751
 
@@ -771,12 +761,10 @@ export class FakeEditor implements Editor {
771
761
  return subscribe(this.gutterMarkerListeners, listener);
772
762
  }
773
763
 
774
- /* A press on a gutter marker. */
775
764
  pressGutterMarker(id: string): void {
776
765
  emit(this.gutterMarkerListeners, id);
777
766
  }
778
767
 
779
- /* A press on the gutter button, if there is one. */
780
768
  pressGutterAction(): void {
781
769
  if (this.gutterAction !== null) {
782
770
  emit(this.gutterActionListeners, this.gutterAction.line);
@@ -874,7 +862,6 @@ export class FakeEditor implements Editor {
874
862
  emit(this.copies, { text, wholeLines, cut });
875
863
  }
876
864
 
877
- /* Every paste a host asked for, with its options. */
878
865
  readonly pastes: Array<{ text: string; options: EditorPasteOptions | undefined }> = [];
879
866
 
880
867
  /* Puts the text at every caret, one line per caret when the lines are as many as the carets, and leaves the carets behind it. */
@@ -922,7 +909,6 @@ export class FakeEditor implements Editor {
922
909
  this.indentation = indentation;
923
910
  }
924
911
 
925
- /* What the host marked and highlighted last. */
926
912
  markers: readonly EditorMarker[] = [];
927
913
  highlights: readonly EditorHighlight[] = [];
928
914
  /* Where `rectAt` puts a position, which a test can move to simulate scrolling. */
@@ -961,7 +947,6 @@ export class FakeEditor implements Editor {
961
947
  return subscribe(this.inlayHovers, listener);
962
948
  }
963
949
 
964
- /* The pointer resting on a hint or a part of one, or leaving them. */
965
950
  hoverInlay(id: string | null, part: number | null = null): void {
966
951
  emit(this.inlayHovers, id === null ? null : { id, part, rect: { left: 0, top: 0, right: 40, bottom: 20 } });
967
952
  }
@@ -981,21 +966,53 @@ export class FakeEditor implements Editor {
981
966
  this.inlayLink = target;
982
967
  }
983
968
 
984
- /* The suggestion after the caret now, which any change of the text takes away as the real editor does. */
969
+ /* The suggestion after the caret now, which any change of the text takes away as the real editor does. Its accessory is mounted and disposed as there too. */
985
970
  ghost: EditorGhostText | null = null;
971
+ private ghostSerial = 0;
972
+ private ghostDispose: (() => void) | void = undefined;
986
973
 
987
974
  setGhostText(ghost: EditorGhostText | null): void {
988
- this.ghost = ghost;
975
+ const serial = this.dropGhost();
976
+
977
+ // A disposer that set a ghost of its own came later than this call.
978
+ if (serial !== this.ghostSerial) {
979
+ return;
980
+ }
981
+
982
+ this.ghost = ghost === null || ghost.text === '' ? null : ghost;
983
+
984
+ if (this.ghost?.accessory === undefined) {
985
+ return;
986
+ }
987
+
988
+ const dispose = this.ghost.accessory(this.element.ownerDocument?.createElement('div') ?? ({} as HTMLElement));
989
+
990
+ if (serial !== this.ghostSerial) {
991
+ dispose?.();
992
+
993
+ return;
994
+ }
995
+
996
+ this.ghostDispose = dispose;
997
+ }
998
+
999
+ /* Takes the ghost away and disposes its accessory, returning the serial a caller compares after it. */
1000
+ private dropGhost(): number {
1001
+ const serial = ++this.ghostSerial;
1002
+ const dispose = this.ghostDispose;
1003
+ this.ghost = null;
1004
+ this.ghostDispose = undefined;
1005
+ dispose?.();
1006
+
1007
+ return serial;
989
1008
  }
990
1009
 
991
- /* What the host classified last. */
992
1010
  semanticTokens: readonly EditorSemanticToken[] | null = null;
993
1011
 
994
1012
  setSemanticTokens(tokens: readonly EditorSemanticToken[] | null): void {
995
1013
  this.semanticTokens = tokens;
996
1014
  }
997
1015
 
998
- /* What the host drew as a link last. */
999
1016
  link: EditorRange | null = null;
1000
1017
 
1001
1018
  setLink(range: EditorRange | null): void {
@@ -1020,7 +1037,6 @@ export class FakeEditor implements Editor {
1020
1037
  this.selections = [...this.selections.slice(0, -1), { anchor: offset, head: offset }];
1021
1038
  }
1022
1039
 
1023
- /* The folds the host asked to keep. */
1024
1040
  folds: EditorFolds = { collapsed: [], custom: [] };
1025
1041
 
1026
1042
  getFolds(): EditorFolds {
@@ -1077,7 +1093,6 @@ export class FakeEditor implements Editor {
1077
1093
  return rangeIn(this.text, this.selections.at(-1)!);
1078
1094
  }
1079
1095
 
1080
- /* The other carets of the editor, which a test sets. */
1081
1096
  get otherCarets(): EditorPosition[] {
1082
1097
  return this.selections.slice(0, -1).map((selection) => positionIn(this.text, selection.head));
1083
1098
  }
@@ -1137,7 +1152,6 @@ export class FakeEditor implements Editor {
1137
1152
  return subscribe(this.hovers, listener);
1138
1153
  }
1139
1154
 
1140
- /* The pointer resting on a position, or leaving the text. */
1141
1155
  hover(position: EditorPosition | null): void {
1142
1156
  const hover = position === null ? null : { position, rect: this.rectAt(position)! };
1143
1157
  emit(this.hovers, hover);
@@ -1197,7 +1211,6 @@ export class FakeEditor implements Editor {
1197
1211
  return [...this.clickHandlers].some((handler) => handler(click));
1198
1212
  }
1199
1213
 
1200
- /* The context menu asked for at a position. */
1201
1214
  openContextMenu(menu: EditorContextMenu): void {
1202
1215
  emit(this.contextListeners, menu);
1203
1216
  }
@@ -1341,6 +1354,7 @@ export class FakeEditor implements Editor {
1341
1354
  this.finds.clear();
1342
1355
  this.scopes.clear();
1343
1356
  this.tracked.clear();
1357
+ this.dropGhost();
1344
1358
  }
1345
1359
 
1346
1360
  private announceFind(state: EditorFindState): void {
package/src/find.ts CHANGED
@@ -6,7 +6,7 @@ import type { EditorSearchSnapshot } from './search-protocol.ts';
6
6
  import { SEARCH_LIMIT, MAX_REPLACEMENT_PAGE, MAX_REPLACEMENT_CHARACTERS } from './search-protocol.ts';
7
7
  import type { EditorFindQuery, EditorFindState } from './types.ts';
8
8
 
9
- export interface FindMark {
9
+ interface FindMark {
10
10
  from: number;
11
11
  to: number;
12
12
  }
@@ -14,7 +14,7 @@ export interface FindMark {
14
14
  export const FIND_LIMIT = SEARCH_LIMIT;
15
15
  const LIVE_REGEX_LIMIT = 8_000_000;
16
16
 
17
- export interface FindControllerOptions extends FindSearchOptions {
17
+ interface FindControllerOptions extends FindSearchOptions {
18
18
  readonly changed: (reveal?: boolean) => void;
19
19
  }
20
20
 
@@ -93,7 +93,6 @@ export class FindController {
93
93
  };
94
94
  }
95
95
 
96
- /* The range a search in the selection is held to. */
97
96
  get scope(): { from: number; to: number } | null {
98
97
  return this.query?.inSelection === true ? this.bounds : null;
99
98
  }
@@ -205,7 +204,6 @@ export class FindController {
205
204
  this.refresh();
206
205
  }
207
206
 
208
- /* The text of a search in the selection moved with an edit. */
209
207
  mapBounds(changes: readonly DocumentChange[]): void {
210
208
  if (this.pendingAnchor !== undefined) {
211
209
  this.pendingAnchor = mapOffset(this.pendingAnchor, changes);
@@ -1,4 +1,4 @@
1
- import type { Affinity, LineGeometry } from './layout.ts';
1
+ import type { Affinity, LineGeometry } from './line-geometry.ts';
2
2
 
3
3
  export function stopCount(geometry: LineGeometry): number {
4
4
  return geometry.uniform === undefined ? geometry.offsets.length : geometry.text.length + 1;
package/src/index.ts CHANGED
@@ -7,7 +7,7 @@ export { commentSyntax, type CommentSyntax } from '@adecore/editor-core';
7
7
  export { createSmartEditorEngine } from './engine.ts';
8
8
  export { rememberCopy } from './controller.ts';
9
9
  export { DEFAULT_SMART_KEYS } from './smart-keys.ts';
10
- export { shikiScopeColors, shikiTokenizers } from './shiki.ts';
10
+ export { shikiScopeColors, shikiTokenizers } from './shiki-grammar.ts';
11
11
 
12
12
  export type {
13
13
  Editor,
@@ -81,7 +81,6 @@ export type {
81
81
  EditorWidget,
82
82
  EditorZoom,
83
83
  FoldRole,
84
- KeyChord,
85
84
  LineToken,
86
85
  LineTokenKind,
87
86
  ScopeColorSource,
@@ -93,3 +92,4 @@ export type {
93
92
  TokenizedLine,
94
93
  TokenizerSource
95
94
  } from './types.ts';
95
+ export type { KeyChord } from './keymap-table.ts';
@@ -1,7 +1,15 @@
1
- import type { KeyChord } from './types.ts';
1
+ /* A shortcut: `mod` is Cmd on macOS and Ctrl elsewhere, `ctrl` and `meta` the physical keys. */
2
+ export interface KeyChord {
3
+ readonly mod: boolean;
4
+ readonly ctrl: boolean;
5
+ readonly meta: boolean;
6
+ readonly alt: boolean;
7
+ readonly shift: boolean;
8
+ /* An uppercase letter, a digit, a punctuation mark or a named key such as `ArrowLeft`. */
9
+ readonly key: string;
10
+ }
2
11
 
3
12
  export interface TakenKey {
4
- /* The chord the platform binds on the platform this entry is for. */
5
13
  readonly platform: string;
6
14
  /* The host command that owns the chord. */
7
15
  readonly by: string;
@@ -207,7 +215,6 @@ export function resolveKeymap(overrides: KeymapOverrides = {}): Keymap {
207
215
  return Object.fromEntries(KEYMAP_IDS.map((id) => [id, { ...KEYMAP[id], ...overrides[id] }])) as unknown as Keymap;
208
216
  }
209
217
 
210
- /* The chord of a command on a platform, or null when the platform has none. */
211
218
  export function chordOf(id: KeymapId, apple: boolean, keymap: Keymap = KEYMAP): string | null {
212
219
  return (keymap[id] ?? KEYMAP[id])[apple ? 'mac' : 'other'];
213
220
  }
package/src/keymap.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { EditorCommand } from '@adecore/editor-core';
2
2
  import { chordOf, KEYMAP, KEYMAP_IDS, type Keymap, type KeymapId, parseChord, typesInsteadOfChord } from './keymap-table.ts';
3
- import type { EditorViewCommand, KeyChord } from './types.ts';
3
+ import type { KeyChord } from './keymap-table.ts';
4
+ import type { EditorViewCommand } from './types.ts';
4
5
 
5
6
  export interface KeyLike {
6
7
  key: string;
@@ -1,7 +1,7 @@
1
1
  import type { DocumentChange } from '@adecore/editor-core';
2
2
  import { offsetMapper } from './offsets.ts';
3
3
 
4
- export interface LineBounds {
4
+ interface LineBounds {
5
5
  start: number;
6
6
  end: number;
7
7
  }
package/src/layout.ts CHANGED
@@ -2,11 +2,10 @@ import type { DocumentChange, Position } from '@adecore/editor-core';
2
2
  import { BIDI_COLUMNS, bidiControl, visibleBidi } from './bidi.ts';
3
3
  import { offsetOfStop, rowOfStop, stopAtOffset, stopCount, xOfStop } from './geometry-stops.ts';
4
4
  import { lineChangeMapper } from './layout-changes.ts';
5
+ import type { Affinity, Inlay, LayoutMetrics, LineGeometry } from './line-geometry.ts';
5
6
  import { offsetMapper } from './offsets.ts';
6
7
  import { uniformGeometry } from './uniform-geometry.ts';
7
8
 
8
- export type Affinity = 'before' | 'after';
9
-
10
9
  export interface VerticalWindow {
11
10
  top: number;
12
11
  bottom: number;
@@ -27,39 +26,12 @@ export function subRowBand(top: number, subRows: number, lineHeight: number, win
27
26
  };
28
27
  }
29
28
 
30
- export interface LayoutDocument {
29
+ interface LayoutDocument {
31
30
  getLineCount(): number;
32
31
  getLine(line: number): { start: number; end: number; next: number; text: string };
33
32
  positionAt(offset: number): Position;
34
33
  }
35
34
 
36
- export interface LayoutMetrics {
37
- lineHeight: number;
38
- charWidth: number;
39
- tabSize: number;
40
- measureText(text: string): number;
41
- measureInlay(text: string): number;
42
- }
43
-
44
- /* Text drawn between two characters of a line, without being part of the document. */
45
- export interface Inlay {
46
- id: string;
47
- at: number;
48
- text: string;
49
- tooltip?: string;
50
- /* The text cut into pieces drawn as elements of their own; they add up to `text`. */
51
- parts?: readonly string[];
52
- /* Pixels of space kept clear before and after the pill. */
53
- gapLeft?: number;
54
- gapRight?: number;
55
- /* What an input method has composed: drawn as text in the code face, with no padding, so what stands around it does not move. */
56
- composition?: boolean;
57
- /* A suggestion the host drew after the caret: text in the code face with no padding, which the caret stays in front of. */
58
- ghost?: boolean;
59
- /* A square of this CSS color in place of the text, such as the color a literal in the code stands for. */
60
- swatch?: string;
61
- }
62
-
63
35
  /* The side of a swatch in pixels, without its gaps. */
64
36
  export const SWATCH_SIZE = 12;
65
37
 
@@ -111,7 +83,6 @@ export interface FoldState {
111
83
  interface RowBase {
112
84
  key: string;
113
85
  index: number;
114
- /* The first document line the row stands for. */
115
86
  line: number;
116
87
  top: number;
117
88
  height: number;
@@ -131,56 +102,13 @@ export interface TextRow extends RowBase {
131
102
  replacement?: BlockReplacement;
132
103
  }
133
104
 
134
- export interface BlockRow extends RowBase {
105
+ interface BlockRow extends RowBase {
135
106
  kind: 'block';
136
107
  widget: BlockWidget;
137
108
  }
138
109
 
139
110
  export type LayoutRow = TextRow | BlockRow;
140
111
 
141
- export interface TextRun {
142
- /* Line-relative offsets let preceding edits move a line without rewriting its runs. */
143
- from: number;
144
- to: number;
145
- x: number;
146
- /* The visual line of the document line the run is on. */
147
- subRow: number;
148
- text: string;
149
- }
150
-
151
- export interface InlineBox {
152
- inlay: Inlay;
153
- x: number;
154
- width: number;
155
- subRow: number;
156
- }
157
-
158
- /* Where every character of one document line is, relative to the line's own origin. */
159
- export interface LineGeometry {
160
- start: number;
161
- end: number;
162
- next: number;
163
- text: string;
164
- /* Uniform ASCII rows share x prefixes instead of allocating these four arrays per character. */
165
- offsets: number[];
166
- /* The x of each stop before and after the inlays that sit on it. */
167
- before: number[];
168
- after: number[];
169
- /* The visual line each stop is on. */
170
- rowOf: number[];
171
- /* The stop each visual line starts at. */
172
- rowStarts: number[];
173
- /* The x each visual line ends at. */
174
- rowEnds: number[];
175
- /* The furthest stop a greedy wrap decision read, including its lookahead. */
176
- rowTriggers: number[];
177
- uniform?: { first: readonly number[]; continuation: readonly number[] };
178
- runs: TextRun[];
179
- inlays: InlineBox[];
180
- subRows: number;
181
- width: number;
182
- }
183
-
184
112
  export interface LayoutRect {
185
113
  x: number;
186
114
  y: number;
@@ -189,7 +117,7 @@ export interface LayoutRect {
189
117
  }
190
118
 
191
119
  export const TEXT_PADDING = 0;
192
- export const BOTTOM_PADDING = 8;
120
+ const BOTTOM_PADDING = 8;
193
121
  export const RIGHT_PADDING = 16;
194
122
  /* The room the platform keeps past the widest line, in columns of a space. */
195
123
  const ADDITIONAL_COLUMNS = 3;
@@ -304,7 +232,6 @@ export function wrapStops(text: string, offsets: readonly number[], metrics: Lay
304
232
  return wrapRows(text, offsets, metrics, limit).breaks;
305
233
  }
306
234
 
307
- /* A line of text laid out against its metrics; wrapped at `limit` pixels unless that is null. */
308
235
  export function scanDenseLine(
309
236
  line: { start: number; end: number; text: string; next?: number },
310
237
  metrics: LayoutMetrics,
@@ -491,7 +418,6 @@ class LineRow implements TextRow {
491
418
  }
492
419
  }
493
420
 
494
- /* Sorted, with the ranges that overlap or touch joined. */
495
421
  function mergeRanges(ranges: LineRange[]): LineRange[] {
496
422
  ranges.sort((left, right) => left.first - right.first);
497
423
  const merged: LineRange[] = [];
@@ -1004,7 +930,6 @@ export class EditorLayout {
1004
930
  return Math.min(bounds.end, Math.max(bounds.start, offset));
1005
931
  }
1006
932
 
1007
- /* The tops of the rows from `from` on. */
1008
933
  private reflow(from: number): void {
1009
934
  const previous = this.rows[from - 1];
1010
935
  let top = previous === undefined ? 0 : previous.top + previous.height;
@@ -1018,7 +943,6 @@ export class EditorLayout {
1018
943
  this.height = top + BOTTOM_PADDING;
1019
944
  }
1020
945
 
1021
- /* The row of a widget, a replacement or a line by its key. */
1022
946
  rowByKey(key: string): LayoutRow | undefined {
1023
947
  if (key.startsWith('line:')) {
1024
948
  const row = this.rowForLine(Number(key.slice(5)));
@@ -1029,7 +953,6 @@ export class EditorLayout {
1029
953
  return this.keyed.get(key);
1030
954
  }
1031
955
 
1032
- /* A widget's measured height. Returns whether it moved anything. */
1033
956
  setMeasuredHeight(key: string, height: number): boolean {
1034
957
  const row = this.rowByKey(key);
1035
958
  const next = Math.max(1, Math.round(height));
@@ -0,0 +1,69 @@
1
+ export type Affinity = 'before' | 'after';
2
+
3
+ export interface LayoutMetrics {
4
+ lineHeight: number;
5
+ charWidth: number;
6
+ tabSize: number;
7
+ measureText(text: string): number;
8
+ measureInlay(text: string): number;
9
+ }
10
+
11
+ /* Text drawn between two characters of a line, without being part of the document. */
12
+ export interface Inlay {
13
+ id: string;
14
+ at: number;
15
+ text: string;
16
+ tooltip?: string;
17
+ /* The text cut into pieces drawn as elements of their own; they add up to `text`. */
18
+ parts?: readonly string[];
19
+ /* Pixels of space kept clear before and after the pill. */
20
+ gapLeft?: number;
21
+ gapRight?: number;
22
+ /* What an input method has composed: drawn as text in the code face, with no padding, so what stands around it does not move. */
23
+ composition?: boolean;
24
+ /* A suggestion the host drew after the caret: text in the code face with no padding, which the caret stays in front of. */
25
+ ghost?: boolean;
26
+ /* A square of this CSS color in place of the text, such as the color a literal in the code stands for. */
27
+ swatch?: string;
28
+ }
29
+
30
+ interface TextRun {
31
+ /* Line-relative offsets let preceding edits move a line without rewriting its runs. */
32
+ from: number;
33
+ to: number;
34
+ x: number;
35
+ subRow: number;
36
+ text: string;
37
+ }
38
+
39
+ interface InlineBox {
40
+ inlay: Inlay;
41
+ x: number;
42
+ width: number;
43
+ subRow: number;
44
+ }
45
+
46
+ /* Where every character of one document line is, relative to the line's own origin. */
47
+ export interface LineGeometry {
48
+ start: number;
49
+ end: number;
50
+ next: number;
51
+ text: string;
52
+ /* Uniform ASCII rows share x prefixes instead of allocating these four arrays per character. */
53
+ offsets: number[];
54
+ /* The x of each stop before and after the inlays that sit on it. */
55
+ before: number[];
56
+ after: number[];
57
+ rowOf: number[];
58
+ /* The stop each visual line starts at. */
59
+ rowStarts: number[];
60
+ /* The x each visual line ends at. */
61
+ rowEnds: number[];
62
+ /* The furthest stop a greedy wrap decision read, including its lookahead. */
63
+ rowTriggers: number[];
64
+ uniform?: { first: readonly number[]; continuation: readonly number[] };
65
+ runs: TextRun[];
66
+ inlays: InlineBox[];
67
+ subRows: number;
68
+ width: number;
69
+ }
package/src/metrics.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { LayoutMetrics } from './layout.ts';
1
+ import type { LayoutMetrics } from './line-geometry.ts';
2
2
 
3
3
  export interface EditorFont {
4
4
  family: string;
@@ -14,9 +14,8 @@ export interface GestureEvent {
14
14
  shiftKey: boolean;
15
15
  }
16
16
 
17
- export type GestureAction = 'above' | 'below';
17
+ type GestureAction = 'above' | 'below';
18
18
 
19
- /* How long the taps may be apart. */
20
19
  const TAP_MS = 300;
21
20
  /* A first tap this old is forgotten even by a press that comes after the slower rule. */
22
21
  const FORGET_MS = 500;
@@ -9,7 +9,7 @@ interface InputContext {
9
9
  end: number;
10
10
  }
11
11
 
12
- export interface NativeInputHost {
12
+ interface NativeInputHost {
13
13
  readOnly(): boolean;
14
14
  replace(text: string): void;
15
15
  /* One typed character, with the pairing and the overtyping a keystroke gets. */
package/src/outline.ts CHANGED
@@ -3,7 +3,7 @@ import { offsetMapper } from './offsets.ts';
3
3
  import type { EditorBlock } from './types.ts';
4
4
 
5
5
  /* A block with a header line, in zero-based lines and both ends inclusive. */
6
- export interface OutlineBlock {
6
+ interface OutlineBlock {
7
7
  startLine: number;
8
8
  endLine: number;
9
9
  /* What a breadcrumb calls it. Blocks of the editor's own structure only have one when their header declares something. */
@@ -19,7 +19,7 @@ interface OutlineEntry {
19
19
  kind?: string;
20
20
  }
21
21
 
22
- export interface OutlineDocument {
22
+ interface OutlineDocument {
23
23
  getLine(line: number): { start: number; end: number; text: string };
24
24
  positionAt(offset: number): { line: number };
25
25
  getLineCount(): number;
@@ -256,8 +256,7 @@ export class Outline {
256
256
  }
257
257
 
258
258
  /* Where the rows of the document are, which the pinned headers are placed by. */
259
- export interface StickyRows {
260
- /* The top and the bottom of the row a line is drawn in. */
259
+ interface StickyRows {
261
260
  top(line: number): number;
262
261
  bottom(line: number): number;
263
262
  /* Whether the line starts a row of its own, which a line a fold hides does not. */
@@ -302,7 +301,6 @@ export function stickyPlacements(blocks: readonly OutlineBlock[], scrollTop: num
302
301
  return placements;
303
302
  }
304
303
 
305
- /* How far down from the top the pinned headers reach. */
306
304
  export function stickyCover(placements: readonly StickyPlacement[], lineHeight: number): number {
307
305
  return Math.max(0, ...placements.map((placement) => (placement.depth + 1) * lineHeight + placement.offset));
308
306
  }
package/src/overview.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type OverviewKind = 'added' | 'modified' | 'deleted' | 'find' | 'find-current' | 'occurrence' | 'todo' | 'info' | 'warning' | 'error';
1
+ type OverviewKind = 'added' | 'modified' | 'deleted' | 'find' | 'find-current' | 'occurrence' | 'todo' | 'info' | 'warning' | 'error';
2
2
 
3
3
  /* A stretch of the content, in the pixels the content is laid out in. */
4
4
  export interface OverviewSpan {
@@ -10,7 +10,7 @@ export interface OverviewSpan {
10
10
  title?: string;
11
11
  }
12
12
 
13
- export interface OverviewTick {
13
+ interface OverviewTick {
14
14
  kind: OverviewKind;
15
15
  y: number;
16
16
  height: number;