How to contribute code ? (Improvements for the Text widget) 
Author Message
 How to contribute code ? (Improvements for the Text widget)

Hi !

Due to my problems with the new text-widget, I started to play around
with the source.

I posted a question twice a few month ago about the behavior of the
Up/Down keys in the Textwidget when the text is wrapped.
It doesn't behave like in all other text editors, it jumps over all
wrapped lines to the next "real line" (means the next
index-line-number).
But unfortionatly nobody knew how to fix this behavior.

So I managed after a few hours of exploring the thing a little patch for
the UpDownLine function in Text.pm that makes these
cursor mevements like they are in all other text editors and word
processors.

It has only a little bug, when moving up/down, the cursor slightly moves
left if you do not use a fixed-width font.
(Maybe somebody has an idea how to prevent this)

I do not know how to contribute that code (just a few lines), so I post
the whole function here and mark the added/changed lines with 2 comment
lines:

-----cut here -----
sub UpDownLine
{

 my $i = $w->index('insert');
 my ($line,$char) = split(/\./,$i);
 my $string = $w->get($line.'.0', $i);

 $string = expand($string);
 $char=length($string);
 $line += $n;

 $string = $w->get($line.'.0', $line.'.0 lineend');
 $string = expand($string);
 $string = substr($string, 0, $char);

 $string = unexpand($string);
 $char = length($string);

####### CHANGES START HERE ##########
 my $new;
 my $line_offset = $w->cget('-spacing2');
 $w->see("$line.0") ;
 (my $bx, my $by, my $bw, my $bh) = $w->bbox($i);
 (my $lx, my $ly, my $lw, my $lh) = $w->dlineinfo($i);

 {
 (my $nx, my $ny, my $nw, my $nh) = $w->dlineinfo("$line.end");

 }

$w->index(($line-$n).".end") and $n==1)
 {
 $new =
)));

 }
 elsif ($n == -1)
 {

 }
 elsif ($n == 1)
 {

 }

 if ($w->compare($new,'==','end') || $w->compare($new,'==','1.0'))
  {
   $new = $i
  }
####### CHANGES END HERE ##########

 $Tk::prevPos = $new;
 $Tk::char = $char;
 return $new;

Quote:
}

----cut here----

Maybe this is interresting for some others,
if not, please excuse this quite long posting, but I didn't knew how
else to share it.
The changes are tested with the actual AS Perl/Tk package 800.018 and AS
Perl 522

ciao, thomas.

----------------------------------------------------
Thomas Schmickl,
Department for zoology
Karl Franzens University Graz, Austria.
----------------------------------------------------
Visit the GPL e:doc-project on http://www.*-*-*.com/

----------------------------------------------------



Wed, 21 Aug 2002 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Color Coding Text in a Tk::Text Widget

2. Slow code, improvements requested

3. Code Improvement

4. Performance improvement for Text::CSV -- Long

5. Q: Changing Text-Color in Text-Widget?

6. text formatting in a Text widget

7. How update text in text widget when executing some other callback

8. Checking for marked or selected text in a Text widget

9. Grabbing Text from Text widget

10. Retrieving a line of text from a Text Widget when clicking on it

11. Making text appear in a text widget...

12. best way to save text in Text widget

 

 
Powered by phpBB® Forum Software