From 7c4a45f41316886a99d8a9ae1d4d2b88e4f0455e Mon Sep 17 00:00:00 2001 From: Kyren223 Date: Sun, 19 Jan 2025 18:07:25 +0200 Subject: Made UI more responsive --- internal/client/ui/core/chat/chat.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'internal/client/ui/core/chat/chat.go') diff --git a/internal/client/ui/core/chat/chat.go b/internal/client/ui/core/chat/chat.go index 7c3bec0..1895c0d 100644 --- a/internal/client/ui/core/chat/chat.go +++ b/internal/client/ui/core/chat/chat.go @@ -69,6 +69,8 @@ var ( SelectedEditedIndicatorNL = lipgloss.NewStyle(). Foreground(colors.LightGray).Background(colors.BackgroundDim). SetString("\n(edited)").String() + + WidthWithoutVi = PaddingCount*2 + lipgloss.Width(LeftCorner) + lipgloss.Width(RightCorner) ) const ( @@ -108,10 +110,8 @@ type Model struct { borderStyle lipgloss.Style } -func New(width int) Model { - viWidth := width - PaddingCount*2 - lipgloss.Width(LeftCorner) - lipgloss.Width(RightCorner) - vi := viminput.New(viWidth, ui.Height/2) - vi.Placeholder = SendMessagePlaceholder +func New() Model { + vi := viminput.New() vi.PlaceholderStyle = lipgloss.NewStyle().Foreground(colors.Gray) return Model{ @@ -131,7 +131,7 @@ func New(width int) Model { maxMessagesHeight: -1, messagesCache: nil, prerender: "", - width: width, + width: -1, style: blurStyle, borderStyle: ViBlurredBorder, } @@ -165,6 +165,10 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { // TODO: properly invalidate cache m.messagesCache = nil + viWidth := m.width - WidthWithoutVi + m.vi.SetWidth(viWidth) + m.vi.SetMaxHeight(ui.Height / 2) + networkId := state.NetworkId(m.networkIndex) if m.frequencyIndex != -1 && networkId != nil { frequencies := state.State.Frequencies[*networkId] @@ -862,3 +866,7 @@ func (m *Model) editMessage() tea.Cmd { Content: message, }) } + +func (m *Model) SetWidth(width int) { + m.width = width +} -- cgit v1.3.1