Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Editor

A global editor object is available in all action scripts. This object allows manipulation of the main editing window in Drafts, altering the text, text selections, or loading a different draft into the editor, etc.

Typically scripting actions that work like custom keyboard commands and similar will utilize the editor functions to manipulate text.

NOTE: Generally speaking, editor methods are best used for quick text manipulations of the type used in the extended keyboard. Most substantial updates to draft content are better applied using the draft object.

Hierarchy

  • Editor

Index

Properties

focusModeEnabled

focusModeEnabled: boolean

Access or set current focus mode status.

isActive

isActive: boolean

Is editor current focused for editing.

linkModeEnabled

linkModeEnabled: boolean

Access or set current link mode status.

Methods

activate

  • activate(): void
  • Request focus for the editor. This will dismiss other views and show the keyboard on the currently loaded draft. Useful if an action opens user interface elements or otherwise causes the editor to resign focus and you would like to return to editing at the end of the action's execution.

    Returns void

arrange

  • arrange(text: string): string
  • Opens the arrange mode view with the passed text for arranging. Returns the arranged text if the user makes changes and taps "Done", the original text if the user cancels.

    Parameters

    • text: string

      The text to arrange

    Returns string

    String containing result of arrange. If user cancels, it will be the same as the original text passed.

deactivate

  • deactivate(): void
  • Resign focus for the editor. If the editor text view is currently focused for editing (e.g. showing keyboard), resign focus.

    Returns void

dictate

  • dictate(locale?: string): string
  • Open dictation interface, and return the result as a string. The string will be empty if user cancels.

    Parameters

    • Optional locale: string

      the preferred locale can be passed in the format "en-US" (U.S. English), "it-IT" (Italian-Italian), "es-MX" (Mexican Spanish), etc.

    Returns string

    The accepted dictation text.

getSelectedLineRange

getSelectedRange

  • Get the current selected text range extended to the beginning and end of the lines it encompasses.

    Returns selectionRange

getSelectedText

  • getSelectedText(): string
  • Get text range that was last selected.

    Returns string

getText

  • getText(): string
  • Get the full text currently loaded in the editor.

    Returns string

getTextInRange

  • getTextInRange(location: number, length: number): string
  • Get the substring in a range from the text in the editor.

    Parameters

    • location: number
    • length: number

    Returns string

load

  • load(draft: Draft): void
  • Loads an existing draft into the editor.

    Parameters

    Returns void

new

  • new(): void
  • Creates a new blank draft and loads it into the editor.

    Returns void

redo

  • redo(): void
  • Apply redo action to editor, if one is available.

    Returns void

save

  • save(): void
  • Save any current changes to the draft.

    Returns void

setSelectedRange

  • setSelectedRange(location: number, length: number): void
  • Update the text selection in the editor by passing the start location and the length of the new selection.

    Parameters

    • location: number
    • length: number

    Returns void

setSelectedText

  • setSelectedText(text: string): void
  • Replace the contents of the last text selection with a string.

    Parameters

    • text: string

    Returns void

setText

  • setText(text: string): void
  • Replace the contents of the editor with a string.

    Parameters

    • text: string

    Returns void

setTextInRange

  • setTextInRange(location: number, length: number, text: string): void
  • Replace the text in the passed range with new text.

    Parameters

    • location: number
    • length: number
    • text: string

    Returns void

showArrange

  • showArrange(): void
  • Open arrange mode in editor. This is a non-blocking method and returns immediately. It is intended only to mimic the tapping of the arrange button. Use editor.arrange(text) to wait for a result.

    Returns void

showDictate

  • showDictate(): void
  • Open dictation mode in editor. This is a non-blocking method and returns immediately. It is intended only to mimic the tapping of the dictate button. Use editor.dictate() to wait for a result and use it in further scripting.

    Returns void

showFind

  • showFind(): void
  • Open find mode in editor.

    Returns void

undo

  • undo(): void
  • Apply undo action to editor, if one is available.

    Returns void

Generated using TypeDoc