Skip to content

API > @blocksuite/virgo > VirgoDeltaService

Class: VirgoDeltaService<TextAttributes> ​

Constructors ​

constructor ​

new VirgoDeltaService<TextAttributes>(editor): VirgoDeltaService< TextAttributes >

Type parameters ​

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

Parameters ​

ParameterType
editorVEditor< TextAttributes >

Returns ​

VirgoDeltaService< TextAttributes >

Defined In ​

packages/virgo/src/services/delta.ts:12

Properties ​

editor ​

readonly editor: VEditor< TextAttributes >

Defined In ​

packages/virgo/src/services/delta.ts:12

Accessors ​

deltas ​

get deltas(): DeltaInsert< TextAttributes >[]

Defined In ​

packages/virgo/src/services/delta.ts:14


normalizedDeltas ​

get normalizedDeltas(): DeltaInsert< TextAttributes >[]

Defined In ​

packages/virgo/src/services/delta.ts:18

Methods ​

getDeltaByRangeIndex ​

getDeltaByRangeIndex(rangeIndex): null | DeltaInsert< TextAttributes >

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/services/delta.ts:119


getDeltasByVRange ​

getDeltasByVRange(vRange): DeltaEntry< TextAttributes >[]

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/services/delta.ts:189


isNormalizedDeltaSelected ​

isNormalizedDeltaSelected(normalizedDeltaIndex, vRange): boolean

Parameters ​

ParameterType
normalizedDeltaIndexnumber
vRangeVRange

Returns ​

boolean

Defined In ​

packages/virgo/src/services/delta.ts:70


mapDeltasInVRange ​

mapDeltasInVRange<Result>( vRange, callback, normalize = false): Result[]

Type parameters ​

Parameter
Result

Parameters ​

ParameterTypeDefault value
vRangeVRangeundefined
callbackfunctionundefined
normalizebooleanfalse

Returns ​

Result[]

Defined In ​

packages/virgo/src/services/delta.ts:37


render ​

render(syncVRange = true): Promise< void >

Parameters ​

ParameterTypeDefault value
syncVRangebooleantrue

Returns ​

Promise< void >

Defined In ​

packages/virgo/src/services/delta.ts:200