handsontable
Version:
Handsontable is a JavaScript Data Grid available for React, Angular and Vue.
38 lines (35 loc) • 1.13 kB
JavaScript
;
exports.__esModule = true;
const command = exports.command = {
name: 'moveCellSelectionDownByViewportHeight',
callback(hot) {
const {
selection
} = hot;
const {
navigableHeaders
} = hot.getSettings();
const columnHeadersCount = navigableHeaders ? hot.countColHeaders() : 0;
const {
row
} = hot.getSelectedRangeLast().highlight;
let rowsStep = hot.countVisibleRows() + columnHeadersCount;
rowsStep = rowsStep === 0 ? 1 : rowsStep;
// if the last row is currently selected move the focus to the first row (if autoWrap is enabled)
if (row === hot.countRows() - 1) {
rowsStep = 1;
// if the next move would move the focus off the table calculate the delta to move the selection to
// the last row
} else if (row + rowsStep > hot.countRows()) {
rowsStep = hot.countRows() - row - 1;
}
selection.markSource('keyboard');
selection.transformStart(rowsStep, 0);
selection.markEndSource();
if (hot.getSelectedRangeLast().highlight.row < 0) {
hot.scrollViewportTo({
row: 0
});
}
}
};