Parcourir la source

chore: cleanup

Adam il y a 2 mois
Parent
commit
df2713a6c2

+ 6 - 15
packages/desktop/src/components/prompt-input.tsx

@@ -77,7 +77,6 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
   const command = useCommand()
   const command = useCommand()
   let editorRef!: HTMLDivElement
   let editorRef!: HTMLDivElement
 
 
-  // Session-derived state
   const sessionKey = createMemo(() => `${params.dir}${params.id ? "/" + params.id : ""}`)
   const sessionKey = createMemo(() => `${params.dir}${params.id ? "/" + params.id : ""}`)
   const tabs = createMemo(() => layout.tabs(sessionKey()))
   const tabs = createMemo(() => layout.tabs(sessionKey()))
   const info = createMemo(() => (params.id ? sync.session.get(params.id) : undefined))
   const info = createMemo(() => (params.id ? sync.session.get(params.id) : undefined))
@@ -183,10 +182,10 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
   }
   }
 
 
   onMount(() => {
   onMount(() => {
-    editorRef?.addEventListener("paste", handlePaste)
+    editorRef.addEventListener("paste", handlePaste)
   })
   })
   onCleanup(() => {
   onCleanup(() => {
-    editorRef?.removeEventListener("paste", handlePaste)
+    editorRef.removeEventListener("paste", handlePaste)
   })
   })
 
 
   createEffect(() => {
   createEffect(() => {
@@ -208,7 +207,6 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
     onSelect: handleFileSelect,
     onSelect: handleFileSelect,
   })
   })
 
 
-  // Get slash commands from registered commands (only those with explicit slash trigger)
   const slashCommands = createMemo<SlashCommand[]>(() => {
   const slashCommands = createMemo<SlashCommand[]>(() => {
     const builtin = command.options
     const builtin = command.options
       .filter((opt) => !opt.disabled && !opt.id.startsWith("suggested.") && opt.slash)
       .filter((opt) => !opt.disabled && !opt.id.startsWith("suggested.") && opt.slash)
@@ -237,12 +235,10 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
     setStore("popover", null)
     setStore("popover", null)
 
 
     if (cmd.type === "custom") {
     if (cmd.type === "custom") {
-      // For custom commands, insert the command text so user can add arguments
       const text = `/${cmd.trigger} `
       const text = `/${cmd.trigger} `
       editorRef.innerHTML = ""
       editorRef.innerHTML = ""
       editorRef.textContent = text
       editorRef.textContent = text
       prompt.set([{ type: "text", content: text, start: 0, end: text.length }], text.length)
       prompt.set([{ type: "text", content: text, start: 0, end: text.length }], text.length)
-      // Set cursor at end
       requestAnimationFrame(() => {
       requestAnimationFrame(() => {
         editorRef.focus()
         editorRef.focus()
         const range = document.createRange()
         const range = document.createRange()
@@ -255,7 +251,6 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
       return
       return
     }
     }
 
 
-    // For built-in commands, clear input and execute immediately
     editorRef.innerHTML = ""
     editorRef.innerHTML = ""
     prompt.set([{ type: "text", content: "", start: 0, end: 0 }], 0)
     prompt.set([{ type: "text", content: "", start: 0, end: 0 }], 0)
     command.trigger(cmd.id, "slash")
     command.trigger(cmd.id, "slash")
@@ -287,7 +282,7 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
         }
         }
 
 
         editorRef.innerHTML = ""
         editorRef.innerHTML = ""
-        currentParts.forEach((part: ContentPart) => {
+        currentParts.forEach((part) => {
           if (part.type === "text") {
           if (part.type === "text") {
             editorRef.appendChild(document.createTextNode(part.content))
             editorRef.appendChild(document.createTextNode(part.content))
           } else if (part.type === "file") {
           } else if (part.type === "file") {
@@ -374,7 +369,7 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
 
 
     const cursorPosition = getCursorPosition(editorRef)
     const cursorPosition = getCursorPosition(editorRef)
     const currentPrompt = prompt.current()
     const currentPrompt = prompt.current()
-    const rawText = currentPrompt.map((p: ContentPart) => p.content).join("")
+    const rawText = currentPrompt.map((p) => p.content).join("")
     const textBeforeCursor = rawText.substring(0, cursorPosition)
     const textBeforeCursor = rawText.substring(0, cursorPosition)
     const atMatch = textBeforeCursor.match(/@(\S*)$/)
     const atMatch = textBeforeCursor.match(/@(\S*)$/)
 
 
@@ -498,7 +493,6 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
   }
   }
 
 
   const handleKeyDown = (event: KeyboardEvent) => {
   const handleKeyDown = (event: KeyboardEvent) => {
-    // Handle popover navigation
     if (store.popover && (event.key === "ArrowUp" || event.key === "ArrowDown" || event.key === "Enter")) {
     if (store.popover && (event.key === "ArrowUp" || event.key === "ArrowDown" || event.key === "Enter")) {
       if (store.popover === "file") {
       if (store.popover === "file") {
         onKeyDown(event)
         onKeyDown(event)
@@ -510,7 +504,6 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
     }
     }
 
 
     if (event.key === "ArrowUp" || event.key === "ArrowDown") {
     if (event.key === "ArrowUp" || event.key === "ArrowDown") {
-      // Skip history navigation when modifier keys are pressed (used for other commands)
       if (event.altKey || event.ctrlKey || event.metaKey) return
       if (event.altKey || event.ctrlKey || event.metaKey) return
       const { collapsed, onFirstLine, onLastLine } = getCaretLineState()
       const { collapsed, onFirstLine, onLastLine } = getCaretLineState()
       if (!collapsed) return
       if (!collapsed) return
@@ -554,7 +547,7 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
   const handleSubmit = async (event: Event) => {
   const handleSubmit = async (event: Event) => {
     event.preventDefault()
     event.preventDefault()
     const currentPrompt = prompt.current()
     const currentPrompt = prompt.current()
-    const text = currentPrompt.map((part: ContentPart) => part.content).join("")
+    const text = currentPrompt.map((part) => part.content).join("")
     if (text.trim().length === 0) {
     if (text.trim().length === 0) {
       if (working()) abort()
       if (working()) abort()
       return
       return
@@ -574,7 +567,7 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
 
 
     const toAbsolutePath = (path: string) => (path.startsWith("/") ? path : sync.absolute(path))
     const toAbsolutePath = (path: string) => (path.startsWith("/") ? path : sync.absolute(path))
     const attachments = currentPrompt.filter(
     const attachments = currentPrompt.filter(
-      (part: ContentPart) => part.type === "file",
+      (part) => part.type === "file",
     ) as import("@/context/prompt").FileAttachmentPart[]
     ) as import("@/context/prompt").FileAttachmentPart[]
 
 
     const attachmentParts = attachments.map((attachment) => {
     const attachmentParts = attachments.map((attachment) => {
@@ -603,7 +596,6 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
     editorRef.innerHTML = ""
     editorRef.innerHTML = ""
     prompt.set([{ type: "text", content: "", start: 0, end: 0 }], 0)
     prompt.set([{ type: "text", content: "", start: 0, end: 0 }], 0)
 
 
-    // Check if this is a custom command
     if (text.startsWith("/")) {
     if (text.startsWith("/")) {
       const [cmdName, ...args] = text.split(" ")
       const [cmdName, ...args] = text.split(" ")
       const commandName = cmdName.slice(1) // Remove leading "/"
       const commandName = cmdName.slice(1) // Remove leading "/"
@@ -639,7 +631,6 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
 
 
   return (
   return (
     <div class="relative size-full _max-h-[320px] flex flex-col gap-3">
     <div class="relative size-full _max-h-[320px] flex flex-col gap-3">
-      {/* Popover for file mentions and slash commands */}
       <Show when={store.popover}>
       <Show when={store.popover}>
         <div
         <div
           class="absolute inset-x-0 -top-3 -translate-y-full origin-bottom-left max-h-80 min-h-10
           class="absolute inset-x-0 -top-3 -translate-y-full origin-bottom-left max-h-80 min-h-10

+ 0 - 17
packages/desktop/src/context/command.tsx

@@ -6,12 +6,6 @@ import { List } from "@opencode-ai/ui/list"
 
 
 const IS_MAC = typeof navigator === "object" && /(Mac|iPod|iPhone|iPad)/.test(navigator.platform)
 const IS_MAC = typeof navigator === "object" && /(Mac|iPod|iPhone|iPad)/.test(navigator.platform)
 
 
-/**
- * Keybind configuration type.
- * Format: "mod+key" where mod can be ctrl, alt, shift, meta (or cmd on mac)
- * Multiple keybinds can be separated by comma: "mod+p,ctrl+shift+p"
- * Use "mod" for platform-appropriate modifier (cmd on mac, ctrl elsewhere)
- */
 export type KeybindConfig = string
 export type KeybindConfig = string
 
 
 export interface Keybind {
 export interface Keybind {
@@ -23,23 +17,14 @@ export interface Keybind {
 }
 }
 
 
 export interface CommandOption {
 export interface CommandOption {
-  /** Unique identifier for the command */
   id: string
   id: string
-  /** Display title in the command palette */
   title: string
   title: string
-  /** Optional description */
   description?: string
   description?: string
-  /** Category for grouping in the palette */
   category?: string
   category?: string
-  /** Keybind string (e.g., "mod+p", "ctrl+shift+t") */
   keybind?: KeybindConfig
   keybind?: KeybindConfig
-  /** Slash command trigger (e.g., "models" for /models) */
   slash?: string
   slash?: string
-  /** Whether to show in the "Suggested" section */
   suggested?: boolean
   suggested?: boolean
-  /** Whether the command is disabled */
   disabled?: boolean
   disabled?: boolean
-  /** Handler when command is selected */
   onSelect?: (source?: "palette" | "keybind" | "slash") => void
   onSelect?: (source?: "palette" | "keybind" | "slash") => void
 }
 }
 
 
@@ -197,7 +182,6 @@ export const { use: useCommand, provider: CommandProvider } = createSimpleContex
     const handleKeyDown = (event: KeyboardEvent) => {
     const handleKeyDown = (event: KeyboardEvent) => {
       if (suspended()) return
       if (suspended()) return
 
 
-      // Check for command palette keybind (mod+shift+p)
       const paletteKeybinds = parseKeybind("mod+shift+p")
       const paletteKeybinds = parseKeybind("mod+shift+p")
       if (matchKeybind(paletteKeybinds, event)) {
       if (matchKeybind(paletteKeybinds, event)) {
         event.preventDefault()
         event.preventDefault()
@@ -205,7 +189,6 @@ export const { use: useCommand, provider: CommandProvider } = createSimpleContex
         return
         return
       }
       }
 
 
-      // Check registered command keybinds
       for (const option of options()) {
       for (const option of options()) {
         if (option.disabled) continue
         if (option.disabled) continue
         if (!option.keybind) continue
         if (!option.keybind) continue

+ 3 - 16
packages/desktop/src/pages/session.tsx

@@ -49,7 +49,6 @@ export default function Page() {
   const params = useParams()
   const params = useParams()
   const navigate = useNavigate()
   const navigate = useNavigate()
 
 
-  // Session-specific derived state
   const sessionKey = createMemo(() => `${params.dir}${params.id ? "/" + params.id : ""}`)
   const sessionKey = createMemo(() => `${params.dir}${params.id ? "/" + params.id : ""}`)
   const tabs = createMemo(() => layout.tabs(sessionKey()))
   const tabs = createMemo(() => layout.tabs(sessionKey()))
 
 
@@ -132,7 +131,6 @@ export default function Page() {
     }
     }
   })
   })
 
 
-  // Register commands for this page
   command.register(() => [
   command.register(() => [
     {
     {
       id: "session.new",
       id: "session.new",
@@ -230,28 +228,17 @@ export default function Page() {
     },
     },
   ])
   ])
 
 
-  // Handle keyboard events that aren't commands
   const handleKeyDown = (event: KeyboardEvent) => {
   const handleKeyDown = (event: KeyboardEvent) => {
-    // Don't interfere with terminal
     // @ts-expect-error
     // @ts-expect-error
-    if (document.activeElement?.dataset?.component === "terminal") {
-      return
-    }
-
-    // Don't interfere with dialogs
-    if (dialog.stack.length > 0) {
-      return
-    }
+    if (document.activeElement?.dataset?.component === "terminal") return
+    if (dialog.stack.length > 0) return
 
 
     const focused = document.activeElement === inputRef
     const focused = document.activeElement === inputRef
     if (focused) {
     if (focused) {
-      if (event.key === "Escape") {
-        inputRef?.blur()
-      }
+      if (event.key === "Escape") inputRef?.blur()
       return
       return
     }
     }
 
 
-    // Focus input when typing characters
     if (event.key.length === 1 && event.key !== "Unidentified" && !(event.ctrlKey || event.metaKey)) {
     if (event.key.length === 1 && event.key !== "Unidentified" && !(event.ctrlKey || event.metaKey)) {
       inputRef?.focus()
       inputRef?.focus()
     }
     }

+ 0 - 1
packages/ui/src/components/session-turn.tsx

@@ -228,7 +228,6 @@ export function SessionTurn(
                 duration: duration(),
                 duration: duration(),
               })
               })
 
 
-              // Sync with controlled prop
               createEffect(() => {
               createEffect(() => {
                 if (props.stepsExpanded !== undefined) {
                 if (props.stepsExpanded !== undefined) {
                   setStore("stepsExpanded", props.stepsExpanded)
                   setStore("stepsExpanded", props.stepsExpanded)