* Returns data range as array. * * @param {object} [start] Start selection position. Visual indexes. * @param {object} [end] End selection position. Visual indexes. * @param {number} destination Destination of datamap.get. * @returns {Array}
(start: { row: number; col: number }, end: { row: number; col: number }, destination: number)
| 1087 | * @returns {Array} |
| 1088 | */ |
| 1089 | getRange(start: { row: number; col: number }, end: { row: number; col: number }, destination: number) { |
| 1090 | const output: unknown[][] = []; |
| 1091 | let r; |
| 1092 | let c; |
| 1093 | let row: unknown[]; |
| 1094 | |
| 1095 | const maxRows = this.tableMeta.maxRows; |
| 1096 | const maxCols = this.tableMeta.maxCols; |
| 1097 | |
| 1098 | if (maxRows === 0 || maxCols === 0) { |
| 1099 | return []; |
| 1100 | } |
| 1101 | |
| 1102 | const getFn = destination === DataMap.DESTINATION_CLIPBOARD_GENERATOR ? this.getCopyable : this.get; |
| 1103 | |
| 1104 | const rlen = Math.min(Math.max((maxRows ?? Infinity) - 1, 0), Math.max(start.row, end.row)); |
| 1105 | const clen = Math.min(Math.max((maxCols ?? Infinity) - 1, 0), Math.max(start.col, end.col)); |
| 1106 | |
| 1107 | for (r = Math.min(start.row, end.row); r <= rlen; r++) { |
| 1108 | row = []; |
| 1109 | // We just store indexes for rows without headers. |
| 1110 | const physicalRow = r >= 0 ? this.hot!.toPhysicalRow(r) : r; |
| 1111 | |
| 1112 | for (c = Math.min(start.col, end.col); c <= clen; c++) { |
| 1113 | |
| 1114 | if (physicalRow === null) { |
| 1115 | break; |
| 1116 | } |
| 1117 | row.push(getFn.call(this, r, this.colToProp(c))); |
| 1118 | } |
| 1119 | if (physicalRow !== null) { |
| 1120 | output.push(row); |
| 1121 | } |
| 1122 | } |
| 1123 | |
| 1124 | return output; |
| 1125 | } |
| 1126 | |
| 1127 | /** |
| 1128 | * Return data as text (tab separated columns). |
no test coverage detected