MCPcopy Create free account
hub / github.com/UI5/webcomponents / _handleRangeSelection

Method _handleRangeSelection

packages/main/src/TableSelection.ts:358–390  ·  view source on GitHub ↗

* Handles the range selection * @param targetRow row that is currently focused * @param change indicates direction * @private

(targetRow: TableRow, change: number)

Source from the content-addressed store, hash-verified

356 * @private
357 */
358 _handleRangeSelection(targetRow: TableRow, change: number) {
359 if (!this._rangeSelection) {
360 return;
361 }
362
363 const isUp = change > 0;
364 this._rangeSelection.isUp ??= isUp;
365
366 const shouldReverseSelection = isUp !== this._rangeSelection.isUp && !this._rangeSelection.isMouse;
367 let selectionChanged = shouldReverseSelection && this.isSelected(targetRow);
368
369 if (shouldReverseSelection) {
370 this._reverseRangeSelection();
371 } else {
372 const rowIndex = this._table!.rows.indexOf(targetRow);
373 const [startIndex, endIndex] = [rowIndex, rowIndex - change].sort((a, b) => a - b);
374
375 selectionChanged = this._table?.rows.slice(startIndex, endIndex + 1).reduce((changed, row) => {
376 const isRowNotInSelection = !this._rangeSelection?.rows.includes(row);
377 const isRowSelectionDifferent = this.isSelected(row) !== this._rangeSelection!.selected;
378
379 if (isRowNotInSelection) {
380 this._rangeSelection?.rows.push(row);
381 }
382
383 this._selectRow(row, this._rangeSelection!.selected);
384
385 return changed || isRowSelectionDifferent;
386 }, selectionChanged) || false;
387 }
388
389 selectionChanged && this.fireDecoratorEvent("change");
390 }
391
392 _stopRangeSelection() {
393 this._rangeSelection = null;

Callers 2

_onkeydownMethod · 0.95
_onClickCaptureMethod · 0.95

Calls 4

isSelectedMethod · 0.95
_selectRowMethod · 0.95
pushMethod · 0.80

Tested by

no test coverage detected