Changeset 11106
- Timestamp:
- 03/13/10 13:31:35 (2 years ago)
- Location:
- trunk/Padre/lib/Padre
- Files:
-
- 2 edited
-
Config.pm (modified) (1 diff)
-
Wx/Editor.pm (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Padre/lib/Padre/Config.pm
r11057 r11106 673 673 default => 0, 674 674 ); 675 676 setting( 677 name => 'editor_brace_expression_highlighting', 678 type => Padre::Constant::BOOLEAN, 679 store => Padre::Constant::HUMAN, 680 default => 0, 681 ); 682 675 683 setting( 676 684 name => 'save_autoclean', -
trunk/Padre/lib/Padre/Wx/Editor.pm
r11105 r11106 504 504 # 505 505 506 sub apply_style { 507 my ($self, $style_info) = @_; 508 my %previous_style = %$style_info; 509 $previous_style{style} = $self->GetStyleAt($style_info->{start}); 510 511 $self->StartStyling( $style_info->{start}, 0xFF ); 512 $self->SetStyling( $style_info->{len}, $style_info->{style} ); 513 514 return \%previous_style; 515 } 516 517 518 my $previous_expr_hiliting_style; 506 519 sub highlight_braces { 507 520 my ($self) = @_; 508 521 522 my $expression_highlighting = $self->get_config->editor_brace_expression_highlighting; 523 509 524 # remove current highlighting if any 510 525 $self->BraceHighlight( $STC_INVALID_POSITION, $STC_INVALID_POSITION ); 526 if ($previous_expr_hiliting_style) { 527 $self->apply_style($previous_expr_hiliting_style); 528 $previous_expr_hiliting_style = undef; 529 } 511 530 512 531 my $pos1 = $self->GetCurrentPos; … … 520 539 521 540 $self->BraceHighlight( $actual_pos1, $actual_pos2 ); 522 523 return; 524 } 525 526 =head2 goto_matching_brace 527 528 Move the cursor to the matching brace if any. If the cursor is inside the braces the destination 541 542 if ($expression_highlighting) { 543 my $pos2 = $self->find_matching_brace($pos1) or return; 544 my %style = (start => $pos1 < $pos2 ? $pos1 : $pos2, 545 len => abs($pos1-$pos2), style => Wx::wxSTC_STYLE_DEFAULT); 546 $previous_expr_hiliting_style = $self->apply_style(\%style); 547 } 548 549 550 return; 551 } 552 553 554 =head2 find_matching_brace 555 556 Find the position of to the matching brace if any. If the cursor is inside the braces the destination 529 557 will be inside too, same it is outside. 530 558 … … 532 560 pos - the cursor position in the editor [defaults to cursor position) : int 533 561 534 562 Return: 563 matching_pos - the matching position, or undef if none 535 564 536 565 =cut 537 sub goto_matching_brace {566 sub find_matching_brace { 538 567 my ($self, $pos) = @_; 539 568 $pos = $self->GetCurrentPos unless defined $pos; … … 543 572 my $actual_pos2 = $self->BraceMatch($actual_pos1); 544 573 return if $actual_pos2 == $STC_INVALID_POSITION; 545 546 # several cases: 547 my $pos2 = $actual_pos2; 548 $pos2++ if $is_after; # ensure is stays inside if origin is inside, same four outside 549 550 $self->GotoPos($pos2); 551 } 552 553 =head2 select_to_matching_brace 554 555 Select to the matching opening or closing brace. If the cursor is inside the braces the destination 574 $actual_pos2++ if $is_after; # ensure is stays inside if origin is inside, same four outside 575 return $actual_pos2; 576 } 577 578 579 =head2 goto_matching_brace 580 581 Move the cursor to the matching brace if any. If the cursor is inside the braces the destination 556 582 will be inside too, same it is outside. 557 583 … … 560 586 561 587 588 =cut 589 sub goto_matching_brace { 590 my ($self, $pos) = @_; 591 my $pos2 = $self->find_matching_brace($pos) or return; 592 $self->GotoPos($pos2); 593 } 594 595 =head2 select_to_matching_brace 596 597 Select to the matching opening or closing brace. If the cursor is inside the braces the destination 598 will be inside too, same it is outside. 599 600 Params: 601 pos - the cursor position in the editor [defaults to cursor position) : int 602 603 562 604 563 605 =cut … … 566 608 my ($self, $pos) = @_; 567 609 $pos = $self->GetCurrentPos unless defined $pos; 568 569 570 my $info1 = $self->get_brace_info($pos) or return; 571 my ($actual_pos1, $brace, $is_after, $is_opening) = @$info1; 572 573 my $actual_pos2 = $self->BraceMatch($actual_pos1); 574 return if $actual_pos2 == $STC_INVALID_POSITION; 575 576 # several cases: 577 my $pos2 = $actual_pos2; 578 $pos2++ if $is_after; # ensure is stays inside if origin is inside, same four outside 579 580 my $start = $is_opening ? $self->GetSelectionStart() : $self->GetSelectionEnd(); 610 my $pos2 = $self->find_matching_brace($pos) or return; 611 my $start = ($pos < $pos2) ? $self->GetSelectionStart() : $self->GetSelectionEnd(); 581 612 $self->SetSelection($start, $pos2); 582 613 … … 1021 1052 foreach my $style ( @{ $self->{styles} } ) { 1022 1053 $self->StartStyling( $style->{start}, 0xFF ); 1023 $self->SetStyling( $style->{len}, 32);1054 $self->SetStyling( $style->{len}, Wx::wxSTC_STYLE_DEFAULT ); 1024 1055 } 1025 1056 }
Note: See TracChangeset
for help on using the changeset viewer.
