Skip to content

Commit a49ede2

Browse files
gergeshshuv1337
authored andcommitted
Add backslash newline
1 parent ce60572 commit a49ede2

4 files changed

Lines changed: 24 additions & 0 deletions

File tree

packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,17 @@ export function Prompt(props: PromptProps) {
530530
if (props.disabled) return
531531
if (autocomplete?.visible) return
532532
if (!store.prompt.input) return
533+
const cursorOffset = input.cursorOffset
534+
const before = cursorOffset > 0 ? input.plainText[cursorOffset - 1] : ""
535+
if (sync.data.config.experimental?.backslash_newline !== false && before === "\\") {
536+
input.cursorOffset = cursorOffset - 1
537+
const start = input.logicalCursor
538+
input.cursorOffset = cursorOffset
539+
const end = input.logicalCursor
540+
input.deleteRange(start.row, start.col, end.row, end.col)
541+
input.insertText("\n")
542+
return
543+
}
533544
const trimmed = store.prompt.input.trim()
534545
if (trimmed === "exit" || trimmed === "quit" || trimmed === ":q") {
535546
exit()
@@ -916,6 +927,7 @@ export function Prompt(props: PromptProps) {
916927
return
917928
}
918929
}
930+
919931
if (store.mode === "normal") autocomplete.onKeyDown(e)
920932
if (!autocomplete.visible) {
921933
if (

packages/opencode/src/config/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,10 @@ export namespace Config {
12621262
experimental: z
12631263
.object({
12641264
disable_paste_summary: z.boolean().optional(),
1265+
backslash_newline: z
1266+
.boolean()
1267+
.optional()
1268+
.describe("Enable backslash+enter to insert newline instead of submitting (default: true)"),
12651269
batch_tool: z.boolean().optional().describe("Enable the batch tool"),
12661270
openTelemetry: z
12671271
.boolean()

packages/sdk/js/src/gen/types.gen.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,6 +1389,10 @@ export type Config = {
13891389
*/
13901390
chatMaxRetries?: number
13911391
disable_paste_summary?: boolean
1392+
/**
1393+
* Enable backslash+enter to insert newline instead of submitting (default: true)
1394+
*/
1395+
backslash_newline?: boolean
13921396
/**
13931397
* Enable the batch tool
13941398
*/

packages/sdk/js/src/v2/gen/types.gen.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,6 +1958,10 @@ export type Config = {
19581958
}
19591959
experimental?: {
19601960
disable_paste_summary?: boolean
1961+
/**
1962+
* Enable backslash+enter to insert newline instead of submitting (default: true)
1963+
*/
1964+
backslash_newline?: boolean
19611965
/**
19621966
* Enable the batch tool
19631967
*/

0 commit comments

Comments
 (0)