Skip to content

API > @blocksuite/store > Text

Class: Text ​

Constructors ​

constructor ​

new Text(input?): Text

Parameters ​

ParameterType
input?string | Text

Returns ​

Text

Defined In ​

packages/store/src/yjs/text-adapter.ts:19

Properties ​

_yText ​

private readonly _yText: Text

Defined In ​

packages/store/src/yjs/text-adapter.ts:17

Accessors ​

length ​

get length(): number

Defined In ​

packages/store/src/yjs/text-adapter.ts:35


yText ​

get yText(): Text

Defined In ​

packages/store/src/yjs/text-adapter.ts:39

Methods ​

_transact ​

private _transact(callback): void

Parameters ​

ParameterType
callbackfunction

Returns ​

void

Defined In ​

packages/store/src/yjs/text-adapter.ts:43


applyDelta ​

applyDelta(delta): void

Parameters ​

ParameterType
deltaDeltaOperation[]

Returns ​

void

Defined In ​

packages/store/src/yjs/text-adapter.ts:241


clear ​

clear(): void

Returns ​

void

Defined In ​

packages/store/src/yjs/text-adapter.ts:232


clone ​

clone(): Text

Returns ​

Text

Defined In ​

packages/store/src/yjs/text-adapter.ts:55


delete ​

delete(index, length): void

Parameters ​

ParameterType
indexnumber
lengthnumber

Returns ​

void

Defined In ​

packages/store/src/yjs/text-adapter.ts:190


format ​

format( index, length, format): void

Parameters ​

ParameterType
indexnumber
lengthnumber
formatany

Returns ​

void

Defined In ​

packages/store/src/yjs/text-adapter.ts:171


insert ​

insert( content, index, attributes?): void

Parameters ​

ParameterType
contentstring
indexnumber
attributes?Record< string, unknown >

Returns ​

void

Defined In ​

packages/store/src/yjs/text-adapter.ts:121


insertList ​

insertList(insertTexts, index): void

Parameters ​

ParameterType
insertTextsDeltaOperation[]
indexnumber

Returns ​

void

Deprecated ​

Use insert or applyDelta instead.

Defined In ​

packages/store/src/yjs/text-adapter.ts:143


join ​

join(other): void

Parameters ​

ParameterType
otherText

Returns ​

void

Defined In ​

packages/store/src/yjs/text-adapter.ts:159


replace ​

replace( index, length, content, attributes?): void

Parameters ​

ParameterType
indexnumber
lengthnumber
contentstring
attributes?object
attributes.bold?null | true
attributes.code?null | true
attributes.italic?null | true
attributes.link?null | string
attributes.strike?null | true
attributes.underline?null | true

Returns ​

void

Defined In ​

packages/store/src/yjs/text-adapter.ts:209


sliceToDelta ​

sliceToDelta(begin, end?): DeltaOperation[]

Parameters ​

ParameterType
beginnumber
end?number

Returns ​

DeltaOperation[]

Defined In ​

packages/store/src/yjs/text-adapter.ts:251


split ​

split(index, length = 0): Text

NOTE: The string included in [index, index + length) will be deleted.

Here are three cases for point position(index + length): [{insert: 'abc', ...}, {insert: 'def', ...}, {insert: 'ghi', ...}]

  1. abc|de|fghi left: [{insert: 'abc', ...}] right: [{insert: 'f', ...}, {insert: 'ghi', ...}]
  2. abc|def|ghi left: [{insert: 'abc', ...}] right: [{insert: 'ghi', ...}]
  3. abc|defg|hi left: [{insert: 'abc', ...}] right: [{insert: 'hi', ...}]

Parameters ​

ParameterTypeDefault value
indexnumberundefined
lengthnumber0

Returns ​

Text

Defined In ​

packages/store/src/yjs/text-adapter.ts:74


toDelta ​

toDelta(): DeltaOperation[]

Returns ​

DeltaOperation[]

Defined In ​

packages/store/src/yjs/text-adapter.ts:247


toString ​

toString(): string

Returns ​

string

Defined In ​

packages/store/src/yjs/text-adapter.ts:301


fromDelta ​

static fromDelta(delta): Text

Parameters ​

ParameterType
deltaDeltaOperation[]

Returns ​

Text

Defined In ​

packages/store/src/yjs/text-adapter.ts:29