Skip to content

API > @blocksuite/virgo > VEditor

Class: VEditor<TextAttributes> ​

Constructors ​

constructor ​

new VEditor<TextAttributes>(yText, ops = {}): VEditor< TextAttributes >

Type parameters ​

ParameterDefault
TextAttributes extends {bold: null | true; code: null | true; italic: null | true; link: null | string; strike: null | true; underline: null | true;}{bold: null | true; code: null | true; italic: null | true; link: null | string; strike: null | true; underline: null | true;}

Parameters ​

ParameterType
yTextText
opsobject
ops.hooks?object
ops.hooks.beforeinput?function
ops.hooks.compositionEnd?function
ops.isEmbed?function
ops.vRangeProvider?VRangeProvider

Returns ​

VEditor< TextAttributes >

Defined In ​

packages/virgo/src/virgo.ts:158

Properties ​

_attributeService ​

private _attributeService: VirgoAttributeService< TextAttributes >

Defined In ​

packages/virgo/src/virgo.ts:56


_deltaService ​

private _deltaService: VirgoDeltaService< TextAttributes >

Defined In ​

packages/virgo/src/virgo.ts:59


_disposables ​

private _disposables: DisposableGroup

Defined In ​

packages/virgo/src/virgo.ts:41


_eventService ​

private _eventService: VirgoEventService< TextAttributes >

Defined In ​

packages/virgo/src/virgo.ts:50


_hooksService ​

private _hooksService: VirgoHookService< TextAttributes >

Defined In ​

packages/virgo/src/virgo.ts:62


_isReadonly ​

private _isReadonly: boolean = false

Defined In ​

packages/virgo/src/virgo.ts:48


_mounted ​

private _mounted: boolean = false

Defined In ​

packages/virgo/src/virgo.ts:64


_rangeService ​

private _rangeService: VirgoRangeService< TextAttributes >

Defined In ​

packages/virgo/src/virgo.ts:53


_rootElement ​

private _rootElement: null | VirgoRootElement< TextAttributes > = null

Defined In ​

packages/virgo/src/virgo.ts:47


_yText ​

private readonly _yText: Text

Defined In ​

packages/virgo/src/virgo.ts:46


focusEnd ​

focusEnd: function

Returns ​

void

Defined In ​

packages/virgo/src/virgo.ts:142


focusIndex ​

focusIndex: function

Parameters ​

ParameterType
indexnumber

Returns ​

void

Defined In ​

packages/virgo/src/virgo.ts:144


focusStart ​

focusStart: function

Returns ​

void

Defined In ​

packages/virgo/src/virgo.ts:141


getDeltaByRangeIndex ​

getDeltaByRangeIndex: function

Here are examples of how this function computes and gets the delta.

We have such a text:

[
  {
     insert: 'aaa',
     attributes: { bold: true },
  },
  {
     insert: 'bbb',
     attributes: { italic: true },
  },
]
[
  {
     insert: 'aaa',
     attributes: { bold: true },
  },
  {
     insert: 'bbb',
     attributes: { italic: true },
  },
]

getDeltaByRangeIndex(0) returns { insert: 'aaa', attributes: { bold: true } }.

getDeltaByRangeIndex(1) returns { insert: 'aaa', attributes: { bold: true } }.

getDeltaByRangeIndex(3) returns { insert: 'aaa', attributes: { bold: true } }.

getDeltaByRangeIndex(4) returns { insert: 'bbb', attributes: { italic: true } }.

Parameters ​

ParameterType
rangeIndexnumber

Returns ​

null | DeltaInsert< TextAttributes >

Defined In ​

packages/virgo/src/virgo.ts:149


getDeltasByVRange ​

getDeltasByVRange: function

Here are examples of how this function computes and gets the deltas.

We have such a text:

[
  {
     insert: 'aaa',
     attributes: { bold: true },
  },
  {
     insert: 'bbb',
     attributes: { italic: true },
  },
  {
     insert: 'ccc',
     attributes: { underline: true },
  },
]
[
  {
     insert: 'aaa',
     attributes: { bold: true },
  },
  {
     insert: 'bbb',
     attributes: { italic: true },
  },
  {
     insert: 'ccc',
     attributes: { underline: true },
  },
]

getDeltasByVRange({ index: 0, length: 0 }) returns

[{ insert: 'aaa', attributes: { bold: true }, }, { index: 0, length: 3, }]]
[{ insert: 'aaa', attributes: { bold: true }, }, { index: 0, length: 3, }]]

getDeltasByVRange({ index: 0, length: 1 }) returns

[{ insert: 'aaa', attributes: { bold: true }, }, { index: 0, length: 3, }]]
[{ insert: 'aaa', attributes: { bold: true }, }, { index: 0, length: 3, }]]

getDeltasByVRange({ index: 0, length: 4 }) returns

[{ insert: 'aaa', attributes: { bold: true }, }, { index: 0, length: 3, }],
 [{ insert: 'bbb', attributes: { italic: true }, }, { index: 3, length: 3, }]]
[{ insert: 'aaa', attributes: { bold: true }, }, { index: 0, length: 3, }],
 [{ insert: 'bbb', attributes: { italic: true }, }, { index: 3, length: 3, }]]

getDeltasByVRange({ index: 3, length: 1 }) returns

[{ insert: 'aaa', attributes: { bold: true }, }, { index: 0, length: 3, }],
 [{ insert: 'bbb', attributes: { italic: true }, }, { index: 3, length: 3, }]]
[{ insert: 'aaa', attributes: { bold: true }, }, { index: 0, length: 3, }],
 [{ insert: 'bbb', attributes: { italic: true }, }, { index: 3, length: 3, }]]

getDeltasByVRange({ index: 3, length: 3 }) returns

[{ insert: 'aaa', attributes: { bold: true }, }, { index: 0, length: 3, }],
 [{ insert: 'bbb', attributes: { italic: true }, }, { index: 3, length: 3, }]]
[{ insert: 'aaa', attributes: { bold: true }, }, { index: 0, length: 3, }],
 [{ insert: 'bbb', attributes: { italic: true }, }, { index: 3, length: 3, }]]

getDeltasByVRange({ index: 3, length: 4 }) returns

[{ insert: 'aaa', attributes: { bold: true }, }, { index: 0, length: 3, }],
 [{ insert: 'bbb', attributes: { italic: true }, }, { index: 3, length: 3, }],
 [{ insert: 'ccc', attributes: { underline: true }, }, { index: 6, length: 3, }]]
[{ insert: 'aaa', attributes: { bold: true }, }, { index: 0, length: 3, }],
 [{ insert: 'bbb', attributes: { italic: true }, }, { index: 3, length: 3, }],
 [{ insert: 'ccc', attributes: { underline: true }, }, { index: 6, length: 3, }]]

Parameters ​

ParameterType
vRangeVRange

Returns ​

DeltaEntry< TextAttributes >[]

Defined In ​

packages/virgo/src/virgo.ts:148


getFormat ​

getFormat: function

Parameters ​

ParameterTypeDefault value
vRangeVRangeundefined
loosebooleanfalse

Returns ​

TextAttributes

Defined In ​

packages/virgo/src/virgo.ts:127


getLine ​

getLine: function

Parameters ​

ParameterType
rangeIndexnumber

Returns ​

readonly [VirgoLine, number]

Defined In ​

packages/virgo/src/virgo.ts:136


getNativeSelection ​

getNativeSelection: function

Returns ​

null | Selection

Defined In ​

packages/virgo/src/virgo.ts:134


getTextPoint ​

getTextPoint: function

Parameters ​

ParameterType
rangeIndexnumber

Returns ​

TextPoint

Defined In ​

packages/virgo/src/virgo.ts:135


getVRange ​

getVRange: function

Returns ​

null | VRange

Defined In ​

packages/virgo/src/virgo.ts:132


getVRangeFromElement ​

getVRangeFromElement: function

Parameters ​

ParameterType
elementElement

Returns ​

null | VRange

Defined In ​

packages/virgo/src/virgo.ts:133


isEmbed ​

readonly isEmbed: function

Parameters ​

ParameterType
deltaDeltaInsert< TextAttributes >

Returns ​

boolean

Defined In ​

packages/virgo/src/virgo.ts:66


isFirstLine ​

isFirstLine: function

There are two cases to have the second line:

  1. long text auto wrap in span element
  2. soft break

Parameters ​

ParameterType
vRangenull | VRange

Returns ​

boolean

Defined In ​

packages/virgo/src/virgo.ts:138


isLastLine ​

isLastLine: function

There are two cases to have the second line:

  1. long text auto wrap in span element
  2. soft break

Parameters ​

ParameterType
vRangenull | VRange

Returns ​

boolean

Defined In ​

packages/virgo/src/virgo.ts:139


isNormalizedDeltaSelected ​

isNormalizedDeltaSelected: function

Parameters ​

ParameterType
normalizedDeltaIndexnumber
vRangeVRange

Returns ​

boolean

Defined In ​

packages/virgo/src/virgo.ts:151


isVRangeValid ​

isVRangeValid: function

Parameters ​

ParameterType
vRangenull | VRange

Returns ​

boolean

Defined In ​

packages/virgo/src/virgo.ts:137


mapDeltasInVRange ​

mapDeltasInVRange: function

Type parameters ​

Parameter
Result

Parameters ​

ParameterTypeDefault value
vRangeVRangeundefined
callbackfunctionundefined
normalizebooleanfalse

Returns ​

Result[]

Defined In ​

packages/virgo/src/virgo.ts:150


resetMarks ​

resetMarks: function

Returns ​

void

Defined In ​

packages/virgo/src/virgo.ts:126


selectAll ​

selectAll: function

Returns ​

void

Defined In ​

packages/virgo/src/virgo.ts:143


setAttributeRenderer ​

setAttributeRenderer: function

Parameters ​

ParameterType
rendererAttributeRenderer< TextAttributes >

Returns ​

void

Defined In ​

packages/virgo/src/virgo.ts:124


setAttributeSchema ​

setAttributeSchema: function

Parameters ​

ParameterType
schemaZodType< TextAttributes, ZodTypeDef, unknown >

Returns ​

void

Defined In ​

packages/virgo/src/virgo.ts:123


setMarks ​

setMarks: function

Parameters ​

ParameterType
marksTextAttributes

Returns ​

void

Defined In ​

packages/virgo/src/virgo.ts:125


setVRange ​

setVRange: function

the vRange is synced to the native selection asynchronically if sync is true, the native selection will be synced immediately

Parameters ​

ParameterTypeDefault value
vRangenull | VRangeundefined
syncbooleantrue

Returns ​

void

Defined In ​

packages/virgo/src/virgo.ts:140


slots ​

slots: object

Type declaration ​

slots.mounted ​

mounted: Slot< void >

slots.rangeUpdated ​

rangeUpdated: Slot< Range >

slots.unmounted ​

unmounted: Slot< void >

slots.updated ​

updated: Slot< void >

slots.vRangeUpdated ​

vRangeUpdated: Slot< VRangeUpdatedProp >

Defined In ​

packages/virgo/src/virgo.ts:69


syncVRange ​

syncVRange: function

sync the dom selection from vRange for this Editor

Returns ​

void

Defined In ​

packages/virgo/src/virgo.ts:145


toDomRange ​

toDomRange: function

calculate the dom selection from vRange for this Editor

Parameters ​

ParameterType
vRangeVRange

Returns ​

null | Range

Defined In ​

packages/virgo/src/virgo.ts:130


toVRange ​

toVRange: function

calculate the vRange from dom selection for this Editor there are three cases when the vRange of this Editor is not null: (In the following, "|" mean anchor and focus, each line is a separate Editor)

  1. anchor and focus are in this Editor aaaaaa b|bbbb|b cccccc the vRange of second Editor is {index: 1, length: 4}, the others are null
  2. anchor and focus one in this Editor, one in another Editor aaa|aaa aaaaaa bbbbb|b or bbbbb|b cccccc cc|cccc 2.1 the vRange of first Editor is {index: 3, length: 3}, the second is {index: 0, length: 5}, the third is null 2.2 the vRange of first Editor is null, the second is {index: 5, length: 1}, the third is
  3. anchor and focus are in another Editor aa|aaaa bbbbbb cccc|cc the vRange of first Editor is {index: 2, length: 4}, the second is {index: 0, length: 6}, the third is

Parameters ​

ParameterType
rangeRange

Returns ​

null | VRange

Defined In ​

packages/virgo/src/virgo.ts:131


vRangeProvider ​

readonly vRangeProvider: null | VRangeProvider

Defined In ​

packages/virgo/src/virgo.ts:67


getTextNodesFromElement ​

static getTextNodesFromElement: function = getTextNodesFromElement

Parameters ​

ParameterType
elementElement

Returns ​

Text[]

Defined In ​

packages/virgo/src/virgo.ts:39


nativePointToTextPoint ​

static nativePointToTextPoint: function = nativePointToTextPoint

Parameters ​

ParameterType
nodeunknown
offsetnumber

Returns ​

TextPoint | null

Defined In ​

packages/virgo/src/virgo.ts:37


textPointToDomPoint ​

static textPointToDomPoint: function = textPointToDomPoint

Parameters ​

ParameterType
textText
offsetnumber
rootElementHTMLElement

Returns ​

DomPoint | null

Defined In ​

packages/virgo/src/virgo.ts:38

Accessors ​

attributeService ​

get attributeService(): VirgoAttributeService< TextAttributes >

Defined In ​

packages/virgo/src/virgo.ts:106


deltaService ​

get deltaService(): VirgoDeltaService< TextAttributes >

Defined In ​

packages/virgo/src/virgo.ts:110


disposables ​

get disposables(): DisposableGroup

Defined In ​

packages/virgo/src/virgo.ts:42


eventService ​

get eventService(): VirgoEventService< TextAttributes >

Defined In ​

packages/virgo/src/virgo.ts:98


hooks ​

get hooks(): object

Defined In ​

packages/virgo/src/virgo.ts:154


isReadonly ​

get isReadonly(): boolean

Defined In ​

packages/virgo/src/virgo.ts:238


marks ​

get marks(): null | TextAttributes

Defined In ​

packages/virgo/src/virgo.ts:119


mounted ​

get mounted(): boolean

Defined In ​

packages/virgo/src/virgo.ts:114


rangeService ​

get rangeService(): VirgoRangeService< TextAttributes >

Defined In ​

packages/virgo/src/virgo.ts:102


rootElement ​

get rootElement(): VirgoRootElement< TextAttributes >

Defined In ​

packages/virgo/src/virgo.ts:93


yText ​

get yText(): Text

Defined In ​

packages/virgo/src/virgo.ts:77


yTextDeltas ​

get yTextDeltas(): any

Defined In ​

packages/virgo/src/virgo.ts:89


yTextLength ​

get yTextLength(): number

Defined In ​

packages/virgo/src/virgo.ts:85


yTextString ​

get yTextString(): string

Defined In ​

packages/virgo/src/virgo.ts:81

Methods ​

_bindYTextObserver ​

private _bindYTextObserver(): void

Returns ​

void

Defined In ​

packages/virgo/src/virgo.ts:371


_onYTextChange ​

private _onYTextChange(): void

Returns ​

void

Defined In ​

packages/virgo/src/virgo.ts:350


_transact ​

private _transact(fn): void

Parameters ​

ParameterType
fnfunction

Returns ​

void

Defined In ​

packages/virgo/src/virgo.ts:362


deleteText ​

deleteText(vRange): void

Parameters ​

ParameterType
vRangeVRange

Returns ​

void

Defined In ​

packages/virgo/src/virgo.ts:242


formatText ​

formatText( vRange, attributes, options = {}): void

Parameters ​

ParameterType
vRangeVRange
attributesTextAttributes
optionsobject
options.match?function
options.mode?"replace" | "merge"

Returns ​

void

Defined In ​

packages/virgo/src/virgo.ts:276


insertLineBreak ​

insertLineBreak(vRange): void

Parameters ​

ParameterType
vRangeVRange

Returns ​

void

Defined In ​

packages/virgo/src/virgo.ts:269


insertText ​

insertText( vRange, text, attributes = ...): void

Parameters ​

ParameterType
vRangeVRange
textstring
attributesTextAttributes

Returns ​

void

Defined In ​

packages/virgo/src/virgo.ts:248


mount ​

mount(rootElement): void

Parameters ​

ParameterType
rootElementHTMLElement

Returns ​

void

Defined In ​

packages/virgo/src/virgo.ts:198


requestUpdate ​

requestUpdate(syncVRange = true): void

Parameters ​

ParameterTypeDefault value
syncVRangebooleantrue

Returns ​

void

Defined In ​

packages/virgo/src/virgo.ts:224


rerenderWholeEditor ​

rerenderWholeEditor(): void

Returns ​

void

Defined In ​

packages/virgo/src/virgo.ts:345


resetText ​

resetText(vRange): void

Parameters ​

ParameterType
vRangeVRange

Returns ​

void

Defined In ​

packages/virgo/src/virgo.ts:311


setReadonly ​

setReadonly(isReadonly): void

Parameters ​

ParameterType
isReadonlyboolean

Returns ​

void

Defined In ​

packages/virgo/src/virgo.ts:233


setText ​

setText(text, attributes = ...): void

Parameters ​

ParameterType
textstring
attributesTextAttributes

Returns ​

void

Defined In ​

packages/virgo/src/virgo.ts:335


unmount ​

unmount(): void

Returns ​

void

Defined In ​

packages/virgo/src/virgo.ts:215


waitForUpdate ​

waitForUpdate(): Promise< void >

Returns ​

Promise< void >

Defined In ​

packages/virgo/src/virgo.ts:228