Subject: | Perl Tk; Text-widget; there: the "insert"-method |
Dear developer,
I use Perl, v5.6.1, "perl -v" gives:
This is perl, v5.6.1 built for i586-linux
which came with my SuSS Linux 7.3; uname -a gives
Linux linux 2.4.10-4GB #1 Tue Sep 25 12:33:54 GMT 2001 i586 unknown
I have a problem, which might be a bug, but I am not sure:
With Perl Tk I made a Text widget, bound a callback to a keystroke, which
should insert a special character in the text. The insertion works, but it
has a side effect, which could be the bug, where I am talking about:
The text from the insert-cursor to the end of the line is deleted.
The script contains the following code:
$HF = MainWindow -> new;
$Text = $HF -> Scrolled ('Text', -scrollbars => 'se')
-> pack (-side => "bottom");
$Text -> bin ("<Control-k>", \&Taste);
sub Taste { $Text -> insert ("insert", "X"); }
As I wrote, the insertion works, but the rest of the line is being deleted. If there are no more characters on the line behind the insert-cursor, the EOL is deleted and the next line comes up. For experiment, I used "1.5" instead of "insert" as insert-position in the insert-method:
sub Taste { $Text -> insert ("1.5", "X"); }
That makes the insertion at this position, and then deletes the rest of the line behind the insert-cursor on its actual position.
Can You help me?
By the way, in future not the "X" has to be inserted, but the backslash. I am writing my own editor, which inserts spcial characters for TEX-scripts ("\", "{", "}", "[", "]") by the keystrokes Ctrl-k,
Ctrl-u, Ctrl-p, Ctrl-i and Ctrl-o. That makes it easyer to write fast without looking at the keyboard.
Many thanks, Your
Ulrich Goebel