@opencode/ui 2.2.5 → 2.2.7

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 (119) hide show
  1. package/dist/actions/button/button.d.ts +2 -2
  2. package/dist/actions/icon-button/icon-button.d.ts +1 -1
  3. package/dist/components/animated-number-machine.d.ts +95 -0
  4. package/dist/components/file-icon-machine.d.ts +40 -0
  5. package/dist/components/file-icon.d.ts +0 -2
  6. package/dist/components/file-icons/choose-icon-name.d.ts +2 -0
  7. package/dist/components/image-flight-machine.d.ts +135 -0
  8. package/dist/components/image-zoom-machine.d.ts +95 -0
  9. package/dist/components/image-zoom.d.ts +6 -3
  10. package/dist/components/list.d.ts +2 -6
  11. package/dist/components/menu-scroll.d.ts +9 -3
  12. package/dist/components/popover-machine.d.ts +96 -0
  13. package/dist/components/popover.d.ts +2 -2
  14. package/dist/components/resize-handle-machine.d.ts +71 -0
  15. package/dist/components/resize-handle.d.ts +2 -0
  16. package/dist/components/scroll-view-machine.d.ts +68 -0
  17. package/dist/components/scroll-view.d.ts +2 -2
  18. package/dist/components/spinner.d.ts +11 -3
  19. package/dist/components/text-field-machine.d.ts +62 -0
  20. package/dist/components/text-reveal-machine.d.ts +90 -0
  21. package/dist/components/typewriter-machine.d.ts +62 -0
  22. package/dist/context/dialog-machine.d.ts +125 -0
  23. package/dist/context/dialog.d.ts +17 -16
  24. package/dist/data-display/line-comment/machine.d.ts +157 -0
  25. package/dist/data-display/project-avatar/animation-machine.d.ts +62 -0
  26. package/dist/data-display/project-avatar/animation.d.ts +1 -1
  27. package/dist/feedback/activity-ring/activity-ring.d.ts +2 -1
  28. package/dist/feedback/toast/machine.d.ts +57 -0
  29. package/dist/feedback/toast/toast.d.ts +1 -1
  30. package/dist/forms/checkbox/checkbox.d.ts +6 -1
  31. package/dist/forms/select/machine.d.ts +45 -0
  32. package/dist/forms/select/select.d.ts +4 -0
  33. package/dist/forms/typeahead/machine.d.ts +85 -0
  34. package/dist/hooks/auto-scroll-machine.d.ts +89 -0
  35. package/dist/hooks/create-auto-scroll.d.ts +1 -1
  36. package/dist/hooks/list-machine.d.ts +150 -0
  37. package/dist/hooks/use-filtered-list.d.ts +21 -35
  38. package/dist/i18n/en.d.ts +5 -0
  39. package/dist/icons/catalog.d.ts +8 -0
  40. package/dist/navigation/menu/machine.d.ts +49 -0
  41. package/dist/navigation/menu/menu.d.ts +5 -3
  42. package/dist/navigation/segmented-control/machine.d.ts +46 -0
  43. package/dist/overlays/mcp-sign-in/machine.d.ts +184 -0
  44. package/dist/overlays/mcp-sign-in/mcp-sign-in.d.ts +40 -0
  45. package/dist/overlays/tooltip/machine.d.ts +146 -0
  46. package/dist/theme/context.d.ts +38 -14
  47. package/dist/theme/machine.d.ts +174 -0
  48. package/dist/typography/text-shimmer/machine.d.ts +48 -0
  49. package/package.json +128 -111
  50. package/src/actions/button/button.tsx +11 -6
  51. package/src/actions/icon-button/icon-button.tsx +17 -4
  52. package/src/components/animated-number-machine.ts +214 -0
  53. package/src/components/animated-number.tsx +134 -83
  54. package/src/components/file-icon-machine.ts +78 -0
  55. package/src/components/file-icon.tsx +96 -579
  56. package/src/components/file-icons/choose-icon-name.ts +574 -0
  57. package/src/components/image-flight-machine.ts +247 -0
  58. package/src/components/image-preview.css +5 -2
  59. package/src/components/image-preview.tsx +390 -252
  60. package/src/components/image-zoom-machine.ts +191 -0
  61. package/src/components/image-zoom.ts +22 -14
  62. package/src/components/list.tsx +46 -137
  63. package/src/components/menu-scroll.css +19 -8
  64. package/src/components/menu-scroll.tsx +111 -34
  65. package/src/components/popover-machine.ts +198 -0
  66. package/src/components/popover.tsx +157 -89
  67. package/src/components/resize-handle-machine.ts +174 -0
  68. package/src/components/resize-handle.tsx +116 -67
  69. package/src/components/scroll-view-machine.ts +244 -0
  70. package/src/components/scroll-view.tsx +163 -116
  71. package/src/components/spinner.css +18 -5
  72. package/src/components/spinner.tsx +28 -14
  73. package/src/components/text-field-machine.ts +102 -0
  74. package/src/components/text-field.tsx +78 -24
  75. package/src/components/text-reveal-machine.ts +184 -0
  76. package/src/components/text-reveal.tsx +96 -93
  77. package/src/components/typewriter-machine.ts +134 -0
  78. package/src/components/typewriter.tsx +50 -39
  79. package/src/context/dialog-machine.ts +280 -0
  80. package/src/context/dialog.tsx +168 -177
  81. package/src/data-display/line-comment/line-comment.tsx +157 -178
  82. package/src/data-display/line-comment/machine.ts +391 -0
  83. package/src/data-display/project-avatar/animation-machine.ts +182 -0
  84. package/src/data-display/project-avatar/animation.ts +67 -38
  85. package/src/feedback/activity-ring/activity-ring.tsx +1 -1
  86. package/src/feedback/toast/machine.ts +115 -0
  87. package/src/feedback/toast/toast.tsx +59 -59
  88. package/src/forms/checkbox/checkbox-compact.css +169 -0
  89. package/src/forms/checkbox/checkbox.tsx +93 -31
  90. package/src/forms/inline-input/inline-input.css +0 -1
  91. package/src/forms/search-list/search-list.css +5 -1
  92. package/src/forms/search-list/search-list.tsx +18 -10
  93. package/src/forms/select/machine.ts +81 -0
  94. package/src/forms/select/select.css +59 -17
  95. package/src/forms/select/select.tsx +74 -32
  96. package/src/forms/typeahead/machine.ts +253 -0
  97. package/src/forms/typeahead/typeahead.tsx +70 -62
  98. package/src/hooks/auto-scroll-machine.ts +261 -0
  99. package/src/hooks/create-auto-scroll.tsx +110 -205
  100. package/src/hooks/list-machine.ts +359 -0
  101. package/src/hooks/use-filtered-list.tsx +101 -112
  102. package/src/i18n/en.ts +6 -1
  103. package/src/i18n/uk.ts +3 -3
  104. package/src/icons/catalog.ts +8 -0
  105. package/src/navigation/menu/machine.ts +109 -0
  106. package/src/navigation/menu/menu.tsx +133 -22
  107. package/src/navigation/segmented-control/machine.ts +72 -0
  108. package/src/navigation/segmented-control/segmented-control.tsx +46 -46
  109. package/src/overlays/dialog/dialog.tsx +7 -1
  110. package/src/overlays/mcp-sign-in/machine.ts +343 -0
  111. package/src/overlays/mcp-sign-in/mcp-sign-in.ts +159 -0
  112. package/src/overlays/tooltip/machine.ts +303 -0
  113. package/src/overlays/tooltip/tooltip.tsx +159 -92
  114. package/src/styles/theme.css +10 -2
  115. package/src/theme/context.tsx +192 -269
  116. package/src/theme/machine.ts +508 -0
  117. package/src/typography/text-shimmer/machine.ts +90 -0
  118. package/src/typography/text-shimmer/text-shimmer.css +71 -39
  119. package/src/typography/text-shimmer/text-shimmer.tsx +41 -24
@@ -1,18 +1,20 @@
1
1
  import {
2
2
  For,
3
3
  Show,
4
+ createComputed,
4
5
  createEffect,
6
+ createMemo,
5
7
  createSignal,
6
8
  on,
7
9
  onCleanup,
8
10
  onMount,
9
11
  splitProps,
12
+ untrack,
10
13
  type ComponentProps,
11
14
  type JSX,
12
15
  } from "solid-js"
13
16
  import { FileIcon } from "@opencode/ui/file-icon"
14
17
  import { useI18n } from "../../context/i18n"
15
- import { useFilteredList } from "../../hooks"
16
18
  import { Button } from "@opencode/ui/button"
17
19
  import { Icon } from "@opencode/ui/icon"
18
20
  import { IconButton } from "@opencode/ui/icon-button"
@@ -20,6 +22,16 @@ import { Keybind } from "@opencode/ui/keybind"
20
22
  import { Tooltip } from "@opencode/ui/tooltip"
21
23
  import { Loader } from "@opencode/ui/loader"
22
24
  import { makeEventListener } from "@solid-primitives/event-listener"
25
+ import {
26
+ createLineCommentEditorState,
27
+ MENTION_TIMEOUT_MS,
28
+ parseMentionToken,
29
+ transitionLineCommentEditor,
30
+ viewLineCommentEditor,
31
+ type LineCommentEditorConfig,
32
+ type LineCommentEditorEffect,
33
+ type LineCommentEditorEvent,
34
+ } from "./machine"
23
35
  import check from "./quote-check.svg"
24
36
  import "./line-comment.css"
25
37
 
@@ -128,9 +140,8 @@ function pathDirectory(path: string) {
128
140
  export function LineCommentEditor(props: LineCommentEditorProps) {
129
141
  const i18n = useI18n()
130
142
  let textareaRef: HTMLTextAreaElement | undefined
131
- const [mentionOpen, setMentionOpen] = createSignal(false)
132
-
133
- const [alternate, setAlternate] = createSignal(false)
143
+ let mentionTimer: ReturnType<typeof setTimeout> | undefined
144
+ const [editorState, setEditorState] = createSignal(createLineCommentEditorState())
134
145
 
135
146
  const [local, rest] = splitProps(props, [
136
147
  "label",
@@ -153,125 +164,133 @@ export function LineCommentEditor(props: LineCommentEditorProps) {
153
164
  "classList",
154
165
  ])
155
166
 
156
- const canSubmit = () => !!local.allowEmpty || local.value.trim().length > 0
157
- const compactCancel = () => !canSubmit()
167
+ const readConfig = (): LineCommentEditorConfig => ({
168
+ value: local.value,
169
+ allowEmpty: !!local.allowEmpty,
170
+ variant: local.variant ?? "default",
171
+ alternateSubmit: local.alternateSubmit ? { disabled: !!local.alternateSubmit.disabled } : null,
172
+ submitting: !!local.submitting,
173
+ })
158
174
 
159
- const alternateActive = () => !!local.alternateSubmit && alternate()
175
+ const view = createMemo(() => viewLineCommentEditor(editorState(), readConfig()))
160
176
 
161
177
  const compactLabel = () =>
162
- alternateActive()
178
+ view().alternateActive
163
179
  ? local.alternateSubmit!.label
164
- : compactCancel()
180
+ : view().compactCancel
165
181
  ? (local.cancelLabel ?? i18n.t("ui.lineComment.cancel"))
166
182
  : (local.submitLabel ?? i18n.t("ui.lineComment.submit"))
167
183
 
168
- createEffect(() => {
169
- if (local.variant !== "compact" || !local.alternateSubmit) return
184
+ const currentToken = () =>
185
+ local.mention && textareaRef
186
+ ? parseMentionToken(textareaRef.value, textareaRef.selectionStart, textareaRef.selectionEnd)
187
+ : null
170
188
 
171
- const update = (event: KeyboardEvent) => setAlternate(modified(event))
189
+ const dispatch = (event: LineCommentEditorEvent) => {
190
+ const transition = transitionLineCommentEditor(untrack(editorState), event)
191
+ setEditorState(transition.state)
172
192
 
173
- // Capture modifier releases; the textarea stops key propagation.
174
- makeEventListener(document, "keydown", update, { capture: true })
175
- makeEventListener(document, "keyup", update, { capture: true })
176
- makeEventListener(window, "blur", () => setAlternate(false))
177
- })
193
+ if (transition.state.status !== "mention-loading") clearTimeout(mentionTimer)
194
+ transition.effects.forEach(run)
178
195
 
179
- const closeMention = () => {
180
- setMentionOpen(false)
181
- mention.clear()
196
+ return transition.handled
182
197
  }
183
198
 
184
- const currentMention = () => {
185
- const textarea = textareaRef
186
-
187
- if (!textarea) return
199
+ const run = (effect: LineCommentEditorEffect) => {
200
+ if (effect.type === "mention.load") {
201
+ const attempt = effect.attempt
202
+ clearTimeout(mentionTimer)
203
+ mentionTimer = setTimeout(() => dispatch({ type: "mention.timeout", attempt }), MENTION_TIMEOUT_MS)
204
+ const result = untrack(() => local.mention?.items(effect.query) ?? [])
188
205
 
189
- if (!local.mention) return
206
+ if (Array.isArray(result)) return dispatch({ type: "mention.loaded", attempt, items: result })
207
+ void result.then(
208
+ (items) => dispatch({ type: "mention.loaded", attempt, items }),
209
+ () => dispatch({ type: "mention.failed", attempt }),
210
+ )
190
211
 
191
- if (textarea.selectionStart !== textarea.selectionEnd) return
192
-
193
- const end = textarea.selectionStart
194
- const match = textarea.value.slice(0, end).match(/@(\S*)$/)
195
-
196
- if (!match) return
197
-
198
- return {
199
- query: match[1] ?? "",
200
- start: end - match[0].length,
201
- end,
212
+ return
202
213
  }
203
- }
204
214
 
205
- function selectMention(item: { path: string } | undefined) {
206
- if (!item) return
215
+ if (effect.type === "mention.insert") {
216
+ const textarea = textareaRef
207
217
 
208
- const textarea = textareaRef
209
- const query = currentMention()
218
+ if (!textarea) return
219
+ const value = `${textarea.value.slice(0, effect.token.start)}@${effect.path} ${textarea.value.slice(effect.token.end)}`
220
+ const cursor = effect.token.start + effect.path.length + 2
221
+ local.onInput(value)
222
+ requestAnimationFrame(() => {
223
+ if (untrack(editorState).status === "disposed") return
224
+ textarea.focus()
225
+ textarea.setSelectionRange(cursor, cursor)
226
+ })
210
227
 
211
- if (!textarea || !query) return
228
+ return
229
+ }
212
230
 
213
- const value = `${textarea.value.slice(0, query.start)}@${item.path} ${textarea.value.slice(query.end)}`
214
- const cursor = query.start + item.path.length + 2
231
+ if (effect.type === "submit") {
232
+ if (effect.mode === "alternate") return local.alternateSubmit?.onSubmit(effect.value)
215
233
 
216
- local.onInput(value)
217
- closeMention()
234
+ return local.onSubmit(effect.value)
235
+ }
218
236
 
219
- requestAnimationFrame(() => {
220
- textarea.focus()
221
- textarea.setSelectionRange(cursor, cursor)
222
- })
237
+ if (effect.blur) textareaRef?.blur()
238
+ local.onCancel()
223
239
  }
224
240
 
225
- const mention = useFilteredList<{ path: string }>({
226
- items: async (query) => {
227
- if (!local.mention) return []
228
-
229
- if (!query.trim()) return []
230
- const paths = await local.mention.items(query)
231
-
232
- return paths.map((path) => ({ path }))
233
- },
234
- key: (item) => item.path,
235
- filterKeys: ["path"],
236
- skipFilter: () => true,
237
- onSelect: selectMention,
238
- })
239
-
240
- const syncMention = () => {
241
- const item = currentMention()
242
-
243
- if (!item) {
244
- closeMention()
245
-
246
- return
247
- }
241
+ const keyEvent = (event: KeyboardEvent, target: "textarea" | "action") =>
242
+ dispatch({
243
+ type: "key.down",
244
+ target,
245
+ key: event.key,
246
+ ctrl: event.ctrlKey,
247
+ meta: event.metaKey,
248
+ alt: event.altKey,
249
+ shift: event.shiftKey,
250
+ repeat: event.repeat,
251
+ config: readConfig(),
252
+ })
248
253
 
249
- setMentionOpen(true)
250
- mention.onInput(item.query)
251
- }
254
+ createComputed(
255
+ on(
256
+ [
257
+ () => local.submitting,
258
+ () => local.variant,
259
+ () => local.allowEmpty,
260
+ () => !!local.mention,
261
+ () => local.alternateSubmit?.disabled,
262
+ () => !!local.alternateSubmit,
263
+ ],
264
+ () => dispatch({ type: "props.synced", config: readConfig(), token: currentToken() }),
265
+ ),
266
+ )
252
267
 
253
- const selectActiveMention = () => {
254
- const items = mention.flat()
268
+ // An owner that resets or rewrites the value closes a mention list the new text no longer has.
269
+ createEffect(
270
+ on(
271
+ () => local.value,
272
+ () => dispatch({ type: "props.synced", config: readConfig(), token: currentToken() }),
273
+ { defer: true },
274
+ ),
275
+ )
255
276
 
256
- if (items.length === 0) return
257
- const active = mention.active()
258
- selectMention(items.find((item) => item.path === active) ?? items[0])
259
- }
277
+ onCleanup(() => dispatch({ type: "disposed" }))
260
278
 
261
- const submit = (alternate = false) => {
262
- if (local.submitting) return
263
- const v = local.value.trim()
279
+ const trackModifiers = createMemo(() => view().trackModifiers)
264
280
 
265
- if (!v && !local.allowEmpty) return
281
+ createEffect(() => {
282
+ if (!trackModifiers()) return
266
283
 
267
- if (alternate && local.alternateSubmit) {
268
- if (!local.alternateSubmit.disabled) local.alternateSubmit.onSubmit(v)
284
+ const update = (event: KeyboardEvent) =>
285
+ dispatch({ type: "modifier.changed", active: modified(event), config: readConfig() })
269
286
 
270
- return
271
- }
287
+ // Capture modifier releases; the textarea stops key propagation.
288
+ makeEventListener(document, "keydown", update, { capture: true })
289
+ makeEventListener(document, "keyup", update, { capture: true })
290
+ makeEventListener(window, "blur", () => dispatch({ type: "window.blurred" }))
291
+ })
272
292
 
273
- local.onSubmit(v)
274
- }
293
+ const syncMention = () => dispatch({ type: "mention.synced", token: currentToken() })
275
294
 
276
295
  onMount(() => {
277
296
  if (local.autofocus === false) return
@@ -316,7 +335,7 @@ export function LineCommentEditor(props: LineCommentEditorProps) {
316
335
  data-component="line-comment-v2"
317
336
  data-variant="editor"
318
337
  data-layout={local.variant ?? "default"}
319
- aria-busy={local.submitting || undefined}
338
+ aria-busy={view().submitting || undefined}
320
339
  classList={{
321
340
  ...local.classList,
322
341
  [local.class ?? ""]: !!local.class,
@@ -333,13 +352,15 @@ export function LineCommentEditor(props: LineCommentEditorProps) {
333
352
  textareaRef = el
334
353
  }}
335
354
  data-slot="line-comment-v2-textarea"
355
+ // Escape here closes the mention list or cancels the comment, not a dialog or popover around the editor.
356
+ data-owns-escape
336
357
  data-scrollable
337
358
  aria-label={local.label ?? i18n.t("ui.lineComment.submit")}
338
359
  dir="auto"
339
360
  rows={local.rows ?? (local.variant === "compact" ? 1 : 4)}
340
361
  placeholder={local.placeholder ?? i18n.t("ui.lineComment.contextPlaceholder")}
341
362
  value={local.value}
342
- readOnly={local.submitting}
363
+ readOnly={view().submitting}
343
364
  style={{ "unicode-bidi": "plaintext", "text-align": "start" }}
344
365
  onInput={(e) => {
345
366
  local.onInput(e.currentTarget.value)
@@ -352,70 +373,26 @@ export function LineCommentEditor(props: LineCommentEditorProps) {
352
373
 
353
374
  if (e.isComposing || e.keyCode === 229) return
354
375
 
355
- if (mentionOpen() && !local.submitting) {
356
- if (e.key === "Escape") {
357
- e.preventDefault()
358
- closeMention()
359
-
360
- return
361
- }
362
-
363
- if (e.key === "Tab") {
364
- if (mention.flat().length === 0) return
365
- e.preventDefault()
366
- selectActiveMention()
367
-
368
- return
369
- }
370
-
371
- const nav = e.key === "ArrowUp" || e.key === "ArrowDown" || e.key === "Enter"
372
-
373
- const ctrlNav =
374
- e.ctrlKey && !e.metaKey && !e.altKey && !e.shiftKey && (e.key === "n" || e.key === "p")
375
-
376
- if ((nav || ctrlNav) && mention.flat().length > 0) {
377
- mention.onKeyDown(e)
378
- e.preventDefault()
379
-
380
- return
381
- }
382
- }
383
-
384
- if (e.key === "Escape") {
385
- e.preventDefault()
386
-
387
- if (local.submitting) return
388
- e.currentTarget.blur()
389
- local.onCancel()
390
-
391
- return
392
- }
393
-
394
- if (e.key === "Enter" && !e.shiftKey) {
395
- e.preventDefault()
396
-
397
- if (e.repeat) return
398
- submit(modified(e))
399
- }
376
+ if (keyEvent(e, "textarea")) e.preventDefault()
400
377
  }}
401
378
  />
402
- <Show when={!local.submitting && mentionOpen() && mention.flat().length > 0}>
379
+ <Show when={view().mentionItems.length > 0}>
403
380
  <div data-slot="line-comment-v2-mention-list">
404
- <For each={mention.flat().slice(0, 10)}>
405
- {(item) => {
406
- const directory = item.path.endsWith("/") ? item.path : pathDirectory(item.path)
407
- const name = item.path.endsWith("/") ? "" : pathFilename(item.path)
381
+ <For each={view().mentionItems}>
382
+ {(path, index) => {
383
+ const directory = path.endsWith("/") ? path : pathDirectory(path)
384
+ const name = path.endsWith("/") ? "" : pathFilename(path)
408
385
 
409
386
  return (
410
387
  <button
411
388
  type="button"
412
389
  data-slot="line-comment-v2-mention-item"
413
- data-active={mention.active() === item.path ? "" : undefined}
390
+ data-active={view().activeMentionPath === path ? "" : undefined}
414
391
  onMouseDown={(event) => event.preventDefault()}
415
- onMouseEnter={() => mention.setActive(item.path)}
416
- onClick={() => selectMention(item)}
392
+ onMouseEnter={() => dispatch({ type: "mention.hovered", index: index() })}
393
+ onClick={() => dispatch({ type: "mention.selected", index: index() })}
417
394
  >
418
- <FileIcon node={{ path: item.path, type: "file" }} class="shrink-0 size-4" />
395
+ <FileIcon node={{ path, type: "file" }} class="shrink-0 size-4" />
419
396
  <div data-slot="line-comment-v2-mention-path">
420
397
  <span data-slot="line-comment-v2-mention-dir">{directory}</span>
421
398
  <Show when={name}>
@@ -436,11 +413,11 @@ export function LineCommentEditor(props: LineCommentEditorProps) {
436
413
  <div class="flex items-center gap-1.5">
437
414
  {compactLabel()}
438
415
  <Keybind
439
- keys={alternateActive() ? local.alternateSubmit!.keys : [compactCancel() ? "Esc" : "⏎"]}
416
+ keys={view().alternateActive ? local.alternateSubmit!.keys : [view().compactCancel ? "Esc" : "⏎"]}
440
417
  variant="neutral"
441
418
  />
442
419
  </div>
443
- <Show when={local.alternateSubmit && !alternateActive()}>
420
+ <Show when={local.alternateSubmit && !view().alternateActive}>
444
421
  <div class="flex items-center gap-1.5">
445
422
  {local.alternateSubmit!.label}
446
423
  <Keybind keys={local.alternateSubmit!.keys} variant="neutral" />
@@ -452,18 +429,17 @@ export function LineCommentEditor(props: LineCommentEditorProps) {
452
429
  >
453
430
  <IconButton
454
431
  data-slot="line-comment-v2-submit"
432
+ data-owns-escape
455
433
  type="button"
456
434
  size="small"
457
- variant={
458
- alternateActive() || local.submitting ? "submit" : local.value.trim() ? "neutral" : "ghost-muted"
459
- }
460
- disabled={local.submitting || (alternateActive() && local.alternateSubmit?.disabled)}
435
+ variant={view().compactVariant}
436
+ disabled={view().compactDisabled}
461
437
  icon={
462
- local.submitting ? (
438
+ view().submitting ? (
463
439
  <Loader />
464
- ) : alternateActive() ? (
440
+ ) : view().alternateActive ? (
465
441
  <Icon name="arrow-up" />
466
- ) : compactCancel() ? (
442
+ ) : view().compactCancel ? (
467
443
  <Icon name="close" />
468
444
  ) : (
469
445
  <span
@@ -474,30 +450,21 @@ export function LineCommentEditor(props: LineCommentEditorProps) {
474
450
  )
475
451
  }
476
452
  aria-label={compactLabel()}
477
- onPointerEnter={(event) => {
478
- if (modified(event)) setAlternate(true)
479
- }}
480
- onClick={(event) => {
481
- if (compactCancel() && !alternateActive()) return local.onCancel()
482
- submit(alternateActive() || modified(event))
483
- }}
453
+ onPointerEnter={(event) =>
454
+ dispatch({ type: "modifier.changed", active: modified(event), config: readConfig() })
455
+ }
456
+ onPointerDown={(event) =>
457
+ dispatch({ type: "modifier.changed", active: modified(event), config: readConfig() })
458
+ }
459
+ onClick={(event) =>
460
+ dispatch({ type: "action.clicked", modified: modified(event), config: readConfig() })
461
+ }
484
462
  onKeyDown={(event) => {
485
463
  if (event.isComposing) return
486
464
 
487
- if (event.key === "Enter" && modified(event) && local.alternateSubmit) {
488
- event.preventDefault()
489
- event.stopPropagation()
490
-
491
- if (!event.repeat) submit(true)
492
-
493
- return
494
- }
495
-
496
- if (event.key !== "Escape") return
465
+ if (!keyEvent(event, "action")) return
497
466
  event.preventDefault()
498
467
  event.stopPropagation()
499
-
500
- if (!local.submitting) local.onCancel()
501
468
  }}
502
469
  />
503
470
  </Tooltip>
@@ -509,10 +476,22 @@ export function LineCommentEditor(props: LineCommentEditorProps) {
509
476
  {(selection) => <div data-slot="line-comment-v2-footer-meta">{selection()}</div>}
510
477
  </Show>
511
478
  <div data-slot="line-comment-v2-footer-actions">
512
- <Button type="button" size="small" variant="ghost" onClick={() => local.onCancel()}>
479
+ <Button
480
+ type="button"
481
+ size="small"
482
+ variant="ghost"
483
+ disabled={view().submitting}
484
+ onClick={() => dispatch({ type: "cancel.requested" })}
485
+ >
513
486
  {local.cancelLabel ?? i18n.t("ui.lineComment.cancel")}
514
487
  </Button>
515
- <Button type="button" size="small" variant="contrast" disabled={!canSubmit()} onClick={submit}>
488
+ <Button
489
+ type="button"
490
+ size="small"
491
+ variant="contrast"
492
+ disabled={!view().canSubmit || view().submitting}
493
+ onClick={() => dispatch({ type: "submit.requested", config: readConfig() })}
494
+ >
516
495
  {local.submitLabel ?? i18n.t("ui.lineComment.submit")}
517
496
  </Button>
518
497
  </div>