Articles Archive
Articles Search
Director Wiki
 

Controlling the insertion point location

October 21, 1998
by Alex Zavatone

Often times it comes to task that you must code some solution for a text field in the project that you're working on. Now in Director 4 days, this was pure hell but things have come a long way with the commands to allow the scrolling of text fields by line and page. Other commands like scrollTop really help when making your own custom text fields and custom scrollers. One would like to think that all bases are covered with text fields but once you step into the world of text fields in miaws and on the stage, the trouble starts. It gets even worse if you're trying to create an editable text field and control the position of the insertion point via lingo. There simply aren't any lingo commands that were created to control or set the insertion point of a text field. Once again, we must revert to some tricks to get the job done.

There is method that will allow a programmer to control the position of the insertion point in a text field. Creative use of the selStart and selEnd allows you to put the insertion point of the active text field after a character, line or word in a text field. It's actually pretty easy. Instead of defining a selection to be from one char to another, simply define the selection to be from one character to itself, effectively creating a selection of 0 chars but puts the insertion point at that char. The selStart & the selEnd always refer to the active field so you do not have to specify the sprite or field that you want to affect. Surprisingly it just works.


set the selStart = 1
set the selEnd = 1

Now to get this to work on demand over a text field you can track the cursor position with the lingo locToCharPos and locToLineV commands if necessary. These commands will tell you the exact character index and line index in the field below the cursor. They can be combined with use of selStart and selEnd to have the insertion point track the cursor without having to click the mouse. Useful if needed.

Though not as meaty as my usual topics, I've recently found this technique indispensable on a Spanish language CD where we must insert special characters when the user clicks on a button. Special thanks to Peter Psahoulias for this technique.

A Director user since 1987, Alex (Zav) Zavatone has worked on the engineering teams for both Director and Shockwave, 4, 5, 6 and 7. Recent investigations find him developing foundation classes for Director with asynchronous process management and other life threatening activities. In its early days, he had something to do with this Internet thing known as "DOUG". A noted ne'erdowell, slacker and laggard, Mr. Zavatone is nonetheless is trusted by children, small animals and the elderly. In his spare time, Mr. Zavatone rehabilitates lame desert trout.

Copyright 1997-2024, Director Online. Article content copyright by respective authors.