make divider draggable + add space/h keys actions

This commit is contained in:
2026-01-04 02:14:26 +00:00
parent 8609cbd90c
commit 2caa47b8d0
3 changed files with 192 additions and 29 deletions
+47
View File
@@ -0,0 +1,47 @@
package main
// Layout constants to avoid magic numbers
const (
minFsTreeWidth = 5
minNoteViewWidth = 10
dividerWidth = 1
dragHitArea = 2 // +/- chars around divider
)
// calculateLayout computes the widths for the file tree and note view
// based on the terminal dimensions and the desired tree width.
// It returns the constrained tree width and the resulting note view width.
func calculateLayout(totalWidth, requestedTreeWidth int) (treeWidth, noteWidth int) {
treeWidth = requestedTreeWidth
// Default initial width if not set
if treeWidth == 0 {
treeWidth = totalWidth / 4
}
// Calculate maximum allowed width for the tree
// Total width - divider - minimum note view width
maxTreeWidth := totalWidth - dividerWidth - minNoteViewWidth
// Apply constraints
if treeWidth > maxTreeWidth {
treeWidth = maxTreeWidth
}
if treeWidth < minFsTreeWidth {
treeWidth = minFsTreeWidth
}
noteWidth = totalWidth - treeWidth - dividerWidth
// Safety check to ensure noteWidth is never negative
if noteWidth < 0 {
noteWidth = 0
}
return treeWidth, noteWidth
}
// isHoveringDivider checks if the mouse cursor is within the interaction area of the divider
func isHoveringDivider(mouseX, dividerPos int) bool {
return mouseX >= dividerPos-dragHitArea && mouseX <= dividerPos+dragHitArea
}