CodeManager
view release on metacpan or search on metacpan
lib/Prima/CodeManager/Edit.pm view on Meta::CPAN
my $l = length( $self-> {lines}-> [$y]);
$x = $l if $x < 0 || $x > $l;
$x = 0 if $x < 0;
my $cm = $self-> {chunkMap};
my $r;
( $l, $r) = ( 0, $self-> {maxChunk} + 1);
my $i = int($r / 2);
my $kk = 0;
while (1) {
my $acd = $$cm[$i * 3 + 2];
last if $acd == $y;
$acd > $y ? $r : $l = $i;
$i = int(( $l + $r) / 2);
if ( $kk++ > 200) {
# print "bcs dump to $y\n";
( $l, $r) = ( 0, $self-> {maxChunk} + 1);
$i = int($r / 2);
for ( $kk = 0; $kk < 7; $kk++) {
my $acd = $$cm[$i * 3 + 2];
# print "i:$i [$l $r] f() = $acd\n";
$acd > $y ? $r : $l = $i;
$i = int(( $l + $r) / 2);
}
die;
last;
}
}
$y = $i;
$i*= 3;
$i-= 3, $y-- while $$cm[ $i] != 0;
$i+= 3, $y++ while $x > $$cm[ $i] + $$cm[ $i + 1];
$x -= $$cm[ $i];
return $x, $y;
}
sub make_physical
{
my ( $self, $x, $y) = @_;
return (0,0) if $self-> {maxLine} < 0;
return $x, $y unless $self-> {wordWrap};
my $maxY = $self-> {maxChunk};
$y = $maxY if $y > $maxY || $y < 0;
$y = 0 if $y < 0;
my $cm = $self-> {chunkMap};
my ( $ofs, $l, $nY) = ( $$cm[ $y * 3], $$cm[ $y * 3 + 1], $$cm[ $y * 3 + 2]);
$x = $l if $x < 0 || $x > $l;
$x = 0 if $x < 0;
return $x + $ofs, $nY;
}
sub start_block
{
my $self = $_[0];
return if exists $self-> {anchor};
my $blockType = $_[1] || $self-> {blockType};
$self-> selection(0,0,0,0);
$self-> blockType( $blockType);
$self-> {anchor} = [ $self-> {cursorX}, $self-> {cursorY}];
}
sub update_block
{
my $self = $_[0];
return unless exists $self-> {anchor};
$self-> selection( @{$self-> {anchor}}, $self-> {cursorX}, $self-> {cursorY});
}
sub end_block
{
my $self = $_[0];
return unless exists $self-> {anchor};
my @anchor = @{$self-> {anchor}};
delete $self-> {anchor};
$self-> selection( @anchor, $self-> {cursorX}, $self-> {cursorY});
}
sub cancel_block
{
delete $_[0]-> {anchor};
$_[0]-> selection(0,0,0,0);
}
sub set_marking
{
my ( $self, $mark, $blockType) = @_;
return if $mark == exists $self-> {anchor};
$mark ? $self-> start_block( $blockType || $self-> {blockType}) : $self-> end_block;
}
#wb
sub kursor_w_dol {
my ( $line, $vis_len_prev ) = @_;
$line = '' unless $line;
return $vis_len_prev unless $line =~ /\t/;
$line = $line.(' 'x($vis_len_prev));
my $dlu = 0;
my $res = 0;
while ( $line =~ /(.)/g ) {
last if $dlu >= $vis_len_prev;
if ( $1 eq "\t" ) {
$dlu += 3 - ( $dlu % 4 );
}
$dlu++;
$res++;
}
return $res;
}
sub cursor_down
{
my $d = $_[1] || 1;
#print "cursor_down\n";
my $l1 = $_[0]->get_line( $_[0]-> {cursorYl} );
my $l2 = $_[0]->get_line( $_[0]-> {cursorYl} + $d );
($l1,undef) = wstaw_tab_15( $l1, 0, $_[0]-> {cursorX}, '', 0 );
my $len2 = kursor_w_dol( $l2,length($l1));
( run in 0.514 second using v1.01-cache-2.11-cpan-df04353d9ac )