TextManager

See source code
Table of contents

Extends EditorManager.

class TextManager extends EditorManager {}

Constructor

Constructs a new instance of the TextManager class

Parameters

NameDescription

editor

Editor;

Properties

disposables

readonly
protected readonly disposables: Set<() => void>;

editor

readonly
protected readonly editor: Editor;

Methods

addEditorEvent( )

Subscribe to an editor bus event and register the matching unsubscribe, so the listener is removed automatically on dispose().

protected addEditorEvent<E extends keyof TLEventMap>(
  event: E,
  fn: (...args: TLEventMap[E]) => void,
): void;

Parameters

NameDescription

event

E;

fn

(...args: TLEventMap[E]) => void;

Returns

void;

measureElementTextNodeSpans( )

Given an html element, measure the position of each span of unbroken word/white-space characters within any text nodes it contains.

measureElementTextNodeSpans(
  element: HTMLElement,
  {
    shouldTruncateToFirstLine,
  }?: {
    shouldTruncateToFirstLine?: boolean;
  },
): {
  didTruncate: boolean;
  spans: {
    box: BoxModel;
    text: string;
  }[];
};

Parameters

NameDescription

element

HTMLElement;

{ shouldTruncateToFirstLine }

{
  shouldTruncateToFirstLine?: boolean;
};

Returns

{
  didTruncate: boolean;
  spans: {
    box: BoxModel;
    text: string;
  }[];
};

measureHtml( )

measureHtml(html: string, opts: TLMeasureTextOpts): TLMeasuredTextSize;

Parameters

NameDescription

html

string;

opts

Returns


measureHtmlBatch( )

measureHtmlBatch(requests: BatchMeasurementRequest[]): TLMeasuredTextSize[];

Parameters

NameDescription

requests

Returns


measureText( )

measureText(
  textToMeasure: string,
  opts: TLMeasureTextOpts,
): TLMeasuredTextSize;

Parameters

NameDescription

textToMeasure

string;

opts

Returns


measureTextSpans( )

Measure text into individual spans. Spans are created by rendering the text, then dividing it up according to line breaks and word boundaries.

It works by having the browser render the text, then measuring the position of each character. You can use this to replicate the text-layout algorithm of the current browser in e.g. an SVG export.

measureTextSpans(
  textToMeasure: string,
  opts: TLMeasureTextSpanOpts,
): {
  box: BoxModel;
  text: string;
}[];

Parameters

NameDescription

textToMeasure

string;

opts

Returns

{
  box: BoxModel;
  text: string;
}[];

register( )

Register a teardown function to run on dispose(). The universal way for a manager to make a resource "see itself out". Returns the same function for convenience.

protected register(dispose: () => void): () => void;

Parameters

NameDescription

dispose

() => void;

Returns

() => void;

Prev
StateNode
Next
ThemeManager