Skip to content

Commit 2f597f2

Browse files
engalarako
authored andcommitted
fix(tui): exclude ImageCollection inline images from yank content
1 parent 2b897aa commit 2f597f2

2 files changed

Lines changed: 21 additions & 11 deletions

File tree

tui/miller.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const (
2121
type PreviewPane struct {
2222
childColumn *Column
2323
content string
24+
imageContent string // inline image sequences — excluded from yank
2425
contentLines []string // split content for scrolling
2526
highlighted string
2627
mode PreviewMode
@@ -113,6 +114,7 @@ func (m MillerView) Update(msg tea.Msg) (MillerView, tea.Cmd) {
113114
Trace("miller: PreviewReady key=%q highlight=%q len=%d", msg.NodeKey, msg.HighlightType, len(msg.Content))
114115
m.preview.loading = false
115116
m.preview.content = msg.Content
117+
m.preview.imageContent = msg.ImageContent
116118
m.preview.contentLines = strings.Split(msg.Content, "\n")
117119
m.preview.highlighted = msg.HighlightType
118120
m.preview.childColumn = nil
@@ -181,6 +183,7 @@ func (m MillerView) handleCursorChanged(msg CursorChangedMsg) (MillerView, tea.C
181183
col.SetItems(treeNodesToItems(node.Children))
182184
m.preview.childColumn = &col
183185
m.preview.content = ""
186+
m.preview.imageContent = ""
184187
m.preview.contentLines = nil
185188
m.preview.loading = false
186189
m.preview.scrollOffset = 0
@@ -196,6 +199,7 @@ func (m MillerView) handleCursorChanged(msg CursorChangedMsg) (MillerView, tea.C
196199
return m, cmd
197200
}
198201
m.preview.content = ""
202+
m.preview.imageContent = ""
199203
m.preview.contentLines = nil
200204
m.preview.loading = false
201205
return m, nil
@@ -457,10 +461,14 @@ func (m MillerView) renderPreview(previewWidth int) string {
457461
out.WriteByte('\n')
458462
}
459463

460-
return lipgloss.NewStyle().
464+
rendered := lipgloss.NewStyle().
461465
Width(previewWidth).
462466
MaxHeight(m.height).
463467
Render(out.String())
468+
if m.preview.imageContent != "" {
469+
rendered += "\n" + m.preview.imageContent
470+
}
471+
return rendered
464472
}
465473

466474
return lipgloss.NewStyle().
@@ -740,6 +748,7 @@ func (m *MillerView) updateFocusStyles() {
740748
func (m *MillerView) clearPreview() {
741749
m.preview.childColumn = nil
742750
m.preview.content = ""
751+
m.preview.imageContent = ""
743752
m.preview.contentLines = nil
744753
m.preview.loading = false
745754
m.preview.scrollOffset = 0

tui/preview.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,14 @@ const (
4646
// PreviewResult holds cached preview content.
4747
type PreviewResult struct {
4848
Content string
49+
ImageContent string // rendered inline images (excluded from yank)
4950
HighlightType string // "mdl" / "ndsl" / "plain"
5051
}
5152

5253
// PreviewReadyMsg is sent when async preview content is available.
5354
type PreviewReadyMsg struct {
5455
Content string
56+
ImageContent string // rendered inline images (excluded from yank)
5557
HighlightType string
5658
NodeKey string
5759
}
@@ -131,13 +133,21 @@ func (e *PreviewEngine) RequestPreview(nodeType, qualifiedName string, mode Prev
131133
highlighted = DetectAndHighlight(content)
132134
}
133135

134-
result := PreviewResult{Content: highlighted, HighlightType: highlightType}
136+
// Render inline images separately so yank only copies MDL text.
137+
var imageContent string
138+
if strings.ToLower(nodeType) == "imagecollection" && mode == PreviewMDL {
139+
imagePaths := extractImagePaths(content)
140+
imageContent = renderImages(imagePaths)
141+
}
142+
143+
result := PreviewResult{Content: highlighted, ImageContent: imageContent, HighlightType: highlightType}
135144
e.mu.Lock()
136145
e.cache[key] = result
137146
e.mu.Unlock()
138147

139148
return PreviewReadyMsg{
140149
Content: highlighted,
150+
ImageContent: imageContent,
141151
HighlightType: highlightType,
142152
NodeKey: key,
143153
}
@@ -202,15 +212,6 @@ func (e *PreviewEngine) fetch(ctx context.Context, nodeType, qualifiedName strin
202212
content = stripJavaCodeBlock(content)
203213
}
204214

205-
// For imagecollection MDL preview, append inline images if terminal supports it.
206-
if strings.ToLower(nodeType) == "imagecollection" && mode == PreviewMDL {
207-
imagePaths := extractImagePaths(content)
208-
rendered := renderImages(imagePaths)
209-
if rendered != "" {
210-
content = content + "\n" + rendered
211-
}
212-
}
213-
214215
return content, highlightType
215216
}
216217

0 commit comments

Comments
 (0)