Skip to content

Commit cbb0fd3

Browse files
authored
Merge pull request #5542 from NicolasPerrenoud/fix_table_scroll_reset
Fix table scroll reset
2 parents e368714 + f3c768f commit cbb0fd3

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

widget/table.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ func (t *Table) Select(id TableCellID) {
266266
}
267267

268268
rows, cols := t.Length()
269-
if id.Row >= rows || id.Col >= cols {
269+
if id.Row < 0 || id.Row >= rows || id.Col < 0 || id.Col >= cols {
270270
return
271271
}
272272

@@ -277,6 +277,7 @@ func (t *Table) Select(id TableCellID) {
277277
f(*t.selectedCell)
278278
}
279279
t.selectedCell = &id
280+
t.currentFocus = id
280281

281282
t.ScrollTo(id)
282283

@@ -589,11 +590,11 @@ func (t *Table) Tapped(e *fyne.PointEvent) {
589590
}
590591

591592
col := t.columnAt(e.Position)
592-
if col == noCellMatch {
593+
if col == noCellMatch || col < 0 {
593594
return // out of col range
594595
}
595596
row := t.rowAt(e.Position)
596-
if row == noCellMatch {
597+
if row == noCellMatch || row < 0 {
597598
return // out of row range
598599
}
599600
t.Select(TableCellID{row, col})
@@ -604,7 +605,6 @@ func (t *Table) Tapped(e *fyne.PointEvent) {
604605
if canvas != nil {
605606
canvas.Focus(t)
606607
}
607-
t.currentFocus = TableCellID{row, col}
608608
t.RefreshItem(t.currentFocus)
609609
}
610610
}

widget/table_internal_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ func TestTable_Focus(t *testing.T) {
143143

144144
canvas.Focused().TypedKey(&fyne.KeyEvent{Name: fyne.KeySpace})
145145
assert.Equal(t, &TableCellID{0, 0}, table.selectedCell)
146+
147+
table.Select(TableCellID{Row: 1, Col: 1})
148+
assert.Equal(t, &TableCellID{1, 1}, table.selectedCell)
149+
assert.Equal(t, TableCellID{1, 1}, table.currentFocus)
146150
}
147151

148152
func TestTable_Headers(t *testing.T) {
@@ -729,6 +733,18 @@ func TestTable_Select(t *testing.T) {
729733
assert.Equal(t, 3, selectedCol)
730734
assert.Equal(t, 4, selectedRow)
731735
test.AssertRendersToMarkup(t, "table/selected_scrolled.xml", w.Canvas())
736+
737+
table.Select(TableCellID{1, -1})
738+
assert.Equal(t, 3, table.selectedCell.Col)
739+
assert.Equal(t, 4, table.selectedCell.Row)
740+
assert.Equal(t, 3, selectedCol)
741+
assert.Equal(t, 4, selectedRow)
742+
743+
table.Select(TableCellID{-1, -1})
744+
assert.Equal(t, 3, table.selectedCell.Col)
745+
assert.Equal(t, 4, table.selectedCell.Row)
746+
assert.Equal(t, 3, selectedCol)
747+
assert.Equal(t, 4, selectedRow)
732748
}
733749

734750
func TestTable_SetColumnWidth(t *testing.T) {

0 commit comments

Comments
 (0)