* Ends selection range on given coordinate object. * * @param {CellCoords} coords Visual coords. * @param {number} [layerIndex] The layer index to set the end on. If not provided, the current layer level is used.
(coords: CellCoords, layerIndex = this.getLayerLevel())
| 419 | * @param {number} [layerIndex] The layer index to set the end on. If not provided, the current layer level is used. |
| 420 | */ |
| 421 | setRangeEnd(coords: CellCoords, layerIndex = this.getLayerLevel()) { |
| 422 | if (this.selectedRange.isEmpty()) { |
| 423 | return; |
| 424 | } |
| 425 | |
| 426 | this.setActiveSelectionLayerIndex(layerIndex); |
| 427 | |
| 428 | const coordsClone = coords.clone(); |
| 429 | const countRows = this.tableProps.countRows(); |
| 430 | const countCols = this.tableProps.countCols(); |
| 431 | const isSingle = this.getActiveSelectedRange()?.clone().setTo(coords).isSingleHeader(); |
| 432 | |
| 433 | // Ignore processing the end range when the header selection starts overlapping the corner and |
| 434 | // the selection is not a single header highlight. |
| 435 | if ((countRows > 0 || countCols > 0) && |
| 436 | (countRows === 0 && (coordsClone.col ?? 0) < 0 && !isSingle || |
| 437 | countCols === 0 && (coordsClone.row ?? 0) < 0 && !isSingle)) { |
| 438 | return; |
| 439 | } |
| 440 | |
| 441 | this.runLocalHooks('beforeSetRangeEnd', coordsClone); |
| 442 | this.begin(); |
| 443 | |
| 444 | const cellRange = this.getActiveSelectedRange(); |
| 445 | |
| 446 | if (!cellRange) { |
| 447 | return; |
| 448 | } |
| 449 | |
| 450 | if (!this.settings.navigableHeaders) { |
| 451 | cellRange.highlight.normalize(); |
| 452 | } |
| 453 | |
| 454 | if (this.settings.selectionMode === 'single') { |
| 455 | cellRange.setFrom(cellRange.highlight); |
| 456 | cellRange.setTo(cellRange.highlight); |
| 457 | |
| 458 | } else { |
| 459 | const horizontalDir = cellRange.getHorizontalDirection(); |
| 460 | const verticalDir = cellRange.getVerticalDirection(); |
| 461 | const isMultiple = this.isMultiple(); |
| 462 | |
| 463 | cellRange.setTo(coordsClone); |
| 464 | |
| 465 | if ( |
| 466 | isMultiple && |
| 467 | (horizontalDir !== cellRange.getHorizontalDirection() || |
| 468 | cellRange.getWidth() === 1 && !cellRange.includes(cellRange.highlight)) |
| 469 | ) { |
| 470 | cellRange.from.assign({ |
| 471 | col: cellRange.highlight.col ?? undefined |
| 472 | }); |
| 473 | } |
| 474 | if ( |
| 475 | isMultiple && |
| 476 | (verticalDir !== cellRange.getVerticalDirection() || |
| 477 | cellRange.getHeight() === 1 && !cellRange.includes(cellRange.highlight)) |
| 478 | ) { |
no test coverage detected