line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Kephra::Edit::Comment;
|
2
|
|
|
|
|
|
|
our $VERSION = '0.08';
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
1428
|
use strict;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
40
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1884
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# Comment
|
8
|
|
|
|
|
|
|
sub add_block {
|
9
|
0
|
|
|
0
|
0
|
|
my $csymbol = shift;
|
10
|
0
|
|
|
|
|
|
my $symlength = length $csymbol; |
11
|
0
|
|
|
|
|
|
my $ep = &Kephra::App::EditPanel::_ref;
|
12
|
0
|
|
|
|
|
|
my ($a, $b) = $ep->GetSelection; |
13
|
0
|
|
|
|
|
|
my ($al, $bl) = ($ep->LineFromPosition( $a ), $ep->LineFromPosition( $b )); |
14
|
0
|
|
|
|
|
|
my $lip; |
15
|
0
|
|
|
|
|
|
my $lipa = $ep->GetLineIndentPosition($al); |
16
|
0
|
|
|
|
|
|
my $lipb = $ep->GetLineIndentPosition($bl); |
17
|
0
|
0
|
0
|
|
|
|
$a += $symlength if $ep->GetTextRange($lipa, $lipa + $symlength) ne $csymbol |
18
|
|
|
|
|
|
|
and $a > $lipa; |
19
|
0
|
0
|
0
|
|
|
|
$b -= $symlength if $ep->GetTextRange($lipb, $lipb + $symlength) ne $csymbol |
20
|
|
|
|
|
|
|
and $b <= $lipb; |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
$ep->BeginUndoAction; |
23
|
0
|
|
|
|
|
|
for ( $al .. $bl ) {
|
24
|
0
|
|
|
|
|
|
$lip = $ep->GetLineIndentPosition($_);
|
25
|
0
|
0
|
|
|
|
|
$ep->InsertText($lip, $csymbol), $b += $symlength |
26
|
|
|
|
|
|
|
if $ep->GetTextRange($lip, $lip + $symlength) ne $csymbol;
|
27
|
|
|
|
|
|
|
} |
28
|
0
|
|
|
|
|
|
$ep->SetSelection($a, $b);
|
29
|
0
|
|
|
|
|
|
$ep->EndUndoAction;
|
30
|
|
|
|
|
|
|
}
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub remove_block {
|
33
|
0
|
|
|
0
|
0
|
|
my $csymbol = shift;
|
34
|
0
|
|
|
|
|
|
my $symlength = length $csymbol; |
35
|
0
|
|
|
|
|
|
my $ep = &Kephra::App::EditPanel::_ref; |
36
|
0
|
|
|
|
|
|
my ($a, $b) = $ep->GetSelection; |
37
|
0
|
|
|
|
|
|
my ($al, $bl) = ($ep->LineFromPosition( $a ), $ep->LineFromPosition( $b )); |
38
|
0
|
|
|
|
|
|
my $lip; |
39
|
0
|
|
|
|
|
|
my $lipa = $ep->GetLineIndentPosition($al); |
40
|
0
|
|
|
|
|
|
my $rema = $ep->GetTextRange($lipa, $lipa + $symlength) eq $csymbol; |
41
|
0
|
|
|
|
|
|
my $lipb = $ep->GetLineIndentPosition($bl); |
42
|
0
|
|
|
|
|
|
my $remb = $ep->GetTextRange($lipb, $lipb + $symlength) eq $csymbol; |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
$ep->BeginUndoAction;
|
45
|
0
|
|
|
|
|
|
for ( $al .. $bl ) { |
46
|
0
|
|
|
|
|
|
$lip = $ep->GetLineIndentPosition($_);
|
47
|
0
|
|
|
|
|
|
$ep->SetTargetStart($lip);
|
48
|
0
|
|
|
|
|
|
$ep->SetTargetEnd( $lip + $symlength );
|
49
|
0
|
0
|
|
|
|
|
$ep->ReplaceTarget(''), $b -= $symlength |
50
|
|
|
|
|
|
|
if $ep->SearchInTarget($csymbol) > -1;
|
51
|
|
|
|
|
|
|
} |
52
|
0
|
0
|
0
|
|
|
|
$a -= $symlength if $rema and $a > $lipa; |
53
|
0
|
0
|
0
|
|
|
|
$b += $symlength if $remb and $b <= $lipb;
|
54
|
0
|
|
|
|
|
|
$ep->SetSelection($a, $b); |
55
|
0
|
|
|
|
|
|
$ep->EndUndoAction;
|
56
|
|
|
|
|
|
|
}
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub toggle_block {
|
59
|
0
|
|
|
0
|
0
|
|
my $csymbol = shift; |
60
|
0
|
|
|
|
|
|
my $symlength = length $csymbol; |
61
|
0
|
|
|
|
|
|
my $ep = &Kephra::App::EditPanel::_ref; |
62
|
0
|
|
|
|
|
|
my $lip; |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
$ep->BeginUndoAction; |
65
|
0
|
|
|
|
|
|
my ($a, $b) = $ep->GetSelection; |
66
|
0
|
|
|
|
|
|
my ($al, $bl) = ($ep->LineFromPosition( $a ), $ep->LineFromPosition( $b )); |
67
|
0
|
|
|
|
|
|
$lip = $ep->GetLineIndentPosition($al); |
68
|
0
|
|
|
|
|
|
my $add = $ep->GetTextRange($lip, $lip + $symlength) ne $csymbol; |
69
|
0
|
|
|
|
|
|
my $found; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
$ep->BeginUndoAction;
|
72
|
0
|
|
|
|
|
|
for ($al .. $bl) {
|
73
|
0
|
|
|
|
|
|
$lip = $ep->GetLineIndentPosition($_);
|
74
|
0
|
|
|
|
|
|
$ep->SetTargetStart($lip); |
75
|
0
|
|
|
|
|
|
$ep->SetTargetEnd( $lip + $symlength ); |
76
|
0
|
|
|
|
|
|
$found = $ep->SearchInTarget($csymbol) != -1; |
77
|
0
|
0
|
|
|
|
|
if ($add){ $ep->InsertText($lip, $csymbol), $b += $symlength if not $found } |
|
0
|
0
|
|
|
|
|
|
78
|
0
|
0
|
|
|
|
|
else { $ep->ReplaceTarget('') , $b -= $symlength if $found } |
79
|
|
|
|
|
|
|
} |
80
|
0
|
0
|
|
|
|
|
$a = $add ? $a + $symlength : $a - $symlength; |
81
|
0
|
0
|
|
|
|
|
$a = $ep->PositionFromLine( $al ) if $a < $ep->PositionFromLine( $al ); |
82
|
0
|
0
|
|
|
|
|
$b = $ep->PositionFromLine( $bl ) if $b < $ep->PositionFromLine( $bl );
|
83
|
0
|
|
|
|
|
|
$ep->SetSelection($a, $b); |
84
|
0
|
|
|
|
|
|
$ep->EndUndoAction; |
85
|
|
|
|
|
|
|
}
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub format_block {
|
88
|
0
|
|
|
0
|
0
|
|
my $csymbol = shift;
|
89
|
0
|
|
|
|
|
|
my $ep = Kephra::App::EditPanel::_ref();
|
90
|
0
|
|
|
|
|
|
my $lp;
|
91
|
0
|
|
|
|
|
|
my $a = $ep->LineFromPosition( $ep->GetSelectionStart );
|
92
|
0
|
|
|
|
|
|
my $b = $ep->LineFromPosition( $ep->GetSelectionEnd );
|
93
|
0
|
|
|
|
|
|
$ep->BeginUndoAction;
|
94
|
0
|
|
|
|
|
|
for ($b .. $a) {
|
95
|
0
|
|
|
|
|
|
$lp = $ep->PositionFromLine($_);
|
96
|
|
|
|
|
|
|
}
|
97
|
0
|
|
|
|
|
|
$ep->EndUndoAction;
|
98
|
|
|
|
|
|
|
}
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub add_stream {
|
101
|
0
|
|
|
0
|
0
|
|
my $ep = Kephra::App::EditPanel::_ref();
|
102
|
0
|
|
|
|
|
|
my ( $openbrace, $closebrace ) = @_;
|
103
|
0
|
|
|
|
|
|
my ( $startpos, $endpos ) = $ep->GetSelection;
|
104
|
0
|
|
|
|
|
|
my ( $commentpos, $firstopos, $lastopos, $firstcpos, $lastcpos )
|
105
|
|
|
|
|
|
|
= ( -1, $endpos, -1, $endpos, -1 );
|
106
|
0
|
|
|
|
|
|
$ep->BeginUndoAction;
|
107
|
0
|
|
|
|
|
|
$ep->SetTargetStart($startpos);
|
108
|
0
|
|
|
|
|
|
$ep->SetTargetEnd($endpos);
|
109
|
0
|
|
|
|
|
|
while ( ( $commentpos = $ep->SearchInTarget($openbrace) ) > -1 ) {
|
110
|
0
|
0
|
|
|
|
|
$firstopos = $commentpos if $firstopos > $commentpos;
|
111
|
0
|
|
|
|
|
|
$lastopos = $commentpos;
|
112
|
0
|
|
|
|
|
|
$ep->SetSelectionStart($commentpos);
|
113
|
0
|
|
|
|
|
|
$ep->SetSelectionEnd( $commentpos + length($openbrace) );
|
114
|
0
|
|
|
|
|
|
$ep->ReplaceSelection("");
|
115
|
0
|
|
|
|
|
|
$endpos -= length($openbrace);
|
116
|
0
|
|
|
|
|
|
$ep->SetTargetStart($commentpos);
|
117
|
0
|
|
|
|
|
|
$ep->SetTargetEnd($endpos);
|
118
|
|
|
|
|
|
|
}
|
119
|
0
|
|
|
|
|
|
$ep->SetTargetStart($startpos);
|
120
|
0
|
|
|
|
|
|
$ep->SetTargetEnd($endpos);
|
121
|
0
|
|
|
|
|
|
while ( ( $commentpos = $ep->SearchInTarget($closebrace) ) > -1 ) {
|
122
|
0
|
0
|
|
|
|
|
$firstcpos = $commentpos if ( $firstcpos > $commentpos );
|
123
|
0
|
|
|
|
|
|
$lastcpos = $commentpos;
|
124
|
0
|
|
|
|
|
|
$ep->SetSelectionStart($commentpos);
|
125
|
0
|
|
|
|
|
|
$ep->SetSelectionEnd( $commentpos + length($closebrace) );
|
126
|
0
|
|
|
|
|
|
$ep->ReplaceSelection("");
|
127
|
0
|
|
|
|
|
|
$endpos -= length($closebrace);
|
128
|
0
|
|
|
|
|
|
$ep->SetTargetStart($commentpos);
|
129
|
0
|
|
|
|
|
|
$ep->SetTargetEnd($endpos);
|
130
|
|
|
|
|
|
|
}
|
131
|
0
|
0
|
|
|
|
|
$ep->InsertText( $endpos, $closebrace ) if $lastcpos == -1;
|
132
|
0
|
0
|
|
|
|
|
$ep->InsertText( $startpos, $openbrace ) if $lastopos == -1;
|
133
|
0
|
0
|
|
|
|
|
$ep->InsertText( $startpos, $openbrace ) if $firstopos < $firstcpos;
|
134
|
0
|
0
|
|
|
|
|
$ep->InsertText( $endpos, $closebrace ) if $lastopos < $lastcpos;
|
135
|
|
|
|
|
|
|
#$ep->InsertText($endpos, $closebrace);
|
136
|
|
|
|
|
|
|
#$ep->InsertText($startpos, $openbrace);
|
137
|
0
|
|
|
|
|
|
$ep->EndUndoAction;
|
138
|
|
|
|
|
|
|
}
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub remove_stream { #o=openposition c=closeposition
|
141
|
0
|
|
|
0
|
0
|
|
my ( $openbrace, $closebrace ) = @_;
|
142
|
0
|
|
|
|
|
|
my $ep = Kephra::App::EditPanel::_ref();
|
143
|
0
|
|
|
|
|
|
my ( $startpos, $endpos ) = $ep->GetSelection();
|
144
|
0
|
|
|
|
|
|
my $firstopos = my $firstcpos = $endpos;
|
145
|
0
|
|
|
|
|
|
my $commentpos = my $lastopos = my $lastcpos = -1;
|
146
|
0
|
0
|
|
|
|
|
if ( $startpos < $endpos ) {
|
147
|
0
|
|
|
|
|
|
$ep->BeginUndoAction();
|
148
|
0
|
|
|
|
|
|
$ep->SetTargetStart($startpos);
|
149
|
0
|
|
|
|
|
|
$ep->SetTargetEnd($endpos);
|
150
|
0
|
|
|
|
|
|
while ( ( $commentpos = $ep->SearchInTarget($openbrace) ) > -1 ) {
|
151
|
0
|
0
|
|
|
|
|
$firstopos = $commentpos if ( $firstopos > $commentpos );
|
152
|
0
|
|
|
|
|
|
$lastopos = $commentpos;
|
153
|
0
|
|
|
|
|
|
$ep->SetSelectionStart($commentpos);
|
154
|
0
|
|
|
|
|
|
$ep->SetSelectionEnd( $commentpos + length($openbrace) );
|
155
|
0
|
|
|
|
|
|
$ep->ReplaceSelection("");
|
156
|
0
|
|
|
|
|
|
$endpos -= length($openbrace);
|
157
|
0
|
|
|
|
|
|
$ep->SetTargetStart($commentpos);
|
158
|
0
|
|
|
|
|
|
$ep->SetTargetEnd($endpos);
|
159
|
|
|
|
|
|
|
}
|
160
|
0
|
|
|
|
|
|
$ep->SetTargetStart($startpos);
|
161
|
0
|
|
|
|
|
|
$ep->SetTargetEnd($endpos);
|
162
|
0
|
|
|
|
|
|
while ( ($commentpos = $ep->SearchInTarget($closebrace) ) > -1 ) {
|
163
|
0
|
0
|
|
|
|
|
$firstcpos = $commentpos if ( $firstcpos > $commentpos );
|
164
|
0
|
|
|
|
|
|
$lastcpos = $commentpos;
|
165
|
0
|
|
|
|
|
|
$ep->SetSelectionStart($commentpos);
|
166
|
0
|
|
|
|
|
|
$ep->SetSelectionEnd( $commentpos + length($closebrace) );
|
167
|
0
|
|
|
|
|
|
$ep->ReplaceSelection("");
|
168
|
0
|
|
|
|
|
|
$endpos -= length($closebrace);
|
169
|
0
|
|
|
|
|
|
$ep->SetTargetStart($commentpos);
|
170
|
0
|
|
|
|
|
|
$ep->SetTargetEnd($endpos);
|
171
|
|
|
|
|
|
|
}
|
172
|
0
|
0
|
|
|
|
|
if ( $firstopos > $firstcpos ) {
|
173
|
0
|
|
|
|
|
|
$ep->InsertText( $startpos, $closebrace );
|
174
|
|
|
|
|
|
|
}
|
175
|
0
|
0
|
|
|
|
|
if ( $lastopos > $lastcpos ) {
|
176
|
0
|
|
|
|
|
|
$ep->InsertText( $endpos, $openbrace );
|
177
|
|
|
|
|
|
|
}
|
178
|
0
|
0
|
0
|
|
|
|
if ( ( $lastopos == -1 ) && ( $lastcpos == -1 ) ) {
|
179
|
0
|
|
|
|
|
|
$ep->InsertText( $startpos, $closebrace );
|
180
|
0
|
|
|
|
|
|
$ep->InsertText( $endpos + length($closebrace), $openbrace );
|
181
|
|
|
|
|
|
|
}
|
182
|
0
|
|
|
|
|
|
$ep->EndUndoAction();
|
183
|
|
|
|
|
|
|
}
|
184
|
|
|
|
|
|
|
}
|
185
|
|
|
|
|
|
|
|
186
|
0
|
|
|
0
|
0
|
|
sub add_script { add_block ('#') }
|
187
|
0
|
|
|
0
|
0
|
|
sub sub_script { remove_block('#') }
|
188
|
0
|
|
|
0
|
0
|
|
sub toggle_script { toggle_block('#') }
|
189
|
0
|
|
|
0
|
0
|
|
sub format_script { format_block('#') }
|
190
|
0
|
|
|
0
|
0
|
|
sub sub_xml { remove_stream( '' ) }
|
191
|
0
|
|
|
0
|
0
|
|
sub add_xml { add_stream ( '' ) }
|
192
|
0
|
|
|
0
|
0
|
|
sub add_c { add_stream ( '/*', '*/' ) }
|
193
|
0
|
|
|
0
|
0
|
|
sub sub_c { remove_stream( '/*', '*/' ) }
|
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
1;
|
196
|
|
|
|
|
|
|
__END__ |