Skip to main content
Text operation commands provide basic clipboard and selection functionality.

executeCut

Cuts the selected content to the clipboard.
editor.command.executeCut(): Promise<void>

Example

await editor.command.executeCut()

Notes

  • Disabled in readonly mode
  • Disabled when editor is disabled
  • Removes selected content and copies to clipboard

executeCopy

Copies the selected content to the clipboard.
editor.command.executeCopy(options?: ICopyOption): Promise<void>

Parameters

options
ICopyOption
Optional copy configuration

Example

await editor.command.executeCopy()

Notes

  • Works in all editor modes including readonly
  • Copies to system clipboard

executePaste

Pastes content from the clipboard at the current cursor position.
editor.command.executePaste(options?: IPasteOption): void

Parameters

options
IPasteOption
Optional paste configuration

Example

editor.command.executePaste()

Notes

  • Disabled in readonly mode
  • Disabled when editor is disabled
  • Supports text, HTML, and image data from clipboard

executeSelectAll

Selects all content in the current context.
editor.command.executeSelectAll(): void

Example

editor.command.executeSelectAll()

Notes

  • If cursor is inside a table cell, selects all content in that cell
  • Otherwise, selects all document content

executeBackspace

Deletes the selected content or the character before the cursor.
editor.command.executeBackspace(): void

Example

editor.command.executeBackspace()

Notes

  • Disabled in readonly mode
  • Disabled when editor is disabled
  • Cannot delete the first character if it’s the document zero-width character
  • If text is selected, deletes the selection
  • If no selection, deletes one character before cursor

setRange

Sets the current selection range.
editor.command.executeSetRange(
  startIndex: number,
  endIndex: number,
  tableId?: string,
  startTdIndex?: number,
  endTdIndex?: number,
  startTrIndex?: number,
  endTrIndex?: number
): void

Parameters

startIndex
number
required
Start position index in the element list
endIndex
number
required
End position index in the element list
tableId
string
Table ID if selection is within a table
startTdIndex
number
Starting table cell index
endTdIndex
number
Ending table cell index
startTrIndex
number
Starting table row index
endTrIndex
number
Ending table row index

Example

// Select characters 10-20
editor.command.executeSetRange(10, 20)

// Select in a table
editor.command.executeSetRange(
  0, 5,
  'table-id-123',
  0, 2,  // td indices
  0, 0   // tr indices
)

replaceRange

Replaces the current range with a new range.
editor.command.executeReplaceRange(range: IRange): void

Parameters

range
IRange
required
Range object containing startIndex, endIndex, and optional table coordinates

Example

const range = {
  startIndex: 10,
  endIndex: 20
}
editor.command.executeReplaceRange(range)

setPositionContext

Sets the position context (e.g., entering a table cell).
editor.command.executeSetPositionContext(range: IRange): void

Parameters

range
IRange
required
Range with table information to set context

Example

const range = {
  startIndex: 0,
  endIndex: 0,
  tableId: 'table-123',
  startTrIndex: 0,
  startTdIndex: 0
}
editor.command.executeSetPositionContext(range)

Complete Example

import Editor from '@hufe921/canvas-editor'

const editor = new Editor(container, data)

// Select all and copy
editor.command.executeSelectAll()
await editor.command.executeCopy()

// Set cursor position and paste
editor.command.executeSetRange(50, 50)
editor.command.executePaste()

// Delete selection
editor.command.executeSetRange(10, 20)
editor.command.executeBackspace()

Build docs developers (and LLMs) love