I found a bug in the patch that I sent. If the first lines of the text widget
were blank (i.e just carriage returns) then the up arrow would not bring the
insertion cursor to the first line. I attach the entire UpDownLine sub which
fixes this. The only lines which change are 1242 and 1249.
#####################################
sub UpDownLine
{
my ($w,$n) = @_;
$w->see('insert');
my $i = $w->index('insert');
my ($line,$char) = split(/\./,$i);
my $testX; #used to check the "new" position
my $testY; #used to check the "new" position
(my $bx, my $by, my $bw, my $bh) = $w->bbox($i);
(my $lx, my $ly, my $lw, my $lh) = $w->dlineinfo($i);
if ( ($n == -1) and ($by <= $bh) )
{
#On first display line.. so scroll up and recalculate..
$w->yview('scroll', -1, 'units');
($bx, $by, $bw, $bh) = $w->bbox($i);
($lx, $ly, $lw, $lh) = $w->dlineinfo($i);
}
elsif ( ($n == 1) and
($ly + $lh + $bh) >= ( $w->height - 2*$w->cget(-bd) -
2*$w->cget(-highlightthickness) ) )
{
#On last display line.. so scroll down and recalculate..
$w->yview('scroll', 1, 'units');
($bx, $by, $bw, $bh) = $w->bbox($i);
($lx, $ly, $lw, $lh) = $w->dlineinfo($i);
}
# Calculate the vertical position of the next display line
my $Yoffset = 0;
$Yoffset = $by - $ly + 1 if ($n== -1);
$Yoffset = $ly + $lh + 1 - $by if ($n == 1);
$Yoffset*=$n;
$testY = $by + $Yoffset;
# Save the original 'x' position of the insert cursor if:
# 1. This is the first time through.
# 2. The insert cursor position has changed from the previous
# time the up or down key was pressed.
if (not defined $w->{'origx'} or ($w->{'lastindex'} != $i) )
{
$w->{'origx'} = $bx;
}
$testX = $w->{'origx'};
# Get the coordinates of the possible new position
my $testindex = $w->index('@'.$testX.','.$testY );
$w->see($testindex);
my ($nx,$ny,$nw,$nh) = $w->bbox($testindex);
# Which side of the character should we position the cursor?
if ($testX > $nx+$nw/2)
{
$testX = $nx+$nw+1;
}
# Find the linenumber and index for the end of this
# possible "new" position
my ($testline)=split/\./,$testindex;
my $testlineendindex = $w->index("$testindex lineend");
if ($w->{'newline'} and $testindex eq '1.0' and not
($w->compare('1.0','==',$testlineendindex)) )
{
#Then the cursor is at the end of line 1 (boundary for scrolling up)
$testY = $by;
$testX = $bx;
$w->{'newline'}=1;
}
elsif ($testindex eq '1.0' and not ($w->compare('1.0','==',$testlineendindex)))
{
#Then the cursor is somewhere else on line 1 (boundary for scrolling up)
$testY = $by;
$testX = $bx;
$w->{'newline'}=0;
}
elsif ($w->{'newline'} and ($testindex == $testlineendindex) )
{
# Then cursor is about to move from the end of one line to the end
# of another line (i.e. a shorter or equal or even longer column)
# We keep original X position.
$w->{'newline'}=1;
}
elsif ($w->{'newline'} )
{
# Then cursor is about to move from the end of one line to an
# embedded position in another line (or the same "actual" line)
# Again - we keep the original X position
$w->{'newline'}=0;
}
elsif ($testindex == $testlineendindex )
{
# Then the cursor is about to move from an embedded position in a line
# to the end of another line (i.e. a shorter column)
$w->{'newline'}=1;
}
else
{
# Then the cursor is about to move from an embedded position in a line
# to another embedded position
$w->{'newline'}=0;
}
my $newindex = $w->index('@'.$testX.','.$testY );
if ( $w->compare($newindex,'==','end') )
{
$newindex = $w->index('end');
}
elsif ( $w->compare($newindex,'==','1.0') )
{
if ($bx == $lx)
{
#then we are on actually on the first character of line 1
$newindex = '1.0';
}
else
{
$newindex = $i;
}
}
$w->{'lastindex'} = $newindex;
$w->see($newindex);
return $newindex;
}
#####################################
-++**==--++**==--++**==--++**==--++**==--++**==--++**==
This message was posted through the Stanford campus mailing list
server. If you wish to unsubscribe from this mailing list, send the
message body of "unsubscribe ptk" to majordomo@xxxxxxxxxxxxxxxxxx
|