HyperCard: Auto Hilite Problem



A user has reported a problem in HyperTalk, up to and including version 1.2.2.
A button script cannot manipulate text that is selected in a field, if the
button is set to Auto Hilite. When Auto Hilite is on, the text is
deselected to flash the Auto Hilite attribute. Subsequently, the text is
not reselected. Thus, the script has nothing to select.

For example, a user selects some text in card field. The button script
takes the selection and displays it in another field.

on mouseUp
put selection into it
put it into card field show_me
end mouseUp

If you assign the button the Auto Hilite attribute, this technique will not
work, because the button is highlighted before the text can be deselected
and passed to the variable.

The following script uses a global variable and three handlers. It
requires the Auto Hilite attribute of the button to be turned on. Because
a "mouseWithin" message is generated before the button is highlighted, you
can save the selected text before it is deselected. As a bonus, you can
also save the selection and restore it when done.

on mouseWithin
global temp
put selection into item 1 of temp
put the selectedChunk into item 2 of temp
end mouseWithin

on mouseUp
global temp
put item 1 of temp into card field show_me
select item 2 of temp
end mouseUp

on mouseLeave
global temp
select item 2 of temp
end mouseLeave

This script provides the same result as the previous script. It uses no
global variables and requires only one handler. As with the previous
script, you must have the button's Auto Hilite attribute turned off. If
you are running out of global variables, this routine is better than the
previous script, because it has no global variables. However, the script
is much slower.

on mouseDown
put the selection into temp1
put the selectedChunk into temp2
set hilite of me to true
repeat while the mouse is down
if PointInRect(the mouseLoc, the Rect of me) = true then
set the hilite of me to true
select temp2
else
set the hilite of me to false
select temp2
end if
end repeat
if PointInRect(the mouseLoc, the Rect of me) = true then
put temp1 into card field show_me
end if
set the hilite of me to false
select temp2
end mouseDown

Function PointInRect thePoint, theRect
if (item 1 of thePoint > item 1 of theRect) and *
(item 1 of thePoint < item 3 of theRect) and *
(item 2 of thePoint > item 2 of theRect) and *
(item 2 of thePoint < item 4 of theRect) then
return true
else
return false
end if
end PointInRect

*You must insert a "soft" return (Option-Return) at these locations. (Do
not type these asterisks as part of the script.)


Published Date: Feb 18, 2012