http://www.perlmonks.org?node_id=412909


in reply to Re: right to left Tk text widget
in thread right to left Tk text widget

Okay, I got it working better, but it's still buggy. I fixed the bug that prevented cursor keys from working. Also, delete and backspace function normally now (without causing undue cursor movement), although backspace still goes left rather than right, and vice versa. The proper text direction is more reliable, but still committing errors. When I type "This is a test.", I invariably wind up with " .tseta si sihT". The cursor fails to move left on the space following the "a" every single time I type that sentence. If somebody can figure this out, I'd be grateful, as I am now quite interested in solving this problem.
#!/usr/bin/perl use strict; use warnings; use Tk; my $last=1.0; my $mw = MainWindow->new( -background=>"darkviolet" ); my $t1 = $mw->Text( -background=>"navy", -foreground=>"white", -height=>35, -width=>80, -wrap=>"word", -selectbackground=>"blueviolet" )->pack; $t1->bind("<Key>" => \&rtl); #$t1->bind("<KeyRelease>" => sub {$t1->SetCursor('insert - 1 chars')}) +; sub rtl { my $size = $t1->index('end - 1 chars'); if ($last < $size) { $t1->SetCursor('insert - 1 chars'); } $last = $size; } MainLoop;

edit: Got it! This error occurs on the 10th character of the line, and repeats at the 100th. Our comparison is saying that 1.9 is not less than 1.10 and 1.99 is not less than 1.100. True for integers, but not for line.word count.

--
Linux, sci-fi, and Nat Torkington, all at Penguicon 3.0