Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do you move around a text widget

4 views
Skip to first unread message

Dave Pike

unread,
Oct 3, 2001, 9:53:51 PM10/3/01
to
Hello,

I'm trying to make a simple text editor for an application and I
basically used the one out of Eric Foster-Johnson's book. The problem I
have is with the word wrapping such that when word wrap is turned on and
you use the arrow keys or home/end keys it could cause the cursor to
jump several lines since the actual line has been wrapped without
natural a hard return.

I've tried turning off wrap and putting my own hard returns in with
limited success and I've also tried leaving wrap on and binding the keys
and trying to calculate where the cursor should be with even less
success.

Is there a simpler way to do this or are these the types of things most
people use to do this?

Thanks for any suggestions
Dave

Christian Heide Damm

unread,
Oct 4, 2001, 8:23:59 AM10/4/01
to

The best solution we've come up with corresponds to your second solution,
namely binding up/down to something like this:

# Find the coordinates of the cursor and set the new height
# manually. Note: errors rounding off, since
# coordinates don't match character positions exactly.
lset {lines char} [split [$textWidget index insert] .]
lset {x y textWidth textHeight} [$textWidget bbox [$textWidget
index insert]]
lset {_ maxy _ _} [$textWidget bbox "end - 1 char"]
# When updating position, make sure y is within text boundaries
switch -- $upOrDown {
"up" {
set y [max [expr $y-$textHeight] 0]
}
"down" {
set y [min [expr $y+$textHeight] $maxy]
}
}
lset {newx newy width _} [$textWidget bbox [$textWidget index
@$x,$y]]
# Test on which side of the character
# we should position the cursor
if {$x>[expr $newx+$width/2]} {
set x [expr $newx+$width+1]
}
set newIndex [$textWidget index @$x,$y]

Christian

---

0 new messages