Description
The CodeEditor.Text
property lets you obtain or set the entire contents of the TestComplete active Code Editor. You can use the obtained contents as your needs dictate. For example, you can insert new code using the aqString.Insert
method, replace code with the aqString.Replace
method, and so on.
The changes made to the CodeEditor.Text
property value are immediately reflected in the Code Editor. They are also saved in the undo buffer, so the user can undo and redo them.
Be careful when modifying the CodeEditor.Text property value, so you don’t corrupt the user’s code. |
Declaration
Applies To
The property is applied to the following object:
Property Value
A string that holds the entire text of the Code Editor instance that is currently active in TestComplete.
Remarks
If the Code Editor is not active in the TestComplete Workspace panel, the Text
property raises an error. To check if there is an active Code Editor, use the IsEditorActive
property.
To get the text that is currently selected in the Code Editor, use the SelectedText
property.
Example
The following example inserts the Log.Message
method call to the current insertion point:
JScript
function InsertLogMessage()
{
var oMethodCall = Syntax.CreateInvoke();
oMethodCall.ClassValue = "Log";
oMethodCall.InvokeName = "Message";
oMethodCall.IsProperty = false;
oMethodCall.AddParameter("Hello, world!");
var strCode = Syntax.GenerateSource(oMethodCall) + "\r\n";
if (CodeEditor.IsEditorActive)
{
if (CodeEditor.CursorPos == CodeEditor.Text.length)
CodeEditor.Text += strCode;
else
CodeEditor.Text = aqString.Insert(CodeEditor.Text, strCode, CodeEditor.CursorPos);
}
}
VBScript
Sub InsertLogMessage
Dim oMethodCall, strCode
Set oMethodCall = Syntax.CreateInvoke
oMethodCall.ClassValue = "Log"
oMethodCall.InvokeName = "Message"
oMethodCall.IsProperty = False
oMethodCall.AddParameter "Hello, world!"
strCode = Syntax.GenerateSource(oMethodCall) & vbNewLine
If CodeEditor.IsEditorActive Then
If CodeEditor.CursorPos = Len(CodeEditor.Text) Then
CodeEditor.Text = CodeEditor.Text & strCode
Else
CodeEditor.Text = aqString.Insert(CodeEditor.Text, strCode, CodeEditor.CursorPos)
End If
End If
End Sub
See Also
IsEditorActive Property
SelectedText Property
CursorPos Property
aqString Object
Working With the Code Editor