-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
TextEditingManager.ts
49 lines (41 loc) · 1.11 KB
/
TextEditingManager.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { TPointerEvent } from '../EventTypeDefs';
import type { IText } from '../shapes/itext.class';
import type { Textbox } from '../shapes/textbox.class';
import { removeFromArray } from '../util/internals';
/**
* In charge of synchronizing all interactive text instances of a canvas
*/
export class TextEditingManager {
private targets: (IText | Textbox)[] = [];
private declare target?: IText | Textbox;
exitTextEditing() {
this.target = undefined;
this.targets.forEach((target) => {
if (target.isEditing) {
target.exitEditing();
}
});
}
add(target: IText | Textbox) {
this.targets.push(target);
}
remove(target: IText | Textbox) {
this.unregister(target);
removeFromArray(this.targets, target);
}
register(target: IText | Textbox) {
this.target = target;
}
unregister(target: IText | Textbox) {
if (target === this.target) {
this.target = undefined;
}
}
onMouseMove(e: TPointerEvent) {
this.target?.isEditing && this.target.updateSelectionOnMouseMove(e);
}
dispose() {
this.targets = [];
this.target = undefined;
}
}