[comp.lang.smalltalk] Smalltalk/V286: moving cursor in Texteditor

ott@piyopiyo.hatori.t.u-tokyo.JUNET (ott) (06/16/89)

I finally got 286/V (or the other way around) running yesterday and
started to transfer some of my methods for enhancing the texteditor
from the PC version.

Things have changed a lot and late at night I ran into the following
problem I just cant explain.

I want to move the cursor (I-beam) with the keyboard. Left, right, up
and down works fine, but using the same method I can't properly move
it to the end or beginning of a line.

A stripped down version of the method I added to TextPane:

selectBeginningOfLine
	| curPosition |
	curPosition := selection origin.
	selection selectBefore: ( curPosition x: 1).

It leaves a copy of the cursor at curPosition, moves the cursor to the
beginning and reverses the part of the line between. It does not
select that area, as the reverse part stays.

To move it to the end (only changed 'curPosition x: lastColumn')
things are a bit different. A copy of the old cursor remains, the
cursor is moved to the end, but invisible as a 2nd permanent copy of
the cursor shape is copied to this position as well.

In both cases the cursor is shifted to the right place and character
input appears at the right place as well. But the move creates those
strange artifacts.

Has anyone figured out where exactly the cursor gets moved and
the big idea behind TextSelection.

I am quite lost and would appreciate any help.

Thanks

-max
------------------------------------------------------------------------------
Max Ott			     e-mail:
Hatori Laboratory             ott@piyopiyo.hatori.t.u-tokyo.junet@relay.cs.net
Dept. of E.E.; U of Tokyo             I am not a tourist, I live here, but
+(81)-(03) 812 2111 Ext. 6761         would not mind being one.

cliff@ficc.uu.net (cliff click) (06/20/89)

> A stripped down version of the method I added to TextPane:
> ...[bad code removed]...
> Has anyone figured out where exactly the cursor gets moved and
> the big idea behind TextSelection?

A TextSelection is a pair of points.  The first point is the selection 
start, the second is the selection end.  If the end is before the start
the selection is viewed as a "Gap" or "I-Beam", otherwise a block of text
is selected (and displayed in reverse).  Here is some code for moving to
the start of a line:

! TextPane methods !
jumpLeft
"Move the GapSelector (I-Beam) to line start"
    | line |
"Get the previous Y value"
    line := selection corner y.
"Gaps slide both origin and corner left, selections just origin"
    ^selection isGap
	ifTrue: [selection origin: (1 @ line) corner: (0 @ line)]
	ifFalse: [selection origin: (0 @ line)]! !

I don't call any of the routines for handling the various selections, 
because their smart enough to do proper reverse videoing.  The routines 
which call this simple undo any selection, call this to torture the 
TextSelection, and re-do any selection based only on the new TextSelection.

Good Luck!

==========
Private for Ott:

WARNING:  Your mailer bounced your mail between "piyopiyo" and 
"ccut.cc.u-tokyo.ac.jp" about 8 times before it got out.  My mailer sent my
reply back to your mailer, which detected a mail loop, and sent my reply
back to me.  You need to have your system administraters check it out.  Your
reply mail transcript contained this repeated about 8 times:

Received: from piyopiyo by ccut.cc.u-tokyo.ac.jp (5.61/6.4J.5-ut1.2)
	id AA01305; Tue, 20 Jun 89 03:25:28 +0900
Received: from ccut.cc.u-tokyo.ac.jp by piyopiyo.hatori.t.u-tokyo.junet (3.2/6.3Junet-1.0)
	id AA22136; Tue, 20 Jun 89 03:19:55 JST
.
.
.

-- 
Cliff Click, Software Contractor at Large
Business: uunet.uu.net!ficc!cliff, cliff@ficc.uu.net, +1 713 274 5368 (w).
Disclaimer: lost in the vortices of nilspace...       +1 713 568 3460 (h).