Overview

The Input component handles users' keyboard inputs.

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.


info

readonly info: TokenInfo

The TokenInfo object saved when any key is pressed.


composing

readonly composing: boolean

Indicates whether the input is in composition session or not.


line

readonly line: Element

Keeps the latest focus line.


row

readonly row: number

Keeps the latest focus row index.


value

get

Returns the value of the current line without the tailing line break.

set

Sets a new value to the current line. In most cases, it's better to use apply() to edit the line instead because this does not syncs the change to the editor.


before

get

Returns the string of the current line before the caret position.


after

get

Returns the string of the current line after the caret position.


length

get

Returns the length of the current line.


col

get

Returns the current col index.


disabled

get

Returns true if the input is disabled.

set

Makes the input disabled. All keys are ignored while it is disabled.

Methods

set()

set( type: string, props: Omit<InputState, > ): void

Sets the input state. If the state with the provided type exists, new props will be assigned to it. The props object accepts following values:

State Description
key? The key that makes the input.
startRow? The start row index to replace lines with the current value from.
endRow? The end row index to replace lines with the current value to.
value? The value to replace lines with. If omitted, the current value will be used.
insertion? Specifies the value to insert at the caret position instead of setting the value.
offset? The number of offset cols after the state is applied.
position? Explicitly specifies the position after the state is applied. The offset will be ignored.

Params

type

The type of the state.

props

Optional. An object with state values.


get()

get(): InputState

Returns the current state object if available.

Return

The current state object if available, or null if not.


apply()

apply( state?: InputState ): void

Applies the state to the editor and clears it.

const ryuseiCode = new RyuseiCode();
ryuseiCode.apply( 'textarea' );
ryuseiCode.on( 'focus', () => {
const { Input } = ryuseiCode.Editor.Components;
setTimeout( () => {
Input.apply( {
insertion: 'foo',
offset: 3,
} );
}, 1000 );
} );
TypeScript

Params

state

Optional. A new state to apply.


char()

char( col: number ): string

Returns a character at the current caret position or specified col index.

Params

col

Optional. A col index of the desired character.

Return

A character at the specified position.