CodeEditor
A Panel subclass which encapsulates a Monaco editor to provide rich editing of text.
This requires the Monaco editor to be installed as a Node module, and simply requires a
path to a local node_modules directory.
Editing text is as simple as setting the text and language properties.
const
editorPanel = new CodeEditor({
codePath : 'node_modules/monaco-editor',
width : 1000,
height : 600,
title : 'This is just a Panel',
text : 'This is the text to edit',
language : 'markdown',
appendTo : document.body
}),
// Direct access to the Monaco Editor API
monaco = await editorPanel.editorReady;
The CodeEditor loads the required modules dynamically from the codePath and fulfills the editorReady Promise, yielding the Monaco editor when it is ready for interaction.
Status bar
The bottom toolbar of this Panel is used as a status bar. You may reconfigure
it or its items in the usual way. There are three items provided by default.
These may all be accessed using this Panel's widgetMap.
These may all be styled using the selector [ref="widgetName"] where "widgetName" is one
of the names listed below:
readOnlyA read-only indicator which by default uses the Font-Awesomefa-lockglyph to indicate that the editor is read-only.statusA widget which may be used to display textual status messages.cursorPosA widget which displays the current cursor position.
//<code-header>
fiddle.title = 'Code editor';
//</code-header>
const panel = new CodeEditor({
codePath : window.bryntum.editorPath,
appendTo : targetElement,
height : '30em',
width : '55em',
header : 'Editing this example\'s code. No, it does not reload on change'
});
fetch('../docs/data/Core/examples/widget/CodeEditor.js').then(response => {
response.text().then(t => panel.text = t);
});Configs
114
Configs
114Common
Other
The path from which to load the Monaco editor.
For example:
{
codePath : 'node_modules/monaco-editor'
}
An editor configuration object to be passed to https://microsoft.github.io/monaco-editor/docs.html#functions/editor.create.html
The language being edited may be set and read using this property.
The read-only state of the editor may be set and read. This state is by default reflected by an icon in the bottom toolbar.
The status message displayed un the bottom toolbar may be set and read using this property.
The text being edited may be set and read using this property.
The Monaco theme to use. If not specified, it defaults to 'vs';
Content
CSS
DOM
Float & align
Layout
misc
Misc
Scrolling
Properties
101
Properties
101Class hierarchy
Other
The Monaco editor instance. Use this property to manipulate the editor according to https://microsoft.github.io/monaco-editor/typedoc/index.html
Note that this will only exist when the editor has been loaded from the codePath.
This will be indicated by the editorReady property which yields the monaco editor as its value.
A promise which resolves when the Monaco editor is loaded from the codePath and ready for use which yields the Monaco editor instance.
The language being edited may be set and read using this property.
The read-only state of the editor may be set and read. This state is by default reflected by an icon in the bottom toolbar.
The status message displayed un the bottom toolbar may be set and read using this property.
The text being edited may be set and read using this property.
The Monaco theme to use. If not specified, it defaults to 'vs';
CSS
DOM
Layout
Misc
State
Widget hierarchy
Functions
75
Functions
75Other
Focuses the Monaco editor
Loads text into the editor.
| Parameter | Type | Description |
|---|---|---|
text | String | The text to edit. |
language | String | The language to edit the text with. |
The https://microsoft.github.io/monaco-editor/docs.html#interfaces/editor.ITextModel.html which is handling editing the text.