Skip to content

Commit d0fd5f8

Browse files
committed
The command palette should not move
The command palette tries to stay centered vertically and horizontally in the window, but it would jump around if the inner model changes size. We want to only keep the initial position calculated on window resize, this keeps the command palette nicely in the same spot all the time Signed-off-by: Djordje Lukic <djordje.lukic@docker.com>
1 parent 8661994 commit d0fd5f8

2 files changed

Lines changed: 4 additions & 12 deletions

File tree

pkg/tui/dialog/command_palette.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,8 @@ func (d *commandPaletteDialog) Position() (row, col int) {
283283

284284
maxHeight := min(d.height*70/100, 30)
285285

286-
// Estimate dialog height
287-
dialogHeight := min(8+len(d.filtered), maxHeight)
288-
289286
// Center the dialog
290-
row = max(0, (d.height-dialogHeight)/2)
287+
row = max(0, (d.height-maxHeight)/2)
291288
col = max(0, (d.width-dialogWidth)/2)
292289
return row, col
293290
}
@@ -298,10 +295,3 @@ func (d *commandPaletteDialog) SetSize(width, height int) tea.Cmd {
298295
d.height = height
299296
return nil
300297
}
301-
302-
// OpenCommandPalette returns a command to open the command palette
303-
func OpenCommandPalette(categories []CommandCategory) tea.Cmd {
304-
return core.CmdHandler(OpenDialogMsg{
305-
Model: NewCommandPaletteDialog(categories),
306-
})
307-
}

pkg/tui/tui.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,9 @@ func (a *appModel) handleKeyPressMsg(msg tea.KeyPressMsg) tea.Cmd {
227227
case key.Matches(msg, a.keyMap.CommandPalette):
228228
// Open command palette
229229
categories := a.buildCommandCategories()
230-
return dialog.OpenCommandPalette(categories)
230+
return core.CmdHandler(dialog.OpenDialogMsg{
231+
Model: dialog.NewCommandPaletteDialog(categories),
232+
})
231233
default:
232234
updated, cmd := a.chatPage.Update(msg)
233235
a.chatPage = updated.(chatpage.Page)

0 commit comments

Comments
 (0)