From 937a21633a8e4831200d7c46e9458372b59bb66d Mon Sep 17 00:00:00 2001 From: maruware Date: Fri, 13 Mar 2026 02:32:41 +0900 Subject: [PATCH] feat: Implement custom word deletion with slash in REPL prompt --- repl.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/repl.go b/repl.go index f07f654..3e07aa6 100644 --- a/repl.go +++ b/repl.go @@ -22,6 +22,29 @@ import ( const LongLine = "--------------------------------------------------------------------------" +func deleteWordWithSlash(buf *prompt.Buffer) { + d := buf.Document() + t := d.TextBeforeCursor() + if len(t) == 0 { + return + } + + runes := []rune(t) + i := len(runes) - 1 + + // Skip trailing separators + for i >= 0 && (runes[i] == ' ' || runes[i] == '/') { + i-- + } + // Delete until next separator + for i >= 0 && runes[i] != ' ' && runes[i] != '/' { + i-- + } + + count := len(runes) - (i + 1) + buf.DeleteBeforeCursor(count) +} + type OutputMode string const ( @@ -102,7 +125,7 @@ func (r *Repl) Start() { }), prompt.OptionAddKeyBind(prompt.KeyBind{ Key: prompt.ControlW, - Fn: prompt.DeleteWord, + Fn: deleteWordWithSlash, }), prompt.OptionHistory(history), )