xonecas.io
62159
Sy

symb / commit 6840621

feat: editor? saving send message to llm to apply diff.

xonecas2026-02-16 684062184370eab8db1b76e80be42b09694543ee parent 8efee02

3 files changed

internal/tui/messages.go+31−0
@@ -9,6 +9,9 @@ import (
99 "time"
1010
1111 tea "charm.land/bubbletea/v2"
12+ "github.com/hexops/gotextdiff"
13+ "github.com/hexops/gotextdiff/myers"
14+ "github.com/hexops/gotextdiff/span"
1215 "github.com/rs/zerolog/log"
1316 "github.com/xonecas/symb/internal/delta"
1417 "github.com/xonecas/symb/internal/llm"
@@ -131,6 +134,34 @@ func (m Model) sendToLLM(userInput string) tea.Cmd {
131134 return func() tea.Msg { return llmUserMsg{content: userInput} }
132135 }
133136
137+func (m Model) sendDiffToLLM() tea.Cmd {
138+ return func() tea.Msg {
139+ if m.editorFilePath == "" {
140+ return nil
141+ }
142+ onDisk, err := os.ReadFile(m.editorFilePath)
143+ if err != nil {
144+ return nil
145+ }
146+ current := m.editor.Value()
147+ if current == string(onDisk) {
148+ return nil
149+ }
150+ uri := span.URIFromPath(m.editorFilePath)
151+ edits := myers.ComputeEdits(uri, string(onDisk), current)
152+ if len(edits) == 0 {
153+ return nil
154+ }
155+ diff := fmt.Sprint(gotextdiff.ToUnified(m.editorFilePath, m.editorFilePath, string(onDisk), edits))
156+ if strings.TrimSpace(diff) == "" {
157+ return nil
158+ }
159+ content := "Apply the following diff:\n```diff\n" + diff + "\n```"
160+ return llmUserMsg{content: content}
161+ }
162+}
163+
164+
134165 func (m Model) waitForLLMUpdate() tea.Cmd {
135166 ch := m.updateChan
136167 return func() tea.Msg {
internal/tui/tui.go+1−1
@@ -284,7 +284,7 @@ func New(prov provider.Provider, proxy *mcp.Proxy, tools []mcp.Tool, modelID str
284284
285285 ed := editor.New()
286286 ed.ShowLineNumbers = true
287- ed.ReadOnly = true
287+ ed.ReadOnly = false
288288 ed.Language = "markdown"
289289 ed.SyntaxTheme = constants.SyntaxTheme
290290 ed.CursorStyle = cursorStyle
internal/tui/update.go+6−0
@@ -17,6 +17,7 @@ import (
1717 "github.com/xonecas/symb/internal/tui/modal"
1818 )
1919
20+
2021 // ---------------------------------------------------------------------------
2122 // Update
2223 // ---------------------------------------------------------------------------
@@ -201,6 +202,11 @@ func (m *Model) handleKeyPress(msg tea.KeyPressMsg) (Model, tea.Cmd, bool) {
201202 return *m, nil, true
202203 case "ctrl+shift+v":
203204 return *m, tea.ReadClipboard, true
205+ case "ctrl+s":
206+ if m.turnCancel == nil {
207+ return *m, m.sendDiffToLLM(), true
208+ }
209+ return *m, nil, true
204210 case "esc":
205211 if m.llmInFlight {
206212 m.cancelTurn()