Skip to content

Commit 1e86f47

Browse files
authored
Merge pull request #3774 from udecode/fix/selection-area
Fix/selection area
2 parents 4aa104c + af2f313 commit 1e86f47

File tree

7 files changed

+25
-37
lines changed

7 files changed

+25
-37
lines changed

.changeset/polite-dingos-itch.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@udecode/plate-selection': minor
3+
---
4+
5+
Fix the issue of slow scrolling speed when the cursor is at the bottom.(areaOption needs to be removed to fix the issue.)
6+
If there are no special requirements, there is no need to pass areaOptions; the default configuration is the optimal one.

apps/www/content/docs/block-menu.mdx

-8
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,6 @@ const plugins = [
4545
NodeIdPlugin,
4646
BlockSelectionPlugin.configure({
4747
options: {
48-
areaOptions: {
49-
behaviour: {
50-
scrolling: {
51-
speedDivider: 1.5,
52-
},
53-
startThreshold: 10,
54-
},
55-
},
5648
enableContextMenu: true,
5749
},
5850
}),

apps/www/content/docs/block-selection.mdx

+3-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ BlockSelectionPlugin.configure({
9292

9393
useing `options.areaOptions.behaviour.scrolling.speedDivider` to set the scroll speed.
9494

95-
The value of `1.5` is our recommended speed since it's near the browser-native speed.
95+
The value of `0.8` is our recommended speed since it's near the browser-native speed.
9696

9797

9898
```ts
@@ -101,11 +101,12 @@ BlockSelectionPlugin.configure({
101101
areaOptions: {
102102
behaviour: {
103103
scrolling: {
104+
// You can slow down the scroll speed by setting a bigger value.
104105
speedDivider: 1.5,
105106
},
106107
// The distance needed to move for the selection area to appear.
107108
// If it’s too small, it may cause the mouse click event to be blocked. 10 is a good default.
108-
startThreshold: 10,
109+
startThreshold: 4,
109110
},
110111
},
111112
}

apps/www/src/registry/default/components/editor/plugins/block-selection-plugins.ts

-8
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,6 @@ export const blockSelectionPlugins = [
99
excludePlugins: ['table', 'code_line', 'column_group', 'column'],
1010
},
1111
options: {
12-
areaOptions: {
13-
behaviour: {
14-
scrolling: {
15-
speedDivider: 1.5,
16-
},
17-
startThreshold: 4,
18-
},
19-
},
2012
enableContextMenu: true,
2113
},
2214
}),

packages/selection/src/internal/SelectionArea.ts

+13-9
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,19 @@ export class SelectionArea extends EventTarget<SelectionEvents> {
9999
...opt.behaviour,
100100
scrolling: {
101101
manualSpeed: 750,
102-
speedDivider: 10,
102+
speedDivider: 0.7,
103103
...opt.behaviour?.scrolling,
104104
startScrollMargins: {
105105
x: 20,
106-
y: 20,
106+
y: 40,
107107
...opt.behaviour?.scrolling?.startScrollMargins,
108108
},
109109
},
110110
startThreshold: opt.behaviour?.startThreshold
111111
? typeof opt.behaviour.startThreshold === 'number'
112112
? opt.behaviour.startThreshold
113-
: { x: 20, y: 20, ...opt.behaviour.startThreshold }
114-
: { x: 20, y: 20 },
113+
: { x: 4, y: 4, ...opt.behaviour.startThreshold }
114+
: { x: 4, y: 4 },
115115
},
116116

117117
features: {
@@ -663,7 +663,10 @@ export class SelectionArea extends EventTarget<SelectionEvents> {
663663
) {
664664
_scrollSpeed.y = scrollTop
665665
? -abs(
666-
_containerRect!.top - _areaClientLocation.y2 - this._scrollDelta.y
666+
_containerRect!.top -
667+
_areaClientLocation.y2 -
668+
this._scrollDelta.y +
669+
startScrollMargins.y
667670
)
668671
: 0;
669672
y2 = max(y2, this._container!.scrollTop);
@@ -674,10 +677,11 @@ export class SelectionArea extends EventTarget<SelectionEvents> {
674677
_scrollSpeed.y =
675678
scrollHeight - scrollTop - clientHeight
676679
? abs(
677-
_containerRect!.top +
678-
this._container!.clientHeight -
679-
_areaClientLocation.y2 -
680-
this._scrollDelta.y
680+
_areaClientLocation.y2 +
681+
this._scrollDelta.y -
682+
(_containerRect!.top +
683+
this._container!.clientHeight -
684+
startScrollMargins.y)
681685
)
682686
: 0;
683687
y2 = clientHeight + scrollTop;

packages/selection/src/react/BlockSelectionPlugin.tsx

-7
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,6 @@ export const BlockSelectionPlugin = createTPlatePlugin<BlockSelectionConfig>({
9292
},
9393
options: {
9494
areaOptions: {
95-
behaviour: {
96-
scrolling: {
97-
speedDivider: 5,
98-
startScrollMargins: { x: 20, y: 0 },
99-
},
100-
startThreshold: 5,
101-
},
10295
features: {
10396
singleTap: {
10497
allow: false,

yarn.lock

+3-3
Original file line numberDiff line numberDiff line change
@@ -6203,7 +6203,7 @@ __metadata:
62036203
resolution: "@udecode/plate-ai@workspace:packages/ai"
62046204
dependencies:
62056205
"@udecode/plate-combobox": "npm:40.0.0"
6206-
"@udecode/plate-markdown": "npm:40.0.4"
6206+
"@udecode/plate-markdown": "npm:40.0.5"
62076207
"@udecode/plate-selection": "npm:40.0.0"
62086208
ai: "npm:^3.4.10"
62096209
lodash: "npm:^4.17.21"
@@ -6909,7 +6909,7 @@ __metadata:
69096909
languageName: unknown
69106910
linkType: soft
69116911

6912-
"@udecode/plate-markdown@npm:40.0.4, @udecode/plate-markdown@workspace:^, @udecode/plate-markdown@workspace:packages/markdown":
6912+
"@udecode/plate-markdown@npm:40.0.5, @udecode/plate-markdown@workspace:^, @udecode/plate-markdown@workspace:packages/markdown":
69136913
version: 0.0.0-use.local
69146914
resolution: "@udecode/plate-markdown@workspace:packages/markdown"
69156915
dependencies:
@@ -7300,7 +7300,7 @@ __metadata:
73007300
"@udecode/plate-line-height": "npm:40.0.0"
73017301
"@udecode/plate-link": "npm:40.0.0"
73027302
"@udecode/plate-list": "npm:40.0.0"
7303-
"@udecode/plate-markdown": "npm:40.0.4"
7303+
"@udecode/plate-markdown": "npm:40.0.5"
73047304
"@udecode/plate-media": "npm:40.0.0"
73057305
"@udecode/plate-mention": "npm:40.0.0"
73067306
"@udecode/plate-node-id": "npm:40.0.0"

0 commit comments

Comments
 (0)