summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorphantomreactor <[email protected]>2025-05-15 23:02:11 +0530
committerAdam <[email protected]>2025-05-15 12:55:36 -0500
commit5f5f9dad877300bab3fe5442ea141551ba89421b (patch)
tree57852fb49e50a085ea2300adbd48813dc9d6f8c6
parentaa8b3ce1eedff364e4b2b325f63b538a784ea01f (diff)
downloadopencode-5f5f9dad877300bab3fe5442ea141551ba89421b.tar.gz
opencode-5f5f9dad877300bab3fe5442ea141551ba89421b.zip
add support to preview webp images and paste file paths
-rw-r--r--internal/tui/components/dialog/filepicker.go22
-rw-r--r--internal/tui/image/images.go1
2 files changed, 18 insertions, 5 deletions
diff --git a/internal/tui/components/dialog/filepicker.go b/internal/tui/components/dialog/filepicker.go
index ee13cbfb4..77e64e16f 100644
--- a/internal/tui/components/dialog/filepicker.go
+++ b/internal/tui/components/dialog/filepicker.go
@@ -9,6 +9,9 @@ import (
"strings"
"time"
+ "log/slog"
+
+ "github.com/atotto/clipboard"
"github.com/charmbracelet/bubbles/key"
"github.com/charmbracelet/bubbles/textinput"
"github.com/charmbracelet/bubbles/viewport"
@@ -22,7 +25,6 @@ import (
"github.com/sst/opencode/internal/tui/styles"
"github.com/sst/opencode/internal/tui/theme"
"github.com/sst/opencode/internal/tui/util"
- "log/slog"
)
const (
@@ -40,6 +42,7 @@ type FilePrickerKeyMap struct {
OpenFilePicker key.Binding
Esc key.Binding
InsertCWD key.Binding
+ Paste key.Binding
}
var filePickerKeyMap = FilePrickerKeyMap{
@@ -75,6 +78,10 @@ var filePickerKeyMap = FilePrickerKeyMap{
key.WithKeys("i"),
key.WithHelp("i", "manual path input"),
),
+ Paste: key.NewBinding(
+ key.WithKeys("ctrl+v"),
+ key.WithHelp("ctrl+v", "paste file/directory path"),
+ ),
}
type filepickerCmp struct {
@@ -213,6 +220,15 @@ func (f *filepickerCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
f.getCurrentFileBelowCursor()
}
}
+ case key.Matches(msg, filePickerKeyMap.Paste):
+ if f.cwd.Focused() {
+ val, err := clipboard.ReadAll()
+ if err != nil {
+ slog.Error("failed to read clipboard")
+ return f, cmd
+ }
+ f.cwd.SetValue(f.cwd.Value() + val)
+ }
case key.Matches(msg, filePickerKeyMap.OpenFilePicker):
f.dirs = readDir(f.cwdDetails.directory, false)
f.cursor = 0
@@ -303,10 +319,6 @@ func (f *filepickerCmp) View() string {
}
if file.IsDir() {
filename = filename + "/"
- } else if isExtSupported(file.Name()) {
- filename = filename
- } else {
- filename = filename
}
files = append(files, itemStyle.Padding(0, 1).Render(filename))
diff --git a/internal/tui/image/images.go b/internal/tui/image/images.go
index d10a169fd..b55884d11 100644
--- a/internal/tui/image/images.go
+++ b/internal/tui/image/images.go
@@ -9,6 +9,7 @@ import (
"github.com/charmbracelet/lipgloss"
"github.com/disintegration/imaging"
"github.com/lucasb-eyer/go-colorful"
+ _ "golang.org/x/image/webp"
)
func ValidateFileSize(filePath string, sizeLimit int64) (bool, error) {