run: make minimal mode more minimal (#31227)

This commit is contained in:
Simon Klee 2026-06-07 23:26:14 +02:00 committed by GitHub
commit 07808bea12
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
39 changed files with 3109 additions and 930 deletions

View file

@ -26,7 +26,7 @@ import { useProject } from "../../context/project"
import { useSync } from "../../context/sync"
import { useEvent } from "../../context/event"
import { editorSelectionKey, useEditorContext, type EditorSelection } from "../../context/editor"
import { openEditor } from "../../editor"
import { normalizePromptContent, openEditor } from "../../editor"
import { destroyRenderer } from "../../util/renderer"
import { promptOffsetWidth } from "../../prompt/display"
import { createStore, produce, unwrap } from "solid-js/store"
@ -442,8 +442,9 @@ export function Prompt(props: PromptProps) {
paths.cwd,
})
if (!content) return
const normalized = normalizePromptContent(content)
input.setText(content)
input.setText(normalized)
// Update positions for nonTextParts based on their location in new content
// Filter out parts whose virtual text was deleted
@ -460,7 +461,7 @@ export function Prompt(props: PromptProps) {
if (!virtualText) return part
const newStart = content.indexOf(virtualText)
const newStart = normalized.indexOf(virtualText)
// if the virtual text is deleted, remove the part
if (newStart === -1) return null
@ -495,14 +496,14 @@ export function Prompt(props: PromptProps) {
})
.filter((part) => part !== null)
setStore("prompt", {
input: content,
// keep only the non-text parts because the text parts were
// already expanded inline
parts: updatedNonTextParts,
})
restoreExtmarksFromParts(updatedNonTextParts)
input.cursorOffset = Bun.stringWidth(content)
setStore("prompt", {
input: normalized,
// keep only the non-text parts because the text parts were
// already expanded inline
parts: updatedNonTextParts,
})
restoreExtmarksFromParts(updatedNonTextParts)
input.cursorOffset = Bun.stringWidth(normalized)
},
},
{

View file

@ -4,9 +4,26 @@ import { readFile, rm, writeFile } from "node:fs/promises"
import os from "node:os"
import path from "node:path"
import { spawn } from "node:child_process"
import type { Stream } from "node:stream"
import { resolveZedDbPath, resolveZedSelection } from "./editor-zed"
export async function openEditor(input: { value: string; renderer: CliRenderer; cwd?: string }) {
type EditorStdio = "inherit" | "pipe" | "ignore" | number | Stream
export function normalizePromptContent(content: string) {
if (content.endsWith("\r\n")) {
const body = content.slice(0, -2)
return !body.includes("\n") && !body.includes("\r") ? body : content
}
if (content.endsWith("\n")) {
const body = content.slice(0, -1)
return !body.includes("\n") && !body.includes("\r") ? body : content
}
return content
}
export async function openEditor(input: { value: string; renderer: CliRenderer; cwd?: string; stdin?: EditorStdio }) {
const editor = process.env.VISUAL || process.env.EDITOR
if (!editor) return
const file = path.join(os.tmpdir(), `${Date.now()}.md`)
@ -18,7 +35,7 @@ export async function openEditor(input: { value: string; renderer: CliRenderer;
const parts = editor.split(" ")
const child = spawn(parts[0]!, [...parts.slice(1), file], {
cwd: input.cwd && existsSync(input.cwd) ? input.cwd : process.cwd(),
stdio: "inherit",
stdio: [input.stdin ?? "inherit", "inherit", "inherit"],
shell: process.platform === "win32",
})
child.on("error", reject)