cursedbelt 5.79.3 → 5.80.0

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 (60) hide show
  1. package/dist/looks.css +43 -5
  2. package/dist/react/activity-bar/ActivityBar.d.ts +18 -1
  3. package/dist/react/activity-bar/ActivityBar.d.ts.map +1 -1
  4. package/dist/react/activity-bar/ActivityBar.js +34 -5
  5. package/dist/react/activity-bar/ActivityBar.js.map +1 -1
  6. package/dist/react/activity-bar/activityBar.css +20 -0
  7. package/dist/react/code-editor/CodeEditor.d.ts +5 -1
  8. package/dist/react/code-editor/CodeEditor.d.ts.map +1 -1
  9. package/dist/react/code-editor/CodeEditor.js +13 -6
  10. package/dist/react/code-editor/CodeEditor.js.map +1 -1
  11. package/dist/react/code-editor/keys.d.ts +8 -0
  12. package/dist/react/code-editor/keys.d.ts.map +1 -0
  13. package/dist/react/code-editor/keys.js +16 -0
  14. package/dist/react/code-editor/keys.js.map +1 -0
  15. package/dist/react/code-editor/languages.d.ts.map +1 -1
  16. package/dist/react/code-editor/languages.js +4 -2
  17. package/dist/react/code-editor/languages.js.map +1 -1
  18. package/dist/react/code-editor/lineAbove.d.ts +5 -4
  19. package/dist/react/code-editor/lineAbove.d.ts.map +1 -1
  20. package/dist/react/code-editor/lineAbove.js +6 -10
  21. package/dist/react/code-editor/lineAbove.js.map +1 -1
  22. package/dist/react/code-editor/markdownRules.d.ts +8 -0
  23. package/dist/react/code-editor/markdownRules.d.ts.map +1 -0
  24. package/dist/react/code-editor/markdownRules.js +64 -0
  25. package/dist/react/code-editor/markdownRules.js.map +1 -0
  26. package/dist/react/code-editor/occurrences.d.ts +8 -0
  27. package/dist/react/code-editor/occurrences.d.ts.map +1 -0
  28. package/dist/react/code-editor/occurrences.js +63 -0
  29. package/dist/react/code-editor/occurrences.js.map +1 -0
  30. package/dist/react/code-editor/plainInput.d.ts +4 -0
  31. package/dist/react/code-editor/plainInput.d.ts.map +1 -0
  32. package/dist/react/code-editor/plainInput.js +36 -0
  33. package/dist/react/code-editor/plainInput.js.map +1 -0
  34. package/dist/react/code-editor/theme.d.ts.map +1 -1
  35. package/dist/react/code-editor/theme.js +5 -0
  36. package/dist/react/code-editor/theme.js.map +1 -1
  37. package/dist/react/line-keys/lineKeys.d.ts +12 -8
  38. package/dist/react/line-keys/lineKeys.d.ts.map +1 -1
  39. package/dist/react/line-keys/lineKeys.js +14 -10
  40. package/dist/react/line-keys/lineKeys.js.map +1 -1
  41. package/package.json +1 -1
  42. package/src/looks.css +43 -5
  43. package/src/looks.spec.ts +42 -3
  44. package/src/react/activity-bar/ActivityBar.spec.tsx +46 -0
  45. package/src/react/activity-bar/ActivityBar.tsx +67 -4
  46. package/src/react/activity-bar/activityBar.css +20 -0
  47. package/src/react/code-editor/CodeEditor.tsx +24 -7
  48. package/src/react/code-editor/keys.spec.ts +61 -0
  49. package/src/react/code-editor/keys.ts +17 -0
  50. package/src/react/code-editor/languages.ts +4 -2
  51. package/src/react/code-editor/lineAbove.spec.ts +1 -16
  52. package/src/react/code-editor/lineAbove.ts +6 -10
  53. package/src/react/code-editor/markdownRules.spec.ts +26 -0
  54. package/src/react/code-editor/markdownRules.ts +73 -0
  55. package/src/react/code-editor/occurrences.ts +69 -0
  56. package/src/react/code-editor/plainInput.spec.ts +23 -0
  57. package/src/react/code-editor/plainInput.ts +35 -0
  58. package/src/react/code-editor/theme.ts +5 -0
  59. package/src/react/line-keys/lineKeys.spec.tsx +19 -7
  60. package/src/react/line-keys/lineKeys.ts +14 -10
@@ -63,6 +63,14 @@
63
63
  * It folds again when the mouse leaves, focus leaves, a touch lands outside it, Escape is
64
64
  * pressed, or a control is chosen. {@link ActivityBarProps.expandable} `false` opts out.
65
65
  *
66
+ * ── 🔒 It can be LOCKED open (forge task 3183) ──────────────────────────────────────────
67
+ * The owner, 2026-10-14: *"add lock button for the left nav menu. when locked it should stay
68
+ * open and the right collapses to fit screen size. this does not apply to mobile."* Given
69
+ * {@link ActivityBarProps.onLockedChange}, the rail draws a lock at its floor; locked, it stays
70
+ * expanded and takes its expanded width IN the layout — the page beside it narrows instead of
71
+ * being covered, Linear's and Obsidian's pinned sidebar. Under {@link LOCK_MIN_WIDTH} (a phone)
72
+ * there is no lock and a saved one is ignored: a 15rem rail on a 390px screen is the page.
73
+ *
66
74
  * ── Plain CSS, deliberately ─────────────────────────────────────────────────────────────
67
75
  * `activityBar.css` under the `cbab-` prefix, the same convention (and the same reason) as
68
76
  * `fileTree.css` and `denseGallery.css`: this mounts inside apps whose Tailwind build cannot
@@ -83,6 +91,7 @@ import {
83
91
  useState,
84
92
  } from 'react';
85
93
  import { Tooltip } from '../components/Tooltip.js';
94
+ import { useMediaQuery } from '../hooks/useMediaQuery.js';
86
95
  import './activityBar.css';
87
96
  import { cn, RAW_BUTTON } from '../lib/cn.js';
88
97
 
@@ -169,8 +178,20 @@ export interface ActivityBarProps {
169
178
  * icon-only column (a rail whose every control is already named beside it).
170
179
  */
171
180
  expandable?: boolean;
181
+ /**
182
+ * Whether the rail is locked open — see the file header. Controlled: the consumer keeps it
183
+ * (per device, usually) and hears the lock's presses through {@link onLockedChange}.
184
+ */
185
+ locked?: boolean;
186
+ /** Present ⇒ the rail draws its lock. Ignored when {@link expandable} is `false`. */
187
+ onLockedChange?: (locked: boolean) => void;
172
188
  }
173
189
 
190
+ const noop = (): void => {};
191
+
192
+ /** The narrowest screen the lock works on — below it the rail stays an overlay (a phone). */
193
+ export const LOCK_MIN_WIDTH = 768;
194
+
174
195
  /** How long a mouse rests on the rail before it opens its words. */
175
196
  export const EXPAND_HOVER_MS = 350;
176
197
  /** How long a touch holds before the rail opens its words — Android's long-press. */
@@ -180,7 +201,15 @@ const PRESS_SLOP_PX = 10;
180
201
 
181
202
  type ExpandedBy = 'hover' | 'focus' | 'press' | null;
182
203
 
183
- function ActivityButton({ item, onChosen }: { item: ActivityBarItem; onChosen: () => void }): JSX.Element {
204
+ function ActivityButton({
205
+ item,
206
+ onChosen,
207
+ className,
208
+ }: {
209
+ item: ActivityBarItem;
210
+ onChosen: () => void;
211
+ className?: string;
212
+ }): JSX.Element {
184
213
  const disabled = item.unavailableReason !== undefined;
185
214
  const button = (
186
215
  <button
@@ -189,7 +218,7 @@ function ActivityButton({ item, onChosen }: { item: ActivityBarItem; onChosen: (
189
218
  // layer, which fights `.cbab-btn`'s fixed 48px column geometry on cascade order rather
190
219
  // than composing with it — the same split `GalleryActionButton` records.
191
220
  type='button'
192
- className={cn(RAW_BUTTON, 'cbab-btn')}
221
+ className={cn(RAW_BUTTON, 'cbab-btn', className)}
193
222
  data-active={item.active || undefined}
194
223
  onClick={
195
224
  disabled
@@ -233,6 +262,16 @@ function ActivityButton({ item, onChosen }: { item: ActivityBarItem; onChosen: (
233
262
  );
234
263
  }
235
264
 
265
+ /** The lock's glyph — a padlock, its shackle shut while the rail is locked open. */
266
+ function LockGlyph({ locked }: { locked: boolean }): JSX.Element {
267
+ return (
268
+ <svg aria-hidden='true' viewBox='0 0 24 24' fill='none' stroke='currentColor' strokeWidth='1.7' strokeLinecap='round' strokeLinejoin='round'>
269
+ <rect x='5' y='11' width='14' height='10' rx='2' />
270
+ <path d={locked ? 'M8 11V7a4 4 0 0 1 8 0v4' : 'M8 11V7a4 4 0 0 1 7.6-1.7'} />
271
+ </svg>
272
+ );
273
+ }
274
+
236
275
  function Group({ items, onChosen }: { items: readonly ActivityBarItem[]; onChosen: () => void }): JSX.Element | null {
237
276
  if (items.length === 0) return null;
238
277
  return (
@@ -379,8 +418,14 @@ export function ActivityBar({
379
418
  ariaLabel = 'Views and settings',
380
419
  className,
381
420
  expandable = true,
421
+ locked = false,
422
+ onLockedChange,
382
423
  }: ActivityBarProps): JSX.Element {
383
- const { root, by, handlers, collapse } = useExpand(expandable);
424
+ const wide = useMediaQuery(`(min-width: ${LOCK_MIN_WIDTH}px)`);
425
+ const lockable = expandable && onLockedChange !== undefined && wide;
426
+ const isLocked = lockable && locked;
427
+ // Locked, there is nothing to open or fold: the hover, focus and hold machinery stands down.
428
+ const { root, by, handlers, collapse } = useExpand(expandable && !isLocked);
384
429
  return (
385
430
  /*
386
431
  * A `<fieldset>`, matching `DenseGalleryShell`'s `cbgd-order` next to it — a group of
@@ -393,7 +438,8 @@ export function ActivityBar({
393
438
  className={className ? `cbab ${className}` : 'cbab'}
394
439
  aria-label={ariaLabel}
395
440
  data-expandable={expandable || undefined}
396
- data-expanded={by ?? undefined}
441
+ data-expanded={isLocked ? 'locked' : (by ?? undefined)}
442
+ data-locked={isLocked || undefined}
397
443
  {...handlers}
398
444
  >
399
445
  {/* The panel is what widens; the fieldset keeps its 48px track, so expanding is an
@@ -405,6 +451,23 @@ export function ActivityBar({
405
451
  starts its top group at the top instead of centring it. */}
406
452
  <div className='cbab-spacer' />
407
453
  <Group items={bottom} onChosen={collapse} />
454
+ {lockable && onLockedChange ? (
455
+ <div className='cbab-group'>
456
+ <ActivityButton
457
+ className='cbab-lock'
458
+ // A stable name with the state in aria-pressed — ActivityBarItem.label's own rule.
459
+ item={{
460
+ id: 'cbab-lock',
461
+ label: 'Keep the menu open',
462
+ title: isLocked ? 'Let the menu fold away again' : 'Keep the menu open — the page beside it makes room',
463
+ icon: <LockGlyph locked={isLocked} />,
464
+ active: isLocked,
465
+ onSelect: () => onLockedChange(!isLocked),
466
+ }}
467
+ onChosen={noop}
468
+ />
469
+ </div>
470
+ ) : null}
408
471
  </div>
409
472
  </fieldset>
410
473
  );
@@ -56,6 +56,26 @@
56
56
  box-shadow: var(--shadow-overlay);
57
57
  }
58
58
 
59
+ /*
60
+ * 🔒 Locked open (forge task 3183): the TRACK takes the expanded width, so the page beside the
61
+ * rail narrows to fit instead of being covered — no overlay shadow, no lift over its neighbours.
62
+ * The component only sets `data-locked` on a screen at least LOCK_MIN_WIDTH wide.
63
+ */
64
+ .cbab[data-locked] {
65
+ inline-size: var(--cbab-expanded);
66
+ flex-basis: var(--cbab-expanded);
67
+ z-index: auto;
68
+ }
69
+
70
+ .cbab[data-locked] .cbab-panel {
71
+ box-shadow: none;
72
+ }
73
+
74
+ /* The lock is a toggle, not a place: pressed, it is lit, without the "you are here" hairline. */
75
+ .cbab .cbab-lock[data-active]::before {
76
+ content: none;
77
+ }
78
+
59
79
  @media (prefers-reduced-motion: reduce) {
60
80
  .cbab-panel {
61
81
  transition: none;
@@ -9,7 +9,7 @@
9
9
  // RHF via Controller:
10
10
  // <Controller control={control} name='query'
11
11
  // render={({ field }) => <CodeEditor value={field.value} onChange={field.onChange} language='sql' />} />
12
- import { defaultKeymap, history, historyKeymap, indentWithTab } from '@codemirror/commands';
12
+ import { history } from '@codemirror/commands';
13
13
  import {
14
14
  bracketMatching,
15
15
  defaultHighlightStyle,
@@ -20,12 +20,19 @@ import {
20
20
  } from '@codemirror/language';
21
21
  import type { Extension } from '@codemirror/state';
22
22
  import { Compartment, EditorState, Transaction } from '@codemirror/state';
23
- import { EditorView, keymap, lineNumbers as lineNumbersExt, placeholder as placeholderExt } from '@codemirror/view';
23
+ import {
24
+ drawSelection,
25
+ EditorView,
26
+ keymap,
27
+ lineNumbers as lineNumbersExt,
28
+ placeholder as placeholderExt,
29
+ } from '@codemirror/view';
24
30
  import { useEffect, useMemo, useRef, useState } from 'react';
25
31
  import { cn } from '../lib/cn.js';
26
32
  import type { CodeLanguage } from './languages.js';
27
33
  import { loadLanguageExtension } from './languages.js';
28
- import { lineKeyBindings } from './lineAbove.js';
34
+ import { editorKeyBindings } from './keys.js';
35
+ import { plainInput } from './plainInput.js';
29
36
  import { cbEditorTheme, cbSyntaxHighlighting } from './theme.js';
30
37
 
31
38
  export interface CodeEditorProps {
@@ -45,7 +52,11 @@ export interface CodeEditorProps {
45
52
  lineWrapping?: boolean;
46
53
  /** Text shown, dimmed, while the document is empty. */
47
54
  placeholder?: string;
48
- /** Let the browser spell-check the text — prose like markdown wants it, source does not. Default: false. */
55
+ /**
56
+ * Let the browser spell-check the text — prose like markdown wants it, source does not. Default:
57
+ * false. Only the red underline: autocorrect stays CodeMirror's `off` either way, because an OS
58
+ * that rewrites `--` to `—` or `"` to `“` rewrites the syntax (forge task 3184, `plainInput`).
59
+ */
49
60
  spellCheck?: boolean;
50
61
  /**
51
62
  * Called once with the live `EditorView` after it mounts — the seam for imperative work a
@@ -67,9 +78,15 @@ export interface CodeEditorProps {
67
78
  'aria-label'?: string;
68
79
  }
69
80
 
70
- // Fixed extensions shared across all instances — created once.
81
+ // Fixed extensions shared across all instances — created once. Several cursors, as in VS Code:
82
+ // ⌥-click adds one, ⌥⌘↑ / ⌥⌘↓ (`defaultKeymap`) one above or below, ⌘D the next match, Esc
83
+ // back to one — `drawSelection` is what paints the cursors past the browser's single caret.
71
84
  const FIXED_EXTENSIONS: Extension[] = [
72
85
  history(),
86
+ EditorState.allowMultipleSelections.of(true),
87
+ drawSelection(),
88
+ EditorView.clickAddsSelectionRange.of((event) => event.altKey),
89
+ plainInput,
73
90
  indentOnInput(),
74
91
  bracketMatching(),
75
92
  syntaxHighlighting(defaultHighlightStyle, { fallback: true }),
@@ -125,7 +142,7 @@ export function CodeEditor({
125
142
  const dynExtensions = useMemo<Extension[]>(() => {
126
143
  const exts: Extension[] = [
127
144
  indentUnit.of(' '.repeat(tabSize)),
128
- keymap.of([...lineKeyBindings, ...defaultKeymap, ...historyKeymap, indentWithTab]),
145
+ keymap.of(editorKeyBindings),
129
146
  ];
130
147
  if (showLineNumbers) exts.push(lineNumbersExt());
131
148
  if (showFoldGutter) exts.push(foldGutterExt());
@@ -133,7 +150,7 @@ export function CodeEditor({
133
150
  if (placeholder) exts.push(placeholderExt(placeholder));
134
151
  // The name belongs on the element that takes focus — the textbox — not only on the wrapper.
135
152
  if (ariaLabel) exts.push(EditorView.contentAttributes.of({ 'aria-label': ariaLabel }));
136
- if (spellCheck) exts.push(EditorView.contentAttributes.of({ spellcheck: 'true', autocorrect: 'on', autocapitalize: 'on' }));
153
+ if (spellCheck) exts.push(EditorView.contentAttributes.of({ spellcheck: 'true' }));
137
154
  if (readOnly) exts.push(EditorState.readOnly.of(true));
138
155
  if (langExtension) exts.push(langExtension);
139
156
  exts.push(...extraExtensions);
@@ -0,0 +1,61 @@
1
+ import { describe, expect, test } from 'bun:test';
2
+ import { EditorSelection, EditorState, type Transaction } from '@codemirror/state';
3
+ import type { KeyBinding } from '@codemirror/view';
4
+ import { editorKeyBindings } from './keys.js';
5
+ import { selectAllOccurrences, selectNextOccurrence } from './occurrences.js';
6
+
7
+ /** The command the editor runs for `key` on a Mac — the first binding that names it, as `keymap` resolves. */
8
+ function macCommand(key: string): KeyBinding['run'] {
9
+ const named = (b: KeyBinding) => b.mac === key || (!b.mac && b.key === key.replace('Cmd-', 'Mod-'));
10
+ return editorKeyBindings.find(named)?.run;
11
+ }
12
+
13
+ function press(key: string, doc: string, at: number) {
14
+ let state = EditorState.create({ doc, selection: EditorSelection.cursor(at) });
15
+ const run = macCommand(key);
16
+ run?.({ state, dispatch: (tr: Transaction) => { state = tr.state; } } as never);
17
+ return { doc: state.doc.toString(), caret: state.selection.main.head };
18
+ }
19
+
20
+ describe('CodeEditor keys — VS Code on a Mac (forge task 3182)', () => {
21
+ test('⌘↑ / ⌘↓ jump to the top or bottom and leave the line where it is', () => {
22
+ expect(press('Cmd-ArrowUp', 'one\ntwo\nthree', 6)).toEqual({ doc: 'one\ntwo\nthree', caret: 0 });
23
+ expect(press('Cmd-ArrowDown', 'one\ntwo\nthree', 1)).toEqual({ doc: 'one\ntwo\nthree', caret: 13 });
24
+ });
25
+
26
+ test('⌥↑ / ⌥↓ move the line', () => {
27
+ expect(press('Alt-ArrowUp', 'one\ntwo', 5)).toEqual({ doc: 'two\none', caret: 1 });
28
+ expect(press('Alt-ArrowDown', 'one\ntwo', 1)).toEqual({ doc: 'two\none', caret: 5 });
29
+ });
30
+ });
31
+
32
+ describe('⌘D and ⇧⌘L — several cursors on the same word', () => {
33
+ const multi = EditorState.allowMultipleSelections.of(true);
34
+ function run(command: typeof selectNextOccurrence, state: EditorState): EditorState {
35
+ let next = state;
36
+ command({ state, dispatch: (tr: Transaction) => { next = tr.state; } });
37
+ return next;
38
+ }
39
+ const spans = (state: EditorState) => state.selection.ranges.map((r) => [r.from, r.to]);
40
+
41
+ test('⌘D takes the word under the caret, then each next match, wrapping, then stops', () => {
42
+ let state = EditorState.create({ doc: 'ab x ab y ab', selection: EditorSelection.cursor(6), extensions: multi });
43
+ state = run(selectNextOccurrence, state);
44
+ expect(spans(state)).toEqual([[5, 7]]);
45
+ state = run(selectNextOccurrence, state);
46
+ expect(spans(state)).toEqual([[5, 7], [10, 12]]);
47
+ state = run(selectNextOccurrence, state);
48
+ expect(spans(state)).toEqual([[0, 2], [5, 7], [10, 12]]);
49
+ expect(selectNextOccurrence({ state, dispatch: () => {} })).toBe(false);
50
+ });
51
+
52
+ test('⇧⌘L selects every match at once', () => {
53
+ const state = run(selectAllOccurrences, EditorState.create({ doc: 'ab x ab', selection: EditorSelection.cursor(1), extensions: multi }));
54
+ expect(spans(state)).toEqual([[0, 2], [5, 7]]);
55
+ });
56
+
57
+ test('they sit in front of defaultKeymap, on VS Code\'s keys', () => {
58
+ expect(macCommand('Cmd-d')).toBe(selectNextOccurrence);
59
+ expect(macCommand('Shift-Cmd-l')).toBe(selectAllOccurrences);
60
+ });
61
+ });
@@ -0,0 +1,17 @@
1
+ import { defaultKeymap, historyKeymap, indentWithTab } from '@codemirror/commands';
2
+ import type { KeyBinding } from '@codemirror/view';
3
+ import { lineKeyBindings } from './lineAbove.js';
4
+ import { occurrenceBindings } from './occurrences.js';
5
+
6
+ /**
7
+ * Every key `CodeEditor` answers, first match wins: cb's VS Code additions IN FRONT of
8
+ * CodeMirror's `defaultKeymap`, which is already VS Code's for the rest. Nothing here may shadow
9
+ * a `defaultKeymap` key VS Code means the same way — `keys.spec.ts` holds ⌘↑ / ⌘↓ to the jump.
10
+ */
11
+ export const editorKeyBindings: readonly KeyBinding[] = [
12
+ ...lineKeyBindings,
13
+ ...occurrenceBindings,
14
+ ...defaultKeymap,
15
+ ...historyKeymap,
16
+ indentWithTab,
17
+ ];
@@ -9,6 +9,7 @@
9
9
  // and a snippet shown WITHOUT highlighting is the plain <pre> this component
10
10
  // exists to replace.
11
11
  import type { Extension } from '@codemirror/state';
12
+ import { markdownRules } from './markdownRules.js';
12
13
 
13
14
  /** Supported language identifiers. `text` (the default) means no highlighting. */
14
15
  export type CodeLanguage =
@@ -397,10 +398,11 @@ export async function loadLanguageExtension(language: CodeLanguage): Promise<Ext
397
398
  case 'diff':
398
399
  return stream((await import('@codemirror/legacy-modes/mode/diff')).diff);
399
400
  // The one Lezer grammar past the first six: a markdown fence highlights its own
400
- // code, and `#`, `**` and `[](…)` read as structure rather than as punctuation.
401
+ // code, and `#`, `**` and `[](…)` read as structure rather than as punctuation. A `---`
402
+ // rule is drawn as one while the caret is off its line (`markdownRules`).
401
403
  case 'markdown': {
402
404
  const { markdown } = await import('@codemirror/lang-markdown');
403
- return markdown();
405
+ return [markdown(), markdownRules];
404
406
  }
405
407
  case 'scala':
406
408
  return stream((await import('@codemirror/legacy-modes/mode/clike')).scala);
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, test } from 'bun:test';
2
2
  import { EditorSelection, EditorState, type Transaction } from '@codemirror/state';
3
- import { insertBlankLineAbove, lineKeyBindings } from './lineAbove.js';
3
+ import { insertBlankLineAbove } from './lineAbove.js';
4
4
 
5
5
  function run(doc: string, at: number): { doc: string; caret: number } {
6
6
  let state = EditorState.create({ doc, selection: EditorSelection.cursor(at) });
@@ -19,18 +19,3 @@ describe('insertBlankLineAbove — ⇧⌘↵ in CodeEditor', () => {
19
19
  expect(insertBlankLineAbove({ state, dispatch: () => {} })).toBe(false);
20
20
  });
21
21
  });
22
-
23
- describe('lineKeyBindings — ⌘↑ / ⌘↓ in CodeEditor', () => {
24
- function press(key: string, doc: string, at: number): { doc: string; caret: number } {
25
- let state = EditorState.create({ doc, selection: EditorSelection.cursor(at) });
26
- const binding = lineKeyBindings.find((b) => b.key === key);
27
- // moveLineUp/Down are StateCommands at heart; they read only `state` and `dispatch`.
28
- binding?.run?.({ state, dispatch: (tr: Transaction) => { state = tr.state; } } as never);
29
- return { doc: state.doc.toString(), caret: state.selection.main.head };
30
- }
31
-
32
- test('⌘↑ moves the line up and ⌘↓ moves it down, the caret riding with it', () => {
33
- expect(press('Mod-ArrowUp', 'one\ntwo', 5)).toEqual({ doc: 'two\none', caret: 1 });
34
- expect(press('Mod-ArrowDown', 'one\ntwo', 1)).toEqual({ doc: 'two\none', caret: 5 });
35
- });
36
- });
@@ -1,4 +1,3 @@
1
- import { moveLineDown, moveLineUp } from '@codemirror/commands';
2
1
  import { EditorSelection, type StateCommand } from '@codemirror/state';
3
2
  import type { KeyBinding } from '@codemirror/view';
4
3
 
@@ -23,13 +22,10 @@ export const insertBlankLineAbove: StateCommand = ({ state, dispatch }) => {
23
22
  };
24
23
 
25
24
  /**
26
- * The line keys `CodeEditor` adds IN FRONT of `defaultKeymap`: ⇧⌘↵ above, and ⌘↑ / ⌘↓ moving the
27
- * line — the owner's chord (2026-10-05), which in `defaultKeymap` is the Mac's jump to the top or
28
- * bottom. ⌥↑ / ⌥↓, VS Code's own move, is already in `defaultKeymap`, and so is ⇧⌘↑ (select to
29
- * the top), which stays. The same keys in a `<textarea>` are `cursedbelt/react/line-keys`.
25
+ * The line keys `CodeEditor` adds IN FRONT of `defaultKeymap`: ⇧⌘↵ above. Everything else VS Code
26
+ * binds for lines `defaultKeymap` already has — ⌥↑ / ⌥↓ move, ⇧⌥↑ / ⇧⌥↓ copy, ⌘↑ / ⌘↓ the jump to
27
+ * the top or bottom with the line left where it is. ⌘↑ / ⌘↓ moved the line here from 2026-10-05
28
+ * until the owner asked for VS Code's meaning back (2026-10-14, forge task 3182); the same keys
29
+ * in a `<textarea>` are `cursedbelt/react/line-keys`.
30
30
  */
31
- export const lineKeyBindings: readonly KeyBinding[] = [
32
- { key: 'Shift-Mod-Enter', run: insertBlankLineAbove },
33
- { key: 'Mod-ArrowUp', run: moveLineUp },
34
- { key: 'Mod-ArrowDown', run: moveLineDown },
35
- ];
31
+ export const lineKeyBindings: readonly KeyBinding[] = [{ key: 'Shift-Mod-Enter', run: insertBlankLineAbove }];
@@ -0,0 +1,26 @@
1
+ import { describe, expect, test } from 'bun:test';
2
+ import { markdown } from '@codemirror/lang-markdown';
3
+ import { ensureSyntaxTree } from '@codemirror/language';
4
+ import { EditorSelection, EditorState } from '@codemirror/state';
5
+ import { ruleLines } from './markdownRules.js';
6
+
7
+ function rules(doc: string, caret: number): number[] {
8
+ const state = EditorState.create({ doc, selection: EditorSelection.cursor(caret), extensions: markdown() });
9
+ ensureSyntaxTree(state, state.doc.length, 5000);
10
+ return ruleLines(state, [{ from: 0, to: state.doc.length }]);
11
+ }
12
+
13
+ describe('markdownRules — `---` drawn as a rule while writing (forge task 3184)', () => {
14
+ test('a rule line is drawn, the caret elsewhere', () => {
15
+ expect(rules('one\n\n---\n\ntwo', 0)).toEqual([5]);
16
+ expect(rules('***\n\n___', 0)).toEqual([5]);
17
+ });
18
+
19
+ test('with the caret on it, the dashes show', () => {
20
+ expect(rules('one\n\n---\n\ntwo', 7)).toEqual([]);
21
+ });
22
+
23
+ test('`---` under text is that text\'s heading underline, not a rule — as the preview reads it', () => {
24
+ expect(rules('Title\n---\n', 0)).toEqual([]);
25
+ });
26
+ });
@@ -0,0 +1,73 @@
1
+ import { syntaxTree } from '@codemirror/language';
2
+ import type { EditorState, Extension, Range } from '@codemirror/state';
3
+ import { Decoration, type DecorationSet, EditorView, ViewPlugin, type ViewUpdate } from '@codemirror/view';
4
+
5
+ /**
6
+ * A markdown rule (`---`, `***`, `___`) drawn as a rule while you write, the dashes coming back
7
+ * when the caret is on its line — Obsidian's live preview of the same thing. The owner, 2026-10-14
8
+ * (forge task 3184): "it should show as a solid line in editing and in view". Only a rule the
9
+ * grammar agrees is one: `---` under a line of text is that line's heading underline, and the
10
+ * preview reads it the same way.
11
+ */
12
+ const rule = Decoration.line({ class: 'cb-md-rule' });
13
+
14
+ /** The line starts of every rule in the visible ranges, less any line a selection touches. */
15
+ export function ruleLines(state: EditorState, ranges: readonly { from: number; to: number }[]): number[] {
16
+ const starts: number[] = [];
17
+ const tree = syntaxTree(state);
18
+ for (const { from, to } of ranges) {
19
+ tree.iterate({
20
+ from,
21
+ to,
22
+ enter: (node) => {
23
+ if (node.name !== 'HorizontalRule') return;
24
+ const line = state.doc.lineAt(node.from);
25
+ const touched = state.selection.ranges.some((r) => r.from <= line.to && r.to >= line.from);
26
+ if (!touched && starts.at(-1) !== line.from) starts.push(line.from);
27
+ },
28
+ });
29
+ }
30
+ return starts;
31
+ }
32
+
33
+ function build(view: EditorView): DecorationSet {
34
+ const marks: Range<Decoration>[] = ruleLines(view.state, view.visibleRanges).map((at) => rule.range(at));
35
+ return Decoration.set(marks);
36
+ }
37
+
38
+ const rulePlugin = ViewPlugin.fromClass(
39
+ class {
40
+ decorations: DecorationSet;
41
+ constructor(view: EditorView) {
42
+ this.decorations = build(view);
43
+ }
44
+ update(update: ViewUpdate) {
45
+ if (
46
+ update.docChanged ||
47
+ update.selectionSet ||
48
+ update.viewportChanged ||
49
+ syntaxTree(update.startState) !== syntaxTree(update.state)
50
+ )
51
+ this.decorations = build(update.view);
52
+ }
53
+ },
54
+ { decorations: (plugin) => plugin.decorations },
55
+ );
56
+
57
+ const ruleTheme = EditorView.baseTheme({
58
+ // The rule is the line's background, centred, the width of the text column; the dashes stay
59
+ // in the document (and under the caret's click), just not painted.
60
+ '.cb-md-rule': {
61
+ backgroundImage: 'linear-gradient(var(--border), var(--border))',
62
+ backgroundSize: '100% 1px',
63
+ backgroundPosition: 'center',
64
+ backgroundRepeat: 'no-repeat',
65
+ backgroundOrigin: 'content-box',
66
+ backgroundClip: 'content-box',
67
+ },
68
+ '.cb-md-rule, .cb-md-rule *': {
69
+ color: 'transparent !important',
70
+ },
71
+ });
72
+
73
+ export const markdownRules: Extension = [rulePlugin, ruleTheme];
@@ -0,0 +1,69 @@
1
+ import { EditorSelection, type EditorState, type SelectionRange, type StateCommand } from '@codemirror/state';
2
+ import type { KeyBinding } from '@codemirror/view';
3
+
4
+ /**
5
+ * VS Code's ⌘D and ⇧⌘L — the two multi-cursor keys `defaultKeymap` leaves to `@codemirror/search`,
6
+ * which `CodeEditor` does not load (its find panel would fight the app's own find). Exact text,
7
+ * case-sensitive; a caret with nothing selected first takes the word it is in, as in VS Code.
8
+ */
9
+
10
+ /** The text the commands look for: the main selection, or the word under an empty caret. */
11
+ function queryOf(state: EditorState): { query: string; range: SelectionRange } | null {
12
+ const main = state.selection.main;
13
+ const range = main.empty ? state.wordAt(main.head) : main;
14
+ if (!range || range.empty) return null;
15
+ return { query: state.sliceDoc(range.from, range.to), range: EditorSelection.range(range.from, range.to) };
16
+ }
17
+
18
+ /** Where `query` starts in `text`, matches never overlapping. */
19
+ function matchesOf(text: string, query: string): number[] {
20
+ const starts: number[] = [];
21
+ for (let at = text.indexOf(query); at !== -1; at = text.indexOf(query, at + query.length)) starts.push(at);
22
+ return starts;
23
+ }
24
+
25
+ function isSelected(state: EditorState, from: number, to: number): boolean {
26
+ return state.selection.ranges.some((r) => r.from === from && r.to === to);
27
+ }
28
+
29
+ /** ⌘D — select the word under the caret, then add the next match of it, wrapping at the end. */
30
+ export const selectNextOccurrence: StateCommand = ({ state, dispatch }) => {
31
+ const found = queryOf(state);
32
+ if (!found) return false;
33
+ const { query, range } = found;
34
+ if (state.selection.main.empty) {
35
+ dispatch(state.update({ selection: state.selection.replaceRange(range), scrollIntoView: true, userEvent: 'select' }));
36
+ return true;
37
+ }
38
+ // Every match, the ones after the selection first, then from the top — the first not yet selected.
39
+ const starts = matchesOf(state.doc.toString(), query);
40
+ const at = [...starts.filter((a) => a >= range.to), ...starts.filter((a) => a < range.to)].find(
41
+ (a) => !isSelected(state, a, a + query.length),
42
+ );
43
+ if (at === undefined) return false;
44
+ dispatch(
45
+ state.update({
46
+ selection: state.selection.addRange(EditorSelection.range(at, at + query.length)),
47
+ scrollIntoView: true,
48
+ userEvent: 'select',
49
+ }),
50
+ );
51
+ return true;
52
+ };
53
+
54
+ /** ⇧⌘L — every match of the selection (or the word under the caret) selected at once. */
55
+ export const selectAllOccurrences: StateCommand = ({ state, dispatch }) => {
56
+ const found = queryOf(state);
57
+ if (!found) return false;
58
+ const { query, range } = found;
59
+ const starts = matchesOf(state.doc.toString(), query);
60
+ const ranges = starts.map((at) => EditorSelection.range(at, at + query.length));
61
+ const main = Math.max(0, starts.indexOf(range.from));
62
+ dispatch(state.update({ selection: EditorSelection.create(ranges, main), userEvent: 'select' }));
63
+ return true;
64
+ };
65
+
66
+ export const occurrenceBindings: readonly KeyBinding[] = [
67
+ { key: 'Mod-d', run: selectNextOccurrence, preventDefault: true },
68
+ { key: 'Shift-Mod-l', run: selectAllOccurrences, preventDefault: true },
69
+ ];
@@ -0,0 +1,23 @@
1
+ import { describe, expect, test } from 'bun:test';
2
+ import { unsmarten } from './plainInput.js';
3
+
4
+ describe('unsmarten — the OS\'s smart punctuation, put back (forge task 3184)', () => {
5
+ test('a dash the OS made of typed hyphens is the hyphens again', () => {
6
+ expect(unsmarten('-', '—')).toBe('--');
7
+ expect(unsmarten('--', '—')).toBe('---');
8
+ expect(unsmarten('-', '–')).toBe('--');
9
+ });
10
+
11
+ test('a curly quote where a straight one was pressed is straight', () => {
12
+ expect(unsmarten('', '“')).toBe('"');
13
+ expect(unsmarten('', '’')).toBe("'");
14
+ expect(unsmarten('"', '”')).toBe('"');
15
+ });
16
+
17
+ test('anything else is typing, left alone', () => {
18
+ expect(unsmarten('', '—')).toBeNull();
19
+ expect(unsmarten('a', '—')).toBeNull();
20
+ expect(unsmarten('', '-')).toBeNull();
21
+ expect(unsmarten('x', '“')).toBeNull();
22
+ });
23
+ });
@@ -0,0 +1,35 @@
1
+ import { EditorView } from '@codemirror/view';
2
+
3
+ /**
4
+ * What the OS's "smart punctuation" types into a source editor, put back to what the keys said.
5
+ *
6
+ * iOS (and a Mac with Edit ▸ Substitutions on) rewrites `--` to `—` and `"` to `“` as you type —
7
+ * in markdown that eats a rule's dashes and a code span's quotes (the owner, 2026-10-14, forge
8
+ * task 3184: "when typing three dashes … it shifts and deletes some dashes … please fix all other
9
+ * syntax errors that may be similar"). `CodeEditor` already asks the browser for no autocorrect;
10
+ * this is the half that holds where the OS does not listen. VS Code substitutes nothing, either.
11
+ *
12
+ * Only a substitution is undone: a dash replacing the `-` (or `--`) the keys just typed, or a
13
+ * curly quote arriving where a straight one was pressed. A `—` pasted in is a paste, never seen here.
14
+ */
15
+ const QUOTES: Record<string, string> = { '“': '"', '”': '"', '‘': "'", '’': "'" };
16
+
17
+ /** The text the keys meant, or null when `text` replacing `replaced` is not a substitution. */
18
+ export function unsmarten(replaced: string, text: string): string | null {
19
+ if ((text === '—' || text === '–') && /^-{1,2}$/.test(replaced)) return text === '—' && replaced === '-' ? '--' : `${replaced}-`;
20
+ const quote = QUOTES[text];
21
+ if (quote !== undefined && (replaced === '' || replaced === quote)) return quote;
22
+ return null;
23
+ }
24
+
25
+ export const plainInput = EditorView.inputHandler.of((view, from, to, text) => {
26
+ const meant = unsmarten(view.state.sliceDoc(from, to), text);
27
+ if (meant === null) return false;
28
+ view.dispatch({
29
+ changes: { from, to, insert: meant },
30
+ selection: { anchor: from + meant.length },
31
+ scrollIntoView: true,
32
+ userEvent: 'input.type',
33
+ });
34
+ return true;
35
+ });
@@ -21,6 +21,11 @@ export const cbEditorTheme = EditorView.theme({
21
21
  '.cm-content': {
22
22
  caretColor: 'var(--foreground)',
23
23
  padding: '0.5rem 0',
24
+ // Every character drawn as itself — VS Code's `editor.fontLigatures: false`. A ligature font
25
+ // (JetBrains Mono, desk's) joins `--` and `---` into one glyph that redraws as each dash
26
+ // lands, and turns `!=`, `=>` and `<=` into symbols that are not what was typed (forge task 3184).
27
+ fontVariantLigatures: 'none',
28
+ fontFeatureSettings: '"calt" 0, "liga" 0',
24
29
  },
25
30
  // CodeMirror's own recipe for a minimum height: give it to the content AND the gutter, so the
26
31
  // line-number rail runs the editor's full height instead of stopping under the last line