InputHandler returns the handler for this primitive.
()
| 1368 | |
| 1369 | // InputHandler returns the handler for this primitive. |
| 1370 | func (t *Table) InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive)) { |
| 1371 | return t.WrapInputHandler(func(event *tcell.EventKey, setFocus func(p Primitive)) { |
| 1372 | key := event.Key() |
| 1373 | |
| 1374 | if (!t.rowsSelectable && !t.columnsSelectable && key == tcell.KeyEnter) || |
| 1375 | key == tcell.KeyEscape || |
| 1376 | key == tcell.KeyTab || |
| 1377 | key == tcell.KeyBacktab { |
| 1378 | if t.done != nil { |
| 1379 | t.done(key) |
| 1380 | } |
| 1381 | return |
| 1382 | } |
| 1383 | |
| 1384 | // Movement functions. |
| 1385 | previouslySelectedRow, previouslySelectedColumn := t.selectedRow, t.selectedColumn |
| 1386 | lastColumn := t.content.GetColumnCount() - 1 |
| 1387 | rowCount := t.content.GetRowCount() |
| 1388 | if rowCount == 0 { |
| 1389 | return // No movement on empty tables. |
| 1390 | } |
| 1391 | var ( |
| 1392 | // Move the selection forward, don't go beyond final cell, return |
| 1393 | // true if a selection was found. |
| 1394 | forward = func(finalRow, finalColumn int) bool { |
| 1395 | row, column := t.selectedRow, t.selectedColumn |
| 1396 | for { |
| 1397 | // Stop if the current selection is fine. |
| 1398 | cell := t.content.GetCell(row, column) |
| 1399 | if cell != nil && !cell.NotSelectable { |
| 1400 | t.selectedRow, t.selectedColumn = row, column |
| 1401 | return true |
| 1402 | } |
| 1403 | |
| 1404 | // If we reached the final cell, stop. |
| 1405 | if row == finalRow && column == finalColumn { |
| 1406 | return false |
| 1407 | } |
| 1408 | |
| 1409 | // Move forward. |
| 1410 | column++ |
| 1411 | if column > lastColumn { |
| 1412 | column = 0 |
| 1413 | row++ |
| 1414 | if row >= rowCount { |
| 1415 | row = 0 |
| 1416 | } |
| 1417 | } |
| 1418 | } |
| 1419 | } |
| 1420 | |
| 1421 | // Move the selection backwards, don't go beyond final cell, return |
| 1422 | // true if a selection was found. |
| 1423 | backwards = func(finalRow, finalColumn int) bool { |
| 1424 | row, column := t.selectedRow, t.selectedColumn |
| 1425 | for { |
| 1426 | // Stop if the current selection is fine. |
| 1427 | cell := t.content.GetCell(row, column) |
nothing calls this directly
no test coverage detected