Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!pt.cs.cmu.edu!o.gp.cs.cmu.edu!andrew.cmu.edu!jk3t+ From: jk3t+@andrew.cmu.edu (Jonathan King) Newsgroups: comp.sys.mac.hypercard Subject: Re: problem with returnInField Message-ID: Date: 3 Dec 90 17:17:46 GMT References: <2419@pbhyg.PacBell.COM> Organization: Psychology, Carnegie Mellon, Pittsburgh, PA Lines: 51 In-Reply-To: <2419@pbhyg.PacBell.COM> mwan@PacBell.COM (Miu Wang) writes: > Help...I've just started playing with HC 2.0 and have a proble with the > "returnInField" message. > I have a script: > > on returnInField > do something > pass returnInField > end returnInfield > > What I want to do is to "do something" when the user types a "return" in a > text field, then have the system do its normal thing (put a return character > in the text field and move the insertion point to the beginning of the next > line in the field and allow the user to continue typing. But HC does not > return control to the text field after the "do something". Bummer... Without knowing for sure what "something" you are doing, I can't be *sure* I know what the problem is, but I'm *almost sure* I know what is wrong. The answer depends on two subtle points about the insertion point in HC and how you can clobber it. First, in HC, the current location of the insertion point can be found by looking at "the selected chunk"--the insertion point is sort of a null selection. So, if the insertion point was between character 2 and 3 of card field "foo", then the selected chunk would return "char 3 to 2 of card field foo". Note that this is a "negative" selection; if the selectedChunk had returned "char 2 to 3 of card field foo" then this would mean that characters two and three had been selected. Second, the selection is a pretty fragile thing in Hypercard, and a huge number of "something"s you could be doing will unselect it, which would then cause the selectedChunk to return 'empty' and might cause weird things to happen when the returnInField message eventually reaches Hypercard. So here's a possible fix: on returnInField --insertionPoint is just a mnemonic name, and doesn't imply that the --selectedChunk always returns the insertion point. To be picky you --should test whether selectedChunk is returning an insertionPoint or --actual selected text. put the selectedChunk into insertionPoint --save the insertion do something --do your dance select insertionPoint --restore the insertion pass returnInField --let HC do whatever. end returnInField > Miu Wang 415-867-6476 jking