Skip to content

Commit 426406e

Browse files
committed
code quality fix
1 parent 59ded81 commit 426406e

File tree

4 files changed

+69
-53
lines changed

4 files changed

+69
-53
lines changed

src/internal/key_function.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,9 @@ func (m *model) bulkRenameKey(msg string) tea.Cmd {
290290
case slices.Contains(common.Hotkeys.ConfirmTyping, msg):
291291
m.confirmBulkRename()
292292
case slices.Contains(common.Hotkeys.ListUp, msg):
293-
m.handleBulkRenameUpKey()
293+
m.adjustBulkRenameValue(-1)
294294
case slices.Contains(common.Hotkeys.ListDown, msg):
295-
m.handleBulkRenameDownKey()
295+
m.adjustBulkRenameValue(1)
296296
case msg == "tab":
297297
m.bulkRenameNextType()
298298
case msg == "shift+tab":
@@ -301,14 +301,6 @@ func (m *model) bulkRenameKey(msg string) tea.Cmd {
301301
return nil
302302
}
303303

304-
func (m *model) handleBulkRenameUpKey() {
305-
m.adjustBulkRenameValue(-1)
306-
}
307-
308-
func (m *model) handleBulkRenameDownKey() {
309-
m.adjustBulkRenameValue(1)
310-
}
311-
312304
func (m *model) adjustBulkRenameValue(delta int) {
313305
switch m.bulkRenameModal.renameType {
314306
case 3:

src/internal/model.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -428,15 +428,15 @@ func (m *model) updateFilePanelsState(msg tea.Msg) tea.Cmd {
428428
m.firstTextInput = false
429429
case m.bulkRenameModal.open:
430430
switch m.bulkRenameModal.renameType {
431-
case 0:
431+
case 0:
432432
if m.bulkRenameModal.cursor == 0 {
433433
m.bulkRenameModal.findInput, cmd = m.bulkRenameModal.findInput.Update(msg)
434434
} else {
435435
m.bulkRenameModal.replaceInput, cmd = m.bulkRenameModal.replaceInput.Update(msg)
436436
}
437-
case 1:
437+
case 1:
438438
m.bulkRenameModal.prefixInput, cmd = m.bulkRenameModal.prefixInput.Update(msg)
439-
case 2:
439+
case 2:
440440
m.bulkRenameModal.suffixInput, cmd = m.bulkRenameModal.suffixInput.Update(msg)
441441
}
442442
case m.fileModel.renaming:
@@ -455,7 +455,6 @@ func (m *model) updateFilePanelsState(msg tea.Msg) tea.Cmd {
455455
m.applyZoxideModalAction(action)
456456
}
457457

458-
459458
// The code should never reach this state.
460459
if focusPanel.cursor < 0 {
461460
focusPanel.cursor = 0
@@ -668,12 +667,15 @@ func (m *model) updateRenderForOverlay(finalRender string) string {
668667
}
669668

670669
if m.bulkRenameModal.open {
670+
config := modalOverlayConfig{
671+
width: 80,
672+
height: common.ModalHeight + 15,
673+
}
674+
config.x = m.fullWidth/2 - config.width/2
675+
config.y = m.fullHeight/2 - config.height/2
676+
671677
bulkRenameModal := m.bulkRenameModalRender()
672-
bulkRenameModalWidth := 80
673-
modalHeight := common.ModalHeight + 15
674-
overlayX := m.fullWidth/2 - bulkRenameModalWidth/2
675-
overlayY := m.fullHeight/2 - modalHeight/2
676-
return stringfunction.PlaceOverlay(overlayX, overlayY, bulkRenameModal, finalRender)
678+
return stringfunction.PlaceOverlay(config.x, config.y, bulkRenameModal, finalRender)
677679
}
678680

679681
if m.notifyModel.IsOpen() {

src/internal/model_render.go

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -349,60 +349,67 @@ func (m *model) zoxideModalRender() string {
349349
}
350350

351351
func (m *model) bulkRenameModalRender() string {
352+
config := m.createBulkRenameConfig()
352353
panel := &m.fileModel.filePanels[m.filePanelFocusIndex]
353-
width := 80
354354

355-
title := m.renderBulkRenameTitle(panel, width)
356-
categoriesAndInputs := m.renderBulkRenameCategoriesAndInputs(width)
357-
preview := m.renderBulkRenamePreview(width)
358-
tips := m.renderBulkRenameTips(width)
359-
errorMsg := m.renderBulkRenameError(width)
355+
title := m.renderBulkRenameTitle(panel, config)
356+
categoriesAndInputs := m.renderBulkRenameCategoriesAndInputs(config)
357+
preview := m.renderBulkRenamePreview(config)
358+
tips := m.renderBulkRenameTips(config)
359+
errorMsg := m.renderBulkRenameError(config)
360360

361361
content := title + "\n\n" + categoriesAndInputs + preview + tips + "\n" + errorMsg
362-
return m.wrapBulkRenameContent(content, width)
362+
return m.wrapBulkRenameContent(content, config)
363+
}
364+
365+
func (m *model) createBulkRenameConfig() bulkRenameRenderConfig {
366+
width := 80
367+
leftColWidth := 20
368+
return bulkRenameRenderConfig{
369+
width: width,
370+
modalHeight: common.ModalHeight + 15,
371+
leftColWidth: leftColWidth,
372+
rightColWidth: width - 4 - leftColWidth - 2,
373+
columnHeight: 6,
374+
}
363375
}
364376

365-
func (m *model) wrapBulkRenameContent(content string, width int) string {
366-
modalHeight := common.ModalHeight + 15
377+
func (m *model) wrapBulkRenameContent(content string, config bulkRenameRenderConfig) string {
367378
contentStyle := lipgloss.NewStyle().
368-
MaxHeight(modalHeight - 2).
369-
MaxWidth(width - 4)
379+
MaxHeight(config.modalHeight - 2).
380+
MaxWidth(config.width - 4)
370381

371382
constrainedContent := contentStyle.Render(content)
372-
return common.ModalBorderStyle(modalHeight, width).Render(constrainedContent)
383+
return common.ModalBorderStyle(config.modalHeight, config.width).Render(constrainedContent)
373384
}
374385

375-
func (m *model) renderBulkRenameTitle(panel *filePanel, width int) string {
386+
func (m *model) renderBulkRenameTitle(panel *filePanel, config bulkRenameRenderConfig) string {
376387
titleStyle := lipgloss.NewStyle().
377-
Width(width - 4).
388+
Width(config.width - 4).
378389
Background(common.ModalBGColor)
379390

380391
titleText := common.SidebarTitleStyle.Render(" Bulk Rename") +
381392
common.ModalStyle.Render(fmt.Sprintf(" (%d files selected)", len(panel.selected)))
382393
return titleStyle.Render(titleText)
383394
}
384395

385-
func (m *model) renderBulkRenameCategoriesAndInputs(width int) string {
386-
leftColumnWidth := 20
387-
rightColumnWidth := width - 4 - leftColumnWidth - 2
388-
columnHeight := 6
389-
390-
typeOptions := m.renderRenameTypeOptions(leftColumnWidth)
391-
inputs := m.renderRenameInputs(rightColumnWidth)
396+
func (m *model) renderBulkRenameCategoriesAndInputs(config bulkRenameRenderConfig) string {
397+
typeOptions := m.renderRenameTypeOptions(config.leftColWidth)
398+
inputs := m.renderRenameInputs(config.rightColWidth)
392399

393400
leftColumnStyle := lipgloss.NewStyle().
394-
Width(leftColumnWidth).
395-
Height(columnHeight).
401+
Width(config.leftColWidth).
402+
Height(config.columnHeight).
396403
Background(common.ModalBGColor)
397404

398405
rightColumnStyle := lipgloss.NewStyle().
399-
Width(rightColumnWidth).
400-
Height(columnHeight).
406+
Width(config.rightColWidth).
407+
Height(config.columnHeight).
401408
Background(common.ModalBGColor)
402409

403410
separator := lipgloss.NewStyle().
404411
Width(2).
405-
Height(columnHeight).
412+
Height(config.columnHeight).
406413
Background(common.ModalBGColor).
407414
Render(" ")
408415

@@ -512,7 +519,7 @@ func (m *model) renderCaseConversionOptions(styles bulkRenameStyles) string {
512519
return result
513520
}
514521

515-
func (m *model) renderBulkRenamePreview(width int) string {
522+
func (m *model) renderBulkRenamePreview(config bulkRenameRenderConfig) string {
516523
m.bulkRenameModal.preview = m.generateBulkRenamePreview()
517524
previewCount := min(3, len(m.bulkRenameModal.preview))
518525

@@ -521,7 +528,7 @@ func (m *model) renderBulkRenamePreview(width int) string {
521528
}
522529

523530
previewTitle := lipgloss.NewStyle().
524-
Width(width - 4).
531+
Width(config.width - 4).
525532
Align(lipgloss.Center).
526533
Background(common.ModalBGColor).
527534
Foreground(common.ModalFGColor).
@@ -530,13 +537,13 @@ func (m *model) renderBulkRenamePreview(width int) string {
530537
preview := "\n" + previewTitle + "\n"
531538

532539
for i := 0; i < previewCount; i++ {
533-
preview += m.renderPreviewItem(m.bulkRenameModal.preview[i], width)
540+
preview += m.renderPreviewItem(m.bulkRenameModal.preview[i], config.width)
534541
}
535542

536543
if len(m.bulkRenameModal.preview) > previewCount {
537544
moreText := fmt.Sprintf("... and %d more files", len(m.bulkRenameModal.preview)-previewCount)
538545
centeredMore := lipgloss.NewStyle().
539-
Width(width - 4).
546+
Width(config.width - 4).
540547
Align(lipgloss.Center).
541548
Background(common.ModalBGColor).
542549
Foreground(common.ModalFGColor).
@@ -568,21 +575,21 @@ func (m *model) renderPreviewItem(p renamePreview, width int) string {
568575
return errorStyle.Render(p.newName) + "\n" + errorStyle.Render(fmt.Sprintf("(%s)", p.error)) + "\n"
569576
}
570577

571-
func (m *model) renderBulkRenameTips(width int) string {
578+
func (m *model) renderBulkRenameTips(config bulkRenameRenderConfig) string {
572579
tipsStyle := lipgloss.NewStyle().
573-
Width(width - 4).
580+
Width(config.width - 4).
574581
Background(common.ModalBGColor).
575582
Foreground(common.ModalFGColor)
576583
return tipsStyle.Render("\nTab/Shift+Tab: Change type | ↑/↓: Navigate | Enter (Rename) | Esc (Cancel)\n")
577584
}
578585

579-
func (m *model) renderBulkRenameError(width int) string {
586+
func (m *model) renderBulkRenameError(config bulkRenameRenderConfig) string {
580587
if m.bulkRenameModal.errorMessage == "" {
581588
return ""
582589
}
583590

584591
errStyle := lipgloss.NewStyle().
585-
Width(width - 4).
592+
Width(config.width - 4).
586593
Background(common.ModalBGColor)
587594
return "\n" + errStyle.Render(common.ModalErrorStyle.Render(m.bulkRenameModal.errorMessage))
588595
}

src/internal/type.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,21 @@ type bulkRenameStyles struct {
168168
labelStyle lipgloss.Style
169169
activeLabelStyle lipgloss.Style
170170
inputContainerStyle lipgloss.Style
171+
}
172+
173+
type bulkRenameRenderConfig struct {
174+
width int
175+
modalHeight int
176+
leftColWidth int
177+
rightColWidth int
178+
columnHeight int
179+
}
180+
181+
type modalOverlayConfig struct {
182+
width int
183+
height int
184+
x int
185+
y int
171186
} // Copied items
172187
type copyItems struct {
173188
items []string

0 commit comments

Comments
 (0)