How to start this project...

J. Landman Gay jacque at hyperactivesw.com
Mon Oct 9 20:20:20 EDT 2006


Adrian Williams wrote:
 > Hi Jacqueline,
 >
 > I realise now the selectedChunk is certainly the wrong way to go!

Well, now that you've explained more about it, I think you actually do 
have to use this.

It looks like you want to add intermediate characters between the ones 
the user types, except at the beginning of words. You use a space as the 
word delimiter in your example, but I think you'd have to handle line 
beginnings too. For simplicity, let's just check for spaces and carriage 
returns.

In a field, you'd put a script something like this:

on keydown pkey
   put the selectedChunk into tChunk
   put word 2 of tChunk - 1 into tPrevCharNum -- a number
   put char tPrevCharNum of me into tPrevChar -- this is a character
   if tPrevChar <> space and tPrevChar <> cr and tPrevCharNum <> 0 then 
-- not a word start
     put joinChar(tPrevChar) into tKeys  -- calls a function
   end if
   put pkey after tKeys -- adds the user-typed entry to tKeys variable
   do "put tKeys into" && tChunk
end keydown

function joinChar pChar
   return "~"
end joinChar

This catches keystrokes, calculates the previous character position, and 
checks that character to make sure it isn't the first character in the 
field, a space, or a carriage return. If the criteria are met, it calls 
a function that returns the join character. In my example, that's just a 
tilde. You'd have to write the guts of the function, which you would 
base on the value of the parameter "pChar" which is passed to the 
function. The tilde is inserted into a variable, and then user's 
keystroke is added to it. The two characters are then placed into the 
field using the "do" construct, which is necessary here in order to 
evaluate the variable "tChunk" when using it in a command. (Don't ask.)

That said, when you start using unicode, some of this will break. The 
text chunking capabilities in Rev are one of its strongest points, but 
they break down somewhat when using unicode. I'm a bit weak in that area 
myself, so hopefully someone here can join in and suggest how to alter 
the above to account for the additional bytes that unicode requires. I 
think you have to add/subtract 2 rather than 1 for all the calculations, 
but I haven't tried it.

Maybe this will at least get you started on how to calculate text chunks 
and how to call a function.

-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com



More information about the use-livecode mailing list