AT&T Home | AT&T Labs | Research
AT&T Labs, Inc. - Research

The Yoix® Scripting Language

Home | What's New | Grammar | Documentation | Download | License | YChart | YDAT | YWAIT | Byzgraf | FAQs
deleteText (Object comp, int offset [, int count [, int adjust [, Pointer undo]]]) yoix.awt
 
Updates the AWT or Swing component comp by deleting the character at offset in the text currently displayed by that component and returns the number of characters that were added to the displayed text, which for deleteText will always be a number less than or equal to 0. If the component maintains a text insertion point (e.g., the caret when comp is a JTextArea, JTextField, TextArea or TextField) then deleteText also tries to position it at offset.

The optional count argument, which is 1 by default, is the number of characters that should be deleted The optional adjust argument should be 1 when you want deleteText to try to position the caret (if there is one) at offset, and 0 otherwise. The optional undo argument should be a pointer to an Array with room for at least three elements that deleteText uses to return information (two integers and a string) that can be used to undo the operation. The first element in the array is the offset where the operation took place, the second element is the number of new characters that were added at that IR offset , which will always be 0 for deleteText, and the last element is a String that is the text that was deleted by the operation. The order of the elements in the undo array make it particularly easy to use with unroll and replaceText.

deleteText works with any AWT or Swing component that defines a field named text.
 
 Example:   The following example displays a frame containing a textarea and a button. Pressing the button deletes text from the textarea and positions the caret at the point where the text was deleted.
import yoix.*.*;

Frame f = {
    Dimension size = NULL;

    Array layout = {
        new TextArea {
            String tag = "$_textarea";
            String text = "Spam, spam, spam, baked beans, sausage and spam";
            int    rows = 8;
            int    columns = 50;
            int    scroll = VERTICAL;
        }, CENTER,

        new Button {
            String text = "Delete Spam";
            Array  undo[3];

            actionPerformed(ActionEvent e) {
                deleteText(root.components.$_textarea, 2, 3, TRUE, &undo);
                root.components.$_textarea.requestfocus = TRUE;
                printf("undo=%O\n", undo);
            }
        }, SOUTH,
    };
};

f.visible = TRUE;
The line that requests the focus for the textarea is only included to make it easy to see the caret position.
 
 Return:   int
 
 See Also:   JTextArea, JTextField, JTextPane, TextArea, TextField, TextTerm, appendText, insertText, replaceText, unroll

 

Yoix is a registered trademark of AT&T Inc.