1
0
mirror of https://github.com/mum4k/termdash.git synced 2025-04-27 13:48:49 +08:00

Merge pull request #137 from mum4k/highlight-at-least-two

Don't zoom when only a single column was highlighted.
This commit is contained in:
Jakub Sobon 2019-02-18 15:23:08 -05:00 committed by GitHub
commit 171faac232
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 72 additions and 5 deletions

View File

@ -201,8 +201,10 @@ func (t *Tracker) Mouse(m *terminalapi.Mouse) error {
if err != nil {
return err
}
t.zoomX = zoom
t.highlight.reset()
if zoom != nil {
t.zoomX = zoom
}
default:
t.highlight.reset()
@ -382,7 +384,13 @@ func findCellPair(base *axes.XDetails, minCell, maxCell int) (*axes.Value, *axes
}
// zoomToHighlight zooms the base X axis according to the highlighted range.
// Can return nil axis if the highlight didn't result in zooming.
func zoomToHighlight(base *axes.XDetails, hr *Range, cvsAr image.Rectangle) (*axes.XDetails, error) {
// Only zoom if at least two columns were selected.
if got := numbers.Abs(hr.End - hr.Start); got < 2 {
return nil, nil
}
minL, maxL, err := findCellPair(base, hr.Start, hr.End-1)
if err != nil {
return nil, err

View File

@ -612,8 +612,14 @@ func TestTracker(t *testing.T) {
}); err != nil {
return err
}
return tr.Mouse(&terminalapi.Mouse{
if err := tr.Mouse(&terminalapi.Mouse{
Position: image.Point{6, 0},
Button: mouse.ButtonLeft,
}); err != nil {
return err
}
return tr.Mouse(&terminalapi.Mouse{
Position: image.Point{2, 0},
Button: mouse.ButtonRelease,
})
},
@ -696,7 +702,7 @@ func TestTracker(t *testing.T) {
),
},
{
desc: "highlights of single row maximizes zoom",
desc: "highlights of single row doesn't zoom",
xp: &axes.XProperties{
Min: 0,
Max: 5,
@ -716,6 +722,44 @@ func TestTracker(t *testing.T) {
Button: mouse.ButtonRelease,
})
},
wantHighlight: false,
wantZoom: mustNewXDetails(
image.Rect(0, 0, 8, 8),
&axes.XProperties{
Min: 0,
Max: 5,
ReqYWidth: 2,
},
),
},
{
desc: "highlights of multiple rows maximizes zoom",
xp: &axes.XProperties{
Min: 0,
Max: 5,
ReqYWidth: 2,
},
cvsAr: image.Rect(0, 0, 8, 8),
graphAr: image.Rect(2, 0, 8, 8),
mutate: func(tr *Tracker) error {
if err := tr.Mouse(&terminalapi.Mouse{
Position: image.Point{2, 0},
Button: mouse.ButtonLeft,
}); err != nil {
return err
}
if err := tr.Mouse(&terminalapi.Mouse{
Position: image.Point{3, 0},
Button: mouse.ButtonLeft,
}); err != nil {
return err
}
return tr.Mouse(&terminalapi.Mouse{
Position: image.Point{3, 0},
Button: mouse.ButtonRelease,
})
},
wantHighlight: false,
wantZoom: mustNewXDetails(
@ -904,7 +948,13 @@ func TestTracker(t *testing.T) {
return err
}
if err := tr.Mouse(&terminalapi.Mouse{
Position: image.Point{2, 0},
Position: image.Point{3, 0},
Button: mouse.ButtonLeft,
}); err != nil {
return err
}
if err := tr.Mouse(&terminalapi.Mouse{
Position: image.Point{3, 0},
Button: mouse.ButtonRelease,
}); err != nil {
return err
@ -1279,13 +1329,22 @@ func TestZoomToHighlight(t *testing.T) {
wantErr: true,
},
{
desc: "zooms to highlighted area",
desc: "doesn't zoom when only one row selected",
cvsAr: image.Rect(0, 0, 4, 4),
baseP: &axes.XProperties{
Min: 0,
Max: 3,
},
hRange: &Range{Start: 1, End: 2},
},
{
desc: "zooms to highlighted area",
cvsAr: image.Rect(0, 0, 4, 4),
baseP: &axes.XProperties{
Min: 0,
Max: 3,
},
hRange: &Range{Start: 1, End: 3},
wantP: &axes.XProperties{
Min: 1,
Max: 2,