-
Notifications
You must be signed in to change notification settings - Fork 18
When user press ctrl+a combination selection will be correct #78
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
base: master
Are you sure you want to change the base?
Conversation
var cellsWithData = { | ||
right: tableData[selectedCell.row][selectedCell.col + 1] !== null, | ||
left: tableData[selectedCell.row][selectedCell.col - 1] !== null, | ||
top: tableData[selectedCell.row - 1][selectedCell.col] !== null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
// If there is no true value in cellsWithData object we should select all table | ||
if (countCellsWithData === 0) { | ||
return {selectAll: true}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return {selectAll: true}; | |
return { selectAll: true }; |
|
||
return dataAt; | ||
if (tableData[selectedCell.row][selectedCell.col] !== null) { | ||
return {cellWithData: true}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return {cellWithData: true}; | |
return { cellWithData: true }; |
bottom: false, | ||
all: false, | ||
hasData: false | ||
function nearestCellsWithData(selectedCell, tableData) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function nearestCellsWithData(selectedCell, tableData) { | |
function getAdjacentCellsWithData(selectedCell, tableData) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the explanation, I'd call this adjacentCellHasData()
.
right: tableData[selectedCell.row][selectedCell.col + 1] !== null, | ||
left: tableData[selectedCell.row][selectedCell.col - 1] !== null, | ||
top: tableData[selectedCell.row - 1][selectedCell.col] !== null, | ||
bottom: tableData[selectedCell.row + 1][selectedCell.col] !== null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a current: tableData[selectedCell.row][selectedCell.col] !== null
, then just return the cellsWithData
object. In fact, it doesn't really a var
declared.
The reason for this is that the function will do exactly what the name suggests, and does not add logic on top to dictate what other functions should do with the information. The caller of this function can then decide under what scenario it should select all etc.
} | ||
} | ||
// Return false in the case when we need to select all table data | ||
if (nearestDataAt.selectAll) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move the for (var key in ...)
logic from inside the getAdjacentCellsWithData()
function to here.
* @returns {Array} - coordinats that needs to be selected. Example of the returned data: [[startRow, startCol, endRow, endCol]] | ||
* @param {array} tableData - an array of data from the Handsontable library | ||
* @param {int} startSearchFrom - index of the row/col from what we should start a search | ||
* @param {int} colIndex - a not necessary option that tells us what we need to look, a row index or column index |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I right in suggesting this?
* @param {int} colIndex - a not necessary option that tells us what we need to look, a row index or column index | |
* @param {int} colIndex - (optional) when provided, the search is performed along the rows for the column specified |
|
||
firstCol = firstCol || 0; | ||
// If column index is not 0 it means that data what we need to select is in the next column | ||
firstCol = firstCol === 0 ? firstCol : firstCol + 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm reading this right, if firstCol
is 1
, you'd end up adding 1
to it and make it 2
? What's the reason behind doing this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tonytlwu it would be easier to explain on an example:
How selection will behave without this line.
https://share.getcloudapp.com/yAu2Pode
And with this line.
https://share.getcloudapp.com/WnuG1woX
This behavior occurs because of how we searching for the coordinates.
Our functions getStartIndex
and getEndIndex
are looking for the null
in value of the cell to determine that there is no data in that cell. That is why they are returning an index of the cell with null, but we are interested to select only cells with data, that is why we adding to the row or cell 1 here.
This behavior occurs only in the situation I showed in the example when there is more that 1 data selection available in the data source.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could getStartIndex()
and getEndIndex()
change its output so that it returns the first/last cell with data instead of without data? It would match the function names better.
} | ||
} | ||
// If row index is not 0 it means that data what we need to select is in the next row | ||
firstRow = firstRow === 0 ? firstRow : firstRow + 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above. Why are we turning 1
to 2
while 0
remains the same as 0
?
} | ||
} | ||
lastCol = getEndIndex(tableData[firstRow], firstCol); | ||
lastCol = lastCol < selectedCellPosition.col ? selectedCellPosition.col : lastCol; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lastCol = lastCol < selectedCellPosition.col ? selectedCellPosition.col : lastCol; | |
lastCol = Math.min(lastCol, selectedCellPosition.col); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tonytlwu, in this case, we should use Math.max
as well. Because Math.min
will cause this issue https://share.getcloudapp.com/wbu0AeAb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, indeed. It should be Math.max()
.
@YaroslavOvdii @sofiiakvasnevska What's happening with this? Looks like it's been put on pause. Can we continue with this? |
@sofiiakvasnevska
Issue
https://github.com/Fliplet/fliplet-studio/issues/6108
Description
When user press ctrl+a combination selection will be correct
Screenshots/screencasts
https://share.getcloudapp.com/OAub0Y6m
https://share.getcloudapp.com/Z4uLbO18 - large data selection 60k rows ~100 cols
Backward compatibility
This change is fully backward compatible.
Reviewers
@upplabs-alex-levchenko @MaksymShokin