Skip to content

Commit aa69539

Browse files
committed
chore: migrated navigation & types to new file
1 parent 711f4e3 commit aa69539

File tree

6 files changed

+120
-117
lines changed

6 files changed

+120
-117
lines changed

src/internal/model.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ func (m *model) updateRenderForOverlay(finalRender string) string {
808808

809809
if panel.sortOptions.open {
810810
sortOptions := m.sortOptionsRender()
811-
overlayX := m.fullWidth/2 - panel.sortOptions.width/29
811+
overlayX := m.fullWidth/2 - panel.sortOptions.width/2
812812
overlayY := m.fullHeight/2 - panel.sortOptions.height/2
813813
return stringfunction.PlaceOverlay(overlayX, overlayY, sortOptions, finalRender)
814814
}

src/internal/ui/bulk_rename/model.go

Lines changed: 0 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"strconv"
1010
"strings"
1111

12-
"github.com/charmbracelet/bubbles/textinput"
1312
tea "github.com/charmbracelet/bubbletea"
1413
"github.com/charmbracelet/lipgloss"
1514

@@ -19,8 +18,6 @@ import (
1918
"github.com/yorukot/superfile/src/internal/utils"
2019
)
2120

22-
type RenameType int
23-
2421
const (
2522
FindReplace RenameType = iota
2623
AddPrefix
@@ -30,49 +27,12 @@ const (
3027
EditorMode
3128
)
3229

33-
type CaseType int
34-
3530
const (
3631
CaseLower CaseType = iota
3732
CaseUpper
3833
CaseTitle
3934
)
4035

41-
type Model struct {
42-
open bool
43-
renameType RenameType
44-
caseType CaseType
45-
cursor int
46-
startNumber int
47-
errorMessage string
48-
49-
findInput textinput.Model
50-
replaceInput textinput.Model
51-
prefixInput textinput.Model
52-
suffixInput textinput.Model
53-
54-
preview []RenamePreview
55-
56-
reqCnt int
57-
58-
width int
59-
height int
60-
61-
selectedFiles []string
62-
currentDir string
63-
}
64-
65-
type RenamePreview struct {
66-
OldPath string
67-
OldName string
68-
NewName string
69-
Error string
70-
}
71-
72-
type UpdateMsg struct {
73-
reqID int
74-
}
75-
7636
func (msg UpdateMsg) GetReqID() int {
7737
return msg.reqID
7838
}
@@ -230,21 +190,10 @@ func (m *Model) handleEditorMode() common.ModelAction {
230190
}
231191
}
232192

233-
type EditorModeAction struct {
234-
TmpfilePath string
235-
Editor string
236-
SelectedFiles []string
237-
CurrentDir string
238-
}
239-
240193
func (a EditorModeAction) String() string {
241194
return "EditorModeAction with editor: " + a.Editor
242195
}
243196

244-
type BulkRenameAction struct {
245-
Previews []RenamePreview
246-
}
247-
248197
func (a BulkRenameAction) String() string {
249198
return "BulkRenameAction with " + strconv.Itoa(len(a.Previews)) + " items"
250199
}
@@ -288,64 +237,6 @@ func (m *Model) adjustValue(delta int) {
288237
}
289238
}
290239
}
291-
func (m *Model) navigateCursor(delta int) {
292-
if delta > 0 {
293-
m.navigateDown()
294-
} else {
295-
m.navigateUp()
296-
}
297-
}
298-
299-
func (m *Model) navigateUp() {
300-
if m.cursor > 0 {
301-
m.cursor--
302-
m.focusInput()
303-
}
304-
}
305-
306-
func (m *Model) navigateDown() {
307-
if m.cursor < 1 {
308-
m.cursor++
309-
m.focusInput()
310-
}
311-
}
312-
313-
func (m *Model) focusInput() {
314-
m.findInput.Blur()
315-
m.replaceInput.Blur()
316-
m.prefixInput.Blur()
317-
m.suffixInput.Blur()
318-
319-
switch m.renameType {
320-
case FindReplace:
321-
if m.cursor == 0 {
322-
m.findInput.Focus()
323-
} else {
324-
m.replaceInput.Focus()
325-
}
326-
case AddPrefix:
327-
m.prefixInput.Focus()
328-
case AddSuffix:
329-
m.suffixInput.Focus()
330-
331-
}
332-
}
333-
334-
func (m *Model) nextType() {
335-
m.renameType = RenameType((int(m.renameType) + 1) % 6)
336-
m.focusInput()
337-
m.preview = nil
338-
}
339-
340-
func (m *Model) prevType() {
341-
newType := int(m.renameType) - 1
342-
if newType < 0 {
343-
newType = 5
344-
}
345-
m.renameType = RenameType(newType)
346-
m.focusInput()
347-
m.preview = nil
348-
}
349240
func (m *Model) GeneratePreview() []RenamePreview {
350241
return m.generatePreview(false)
351242
}
@@ -543,11 +434,6 @@ func bulkRenameOperation(processBarModel *processbar.Model, previews []RenamePre
543434
return p.State
544435
}
545436

546-
type BulkRenameResultMsg struct {
547-
state processbar.ProcessState
548-
count int
549-
}
550-
551437
func NewBulkRenameResultMsg(state processbar.ProcessState, count int) BulkRenameResultMsg {
552438
return BulkRenameResultMsg{state: state, count: count}
553439
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package bulkrename
2+
3+
func (m *Model) navigateCursor(delta int) {
4+
if delta > 0 {
5+
m.navigateDown()
6+
} else {
7+
m.navigateUp()
8+
}
9+
}
10+
11+
func (m *Model) navigateUp() {
12+
if m.cursor > 0 {
13+
m.cursor--
14+
m.focusInput()
15+
}
16+
}
17+
18+
func (m *Model) navigateDown() {
19+
if m.cursor < 1 {
20+
m.cursor++
21+
m.focusInput()
22+
}
23+
}
24+
25+
func (m *Model) focusInput() {
26+
m.findInput.Blur()
27+
m.replaceInput.Blur()
28+
m.prefixInput.Blur()
29+
m.suffixInput.Blur()
30+
31+
switch m.renameType {
32+
case FindReplace:
33+
if m.cursor == 0 {
34+
m.findInput.Focus()
35+
} else {
36+
m.replaceInput.Focus()
37+
}
38+
case AddPrefix:
39+
m.prefixInput.Focus()
40+
case AddSuffix:
41+
m.suffixInput.Focus()
42+
43+
}
44+
}
45+
46+
func (m *Model) nextType() {
47+
m.renameType = RenameType((int(m.renameType) + 1) % 6)
48+
m.focusInput()
49+
m.preview = nil
50+
}
51+
52+
func (m *Model) prevType() {
53+
newType := int(m.renameType) - 1
54+
if newType < 0 {
55+
newType = 5
56+
}
57+
m.renameType = RenameType(newType)
58+
m.focusInput()
59+
m.preview = nil
60+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package bulkrename
2+
import (
3+
"github.com/charmbracelet/bubbles/textinput"
4+
"github.com/yorukot/superfile/src/internal/ui/processbar"
5+
)
6+
7+
type RenameType int
8+
type CaseType int
9+
10+
type Model struct {
11+
open bool
12+
renameType RenameType
13+
caseType CaseType
14+
cursor int
15+
startNumber int
16+
errorMessage string
17+
18+
findInput textinput.Model
19+
replaceInput textinput.Model
20+
prefixInput textinput.Model
21+
suffixInput textinput.Model
22+
23+
preview []RenamePreview
24+
25+
reqCnt int
26+
27+
width int
28+
height int
29+
30+
selectedFiles []string
31+
currentDir string
32+
}
33+
34+
type RenamePreview struct {
35+
OldPath string
36+
OldName string
37+
NewName string
38+
Error string
39+
}
40+
41+
type BulkRenameAction struct {
42+
Previews []RenamePreview
43+
}
44+
45+
type UpdateMsg struct {
46+
reqID int
47+
}
48+
49+
type EditorModeAction struct {
50+
TmpfilePath string
51+
Editor string
52+
SelectedFiles []string
53+
CurrentDir string
54+
}
55+
56+
type BulkRenameResultMsg struct {
57+
state processbar.ProcessState
58+
count int
59+
}

src/superfile_config/hotkeys.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# =================================================================================================
22
# Global hotkeys (cannot conflict with other hotkeys)
33

4-
# Need to add vim hotkeys for bulk_rename
5-
64
confirm = ['enter', 'right', 'l']
75
quit = ['q', 'esc']
86
cd_quit = ['Q', '']

superfile

21.4 MB
Binary file not shown.

0 commit comments

Comments
 (0)