Manipulating Text Elements; Adding Text; Setting The Cursor Position - Adobe GoLive CS2 Programmer's Manual

Hide thumbs Also See for GoLive CS2:
Table of Contents

Advertisement

SDK Programmer's Guide
When you access a textArea object, GoLive checks whether the document needs reparsing—that is,
whether there has been a structural change in the markup tree since the last time the document was
parsed. If it is needed, GoLive automatically reparses the document, regenerating the markup and layout
objects, before passing the textArea object to your code.

Manipulating text elements

A
textArea Object
example, you can:
Add or delete source text.
Find and replace strings, using a search with regular expressions.
Set the position of the insertion point, and change the text selection.
Change or set the style of the text; see

Adding text

The
insert
text insertion point without changing the position of the insertion point.
For example, this inserts each text item at the very beginning of the document's <body> element, creating
a document that displays one two three in its main text area:
var theDoc = app.newDocument();// open a new document window
theDoc.view == "layout";
theDoc.mainTextArea.insert("three ");
theDoc.mainTextArea.insert("two ");
theDoc.mainTextArea.insert("one ");
The
insertNewLine
current text insertion point and places the cursor between the new element's start and end tags. You can
leave the newly inserted paragraph element empty to use it as a line separator, or you can use the various
insert methods to add content to the paragraph: see
For example, this adds the three strings to the document's main text area on three separate lines, with
empty paragraph tags between them:
var theDoc = app.newDocument();
theDoc.view == "layout";
theDoc.mainTextArea.insert("three ");
theDoc.mainTextArea.insertNewLine();
theDoc.mainTextArea.insert("two ");
theDoc.mainTextArea.insertNewLine();
theDoc.mainTextArea.insert("one ");

Setting the cursor position

If you know exactly where you want to place the cursor, you can use the textArea object's
setCursorParagraph
the beginning of the document:
document.mainTextArea.setCursor(0); // beginning of doc
document.mainTextArea.setCursor(mainTextArea.length); // end of doc
has methods that allow you to edit the text in a displayed page programmatically. For
method of the textArea object adds text to the document's main text area at the current
method adds a new, empty paragraph element <p></p> to the document at the
method to do so. Pass the setCursor method a zero-based character offset from
Adobe GoLive CS2 SDK
Manipulating Text
Inserting Elements in Layout
Styles.
Editing with Layout
113
View.
or
setCursor

Advertisement

Table of Contents
loading

Table of Contents