From 71c6fdbf334efbbacc90a92ec3d3ebab29ff5707 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Flor=C3=AAncio?= Date: Thu, 5 Feb 2026 00:08:01 +0000 Subject: [PATCH] feat: add JSON viewer word wrap setting and toggle keybinding Add JSONViewerWordWrap config option to enable word wrap in JSON viewer. Add 'w' keybinding to toggle word wrap while viewing JSON. Config usage: [application] JSONViewerWordWrap = true Co-Authored-By: Claude Opus 4.5 --- app/config.go | 1 + app/keymap.go | 1 + commands/commands.go | 3 +++ components/json_viewer.go | 15 +++++++++++---- models/models.go | 1 + 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app/config.go b/app/config.go index 4957bc1..f24241c 100644 --- a/app/config.go +++ b/app/config.go @@ -26,6 +26,7 @@ func defaultConfig() *Config { SidebarOverlay: false, MaxQueryHistoryPerConnection: 100, TreeWidth: 30, + JSONViewerWordWrap: false, }, } } diff --git a/app/keymap.go b/app/keymap.go index 0c85332..064d866 100644 --- a/app/keymap.go +++ b/app/keymap.go @@ -172,6 +172,7 @@ var Keymaps = KeymapSystem{ Bind{Key: Key{Char: 'Z'}, Cmd: cmd.ShowRowJSONViewer, Description: "Toggle JSON viewer"}, Bind{Key: Key{Char: 'z'}, Cmd: cmd.ShowCellJSONViewer, Description: "Toggle JSON viewer"}, Bind{Key: Key{Char: 'y'}, Cmd: cmd.Copy, Description: "Copy value to clipboard"}, + Bind{Key: Key{Char: 'w'}, Cmd: cmd.ToggleJSONViewerWrap, Description: "Toggle word wrap"}, }, }, } diff --git a/commands/commands.go b/commands/commands.go index a432374..9a44e1e 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -73,6 +73,7 @@ const ( ToggleSidebar ShowRowJSONViewer ShowCellJSONViewer + ToggleJSONViewerWrap // Connection NewConnection @@ -221,6 +222,8 @@ func (c Command) String() string { return "ShowRowJSONViewer" case ShowCellJSONViewer: return "ShowCellJSONViewer" + case ToggleJSONViewerWrap: + return "ToggleJSONViewerWrap" case ExportCSV: return "ExportCSV" } diff --git a/components/json_viewer.go b/components/json_viewer.go index a586702..b0b1a95 100644 --- a/components/json_viewer.go +++ b/components/json_viewer.go @@ -20,13 +20,15 @@ type JSONViewer struct { TextView *tview.TextView Pages *tview.Pages primitiveToFocus tview.Primitive + wrapEnabled bool } func NewJSONViewer(pages *tview.Pages) *JSONViewer { + wrapEnabled := app.App.Config().JSONViewerWordWrap textView := tview.NewTextView(). SetDynamicColors(true). SetScrollable(true). - SetWrap(false) + SetWrap(wrapEnabled) textView.SetBorder(true).SetTitle(" JSON Viewer ") flex := tview.NewFlex(). @@ -38,9 +40,10 @@ func NewJSONViewer(pages *tview.Pages) *JSONViewer { AddItem(nil, 0, 1, false) jsonViewer := &JSONViewer{ - Flex: flex, - TextView: textView, - Pages: pages, + Flex: flex, + TextView: textView, + Pages: pages, + wrapEnabled: wrapEnabled, } pages.AddPage(pageNameJSONViewer, jsonViewer, true, false) @@ -58,6 +61,10 @@ func NewJSONViewer(pages *tview.Pages) *JSONViewer { logger.Error("Error copying JSON to clipboard", map[string]any{"error": err.Error()}) } return nil + } else if command == commands.ToggleJSONViewerWrap { + jsonViewer.wrapEnabled = !jsonViewer.wrapEnabled + jsonViewer.TextView.SetWrap(jsonViewer.wrapEnabled) + return nil } return event }) diff --git a/models/models.go b/models/models.go index 4e7e537..e3edc05 100644 --- a/models/models.go +++ b/models/models.go @@ -12,6 +12,7 @@ type AppConfig struct { SidebarOverlay bool MaxQueryHistoryPerConnection int TreeWidth int + JSONViewerWordWrap bool } type Connection struct {