Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Tk::Text - moving through hidden text

by anna_black (Sexton)
on Jan 06, 2009 at 13:43 UTC ( [id://734434]=perlquestion: print w/replies, xml ) Need Help??

anna_black has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

I stumbled upon a weird behaviour in Tk::Text, when trying to move with the keyboard through hidden text, and I think it might be a bug.

Consider the following code:

use strict; use warnings; use Tk; my $mw = MainWindow->new(-title => "Bug?"); my $frame = $mw->Frame() ->pack(-side => "left", -expand => 1, -fill => 'both'); my $text = $frame->Scrolled('Text') ->pack(-expand => 1, -fill => 'both'); my $data; for (my $i = 1; $i <= 20; $i++) { $data .= "abcdefghi $i \n"; } $text->insert('end',$data); $text->tagConfigure("invisible",-elide => 'true'); $text->tagAdd("invisible",'7.0','13.0'); MainLoop();

If you stand on line #6, and move with the arrows down, you jump straight to line #13, as expected. Same thing when you start from #13 and move up. If you stand on line 6 and move to the right, the cursor disappears, which makes sense (even if I'd rather have it jump to #13 as well). However, if after the cursor disappears, you try to move up or down, you immediately get errors.

Is that a bug? If so, where should I report it? (CPAN?)

Thanks :)

Replies are listed 'Best First'.
Re: Tk::Text - moving through hidden text
by zentara (Archbishop) on Jan 06, 2009 at 14:58 UTC
    It's hard to say whether it's a bug or not, but I see your problem. In the perldoc for Tk::Text, it says the text behaves as normal, but what is normal?
    -elide => boolean Elide specifies whether the data should be elided. Elided data is not displayed and takes no space on screen, but further on behaves just as normal data.
    I would say you could submit a bug report at Tk bug reports . But to be honest, the maintainer is very busy, and I wouldn't expect a quick response.

    Your best option is to create a workaround, where you store the hidden ranges in an array

    sub hide_text { my @r = $text->tagRanges('sel'); print "@r\n"; return unless @r; $text->tagAdd('hide',@r); return; }
    then when the cursor position is in one of those ranges, manually skip it. This would require you bind to the arrow-keys. You might also want to ask in the newsgroup comp.lang.perl.tk, where a few Tk::Text experts hang out.

    I'm not really a human, but I play one on earth Remember How Lucky You Are

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://734434]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-16 16:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found