fix:setTimeout error (#215)

This commit is contained in:
DiamondThree
2022-08-12 17:04:12 +08:00
committed by GitHub
parent edfa95057b
commit ce0590449a

View File

@@ -48,7 +48,7 @@ export class SelectionManager implements VirgoSelection {
private _scrollDelay = 150; private _scrollDelay = 150;
private _selectEndDelayTime = 500; private _selectEndDelayTime = 500;
private _hasEmitEndPending = false; private _hasEmitEndPending = false;
private _scrollTimer: number | null = null;
/** /**
* *
* the selection info before current * the selection info before current
@@ -681,6 +681,9 @@ export class SelectionManager implements VirgoSelection {
*/ */
public async activeNodeByNodeId(nodeId: string, position?: CursorTypes) { public async activeNodeByNodeId(nodeId: string, position?: CursorTypes) {
try { try {
if (this._scrollTimer) {
clearTimeout(this._scrollTimer);
}
const node = await this._editor.getBlockById(nodeId); const node = await this._editor.getBlockById(nodeId);
if (node) { if (node) {
this._activatedNodeId = nodeId; this._activatedNodeId = nodeId;
@@ -689,7 +692,7 @@ export class SelectionManager implements VirgoSelection {
} }
this.emit(nodeId, SelectEventTypes.active, this.lastPoint); this.emit(nodeId, SelectEventTypes.active, this.lastPoint);
// TODO: Optimize the related logic after implementing the scroll bar // TODO: Optimize the related logic after implementing the scroll bar
setTimeout(() => { this._scrollTimer = window.setTimeout(() => {
this._editor.scrollManager.keepBlockInView(node); this._editor.scrollManager.keepBlockInView(node);
}, this._scrollDelay); }, this._scrollDelay);
} else { } else {