CodeEditor Object

Applies to TestComplete 15.62, last modified on March 19, 2024

Description

The CodeEditor object provides access to the TestComplete Code Editor from script extensions. The object provides properties that let you obtain or modify the code in the active Code Editor instance and determine the text that is currently selected.

Note: The CodeEditor object can only be used in the script extension code. It does not exist in TestComplete scripts.

Members

Example

The following example demonstrates how to use the CodeEditor object to insert the Log.Message method call to the code displayed in the Code Editor panel:

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

Script Extensions
Working With the Code Editor
Code Editor - Overview

Highlight search results