#!/usr/bin/perl -- use strict; use warnings; use Tk::LineNumberText; use Tk; my $mw = MainWindow->new; my $filename; # Create necessary widgets my $f = $mw->Frame->pack( -side => 'top', -fill => 'x' ); $f->Entry( -textvariable => (\ my $search) )->pack( -side => 'left', -anchor => 'w', -fill => 'x', -expand => 1 ); $f->Button( -text => "Exit", -command => sub { exit; } ) ->pack( -side => 'right' ); my $t = $mw->LineNumberText("Text", -allowbookmarks=>1, -wrap=>'none', -font=>['Courier',11], -linenumfont=>['Courier',10], -curlinehighlight=>'both', -bg=>'white', -selectbackground => 'black') ->pack( -side => 'bottom', -fill => 'both', -expand => 1,); $f->Button(-text => "Findnext", -command => [$t->{'rtext'} => "FindNext(-forward, -exact, -nocase)"]) -> pack(-side => 'right'); $f->Button(-text => "findpop", -command => [$t->{'rtext'} => 'FindPopUp']) -> pack(-side => 'right'); $t->insert( end => join "\n", 1 .. 10 ); $t->insert( 'end', "\nthe_the_the the\n"); $t->insert( 'end', "\nthe_the_the the\n"); $t->bind( '<>', sub { #~ warn @_; my ($t) = @_; $t->tagDelete('ssel'); if ( my (@range) = $t->tagRanges('sel') ) { $t->tagAdd( ssel => @range ); for my $opt (qw' foreground background ') { $t->tagConfigure( ssel => "-$opt" => $t->cget("select$opt") ); } } ## end if ( my (@range) = $t->tagRanges...) return; } ); $t->bind( '', sub { my ($t) = @_; return; } ); MainLoop; sub search(){ print my ($search); #$text->search(?switches,? pattern, index, ?stopIndex?) my $result = $t->search(-forward, $search, '1.0', 'end'); print $result; $t->focus; } sub findnext(){ #@list = $text->tagRanges("tagname") # returns ( begin1, end1, begin2, end2 ... ) my @list = $t->tagRanges("sel"); #print @list; (my $start, my $end) = @list; print $start. "\t". $end. "\n"; #$t = $text->get(index1 [ , index2 ]); my ($search) = $t->get($start, $end); #$t->FindNext(-forward, -exact,-nocase); my $result = $t->FindNext(-forward, -exact, -nocase, $search); #my $result = $t->FindNext(-forward, -exact, -nocase); #print $result; }