Skip to content

Commit b20bc70

Browse files
committed
Fix the searchbar to automatically put the open key into the searchbar
1 parent ec9e256 commit b20bc70

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

Diff for: src/internal/model.go

+16-16
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
5757
case tea.KeyMsg:
5858
m, cmd = m.handleKeyInput(msg, cmd)
5959
}
60-
60+
6161
m.updateFilePanelsState(msg, &cmd)
6262
m.sidebarModel.directories = getDirectories()
6363

@@ -196,20 +196,27 @@ func (m model) handleKeyInput(msg tea.KeyMsg, cmd tea.Cmd) (model, tea.Cmd){
196196
}
197197

198198
func (m *model) updateFilePanelsState(msg tea.Msg, cmd *tea.Cmd) {
199+
focusPanel := &m.fileModel.filePanels[m.filePanelFocusIndex]
199200
if m.firstTextInput {
200201
m.firstTextInput = false
201202
} else if m.fileModel.renaming {
202-
m.fileModel.filePanels[m.filePanelFocusIndex].rename, *cmd = m.fileModel.filePanels[m.filePanelFocusIndex].rename.Update(msg)
203-
} else if m.fileModel.filePanels[m.filePanelFocusIndex].searchBar.Focused() {
204-
m.fileModel.filePanels[m.filePanelFocusIndex].searchBar, *cmd = m.fileModel.filePanels[m.filePanelFocusIndex].searchBar.Update(msg)
203+
focusPanel.rename, *cmd = focusPanel.rename.Update(msg)
204+
} else if focusPanel.searchBar.Focused() {
205+
focusPanel.searchBar, *cmd = focusPanel.searchBar.Update(msg)
206+
for _, hotkey := range hotkeys.SearchBar {
207+
if hotkey == focusPanel.searchBar.Value() {
208+
focusPanel.searchBar.SetValue("")
209+
break
210+
}
211+
}
205212
} else if m.commandLine.input.Focused() {
206213
m.commandLine.input, *cmd = m.commandLine.input.Update(msg)
207214
} else if m.typingModal.open {
208215
m.typingModal.textInput, *cmd = m.typingModal.textInput.Update(msg)
209216
}
210217

211-
if m.fileModel.filePanels[m.filePanelFocusIndex].cursor < 0 {
212-
m.fileModel.filePanels[m.filePanelFocusIndex].cursor = 0
218+
if focusPanel.cursor < 0 {
219+
focusPanel.cursor = 0
213220
}
214221
}
215222

@@ -261,38 +268,31 @@ func (m model) View() string {
261268
finalRender := lipgloss.JoinVertical(0, mainPanel, footer)
262269

263270
// check if need pop up modal
271+
overlayX := m.fullWidth/2 - modalWidth/2
272+
overlayY := m.fullHeight/2 - m.helpMenu.height/2
273+
264274
if m.helpMenu.open {
265275
helpMenu := m.helpMenuRender()
266-
overlayX := m.fullWidth/2 - m.helpMenu.width/2
267-
overlayY := m.fullHeight/2 - m.helpMenu.height/2
268276
return stringfunction.PlaceOverlay(overlayX, overlayY, helpMenu, finalRender)
269277
}
270278

271279
if firstUse {
272280
introduceModal := m.introduceModalRender()
273-
overlayX := m.fullWidth/2 - m.helpMenu.width/2
274-
overlayY := m.fullHeight/2 - m.helpMenu.height/2
275281
return stringfunction.PlaceOverlay(overlayX, overlayY, introduceModal, finalRender)
276282
}
277283

278284
if m.typingModal.open {
279285
typingModal := m.typineModalRender()
280-
overlayX := m.fullWidth/2 - modalWidth/2
281-
overlayY := m.fullHeight/2 - modalHeight/2
282286
return stringfunction.PlaceOverlay(overlayX, overlayY, typingModal, finalRender)
283287
}
284288

285289
if m.warnModal.open {
286290
warnModal := m.warnModalRender()
287-
overlayX := m.fullWidth/2 - modalWidth/2
288-
overlayY := m.fullHeight/2 - modalHeight/2
289291
return stringfunction.PlaceOverlay(overlayX, overlayY, warnModal, finalRender)
290292
}
291293

292294
if m.confirmToQuit {
293295
warnModal := m.warnModalRender()
294-
overlayX := m.fullWidth/2 - modalWidth/2
295-
overlayY := m.fullHeight/2 - modalHeight/2
296296
return stringfunction.PlaceOverlay(overlayX, overlayY, warnModal, finalRender)
297297
}
298298

0 commit comments

Comments
 (0)