Skip to content

Commit 5f7083f

Browse files
authored
fix selection row/col while shift hold (#396)
* fix selction row/col while shift hold * update package
1 parent 055493a commit 5f7083f

5 files changed

Lines changed: 67 additions & 86 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@fileverse-dev/dsheet",
33
"private": false,
44
"description": "DSheet",
5-
"version": "2.0.35",
5+
"version": "2.0.36",
66
"main": "dist/index.es.js",
77
"module": "dist/index.es.js",
88
"exports": {

src/sheet-engine/core/events/mouse.ts

Lines changed: 54 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import {
6161
} from '../modules/protection';
6262
import {
6363
normalizeSelection,
64+
seletedHighlistByindex,
6465
syncPrimaryCellActiveFromSelection,
6566
pasteHandlerOfPaintModel,
6667
} from '../modules/selection';
@@ -4930,49 +4931,34 @@ export function handleRowHeaderMouseDown(
49304931
const last = _.cloneDeep(
49314932
ctx.luckysheet_select_save?.[ctx.luckysheet_select_save.length - 1],
49324933
); // 选区最后一个
4933-
if (
4934-
!last ||
4935-
_.isNil(last.top) ||
4936-
_.isNil(last.height) ||
4937-
_.isNil(last.row_focus)
4938-
) {
4939-
return;
4940-
}
4941-
4942-
let _top = 0;
4943-
let _height = 0;
4944-
let _rowseleted = [];
4945-
if (last.top > row_pre) {
4946-
_top = row_pre;
4947-
_height = last.top + last.height - row_pre;
4948-
4949-
if (last.row[1] > last.row_focus) {
4950-
last.row[1] = last.row_focus;
4934+
if (last) {
4935+
const anchor = last.row_focus ?? last.row?.[0] ?? row_index;
4936+
const rStart = Math.min(anchor, row_index);
4937+
const rEnd = Math.max(anchor, row_index);
4938+
const bounds = seletedHighlistByindex(ctx, rStart, rEnd, 0, col_index);
4939+
4940+
last.row = [rStart, rEnd];
4941+
last.column = [0, col_index];
4942+
if (bounds) {
4943+
last.left = bounds.left;
4944+
last.width = bounds.width;
4945+
last.top = bounds.top;
4946+
last.height = bounds.height;
4947+
last.left_move = bounds.left;
4948+
last.width_move = bounds.width;
4949+
last.top_move = bounds.top;
4950+
last.height_move = bounds.height;
49514951
}
4952-
4953-
_rowseleted = [row_index, last.row[1]];
4954-
} else if (last.top === row_pre) {
4955-
_top = row_pre;
4956-
_height = last.top + last.height - row_pre;
4957-
_rowseleted = [row_index, last.row[0]];
4958-
} else {
4959-
_top = last.top;
4960-
_height = row - last.top - 1;
4961-
4962-
if (last.row[0] < last.row_focus) {
4963-
last.row[0] = last.row_focus;
4952+
last.row_select = true;
4953+
last.column_select = false;
4954+
last.column_focus = 0;
4955+
if (_.isNil(last.row_focus)) {
4956+
last.row_focus = anchor;
49644957
}
49654958

4966-
_rowseleted = [last.row[0], row_index];
4959+
ctx.luckysheet_select_save![ctx.luckysheet_select_save!.length - 1] =
4960+
last;
49674961
}
4968-
4969-
last.row = _rowseleted;
4970-
4971-
last.top_move = _top;
4972-
last.height_move = _height;
4973-
4974-
ctx.luckysheet_select_save![ctx.luckysheet_select_save!.length - 1] =
4975-
last;
49764962
} else if (e.ctrlKey || e.metaKey) {
49774963
ctx.luckysheet_select_save?.push({
49784964
left: colLocationByIndex(0, ctx.visibledatacolumn)[0],
@@ -5347,51 +5333,40 @@ export function handleColumnHeaderMouseDown(
53475333
const last = _.cloneDeep(
53485334
ctx.luckysheet_select_save?.[ctx.luckysheet_select_save.length - 1],
53495335
); // 选区最后一个
5336+
if (last) {
5337+
const anchor = last.column_focus ?? last.column?.[0] ?? col_index;
5338+
const cStart = Math.min(anchor, col_index);
5339+
const cEnd = Math.max(anchor, col_index);
5340+
const bounds = seletedHighlistByindex(
5341+
ctx,
5342+
0,
5343+
row_index,
5344+
cStart,
5345+
cEnd,
5346+
);
53505347

5351-
let _left = 0;
5352-
let _width = 0;
5353-
let _columnseleted = [];
5354-
5355-
if (
5356-
!last ||
5357-
_.isNil(last.left) ||
5358-
_.isNil(last.width) ||
5359-
_.isNil(last.column_focus)
5360-
) {
5361-
return;
5362-
}
5363-
5364-
if (last.left > col_pre) {
5365-
_left = col_pre;
5366-
_width = last.left + last.width - col_pre;
5367-
5368-
if (last.column[1] > last.column_focus) {
5369-
last.column[1] = last.column_focus;
5348+
last.column = [cStart, cEnd];
5349+
last.row = [0, row_index];
5350+
if (bounds) {
5351+
last.left = bounds.left;
5352+
last.width = bounds.width;
5353+
last.top = bounds.top;
5354+
last.height = bounds.height;
5355+
last.left_move = bounds.left;
5356+
last.width_move = bounds.width;
5357+
last.top_move = bounds.top;
5358+
last.height_move = bounds.height;
53705359
}
5371-
5372-
_columnseleted = [col_index, last.column[1]];
5373-
} else if (last.left === col_pre) {
5374-
_left = col_pre;
5375-
_width = last.left + last.width - col_pre;
5376-
_columnseleted = [col_index, last.column[0]];
5377-
} else {
5378-
_left = last.left;
5379-
_width = col - last.left - 1;
5380-
5381-
if (last.column[0] < last.column_focus) {
5382-
last.column[0] = last.column_focus;
5360+
last.column_select = true;
5361+
last.row_select = false;
5362+
last.row_focus = 0;
5363+
if (_.isNil(last.column_focus)) {
5364+
last.column_focus = anchor;
53835365
}
53845366

5385-
_columnseleted = [last.column[0], col_index];
5367+
ctx.luckysheet_select_save![ctx.luckysheet_select_save!.length - 1] =
5368+
last;
53865369
}
5387-
5388-
last.column = _columnseleted;
5389-
5390-
last.left_move = _left;
5391-
last.width_move = _width;
5392-
5393-
ctx.luckysheet_select_save![ctx.luckysheet_select_save!.length - 1] =
5394-
last;
53955370
} else if (e.ctrlKey || e.metaKey) {
53965371
// 选区添加
53975372
ctx.luckysheet_select_save?.push({

src/sheet-engine/react/components/SheetOverlay/ColumnHeader.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ const ColumnHeader: React.FC = () => {
148148
const clickedColIndex = getColIndexClicked(e.pageX, headerEl);
149149
if (clickedColIndex < 0) return;
150150

151-
const sel = api.getSelection(context);
152-
const lastSelectedRow = sel?.[0].row?.[1];
151+
const sel = context.luckysheet_select_save;
152+
const lastSelectedRow = sel?.[0]?.row?.[1];
153153
let data = getFlowdata(context);
154154
if (!data) data = [];
155155

@@ -160,6 +160,7 @@ const ColumnHeader: React.FC = () => {
160160
});
161161
}
162162
if (
163+
e.shiftKey ||
163164
!allColSel ||
164165
(allColSel && sel && clickedColIndex < sel?.[0].column?.[0]) ||
165166
// @ts-ignore
@@ -203,6 +204,8 @@ const ColumnHeader: React.FC = () => {
203204
refs.globalCache,
204205
refs.cellInput,
205206
refs.fxInput,
207+
context.luckysheet_select_save,
208+
context.isFlvReadOnly,
206209
setContext,
207210
getColIndexClicked,
208211
isColDoubleClicked,

src/sheet-engine/react/components/SheetOverlay/RowHeader.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ const RowHeader: React.FC = () => {
162162
const clickedRowIndex = getRowIndexClicked(e.pageY, headerEl);
163163
if (clickedRowIndex < 0) return;
164164

165-
const sel = api.getSelection(context);
166-
const lastSelectedCol = sel?.[0].column?.[1];
165+
const sel = context.luckysheet_select_save;
166+
const lastSelectedCol = sel?.[0]?.column?.[1];
167167
let data = getFlowdata(context);
168168
if (!data) data = [];
169169

@@ -175,6 +175,7 @@ const RowHeader: React.FC = () => {
175175
});
176176
}
177177
if (
178+
e.shiftKey ||
178179
!allRowSel ||
179180
(allRowSel && sel && clickedRowIndex < sel?.[0].row[0]) ||
180181
// @ts-expect-error: `sel?.[0].row` may be missing in some selection shapes.
@@ -218,6 +219,8 @@ const RowHeader: React.FC = () => {
218219
refs.globalCache,
219220
context.visibledatarow,
220221
context.currentSheetId,
222+
context.luckysheet_select_save,
223+
context.isFlvReadOnly,
221224
setContext,
222225
getRowIndexClicked,
223226
isRowDoubleClicked,

0 commit comments

Comments
 (0)