home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / Share / Editores / Perl5 / perl / lib / site / auto / Tk / Entry / Transpose.al < prev    next >
Encoding:
Text File  |  1997-08-10  |  813 b   |  28 lines

  1. # NOTE: Derived from ..\blib\lib\Tk\Entry.pm.  Changes made here will be lost.
  2. package Tk::Entry;
  3.  
  4. # Transpose
  5. # This procedure implements the "transpose" function for entry widgets.
  6. # It tranposes the characters on either side of the insertion cursor,
  7. # unless the cursor is at the end of the line.  In this case it
  8. # transposes the two characters to the left of the cursor.  In either
  9. # case, the cursor ends up to the right of the transposed characters.
  10. #
  11. # Arguments:
  12. # w - The entry window.
  13. sub Transpose
  14. {
  15.  my $w = shift;
  16.  my $i = $w->index('insert');
  17.  $i++ if ($i < $w->index('end'));
  18.  my $first = $i-2;
  19.  return if ($first < 0);
  20.  my $str = $w->get;
  21.  my $new = substr($str,$i-1,1) . substr($str,$first,1);
  22.  $w->delete($first,$i);
  23.  $w->insert('insert',$new);
  24.  $w->SeeInsert;
  25. }
  26.  
  27. 1;
  28.