Fix: show last attached img on ctrl+j
This commit is contained in:
18
llm.go
18
llm.go
@@ -9,29 +9,17 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var imageAttachmentPath string // Global variable to track image attachment for next message
|
var imageAttachmentPath string // Global variable to track image attachment for next message
|
||||||
|
var lastImg string // for ctrl+j
|
||||||
|
|
||||||
// SetImageAttachment sets an image to be attached to the next message sent to the LLM and updates UI
|
// SetImageAttachment sets an image to be attached to the next message sent to the LLM
|
||||||
func SetImageAttachment(imagePath string) {
|
func SetImageAttachment(imagePath string) {
|
||||||
imageAttachmentPath = imagePath
|
imageAttachmentPath = imagePath
|
||||||
// Update the UI to show image is attached (call function from tui.go)
|
lastImg = imagePath
|
||||||
// UpdateImageAttachmentStatus(imagePath)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetImageAttachmentWithoutUI sets an image to be attached without UI updates (for internal use where UI updates might cause hangs)
|
|
||||||
func SetImageAttachmentWithoutUI(imagePath string) {
|
|
||||||
imageAttachmentPath = imagePath
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClearImageAttachment clears any pending image attachment and updates UI
|
// ClearImageAttachment clears any pending image attachment and updates UI
|
||||||
func ClearImageAttachment() {
|
func ClearImageAttachment() {
|
||||||
imageAttachmentPath = ""
|
imageAttachmentPath = ""
|
||||||
// Update the UI to clear image attachment status (call function from tui.go)
|
|
||||||
// UpdateImageAttachmentStatus("")
|
|
||||||
}
|
|
||||||
|
|
||||||
// ClearImageAttachmentWithoutUI clears any pending image attachment without UI updates
|
|
||||||
func ClearImageAttachmentWithoutUI() {
|
|
||||||
imageAttachmentPath = ""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ChunkParser interface {
|
type ChunkParser interface {
|
||||||
|
|||||||
@@ -838,7 +838,7 @@ func makeFilePicker() *tview.Flex {
|
|||||||
// For image files, set it as an attachment for the next LLM message
|
// For image files, set it as an attachment for the next LLM message
|
||||||
// Use the version without UI updates to avoid hangs in event handlers
|
// Use the version without UI updates to avoid hangs in event handlers
|
||||||
logger.Info("setting image", "file", itemText)
|
logger.Info("setting image", "file", itemText)
|
||||||
SetImageAttachmentWithoutUI(filePath)
|
SetImageAttachment(filePath)
|
||||||
logger.Info("after setting image", "file", itemText)
|
logger.Info("after setting image", "file", itemText)
|
||||||
statusView.SetText("Image attached: " + filePath + " (will be sent with next message)")
|
statusView.SetText("Image attached: " + filePath + " (will be sent with next message)")
|
||||||
logger.Info("after setting text", "file", itemText)
|
logger.Info("after setting text", "file", itemText)
|
||||||
|
|||||||
32
tui.go
32
tui.go
@@ -32,18 +32,18 @@ var (
|
|||||||
indexPickWindow *tview.InputField
|
indexPickWindow *tview.InputField
|
||||||
renameWindow *tview.InputField
|
renameWindow *tview.InputField
|
||||||
// pages
|
// pages
|
||||||
historyPage = "historyPage"
|
historyPage = "historyPage"
|
||||||
agentPage = "agentPage"
|
agentPage = "agentPage"
|
||||||
editMsgPage = "editMsgPage"
|
editMsgPage = "editMsgPage"
|
||||||
indexPage = "indexPage"
|
indexPage = "indexPage"
|
||||||
helpPage = "helpPage"
|
helpPage = "helpPage"
|
||||||
renamePage = "renamePage"
|
renamePage = "renamePage"
|
||||||
RAGPage = "RAGPage"
|
RAGPage = "RAGPage"
|
||||||
propsPage = "propsPage"
|
propsPage = "propsPage"
|
||||||
codeBlockPage = "codeBlockPage"
|
codeBlockPage = "codeBlockPage"
|
||||||
imgPage = "imgPage"
|
imgPage = "imgPage"
|
||||||
filePickerPage = "filePicker"
|
filePickerPage = "filePicker"
|
||||||
exportDir = "chat_exports"
|
exportDir = "chat_exports"
|
||||||
// help text
|
// help text
|
||||||
helpText = `
|
helpText = `
|
||||||
[yellow]Esc[white]: send msg
|
[yellow]Esc[white]: send msg
|
||||||
@@ -434,7 +434,7 @@ func init() {
|
|||||||
})
|
})
|
||||||
flex = tview.NewFlex().SetDirection(tview.FlexRow).
|
flex = tview.NewFlex().SetDirection(tview.FlexRow).
|
||||||
AddItem(textView, 0, 40, false).
|
AddItem(textView, 0, 40, false).
|
||||||
AddItem(textArea, 0, 10, true). // Restore original height
|
AddItem(textArea, 0, 10, true). // Restore original height
|
||||||
AddItem(position, 0, 2, false)
|
AddItem(position, 0, 2, false)
|
||||||
editArea = tview.NewTextArea().
|
editArea = tview.NewTextArea().
|
||||||
SetPlaceholder("Replace msg...")
|
SetPlaceholder("Replace msg...")
|
||||||
@@ -814,18 +814,18 @@ func init() {
|
|||||||
}
|
}
|
||||||
if event.Key() == tcell.KeyCtrlJ {
|
if event.Key() == tcell.KeyCtrlJ {
|
||||||
// show image - check for attached image first, then fall back to agent image
|
// show image - check for attached image first, then fall back to agent image
|
||||||
if imageAttachmentPath != "" {
|
if lastImg != "" {
|
||||||
// Load the attached image
|
// Load the attached image
|
||||||
file, err := os.Open(imageAttachmentPath)
|
file, err := os.Open(lastImg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("failed to open attached image", "path", imageAttachmentPath, "error", err)
|
logger.Error("failed to open attached image", "path", lastImg, "error", err)
|
||||||
// Fall back to showing agent image
|
// Fall back to showing agent image
|
||||||
loadImage()
|
loadImage()
|
||||||
} else {
|
} else {
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
img, _, err := image.Decode(file)
|
img, _, err := image.Decode(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("failed to decode attached image", "path", imageAttachmentPath, "error", err)
|
logger.Error("failed to decode attached image", "path", lastImg, "error", err)
|
||||||
// Fall back to showing agent image
|
// Fall back to showing agent image
|
||||||
loadImage()
|
loadImage()
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user