@blocksuite/virgo
Advanced tools
Comparing version 0.5.0-20230310090329-2ebbde2 to 0.5.0-20230310095333-5202fb9
@@ -33,2 +33,4 @@ import { Slot } from '@blocksuite/global/utils'; | ||
private _yText; | ||
private _previousAnchor; | ||
private _previousFocus; | ||
private _attributesRenderer; | ||
@@ -75,3 +77,3 @@ private _attributesSchema; | ||
*/ | ||
syncVRange(type?: 'async' | 'sync'): void; | ||
syncVRange(): void; | ||
/** | ||
@@ -78,0 +80,0 @@ * calculate the dom selection from vRange for **this Editor** |
@@ -146,2 +146,4 @@ import { assertExists, Slot } from '@blocksuite/global/utils'; | ||
this._isReadonly = false; | ||
this._previousAnchor = null; | ||
this._previousFocus = null; | ||
this._attributesRenderer = getDefaultAttributeRenderer(); | ||
@@ -340,2 +342,4 @@ this._attributesSchema = baseTextAttributes; | ||
return; | ||
this._previousAnchor = [range.startContainer, range.startOffset]; | ||
this._previousFocus = [range.endContainer, range.endOffset]; | ||
const vRange = this.toVRange(selection); | ||
@@ -345,5 +349,12 @@ if (vRange) { | ||
} | ||
if (range.startContainer.nodeType !== Node.TEXT_NODE || | ||
range.endContainer.nodeType !== Node.TEXT_NODE) { | ||
this.syncVRange('sync'); | ||
// avoid infinite syncVRange | ||
if (((range.startContainer.nodeType !== Node.TEXT_NODE || | ||
range.endContainer.nodeType !== Node.TEXT_NODE) && | ||
range.startContainer !== this._previousAnchor[0] && | ||
range.endContainer !== this._previousFocus[0] && | ||
range.startOffset !== this._previousAnchor[1] && | ||
range.endOffset !== this._previousFocus[1]) || | ||
range.startContainer.nodeType === Node.COMMENT_NODE || | ||
range.endContainer.nodeType === Node.COMMENT_NODE) { | ||
this.syncVRange(); | ||
} | ||
@@ -568,3 +579,2 @@ }; | ||
}); | ||
this.syncVRange(); | ||
} | ||
@@ -626,22 +636,14 @@ deleteText(vRange) { | ||
*/ | ||
syncVRange(type = 'async') { | ||
const fn = () => { | ||
if (this._vRange) { | ||
const newRange = this.toDomRange(this._vRange); | ||
if (newRange) { | ||
const selectionRoot = findDocumentOrShadowRoot(this); | ||
const selection = selectionRoot.getSelection(); | ||
if (selection) { | ||
selection.removeAllRanges(); | ||
selection.addRange(newRange); | ||
} | ||
syncVRange() { | ||
if (this._vRange) { | ||
const newRange = this.toDomRange(this._vRange); | ||
if (newRange) { | ||
const selectionRoot = findDocumentOrShadowRoot(this); | ||
const selection = selectionRoot.getSelection(); | ||
if (selection) { | ||
selection.removeAllRanges(); | ||
selection.addRange(newRange); | ||
} | ||
} | ||
}; | ||
if (type === 'async') { | ||
requestAnimationFrame(fn); | ||
} | ||
else { | ||
fn(); | ||
} | ||
} | ||
@@ -648,0 +650,0 @@ /** |
{ | ||
"name": "@blocksuite/virgo", | ||
"version": "0.5.0-20230310090329-2ebbde2", | ||
"version": "0.5.0-20230310095333-5202fb9", | ||
"description": "A micro editor.", | ||
@@ -26,3 +26,3 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@blocksuite/global": "0.5.0-20230310090329-2ebbde2", | ||
"@blocksuite/global": "0.5.0-20230310095333-5202fb9", | ||
"zod": "^3.20.6" | ||
@@ -29,0 +29,0 @@ }, |
@@ -9,3 +9,3 @@ import type { | ||
testIgnore: ['**.unit.spec.ts'], | ||
workers: 1, | ||
workers: 4, | ||
use: { | ||
@@ -12,0 +12,0 @@ browserName: |
@@ -205,2 +205,5 @@ import { assertExists, Slot } from '@blocksuite/global/utils'; | ||
private _previousAnchor: NativePoint | null = null; | ||
private _previousFocus: NativePoint | null = null; | ||
private _attributesRenderer: AttributesRenderer<TextAttributes> = | ||
@@ -541,4 +544,2 @@ getDefaultAttributeRenderer<TextAttributes>(); | ||
}); | ||
this.syncVRange(); | ||
} | ||
@@ -636,22 +637,14 @@ | ||
*/ | ||
syncVRange(type: 'async' | 'sync' = 'async'): void { | ||
const fn = () => { | ||
if (this._vRange) { | ||
const newRange = this.toDomRange(this._vRange); | ||
syncVRange(): void { | ||
if (this._vRange) { | ||
const newRange = this.toDomRange(this._vRange); | ||
if (newRange) { | ||
const selectionRoot = findDocumentOrShadowRoot(this); | ||
const selection = selectionRoot.getSelection(); | ||
if (selection) { | ||
selection.removeAllRanges(); | ||
selection.addRange(newRange); | ||
} | ||
if (newRange) { | ||
const selectionRoot = findDocumentOrShadowRoot(this); | ||
const selection = selectionRoot.getSelection(); | ||
if (selection) { | ||
selection.removeAllRanges(); | ||
selection.addRange(newRange); | ||
} | ||
} | ||
}; | ||
if (type === 'async') { | ||
requestAnimationFrame(fn); | ||
} else { | ||
fn(); | ||
} | ||
@@ -1025,2 +1018,5 @@ } | ||
this._previousAnchor = [range.startContainer, range.startOffset]; | ||
this._previousFocus = [range.endContainer, range.endOffset]; | ||
const vRange = this.toVRange(selection); | ||
@@ -1031,7 +1027,14 @@ if (vRange) { | ||
// avoid infinite syncVRange | ||
if ( | ||
range.startContainer.nodeType !== Node.TEXT_NODE || | ||
range.endContainer.nodeType !== Node.TEXT_NODE | ||
((range.startContainer.nodeType !== Node.TEXT_NODE || | ||
range.endContainer.nodeType !== Node.TEXT_NODE) && | ||
range.startContainer !== this._previousAnchor[0] && | ||
range.endContainer !== this._previousFocus[0] && | ||
range.startOffset !== this._previousAnchor[1] && | ||
range.endOffset !== this._previousFocus[1]) || | ||
range.startContainer.nodeType === Node.COMMENT_NODE || | ||
range.endContainer.nodeType === Node.COMMENT_NODE | ||
) { | ||
this.syncVRange('sync'); | ||
this.syncVRange(); | ||
} | ||
@@ -1038,0 +1041,0 @@ }; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
364346
4909
+ Added@blocksuite/global@0.5.0-20230310095333-5202fb9(transitive)
- Removed@blocksuite/global@0.5.0-20230310090329-2ebbde2(transitive)