Skip to content

CodeEditor ​

Since 2.2.1
CodeEditor showing XML, LSS, and JavaScript syntax highlighting
The editor applies language-specific highlighting and keeps independent scrollable documents.

CodeEditor extends TextArea and adds syntax highlighting, code folding, and editor-quality keyboard shortcuts. It uses the built-in JetBrains Mono Bold font by default.

Additional shortcuts over TextArea:

ShortcutAction
TabInserts two spaces at the cursor.
Ctrl+/Toggles // line comments on the current line or selection.
EnterInserts a new line and preserves the leading indentation of the previous line.

Everything from TextArea (styles, value binding, validators, scrollers, etc.) applies here too.

INFO

Everything documented on UIElement (layout, styles, events, data bindings, etc.) applies here too.


Usage ​

java
var editor = new CodeEditor();
editor.setLanguage(Languages.JSON);
editor.setValue(new String[] { "{", "  \"key\": \"value\"", "}" }, false);
editor.setLinesResponder(lines -> System.out.println(String.join("\n", lines)));
parent.addChild(editor);

XML ​

xml
<code-editor>{"key": "value"}</code-editor>

Text content is split by newlines into lines (same as TextArea).


Fields ​

NameTypeAccessDescription
syntaxParserSyntaxParserprivate (getter)The parser that tokenises lines for highlighting.
styleManagerStyleManagergetter/setterThe colour scheme applied to token types. Default: StyleManager.DEFAULT.

Methods ​

MethodReturnsDescription
setLanguage(ILanguageDefinition)CodeEditorSets the language for syntax highlighting (e.g. Languages.JSON, Languages.SNBT).
getLanguage()ILanguageDefinitionReturns the current language.

All methods from TextArea are also available.

Released under the MIT License.