line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Kephra::Edit::Select;
|
2
|
|
|
|
|
|
|
our $VERSION = '0.08';
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
1098
|
use strict;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
34
|
|
5
|
1
|
|
|
1
|
|
14
|
use warnings;
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
1402
|
|
6
|
0
|
0
|
|
0
|
|
|
sub _ep_ref { Kephra::App::EditPanel::is( shift ) || Kephra::App::EditPanel::_ref() }
|
7
|
|
|
|
|
|
|
sub _line_empty {
|
8
|
0
|
|
|
0
|
|
|
my $line = shift;
|
9
|
0
|
|
|
|
|
|
my $ep = _ep_ref( shift );
|
10
|
0
|
0
|
|
|
|
|
$line = $ep->GetCurrentLine() unless defined $line;
|
11
|
0
|
|
|
|
|
|
return $ep->PositionFromLine($line) == $ep->GetLineEndPosition($line);
|
12
|
|
|
|
|
|
|
}
|
13
|
|
|
|
|
|
|
#
|
14
|
|
|
|
|
|
|
sub get_block_start {
|
15
|
0
|
|
|
0
|
0
|
|
my $pos = shift;
|
16
|
0
|
|
|
|
|
|
my $ep = _ep_ref( shift );
|
17
|
0
|
0
|
|
|
|
|
$pos = $ep->GetCurrentPos unless defined $pos;
|
18
|
0
|
|
|
|
|
|
my $line = $ep->LineFromPosition($pos);
|
19
|
0
|
0
|
|
|
|
|
return $pos if _line_empty($line);
|
20
|
0
|
0
|
0
|
|
|
|
return $pos if _line_empty($line-1) and $pos == $ep->PositionFromLine($line);
|
21
|
0
|
|
|
|
|
|
my $cpos = $ep->GetCurrentPos;
|
22
|
0
|
|
|
|
|
|
$ep->SetCurrentPos( $pos );
|
23
|
0
|
|
|
|
|
|
$ep->CmdKeyExecute(&Wx::wxSTC_CMD_PARAUP);
|
24
|
0
|
|
|
|
|
|
$pos = $ep->GetCurrentPos;
|
25
|
0
|
|
|
|
|
|
$ep->SetCurrentPos( $cpos );
|
26
|
0
|
|
|
|
|
|
return $pos;
|
27
|
|
|
|
|
|
|
}
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub get_block_end {
|
30
|
0
|
|
|
0
|
0
|
|
my $pos = shift;
|
31
|
0
|
|
|
|
|
|
my $ep = _ep_ref( shift );
|
32
|
0
|
0
|
|
|
|
|
$pos = $ep->GetCurrentPos unless defined $pos;
|
33
|
0
|
|
|
|
|
|
my $line = $ep->LineFromPosition($pos);
|
34
|
0
|
0
|
|
|
|
|
return $pos if _line_empty($line);
|
35
|
0
|
0
|
0
|
|
|
|
return $pos if _line_empty($line+1) and $pos == $ep->GetLineEndPosition($line);
|
36
|
0
|
|
|
|
|
|
my $cpos = $ep->GetCurrentPos;
|
37
|
0
|
|
|
|
|
|
$ep->SetCurrentPos( $pos );
|
38
|
0
|
|
|
|
|
|
$ep->CmdKeyExecute(&Wx::wxSTC_CMD_PARADOWN);
|
39
|
0
|
|
|
|
|
|
$line = $ep->GetCurrentLine();
|
40
|
0
|
|
|
|
|
|
$line--;
|
41
|
0
|
|
|
|
|
|
$line-- until $ep->PositionFromLine($line)!=$ep->GetLineEndPosition($line);
|
42
|
0
|
|
|
|
|
|
$pos = $ep->GetLineEndPosition($line);
|
43
|
0
|
|
|
|
|
|
$ep->SetCurrentPos( $cpos );
|
44
|
0
|
|
|
|
|
|
return $pos;
|
45
|
|
|
|
|
|
|
}
|
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
0
|
0
|
|
sub to_block_begin{ _ep_ref()->CmdKeyExecute(&Wx::wxSTC_CMD_PARAUPEXTEND) }
|
48
|
0
|
|
|
0
|
0
|
|
sub to_block_end { _ep_ref()->CmdKeyExecute(&Wx::wxSTC_CMD_PARADOWNEXTEND) }
|
49
|
|
|
|
|
|
|
#
|
50
|
|
|
|
|
|
|
sub nothing {
|
51
|
0
|
|
|
0
|
1
|
|
my $ep = _ep_ref( shift );
|
52
|
0
|
|
|
|
|
|
my $pos = $ep->GetCurrentPos;
|
53
|
0
|
|
|
|
|
|
$ep->SetSelection( $pos, $pos )
|
54
|
|
|
|
|
|
|
}
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub word {
|
57
|
0
|
|
|
0
|
1
|
|
my $pos = shift;
|
58
|
0
|
|
|
|
|
|
my $ep = _ep_ref( shift );
|
59
|
0
|
0
|
|
|
|
|
$pos = $ep->GetCurrentPos unless defined $pos;
|
60
|
0
|
|
|
|
|
|
$ep->SetSelection($ep->WordStartPosition($pos,1),$ep->WordEndPosition($pos,1));
|
61
|
|
|
|
|
|
|
}
|
62
|
|
|
|
|
|
|
sub line {
|
63
|
0
|
|
|
0
|
1
|
|
my $line = shift;
|
64
|
0
|
|
|
|
|
|
my $ep = _ep_ref( shift );
|
65
|
0
|
0
|
|
|
|
|
$line = $ep->GetCurrentLine() unless defined $line;
|
66
|
0
|
|
|
|
|
|
$ep->SetSelection($ep->PositionFromLine($line),$ep->GetLineEndPosition($line));
|
67
|
|
|
|
|
|
|
}
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub block {
|
70
|
0
|
|
|
0
|
1
|
|
my $pos = shift;
|
71
|
0
|
|
|
|
|
|
my $ep = _ep_ref( shift );
|
72
|
0
|
0
|
|
|
|
|
$pos = $ep->GetCurrentPos unless defined $pos;
|
73
|
0
|
|
|
|
|
|
$ep->SetSelection( get_block_start($pos), get_block_end($pos) );
|
74
|
|
|
|
|
|
|
}
|
75
|
0
|
|
|
0
|
0
|
|
sub all { &document }
|
76
|
0
|
|
|
0
|
1
|
|
sub document { _ep_ref()->SelectAll }
|
77
|
|
|
|
|
|
|
sub all_if_non {
|
78
|
0
|
|
|
0
|
0
|
|
my $ep = _ep_ref();
|
79
|
0
|
0
|
|
|
|
|
$ep->SelectAll if $ep->GetSelectionStart == $ep->GetSelectionEnd;
|
80
|
0
|
|
|
|
|
|
my ($start, $end) = $ep->GetSelection;
|
81
|
0
|
|
|
|
|
|
return $ep->GetTextRange( $start, $end );
|
82
|
|
|
|
|
|
|
}
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub toggle_simple { # selects word line block or nothing
|
85
|
0
|
|
|
0
|
0
|
|
my $ep = _ep_ref( shift );
|
86
|
0
|
|
|
|
|
|
my ($start, $end)= $ep->GetSelection; # initial selection
|
87
|
0
|
|
|
|
|
|
my $startline = $ep->LineFromPosition($start);
|
88
|
0
|
|
|
|
|
|
my $endline = $ep->LineFromPosition($end);
|
89
|
|
|
|
|
|
|
|
90
|
0
|
0
|
0
|
|
|
|
return if _line_empty($startline) and _line_empty($endline);
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# try select word, if already more selected, do a line
|
93
|
0
|
0
|
|
|
|
|
if ($startline == $endline){
|
94
|
0
|
|
|
|
|
|
word($start);
|
95
|
0
|
|
|
|
|
|
my ($probestart, $probeend) = $ep->GetSelection;
|
96
|
0
|
0
|
0
|
|
|
|
return unless $start <= $probestart and $end >= $probeend;
|
97
|
0
|
|
|
|
|
|
line();
|
98
|
0
|
|
|
|
|
|
($probestart, $probeend) = $ep->GetSelection;
|
99
|
0
|
0
|
0
|
|
|
|
return unless $start == $probestart and $end == $probeend;
|
100
|
|
|
|
|
|
|
}
|
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
my $blockstart = get_block_start($start);
|
103
|
0
|
|
|
|
|
|
my $blockend = get_block_end($end);
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# select nothing because block was selected
|
106
|
0
|
0
|
0
|
|
|
|
return nothing() if $start == $blockstart and $end == $blockend;
|
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
$ep->SetSelection($blockstart, $blockend);
|
109
|
|
|
|
|
|
|
}
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub toggle_content { # selects text inside of < > [] {} () '' ""
|
112
|
0
|
|
|
0
|
0
|
|
my $ep = _ep_ref( shift );
|
113
|
0
|
|
|
|
|
|
my $min = my $max = my $pos = $ep->GetCurrentPos; |
114
|
0
|
|
|
|
|
|
my ($start, $end)= $ep->GetSelection;
|
115
|
0
|
|
|
|
|
|
my $startline = $ep->LineFromPosition($start);
|
116
|
0
|
|
|
|
|
|
my $endline = $ep->LineFromPosition($end); |
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
my $style = $ep->GetStyleAt($pos); |
119
|
|
|
|
|
|
|
# select quotetation, styles: 6" 7' re styles 17, 18
|
120
|
0
|
0
|
0
|
|
|
|
if ($style == 6 or $style == 7){ |
121
|
0
|
|
|
|
|
|
$min-- while $ep->GetStyleAt($min-1) == $style; |
122
|
0
|
|
|
|
|
|
$max++ while $ep->GetStyleAt($max+1) == $style; |
123
|
|
|
|
|
|
|
|
124
|
0
|
0
|
0
|
|
|
|
unless ($start==$min and $end-1==$max) { |
125
|
0
|
0
|
0
|
|
|
|
if ($start-1==$min and $end==$max) {$ep->SetSelection($min, $max+1)} |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
else {$ep->SetSelection($min+1, $max)} |
127
|
0
|
|
|
|
|
|
return; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
#my %delimiter = ( |
131
|
|
|
|
|
|
|
#'>' => '<', ']'=>'[', '}'=>'{', ')'=>'(', |
132
|
|
|
|
|
|
|
#'/' => '/', '\'' => '\'', '"' => '"' |
133
|
|
|
|
|
|
|
#); |
134
|
|
|
|
|
|
|
#print "$start, $end--\n";
|
135
|
|
|
|
|
|
|
#$ep->GetTextRange();
|
136
|
|
|
|
|
|
|
#$ep->PositionFromLine($line) $ep->GetLineEndPosition($line);
|
137
|
|
|
|
|
|
|
#$ep->BraceMatch($newpos)
|
138
|
|
|
|
|
|
|
#my $blockstart = get_block_start($start);
|
139
|
|
|
|
|
|
|
#my $blockend = get_block_end($end);
|
140
|
|
|
|
|
|
|
#$ep->PositionFromLine($line);
|
141
|
|
|
|
|
|
|
#$ep->GetLineEndPosition($line);
|
142
|
|
|
|
|
|
|
#$pasttext =~ /([||||||])/
|
143
|
|
|
|
|
|
|
#/{|}|\(|\)|\[|\]/
|
144
|
|
|
|
|
|
|
#tr/{}()\[\]//;
|
145
|
|
|
|
|
|
|
#$`
|
146
|
|
|
|
|
|
|
#my $matchpos = $ep->BraceMatch(--$pos);
|
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
#print '',($ep->GetSelection),"\n"; |
149
|
|
|
|
|
|
|
}
|
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
# expand rectangular selection |
153
|
0
|
|
|
0
|
0
|
|
sub expand_rect_left{} |
154
|
0
|
|
|
0
|
0
|
|
sub expand_rect_right{} |
155
|
0
|
|
|
0
|
0
|
|
sub expand_rect_up{} |
156
|
0
|
|
|
0
|
0
|
|
sub expand_rect_down{} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
1;
|
159
|
|
|
|
|
|
|
__END__
|