logo       

Minor UpDownLine bug: msg#00123

Subject: Minor UpDownLine bug
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



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
boot-loaders.gr...    php.pear.genera...    debugging.valgr...    kde.redhat.user...    text.xml.xsl.ge...    culture.languag...    hardware.microc...    java.servicemix...    redhat.release....    web.zope.plone....    user-groups.lin...    opendarwin.webk...    video.mjpeg.use...    sysutils.bcfg2....    encryption.gpg....    lx-office.devel...    xfree86.forum/2...    mail.mutt.devel...    acpi.devel/2003...    qnx.openqnx.dev...    network.irc.irs...    freebsd.devel.m...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe