detached 2a1e879

feat(usecase): round persisted split ratios to avoid noisy floats

commit
2a1e87915fb1c8fcadfb65dcd15361c70ac26556
author
brice · · 2025-12-26 08:01 UTC
parent
c4aef32
signature
unsigned
1 file · +10 -1
M internal/application/usecase/manage_panes.go +10 -1
@@ -4,6 +4,7 @@ import (
44 "context"
55 "errors"
66 "fmt"
7+ "math"
78 "sort"
89
910 "github.com/bnema/dumber/internal/domain/entity"
@@ -298,7 +299,8 @@ func (uc *ManagePanesUseCase) SetSplitRatio(ctx context.Context, input SetSplitR
298299 minRatio := input.MinPanePercent / 100.0
299300 maxRatio := 1.0 - minRatio
300301 oldRatio := splitNode.SplitRatio
301- splitNode.SplitRatio = clampFloat64(input.Ratio, minRatio, maxRatio)
302+ clamped := clampFloat64(input.Ratio, minRatio, maxRatio)
303+ splitNode.SplitRatio = roundSplitRatio(clamped)
302304
303305 log.Debug().
304306 Str("split_node_id", input.SplitNodeID).
@@ -417,6 +419,13 @@ func findNearestSplitForAxis(node *entity.PaneNode, axis resizeAxis) *entity.Pan
417419 return nil
418420 }
419421
422+const splitRatioRoundFactor = 100.0
423+
424+func roundSplitRatio(ratio float64) float64 {
425+ // Keep snapshots stable and readable; avoids persisting noisy float values.
426+ return math.Round(ratio*splitRatioRoundFactor) / splitRatioRoundFactor
427+}
428+
420429 func clampFloat64(v, minVal, maxVal float64) float64 {
421430 if v < minVal {
422431 return minVal
@@ -4,6 +4,7 @@ import (
4 "context"4 "context"
5 "errors"5 "errors"
6 "fmt"6 "fmt"
7+ "math"
7 "sort"8 "sort"
8 9
9 "github.com/bnema/dumber/internal/domain/entity"10 "github.com/bnema/dumber/internal/domain/entity"
@@ -298,7 +299,8 @@ func (uc *ManagePanesUseCase) SetSplitRatio(ctx context.Context, input SetSplitR
298 minRatio := input.MinPanePercent / 100.0299 minRatio := input.MinPanePercent / 100.0
299 maxRatio := 1.0 - minRatio300 maxRatio := 1.0 - minRatio
300 oldRatio := splitNode.SplitRatio301 oldRatio := splitNode.SplitRatio
301- splitNode.SplitRatio = clampFloat64(input.Ratio, minRatio, maxRatio)302+ clamped := clampFloat64(input.Ratio, minRatio, maxRatio)
303+ splitNode.SplitRatio = roundSplitRatio(clamped)
302 304
303 log.Debug().305 log.Debug().
304 Str("split_node_id", input.SplitNodeID).306 Str("split_node_id", input.SplitNodeID).
@@ -417,6 +419,13 @@ func findNearestSplitForAxis(node *entity.PaneNode, axis resizeAxis) *entity.Pan
417 return nil419 return nil
418 }420 }
419 421
422+const splitRatioRoundFactor = 100.0
423+
424+func roundSplitRatio(ratio float64) float64 {
425+ // Keep snapshots stable and readable; avoids persisting noisy float values.
426+ return math.Round(ratio*splitRatioRoundFactor) / splitRatioRoundFactor
427+}
428+
420 func clampFloat64(v, minVal, maxVal float64) float64 {429 func clampFloat64(v, minVal, maxVal float64) float64 {
421 if v < minVal {430 if v < minVal {
422 return minVal431 return minVal

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 8

Tags 42

↑↓ moveenter openesc close