home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / Share / Editores / Perl5 / perl / lib / site / auto / Tk / Text / UpDownLine.al < prev   
Encoding:
Text File  |  1997-08-10  |  1.0 KB  |  36 lines

  1. # NOTE: Derived from ..\blib\lib\Tk\Text.pm.  Changes made here will be lost.
  2. package Tk::Text;
  3.  
  4. # UpDownLine --
  5. # Returns the index of the character one line above or below the
  6. # insertion cursor. There are two tricky things here. First,
  7. # we want to maintain the original column across repeated operations,
  8. # even though some lines that will get passed through do not have
  9. # enough characters to cover the original column. Second, do not
  10. # try to scroll past the beginning or end of the text.
  11. #
  12. # Arguments:
  13. # w - The text window in which the cursor is to move.
  14. # n - The number of lines to move: -1 for up one line,
  15. # +1 for down one line.
  16. sub UpDownLine
  17. {
  18.  my $w = shift;
  19.  my $n = shift;
  20.  my $i = $w->index("insert");
  21.  my ($line,$char) = split(/\./,$i);
  22.  if (!defined $Tk::prevPos || ($Tk::prevPos cmp $i) != 0)
  23.   {
  24.    $Tk::char = $char
  25.   }
  26.  my $new = $w->index($line+$n . "." . $Tk::char);
  27.  if ($w->compare($new,"==","end") || $w->compare($new,"==","insert linestart"))
  28.   {
  29.    $new = $i
  30.   }
  31.  $Tk::prevPos = $new;
  32.  return $new;
  33. }
  34.  
  35. 1;
  36.