Constrained Editor Instance
This page will list down all the available APIs in Constrained Editor
#
Available APIs#
InitializeInThis API is used to add the necessary functions to monaco editor instance to faciliate the constrains.
#
ArgumentsReturns Boolean : True, if the instance is properly initialized
const instanceOfConstrainedEditor = constrainedEditor(monaco);instanceOfConstrainedEditor.initializeIn(monacoEditorInstance);
#
AddRestrictionsToThis API is used to add the restrictions to the constrained editor instance. This should be called after the initialization of the constrained editor.
#
Arguments :Returns model : after addition of the constrains
instanceOfConstrainedEditor.addRestrictionsTo(model, [ /** * range : [ startLine, startColumn, endLine, endColumn ] */ { range: [1, 7, 1, 12], // Range of Util Variable name label: "utilName", validate: function (currentlyTypedValue, newRange, info) { // console.log({ currentlyTypedValue }); const noSpaceAndSpecialChars = /^[a-z0-9A-Z]*$/; return noSpaceAndSpecialChars.test(currentlyTypedValue); }, }, { range: [3, 1, 3, 1], // Range of Function definition allowMultiline: true, label: "funcDefinition", },]);
#
RemoveRestrictionsInThis API is used to remove all restrictions from the model.
caution
This will completely remove all restrictions and at present, there is no provision for removing a particular restriction.
#
ArgumentsReturns Boolean : True, if all the restrictions are removed
instanceOfConstrainedEditor.removeRestrictionsIn(model);
#
DisposeConstrainerThis will dispose all the functions added to the editor instance. The editor Instance will revert back to normal state as it was before initialization.
instanceOfConstrainedEditor.disposeConstrainer();
#
ToggleDevModeThis API can be used during development. This will add a entry in the context menu to expose the selected range, which can be used in the range objects While enabled, the context menu will have a new entry named Show Range in console, on clicking it, it will display the selected range in console
This can be used to add in the range restriction object.
instanceOfConstrainedEditor.toggleDevMode();