Skip to content
Reference > AmiScript API > Classes

TextEditor

Definition

TextEditor var = .... ;

Extends

Extended By

None

Description

AMI Web editor for a single editable text/code payload (AMIScript callback body, HTML template, custom-methods script, ...). Provides read / mutate / search via getCode / setCode / lines / insertBefore / replace / find / replaceAll. Capability mixins (AmiWebFormattableEditor for format, AmiWebBraceBlockEditor for brace-block edits) appear on the same runtime object when the underlying portlet implements them.

Method Summary

Owner Name Return Type Description
PanelEditor apply() Boolean Persist the editor working copy to the underlying object. Call validate() first.
PanelEditor close() Boolean Dismiss this editor's window and unregister it from the editor registry. Triggers the same lifecycle as the user clicking the window's close button.
TextEditor delete(startLine, endLine) Long Delete the 1-based inclusive line range. Returns the new revision.
TextEditor deleteBlock(line) Long Delete the brace block containing the supplied 1-based line. Only supported when the editor implements AmiWebBraceBlockEditor. Returns the new revision.
TextEditor findLines(pattern) List Return 1-based line numbers whose contents match the supplied regular expression.
TextEditor format() Long Format the editor's working copy in place using the default indent width. Only supported when the editor implements AmiWebFormattableEditor. Returns the new revision.
TextEditor format(indentWidth) Long Format the editor's working copy in place using the supplied indent width. Only supported when the editor implements AmiWebFormattableEditor. Returns the new revision.
TextEditor formatPreview(code, indentWidth) String Return formatted code WITHOUT mutating the editor -- pure preview. Use format() / format(indentWidth) to actually apply formatting to the editor's working copy.
PanelEditor getBinding() Map Return the editor's binding metadata as a map: {handle, editorType, contentType, ari, name, parentHandle, scope, capabilities:[...], readonly}. Use this to ask 'what kind of editor is this?' or 'can I setCode on it?' (check capabilities for 'set_code') without runtime-type-checking the editor instance.
Object getClassName() String Returns the string name of this object's class type.
TextEditor getCode() String Return the editor's current working-copy text -- this includes any edits the user has typed in the editor UI that have not yet been applied. To inspect what has been persisted to the underlying object, you must apply() the working copy first. Use hasChanged() to test whether there are uncommitted edits.
PanelEditor getHandle() String Return this editor's stable session handle.
PanelEditor getRevision() Long Return the editor's monotonic working-copy revision.
PanelEditor hasChanged() Boolean Return true if the working copy differs from persisted state.
TextEditor insertAfter(line, text) Long Insert text after the 1-based line. Passing 0 prepends before the first line. Returns the new revision.
TextEditor insertBefore(line, text) Long Insert text before the 1-based line. Passing lineCount+1 appends to EOF. Returns the new revision.
TextEditor lines(startLine, endLine) List Return 1-based inclusive lines from the editor working copy.
PanelEditor open() Boolean Open this editor in the UI, bringing it onto the user's screen if it is not already visible. Editing can be done without calling open().
TextEditor replace(startLine, endLine, text) Long Replace the 1-based inclusive line range with text. Returns the new revision.
TextEditor replaceAll(pattern, replacement) Long Replace all occurrences of the supplied regular expression. Returns the new revision.
TextEditor replaceBlock(line, text) Long Replace the brace block containing the supplied 1-based line. Only supported when the editor implements AmiWebBraceBlockEditor. Returns the new revision.
PanelEditor revert() Boolean Discard unsaved working-copy changes and return to persisted state.
TextEditor setCode(code) Long Replace the editor contents unconditionally. Returns the new revision (use it to chain subsequent stale-write-protected operations). Use trySetCode() if you need to detect concurrent edits before writing.
PanelEditor test() Map Execute the editor's payload in its runtime context without persisting. Returns {ok, revision, returnValue, output, errorMessage}. Only valid when capabilities contains 'test' -- other editor kinds return a not-supported result. Mirrors the editor_test admin/MCP shape.
Object toJson() String Returns a string of a json representation of this object.
TextEditor trySetCode(code, expectedRevision) Map Replace editor contents only if expectedRevision is current. Returns {applied, revision}: applied=true and the new revision on success; applied=false and the editor's current revision on stale (retry with that revision).
PanelEditor validate() Map Validate the editor's working copy. Returns {ok, revision, diagnostics}. Does not surface validation errors as UI alerts -- callers inspect the returned diagnostics list instead.

Method Definitions


apply()

Boolean PanelEditor::apply()

Description

Persist the editor working copy to the underlying object. Call validate() first.


close()

Boolean PanelEditor::close()

Description

Dismiss this editor's window and unregister it from the editor registry. Triggers the same lifecycle as the user clicking the window's close button.


delete(startLine,endLine)

Long TextEditor::delete(Integer startLine, Integer endLine)

Description

Delete the 1-based inclusive line range. Returns the new revision.

Parameter Definition

Name Type Description
startLine Integer 
endLine Integer 

deleteBlock(line)

Long TextEditor::deleteBlock(Integer line)

Description

Delete the brace block containing the supplied 1-based line. Only supported when the editor implements AmiWebBraceBlockEditor. Returns the new revision.

Parameter Definition

Name Type Description
line Integer 

findLines(pattern)

List TextEditor::findLines(String pattern)

Description

Return 1-based line numbers whose contents match the supplied regular expression.

Parameter Definition

Name Type Description
pattern String 

format()

Long TextEditor::format()

Description

Format the editor's working copy in place using the default indent width. Only supported when the editor implements AmiWebFormattableEditor. Returns the new revision.


format(indentWidth)

Long TextEditor::format(Integer indentWidth)

Description

Format the editor's working copy in place using the supplied indent width. Only supported when the editor implements AmiWebFormattableEditor. Returns the new revision.

Parameter Definition

Name Type Description
indentWidth Integer 

formatPreview(code,indentWidth)

String TextEditor::formatPreview(String code, Integer indentWidth)

Description

Return formatted code WITHOUT mutating the editor -- pure preview. Use format() / format(indentWidth) to actually apply formatting to the editor's working copy.

Parameter Definition

Name Type Description
code String 
indentWidth Integer 

getBinding()

Map PanelEditor::getBinding()

Description

Return the editor's binding metadata as a map: {handle, editorType, contentType, ari, name, parentHandle, scope, capabilities:[...], readonly}. Use this to ask 'what kind of editor is this?' or 'can I setCode on it?' (check capabilities for 'set_code') without runtime-type-checking the editor instance.


getClassName()

String Object::getClassName()

Description

Returns the string name of this object's class type.


getCode()

String TextEditor::getCode()

Description

Return the editor's current working-copy text -- this includes any edits the user has typed in the editor UI that have not yet been applied. To inspect what has been persisted to the underlying object, you must apply() the working copy first. Use hasChanged() to test whether there are uncommitted edits.


getHandle()

String PanelEditor::getHandle()

Description

Return this editor's stable session handle.


getRevision()

Long PanelEditor::getRevision()

Description

Return the editor's monotonic working-copy revision.


hasChanged()

Boolean PanelEditor::hasChanged()

Description

Return true if the working copy differs from persisted state.


insertAfter(line,text)

Long TextEditor::insertAfter(Integer line, String text)

Description

Insert text after the 1-based line. Passing 0 prepends before the first line. Returns the new revision.

Parameter Definition

Name Type Description
line Integer 
text String 

insertBefore(line,text)

Long TextEditor::insertBefore(Integer line, String text)

Description

Insert text before the 1-based line. Passing lineCount+1 appends to EOF. Returns the new revision.

Parameter Definition

Name Type Description
line Integer 
text String 

lines(startLine,endLine)

List TextEditor::lines(Integer startLine, Integer endLine)

Description

Return 1-based inclusive lines from the editor working copy.

Parameter Definition

Name Type Description
startLine Integer 
endLine Integer 

open()

Boolean PanelEditor::open()

Description

Open this editor in the UI, bringing it onto the user's screen if it is not already visible. Editing can be done without calling open().


replace(startLine,endLine,text)

Long TextEditor::replace(Integer startLine, Integer endLine, String text)

Description

Replace the 1-based inclusive line range with text. Returns the new revision.

Parameter Definition

Name Type Description
startLine Integer 
endLine Integer 
text String 

replaceAll(pattern,replacement)

Long TextEditor::replaceAll(String pattern, String replacement)

Description

Replace all occurrences of the supplied regular expression. Returns the new revision.

Parameter Definition

Name Type Description
pattern String 
replacement String 

replaceBlock(line,text)

Long TextEditor::replaceBlock(Integer line, String text)

Description

Replace the brace block containing the supplied 1-based line. Only supported when the editor implements AmiWebBraceBlockEditor. Returns the new revision.

Parameter Definition

Name Type Description
line Integer 
text String 

revert()

Boolean PanelEditor::revert()

Description

Discard unsaved working-copy changes and return to persisted state.


setCode(code)

Long TextEditor::setCode(String code)

Description

Replace the editor contents unconditionally. Returns the new revision (use it to chain subsequent stale-write-protected operations). Use trySetCode() if you need to detect concurrent edits before writing.

Parameter Definition

Name Type Description
code String 

test()

Map PanelEditor::test()

Description

Execute the editor's payload in its runtime context without persisting. Returns {ok, revision, returnValue, output, errorMessage}. Only valid when capabilities contains 'test' -- other editor kinds return a not-supported result. Mirrors the editor_test admin/MCP shape.


toJson()

String Object::toJson()

Description

Returns a string of a json representation of this object.


trySetCode(code,expectedRevision)

Map TextEditor::trySetCode(String code, Long expectedRevision)

Description

Replace editor contents only if expectedRevision is current. Returns {applied, revision}: applied=true and the new revision on success; applied=false and the editor's current revision on stale (retry with that revision).

Parameter Definition

Name Type Description
code String 
expectedRevision Long 

validate()

Map PanelEditor::validate()

Description

Validate the editor's working copy. Returns {ok, revision, diagnostics}. Does not surface validation errors as UI alerts -- callers inspect the returned diagnostics list instead.