Skip to content

Commit

Permalink
fix crashes when truncating metadata and update some style
Browse files Browse the repository at this point in the history
  • Loading branch information
yorukot committed Apr 12, 2024
1 parent 4433b77 commit b6ed184
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/components/globalController.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ func pasteItem(m model) model {
func panelCreateNewFile(m model) model {
panel := m.fileModel.filePanels[m.filePanelFocusIndex]
ti := textinput.New()
ti.TextStyle = textStyle
ti.Cursor.Blink = true
ti.Placeholder = "File name"
ti.Focus()
ti.CharLimit = 156
Expand All @@ -376,6 +378,8 @@ func panelCreateNewFile(m model) model {
func panelCreateNewFolder(m model) model {
panel := m.fileModel.filePanels[m.filePanelFocusIndex]
ti := textinput.New()
ti.TextStyle = textStyle
ti.Cursor.Blink = true
ti.Placeholder = "Folder name"
ti.Focus()
ti.CharLimit = 156
Expand Down Expand Up @@ -457,7 +461,7 @@ func extractFile(m model) model {
func compressFile(m model) model {
panel := m.fileModel.filePanels[m.filePanelFocusIndex]
fileName := filepath.Base(panel.element[panel.cursor].location)

zipName := strings.TrimSuffix(fileName, filepath.Ext(fileName)) + ".zip"
zipSource(panel.element[panel.cursor].location, filepath.Join(filepath.Dir(panel.element[panel.cursor].location), zipName))
m.fileModel.filePanels[m.filePanelFocusIndex] = panel
Expand Down
18 changes: 15 additions & 3 deletions src/components/modelRender.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,30 @@ func MetaDataRender(m model) string {
// Default comparison
return m.fileMetaData.metaData[i][0] < m.fileMetaData.metaData[j][0]
})

for _, data := range m.fileMetaData.metaData {
if len(data[0]) > maxKeyLength {
maxKeyLength = len(data[0])
}
}

sprintfLength := maxKeyLength + 1
vauleLength := BottomWidth(m.fullWidth) - maxKeyLength - 2
if vauleLength < BottomWidth(m.fullWidth)/2 {
vauleLength = BottomWidth(m.fullWidth)/2 - 2
sprintfLength = vauleLength
}

for i := m.fileMetaData.renderIndex; i < bottomElementHight(bottomBarHeight)+m.fileMetaData.renderIndex && i < len(m.fileMetaData.metaData); i++ {
if i != m.fileMetaData.renderIndex {
metaDataBar += "\n"
}
data := TruncateMiddleText(m.fileMetaData.metaData[i][1], (BottomWidth(m.fullWidth))-maxKeyLength-3)
metaDataBar += fmt.Sprintf("%-*s %s", maxKeyLength+1, m.fileMetaData.metaData[i][0], data)
data := TruncateMiddleText(m.fileMetaData.metaData[i][1], vauleLength)
metadataName := m.fileMetaData.metaData[i][0]
if BottomWidth(m.fullWidth)-maxKeyLength-3 < BottomWidth(m.fullWidth)/2 {
metadataName = TruncateMiddleText(m.fileMetaData.metaData[i][0], vauleLength)
}
metaDataBar += fmt.Sprintf("%-*s %s", sprintfLength, metadataName, data)

}
bottomBorder := GenerateBottomBorder(fmt.Sprintf("%s/%s", strconv.Itoa(m.fileMetaData.renderIndex+1), strconv.Itoa(len(m.fileMetaData.metaData))), BottomWidth(m.fullWidth)-3)
metaDataBar = MetaDataBoarder(bottomElementHight(bottomBarHeight), BottomWidth(m.fullWidth), bottomBorder, m.focusPanel).Render(metaDataBar)
Expand Down
2 changes: 2 additions & 0 deletions src/components/normalModeController.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ func panelItemRename(m model) model {
return m
}
ti := textinput.New()
ti.TextStyle = textStyle
ti.Cursor.Blink = true
ti.Placeholder = "New name"
ti.SetValue(panel.element[panel.cursor].name)
ti.Focus()
Expand Down

0 comments on commit b6ed184

Please sign in to comment.