Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

default range selection initialization can be disabled #4659

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 22 additions & 18 deletions src/js/modules/SelectRange/SelectRange.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export default class SelectRange extends Module {
this.registerTableOption("selectableRangeClearCells", false); //allow clearing of active range
this.registerTableOption("selectableRangeClearCellsValue", undefined); //value for cleared active range
this.registerTableOption("selectableRangeAutoFocus", true); //focus on a cell after resetRanges

this.registerTableOption("selectableRangeInitializeDefault", true); //initializes default range on cell [0,0]

this.registerTableFunction("getRangesData", this.getRangesData.bind(this));
this.registerTableFunction("getRanges", this.getRanges.bind(this));
this.registerTableFunction("addRange", this.addRangeFromComponent.bind(this));
Expand Down Expand Up @@ -84,7 +85,7 @@ export default class SelectRange extends Module {

this.table.rowManager.element.addEventListener("keydown", this.keyDownEvent);

this.resetRanges();
this.resetRanges(false);

this.table.rowManager.element.appendChild(this.overlay);
this.table.columnManager.element.setAttribute("tabindex", 0);
Expand Down Expand Up @@ -119,7 +120,7 @@ export default class SelectRange extends Module {
this.subscribe("scroll-horizontal", this.layoutChange.bind(this));

this.subscribe("data-destroy", this.tableDestroyed.bind(this));
this.subscribe("data-processed", this.resetRanges.bind(this));
this.subscribe("data-processed", this.resetRanges.bind(this, false));

this.subscribe("table-layout", this.layoutElement.bind(this));
this.subscribe("table-redraw", this.redraw.bind(this));
Expand Down Expand Up @@ -758,7 +759,7 @@ export default class SelectRange extends Module {
redraw(force) {
if (force) {
this.selecting = 'cell';
this.resetRanges();
this.resetRanges(false);
this.layoutElement();
}
}
Expand Down Expand Up @@ -873,6 +874,7 @@ export default class SelectRange extends Module {


getActiveCell() {
if(!this.activeRange) return;
return this.getCell(this.activeRange.start.row, this.activeRange.start.col);
}

Expand Down Expand Up @@ -908,27 +910,29 @@ export default class SelectRange extends Module {
return range;
}

resetRanges() {
resetRanges(forceNewRange = true) {
var range, cell, visibleCells;

this.ranges.forEach((range) => range.destroy());
this.ranges = [];

range = this.addRange();

if(this.table.rowManager.activeRows.length){
visibleCells = this.table.rowManager.activeRows[0].cells.filter((cell) => cell.column.visible);
cell = visibleCells[this.rowHeader ? 1 : 0];

if(cell){
range.setBounds(cell);
if(this.options("selectableRangeAutoFocus")){
this.initializeFocus(cell);
if(forceNewRange || this.options("selectableRangeInitializeDefault")) {
range = this.addRange();

if(this.table.rowManager.activeRows.length){
visibleCells = this.table.rowManager.activeRows[0].cells.filter((cell) => cell.column.visible);
cell = visibleCells[this.rowHeader ? 1 : 0];

if(cell){
range.setBounds(cell);
if(this.options("selectableRangeAutoFocus")){
this.initializeFocus(cell);
}
}
}

return range;
}

return range;
}

tableDestroyed(){
Expand Down