Skip to content

Commit c88e6e9

Browse files
author
Vinogradov Victor
committed
scrollZones
1 parent 4edea7c commit c88e6e9

File tree

5 files changed

+37
-61
lines changed

5 files changed

+37
-61
lines changed

dist/editor.js

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

docs/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
### 2.11.2
4+
5+
- `Fix` *RectangeSelection* — Redesign of the scrolling zones
6+
37
### 2.11.1
48

59
- `Fix` *RectangeSelection* — Selection is available only for the main mouse button

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@editorjs/editorjs",
3-
"version": "2.11.1",
3+
"version": "2.11.2",
44
"description": "Editor.js — Native JS, based on API and Open Source",
55
"main": "dist/editor.js",
66
"types": "./types/index.d.ts",

src/components/modules/rectangleSelection.ts

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default class RectangleSelection extends Module {
3636
/**
3737
* Speed of Scrolling
3838
*/
39-
private readonly SCROLL_SPEED: number = 3;
39+
private readonly SCROLL_SPEED: number = 1;
4040

4141
/**
4242
* Height of scroll zone on boundary of screen
@@ -87,45 +87,22 @@ export default class RectangleSelection extends Module {
8787
*/
8888
private overlayRectangle: HTMLDivElement;
8989

90-
/**
91-
* Coords of redactor
92-
*/
93-
private left;
94-
private top;
95-
9690
/**
9791
* Module Preparation
9892
* Creating rect and hang handlers
9993
*/
10094
public prepare(): void {
10195
const {Listeners} = this.Editor;
102-
const {overlayTopScrollZone, overlayBottomScrollZone, container, overlay} = this.genHTML();
103-
104-
Listeners.on(overlayBottomScrollZone, 'mouseenter', (event) => {
105-
this.inScrollZone = this.BOTTOM_SCROLL_ZONE;
106-
this.scrollVertical(this.SCROLL_SPEED);
107-
});
108-
109-
Listeners.on(overlayTopScrollZone, 'mouseenter', (event) => {
110-
this.inScrollZone = this.TOP_SCROLL_ZONE;
111-
this.scrollVertical(-this.SCROLL_SPEED);
112-
});
113-
114-
Listeners.on(overlayBottomScrollZone, 'mouseleave', (event) => {
115-
this.inScrollZone = null;
116-
});
117-
118-
Listeners.on(overlayTopScrollZone, 'mouseleave', (event) => {
119-
this.inScrollZone = null;
120-
});
96+
const {container, overlay} = this.genHTML();
12197

12298
Listeners.on(container, 'mousedown', (event: MouseEvent) => {
12399
if (event.button !== this.MAIN_MOUSE_BUTTON) { return; }
124100
this.startSelection(event.pageX, event.pageY);
125101
}, false);
126102

127-
Listeners.on(document.body, 'mousemove', (event) => {
103+
Listeners.on(document.body, 'mousemove', (event: MouseEvent) => {
128104
this.changingRectangle(event);
105+
this.scrollByZones(event.clientY);
129106
}, false);
130107

131108
Listeners.on(document.body, 'mouseleave', (event) => {
@@ -135,6 +112,7 @@ export default class RectangleSelection extends Module {
135112

136113
Listeners.on(window, 'scroll', (event) => {
137114
this.changingRectangle(event);
115+
this.scrollByZones(null);
138116
}, false);
139117

140118
Listeners.on(document.body, 'mouseup', (event) => {
@@ -188,24 +166,40 @@ export default class RectangleSelection extends Module {
188166
this.isRectSelectionActivated = false;
189167
}
190168

169+
/**
170+
* Scroll If mouse in scroll zone
171+
* @param {number} clientY - Y coord of mouse
172+
*/
173+
private scrollByZones(clientY) {
174+
// Может быть 0
175+
if (clientY !== null) {
176+
this.inScrollZone = null;
177+
if (clientY <= this.HEIGHT_OF_SCROLL_ZONE) {
178+
this.inScrollZone = this.TOP_SCROLL_ZONE;
179+
}
180+
if (document.documentElement.clientHeight - clientY <= this.HEIGHT_OF_SCROLL_ZONE) {
181+
this.inScrollZone = this.BOTTOM_SCROLL_ZONE;
182+
}
183+
}
184+
if (!this.inScrollZone) {
185+
return;
186+
}
187+
188+
this.scrollVertical(this.inScrollZone === this.TOP_SCROLL_ZONE ? -this.SCROLL_SPEED : this.SCROLL_SPEED);
189+
}
190+
191191
private genHTML() {
192192
const container = document.querySelector('.' + UI.CSS.editorWrapper);
193193
const overlay = $.make('div', RectangleSelection.CSS.overlay, {});
194194
const overlayContainer = $.make('div', RectangleSelection.CSS.overlayContainer, {});
195195
const overlayRectangle = $.make('div', RectangleSelection.CSS.rect, {});
196-
const overlayTopScrollZone = $.make('div', RectangleSelection.CSS.topScrollZone, {});
197-
const overlayBottomScrollZone = $.make('div', RectangleSelection.CSS.bottomScrollZone, {});
198196

199197
overlayContainer.appendChild(overlayRectangle);
200198
overlay.appendChild(overlayContainer);
201-
document.body.appendChild(overlayTopScrollZone);
202-
document.body.appendChild(overlayBottomScrollZone);
203199
container.appendChild(overlay);
204200

205201
this.overlayRectangle = overlayRectangle as HTMLDivElement;
206202
return {
207-
overlayBottomScrollZone,
208-
overlayTopScrollZone,
209203
container,
210204
overlay,
211205
};

src/styles/ui.css

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -85,28 +85,6 @@
8585
background-color: rgba(46, 170, 220, 0.2);
8686
border: 1px solid transparent;
8787
}
88-
89-
&__scroll-zone {
90-
91-
92-
&--top {
93-
top: 0;
94-
width: 100%;
95-
height: 30px;
96-
position: fixed;
97-
pointer-events: auto;
98-
z-index: 10500;
99-
}
100-
101-
&--bottom {
102-
bottom: 0;
103-
width: 100%;
104-
height: 30px;
105-
position: fixed;
106-
pointer-events: auto;
107-
z-index: 10500;
108-
}
109-
}
11088
}
11189

11290
svg {

0 commit comments

Comments
 (0)