Skip to content
This repository has been archived by the owner on Jul 3, 2019. It is now read-only.

Commit

Permalink
Add necessary fixes related to non-consecutive selection branch
Browse files Browse the repository at this point in the history
Change all `hot.getSelected()` calls to `hot.getSelectedLast()` and
`hot.getSelectedRange()` to `hot.getSelectedRangeLast()`.

Related-issue: handsontable/handsontable#4708
  • Loading branch information
budnix committed Feb 13, 2018
1 parent 820b8f0 commit 3fee354
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 36 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -55,7 +55,7 @@
"data-spreadsheet"
],
"dependencies": {
"handsontable": "handsontable/handsontable#develop",
"handsontable": "github:handsontable/handsontable#feature/issue-4708",
"hot-formula-parser": "^2.3.1",
"moment": "2.20.1",
"numbro": "1.11.0",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/filters/component/condition.js
Expand Up @@ -183,7 +183,7 @@ class ConditionComponent extends BaseComponent {
reset() {
const lastSelectedColumn = this.hot.getPlugin('filters').getSelectedColumn();
const visualIndex = lastSelectedColumn && lastSelectedColumn.visualIndex;
const columnType = this.hot.getDataType.apply(this.hot, this.hot.getSelected() || [0, visualIndex]);
const columnType = this.hot.getDataType.apply(this.hot, this.hot.getSelectedLast() || [0, visualIndex]);
const items = getOptionsList(columnType);

arrayEach(this.getInputElements(), (element) => element.hide());
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/filters/filters.js
Expand Up @@ -344,7 +344,7 @@ class Filters extends BasePlugin {
* Clear column selection.
*/
clearColumnSelection() {
let [row, col] = this.hot.getSelected() || [];
let [row, col] = this.hot.getSelectedLast() || [];

if (row !== void 0 && col !== void 0) {
this.hot.selectCell(row, col);
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/hiddenColumns/contextMenuItem/hideColumn.js
Expand Up @@ -5,7 +5,7 @@ export default function hideColumnItem(hiddenColumnsPlugin) {
return {
key: 'hidden_columns_hide',
name() {
const selection = this.getSelected();
const selection = this.getSelectedLast();
let pluralForm = 0;

if (Array.isArray(selection)) {
Expand All @@ -19,7 +19,7 @@ export default function hideColumnItem(hiddenColumnsPlugin) {
return this.getTranslatedPhrase(C.CONTEXTMENU_ITEMS_HIDE_COLUMN, pluralForm);
},
callback() {
let {from, to} = this.getSelectedRange();
let {from, to} = this.getSelectedRangeLast();
let start = Math.min(from.col, to.col);
let end = Math.max(from.col, to.col);

Expand Down
6 changes: 3 additions & 3 deletions src/plugins/hiddenColumns/contextMenuItem/showColumn.js
Expand Up @@ -8,7 +8,7 @@ export default function showColumnItem(hiddenColumnsPlugin) {
return {
key: 'hidden_columns_show',
name() {
const selection = this.getSelected();
const selection = this.getSelectedLast();
let pluralForm = 0;

if (Array.isArray(selection)) {
Expand Down Expand Up @@ -37,7 +37,7 @@ export default function showColumnItem(hiddenColumnsPlugin) {
return this.getTranslatedPhrase(C.CONTEXTMENU_ITEMS_SHOW_COLUMN, pluralForm);
},
callback() {
let {from, to} = this.getSelectedRange();
let {from, to} = this.getSelectedRangeLast();
let start = Math.min(from.col, to.col);
let end = Math.max(from.col, to.col);

Expand Down Expand Up @@ -67,7 +67,7 @@ export default function showColumnItem(hiddenColumnsPlugin) {
beforeHiddenColumns.length = 0;
afterHiddenColumns.length = 0;

let {from, to} = this.getSelectedRange();
let {from, to} = this.getSelectedRangeLast();
let start = Math.min(from.col, to.col);
let end = Math.max(from.col, to.col);
let hiddenInSelection = false;
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/hiddenColumns/test/hiddenColumns.e2e.js
Expand Up @@ -365,15 +365,15 @@ describe('HiddenColumns', function() {
selectCell(0, 0, 0, 0);
keyDownUp(Handsontable.helper.KEY_CODES.ARROW_RIGHT);

expect(getSelected()).toEqual([0, 1, 0, 1]);
expect(getSelected()).toEqual([[0, 1, 0, 1]]);

keyDownUp(Handsontable.helper.KEY_CODES.ARROW_RIGHT);

expect(getSelected()).toEqual([0, 3, 0, 3]);
expect(getSelected()).toEqual([[0, 3, 0, 3]]);

keyDownUp(Handsontable.helper.KEY_CODES.ARROW_RIGHT);

expect(getSelected()).toEqual([0, 5, 0, 5]);
expect(getSelected()).toEqual([[0, 5, 0, 5]]);
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/plugins/hiddenRows/contextMenuItem/hideRow.js
Expand Up @@ -5,7 +5,7 @@ export default function hideRowItem(hiddenRowsPlugin) {
return {
key: 'hidden_rows_hide',
name() {
const selection = this.getSelected();
const selection = this.getSelectedLast();
let pluralForm = 0;

if (Array.isArray(selection)) {
Expand All @@ -19,7 +19,7 @@ export default function hideRowItem(hiddenRowsPlugin) {
return this.getTranslatedPhrase(C.CONTEXTMENU_ITEMS_HIDE_ROW, pluralForm);
},
callback() {
let {from, to} = this.getSelectedRange();
let {from, to} = this.getSelectedRangeLast();
let start = Math.min(from.row, to.row);
let end = Math.max(from.row, to.row);

Expand Down
6 changes: 3 additions & 3 deletions src/plugins/hiddenRows/contextMenuItem/showRow.js
Expand Up @@ -8,7 +8,7 @@ export default function showRowItem(hiddenRowsPlugin) {
return {
key: 'hidden_rows_show',
name() {
const selection = this.getSelected();
const selection = this.getSelectedLast();
let pluralForm = 0;

if (Array.isArray(selection)) {
Expand Down Expand Up @@ -37,7 +37,7 @@ export default function showRowItem(hiddenRowsPlugin) {
return this.getTranslatedPhrase(C.CONTEXTMENU_ITEMS_SHOW_ROW, pluralForm);
},
callback() {
let {from, to} = this.getSelectedRange();
let {from, to} = this.getSelectedRangeLast();
let start = Math.min(from.row, to.row);
let end = Math.max(from.row, to.row);

Expand Down Expand Up @@ -67,7 +67,7 @@ export default function showRowItem(hiddenRowsPlugin) {
beforeHiddenRows.length = 0;
afterHiddenRows.length = 0;

let {from, to} = this.getSelectedRange();
let {from, to} = this.getSelectedRangeLast();
let start = Math.min(from.row, to.row);
let end = Math.max(from.row, to.row);

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/hiddenRows/hiddenRows.js
Expand Up @@ -393,7 +393,7 @@ class HiddenRows extends BasePlugin {
* @param {Object} coords Object with `row` and `col` properties.
*/
onBeforeSetRangeStart(coords) {
let actualSelection = this.hot.getSelected() || false;
let actualSelection = this.hot.getSelectedLast() || false;
let lastPossibleIndex = this.hot.countRows() - 1;

let getNextRow = (row) => {
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/hiddenRows/test/hiddenRows.e2e.js
Expand Up @@ -422,15 +422,15 @@ describe('HiddenRows', function() {
selectCell(0, 0, 0, 0);
keyDownUp(Handsontable.helper.KEY_CODES.ARROW_DOWN);

expect(getSelected()).toEqual([1, 0, 1, 0]);
expect(getSelected()).toEqual([[1, 0, 1, 0]]);

keyDownUp(Handsontable.helper.KEY_CODES.ARROW_DOWN);

expect(getSelected()).toEqual([3, 0, 3, 0]);
expect(getSelected()).toEqual([[3, 0, 3, 0]]);

keyDownUp(Handsontable.helper.KEY_CODES.ARROW_DOWN);

expect(getSelected()).toEqual([5, 0, 5, 0]);
expect(getSelected()).toEqual([[5, 0, 5, 0]]);
});

it('should properly highlight selected cell', function() {
Expand All @@ -450,7 +450,7 @@ describe('HiddenRows', function() {
keyDownUp(Handsontable.helper.KEY_CODES.ARROW_UP);
keyDownUp(Handsontable.helper.KEY_CODES.ARROW_UP);

expect(hot.getSelectedRange().highlight.row).toBe(1);
expect(hot.getSelectedRange()[0].highlight.row).toBe(1);
});


Expand Down
4 changes: 2 additions & 2 deletions src/plugins/nestedHeaders/nestedHeaders.js
Expand Up @@ -443,7 +443,7 @@ class NestedHeaders extends BasePlugin {
* @private
*/
updateHeadersHighlight() {
let selection = this.hot.getSelected();
let selection = this.hot.getSelectedLast();

if (selection === void 0) {
return;
Expand Down Expand Up @@ -536,7 +536,7 @@ class NestedHeaders extends BasePlugin {
*/
onBeforeOnCellMouseOver(event, coords, TD, blockCalculations) {
if (coords.row < 0 && coords.col >= 0 && this.hot.view.isMouseDown()) {
let {from, to} = this.hot.getSelectedRange();
let {from, to} = this.hot.getSelectedRangeLast();
let colspan = this.getColspan(coords.row, coords.col);
let lastColIndex = coords.col + colspan - 1;
let changeDirection = false;
Expand Down
12 changes: 6 additions & 6 deletions src/plugins/nestedHeaders/test/nestedHeaders.e2e.js
Expand Up @@ -277,17 +277,17 @@ describe('NestedHeaders', function() {
this.$container.find('.ht_clone_top thead tr:eq(2) th:eq(1)').simulate('mousedown');
this.$container.find('.ht_clone_top thead tr:eq(2) th:eq(1)').simulate('mouseup');

expect(hot.getSelected()).toEqual([0, 1, hot.countRows() - 1, 2]);
expect(hot.getSelected()).toEqual([[0, 1, hot.countRows() - 1, 2]]);

this.$container.find('.ht_clone_top thead tr:eq(1) th:eq(1)').simulate('mousedown');
this.$container.find('.ht_clone_top thead tr:eq(1) th:eq(1)').simulate('mouseup');

expect(hot.getSelected()).toEqual([0, 1, hot.countRows() - 1, 4]);
expect(hot.getSelected()).toEqual([[0, 1, hot.countRows() - 1, 4]]);

this.$container.find('.ht_clone_top thead tr:eq(0) th:eq(1)').simulate('mousedown');
this.$container.find('.ht_clone_top thead tr:eq(0) th:eq(1)').simulate('mouseup');

expect(hot.getSelected()).toEqual([0, 1, hot.countRows() - 1, 8]);
expect(hot.getSelected()).toEqual([[0, 1, hot.countRows() - 1, 8]]);
});

it('should select every column under the extended headers, when changing the selection by dragging the cursor', function() {
Expand All @@ -306,21 +306,21 @@ describe('NestedHeaders', function() {
this.$container.find('.ht_clone_top thead tr:eq(2) th:eq(5)').simulate('mouseover');
this.$container.find('.ht_clone_top thead tr:eq(2) th:eq(5)').simulate('mouseup');

expect(hot.getSelected()).toEqual([0, 3, hot.countRows() - 1, 6]);
expect(hot.getSelected()).toEqual([[0, 3, hot.countRows() - 1, 6]]);

this.$container.find('.ht_clone_top thead tr:eq(2) th:eq(3)').simulate('mousedown');
this.$container.find('.ht_clone_top thead tr:eq(2) th:eq(1)').simulate('mouseover');
this.$container.find('.ht_clone_top thead tr:eq(2) th:eq(1)').simulate('mouseup');

expect(hot.getSelected()).toEqual([0, 4, hot.countRows() - 1, 1]);
expect(hot.getSelected()).toEqual([[0, 4, hot.countRows() - 1, 1]]);

this.$container.find('.ht_clone_top thead tr:eq(2) th:eq(3)').simulate('mousedown');
this.$container.find('.ht_clone_top thead tr:eq(2) th:eq(1)').simulate('mouseover');
this.$container.find('.ht_clone_top thead tr:eq(2) th:eq(3)').simulate('mouseover');
this.$container.find('.ht_clone_top thead tr:eq(2) th:eq(5)').simulate('mouseover');
this.$container.find('.ht_clone_top thead tr:eq(2) th:eq(5)').simulate('mouseup');

expect(hot.getSelected()).toEqual([0, 3, hot.countRows() - 1, 6]);
expect(hot.getSelected()).toEqual([[0, 3, hot.countRows() - 1, 6]]);
});

it('should highlight only last line of headers on cell selection', function() {
Expand Down
10 changes: 5 additions & 5 deletions src/plugins/nestedRows/ui/contextMenu.js
Expand Up @@ -46,12 +46,12 @@ class ContextMenuUI extends BaseUI {
return this.getTranslatedPhrase(C.CONTEXTMENU_ITEMS_NESTED_ROWS_INSERT_CHILD);
},
callback: () => {
const translatedRowIndex = this.dataManager.translateTrimmedRow(this.hot.getSelected()[0]);
const translatedRowIndex = this.dataManager.translateTrimmedRow(this.hot.getSelectedLast()[0]);
const parent = this.dataManager.getDataObject(translatedRowIndex);
this.dataManager.addChild(parent);
},
disabled: () => {
const selected = this.hot.getSelected();
const selected = this.hot.getSelectedLast();

return !selected || selected[0] < 0 || this.hot.selection.selectedHeader.cols || this.hot.countRows() >= this.hot.getSettings().maxRows;
}
Expand All @@ -62,13 +62,13 @@ class ContextMenuUI extends BaseUI {
return this.getTranslatedPhrase(C.CONTEXTMENU_ITEMS_NESTED_ROWS_DETACH_CHILD);
},
callback: () => {
const translatedRowIndex = this.dataManager.translateTrimmedRow(this.hot.getSelected()[0]);
const translatedRowIndex = this.dataManager.translateTrimmedRow(this.hot.getSelectedLast()[0]);
const element = this.dataManager.getDataObject(translatedRowIndex);

this.dataManager.detachFromParent(this.hot.getSelected());
this.dataManager.detachFromParent(this.hot.getSelectedLast());
},
disabled: () => {
const selected = this.hot.getSelected();
const selected = this.hot.getSelectedLast();
const translatedRowIndex = this.dataManager.translateTrimmedRow(selected[0]);
let parent = this.dataManager.getRowParent(translatedRowIndex);

Expand Down
4 changes: 2 additions & 2 deletions test/helpers/common.js
Expand Up @@ -83,11 +83,11 @@ export function getCorrespondingOverlay(cell, container) {
*/
export function contextMenu(cell) {
var hot = spec().$container.data('handsontable');
var selected = hot.getSelected();
var selected = hot.getSelectedLast();

if (!selected) {
hot.selectCell(0, 0);
selected = hot.getSelected();
selected = hot.getSelectedLast();
}
if (!cell) {
cell = getCell(selected[0], selected[1]);
Expand Down

0 comments on commit 3fee354

Please sign in to comment.