Overview

The Measure component computes some positions and sizes, such as offset amount of a specified line or text width. Also, it caches some values for performance.

Properties

lines

get

Returns the latest Lines instance. This is an alias of Code#Lines.


i18n

get

Returns the i18n collection. This is an alias of this.options.i18n.


padding

padding: { top: number, right: number, bottom: number, left: number }

An object with padding values as { top, right, bottom, left };


editorRect

get

Returns a DOMRect object of the editor element.


scrollerRect

get

Returns a DOMRect object of the scroller element.


containerRect

get

Returns a DOMRect object of the container element.


lineHeight

get

Returns the editor line height in pixel.

Methods

getTop()

getTop( row: number ): number

Returns the top position of the line at the specified row. This clamps the row index from 0 and the total length of lines.

Params

row

A row index.

Return

A top position in pixel.


getBottom()

getBottom( row: number ): number

Returns the bottom position of the line at the specified row. This clamps the row index from 0 and the total length of lines.

Params

row

A row index.

Return

A bottom position in pixel.


closest()

closest( top: number ): number

Computes the closest row index to the offset top position.

Params

top

A offset position.

Return

The closest row index to the offset position.


measureWidth()

measureWidth( string: string, useCache: boolean ): number

Measures the provided string and returns the width. This method caches each width of the character in the string for performance.

Params

string

A string to measure.

useCache

Optional. Determines whether to use the cached width or not.

Return

The width of the string.


getOffset()

getOffset( position: Position ): OffsetPosition

Converts the passed position to the OffsetPosition object as { top: number, left: number }.

Params

position

A position to convert.

Return

An object literal with top and left positions.