Changeset 12008
- Timestamp:
- 07/25/10 23:49:09 (19 months ago)
- Location:
- trunk/Padre-Plugin-CSS
- Files:
-
- 3 edited
-
Changes (modified) (1 diff)
-
lib/Padre/Document/CSS.pm (modified) (1 diff)
-
share/css.yml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Padre-Plugin-CSS/Changes
r10877 r12008 4 4 Add context help with very basic data in a yaml file (SZABGAB) 5 5 Renamed to the new Padre 0.43 PO naming scheme (azawawi) 6 Autocompletition support (CHORNY) 6 7 7 8 0.08 2009.05.31 -
trunk/Padre-Plugin-CSS/lib/Padre/Document/CSS.pm
r10877 r12008 46 46 47 47 48 sub event_on_char { 49 my ( $self, $editor, $event ) = @_; 50 51 my $main = Padre->ide->wx->main; 52 my $config = Padre->ide->config; 53 54 $editor->Freeze; 55 56 $self->autocomplete_matching_char( 57 $editor, $event, 58 34 => 34, # " " 59 39 => 39, # ' ' 60 40 => 41, # ( ) 61 60 => 62, # < > 62 91 => 93, # [ ] 63 123 => 125, # { } 64 ); 65 66 $editor->Thaw; 67 68 $main->on_autocompletion($event) if $config->autocomplete_always; 69 70 return; 71 } 72 73 sub autocomplete { 74 my $self = shift; 75 my $event = shift; 76 77 my $editor = $self->editor; 78 my $pos = $editor->GetCurrentPos; 79 my $line = $editor->LineFromPosition($pos); 80 my $first = $editor->PositionFromLine($line); 81 82 # line from beginning to current position 83 my $prefix = $editor->GetTextRange( $first, $pos ); 84 my $suffix = $editor->GetTextRange( $pos, $pos + 15 ); 85 $suffix = $1 if $suffix =~ /^(\w*)/; # Cut away any non-word chars 86 87 # The second parameter may be a reference to the current event or the next 88 # char which will be added to the editor: 89 my $nextchar; 90 if ( defined($event) and ( ref($event) eq 'Wx::KeyEvent' ) ) { 91 my $key = $event->GetUnicodeKey; 92 $nextchar = chr($key); 93 } elsif ( defined($event) and ( !ref($event) ) ) { 94 $nextchar = $event; 95 } 96 97 $prefix =~ s{^.*?((?:\w+-)*\w+)$}{$1}; 98 my $last = $editor->GetLength(); 99 my $text = $editor->GetTextRange( 0, $last ); 100 my $pre_text = $editor->GetTextRange( 0, $first + length($prefix) ); 101 my $post_text = $editor->GetTextRange( $first, $last ); 102 103 my $regex; 104 eval { $regex = qr{\b(\Q$prefix\E\w+(?:-\w+)*)\b} }; 105 if ($@) { 106 return ("Cannot build regex for '$prefix'"); 107 } 108 my @keywords=qw/background-repeat font-variant/; 109 110 my %seen; 111 my @words; 112 push @words, grep { $_ =~ $regex and !$seen{$_}++} @keywords; 113 push @words, grep { !$seen{$_}++ } reverse( $pre_text =~ /$regex/g ); 114 push @words, grep { !$seen{$_}++ } ( $post_text =~ /$regex/g ); 115 116 if ( @words > 20 ) { 117 @words = @words[ 0 .. 19 ]; 118 } 119 120 # Suggesting the current word as the only solution doesn't help 121 # anything, but your need to close the suggestions window before 122 # you may press ENTER/RETURN. 123 if ( ( $#words == 0 ) and ( $prefix eq $words[0] ) ) { 124 return; 125 } 126 127 # While typing within a word, the rest of the word shouldn't be 128 # inserted. 129 if ( defined($suffix) ) { 130 for ( 0 .. $#words ) { 131 $words[$_] =~ s/\Q$suffix\E$//; 132 } 133 } 134 135 # This is the final result if there is no char which hasn't been 136 # saved to the editor buffer until now 137 return ( length($prefix), @words ) if !defined($nextchar); 138 139 # Finally cut out all words which do not match the next char 140 # which will be inserted into the editor (by the current event) 141 my @final_words; 142 for (@words) { 143 144 # Accept everything which has prefix + next char + at least one other char 145 next if !/^\Q$prefix$nextchar\E./; 146 push @final_words, $_; 147 } 148 149 return ( length($prefix), @final_words ); 150 } 151 152 sub autoclean { 153 my $self = shift; 154 155 my $editor = $self->editor; 156 my $text = $editor->GetText; 157 158 $text =~ s/[\s\t]+([\r\n]*?)$/$1/mg; 159 $text .= "\n" if $text !~ /\n$/; 160 161 $editor->SetText($text); 162 163 return 1; 164 165 } 166 48 167 1; -
trunk/Padre-Plugin-CSS/share/css.yml
r11979 r12008 1 1 --- 2 2 topics: 3 azimuth: <angle> | [[ left-side | far-left | left | center-left | center | center-right | right | far-right | right-side ] || behind ] | leftwards | rightwards | inherit 3 4 padding: length | percentage (REPLACE_four), inherit - REPLACE_content_model 4 5 color: Color of an element. Values can be RGB: #AABBCC
Note: See TracChangeset
for help on using the changeset viewer.
