blib/lib/Text/Editor/Vip/Buffer/Plugins/Selection.pm

filter: Statementstmt 92.6% 114 / 123 Branchbran 93.3% 28 / 30 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.3% 28 / 31 Podpod 96.1% 25 / 26 totaltotal 92.8% 195 / 210 CC 16 SCAR 7.1
CC
16
Cov
93%
ExtendSelectionToPreviousWord
6.0
ExtendSelectionHome
3.0
ExtendSelectionLeft
3.0
CRAP 2.0
« blib/lib/Text/Editor/Vip/Buffer/Plugins/InsertDelete.pm ↑ Summary blib/lib/Text/Editor/Vip/Buffer.pm »
1  
2 package Text::Editor::Vip::Buffer::Plugins::Selection;
3  
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use warnings ;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 BEGIN
8 5 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 5 ▶use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 $VERSION = 0.01;
13 5 @ISA = qw (Exporter);
14 5 @EXPORT = qw ();
15 5 @EXPORT_OK = qw ();
16 5 %EXPORT_TAGS = ();
17 }
18  
19 =head1 NAME
20  
21 Text::Editor::Vip::Buffer::Plugins::Selecton- Add extra selection commands to Vip::Buffer
22  
23 =head1 SYNOPSIS
24  
25 use Text::Editor::Vip::Buffer
26
27 =head1 DESCRIPTION
28  
29 Adds Selection commands to the buffer.
30  
31 =head1 Functions
32  
33 =cut
34  
35 #-------------------------------------------------------------------------------
36  
37 sub IsSelectionEmpty
38 123 ▶{
Subroutine IsSelectionEmpty: called CC=1 SCAR=0.0
Pod documented
39  
40 =head2 IsSelectionEmpty
41  
42 =cut
43  
44 123 my $buffer = shift ;
45  
46 123 return($buffer->{SELECTION}->IsEmpty()) ;
47 }
48  
49 #-------------------------------------------------------------------------------
50  
51 sub ClearSelection
52 12 ▶{
Subroutine ClearSelection: called CC=1 SCAR=0.0
Pod documented
53  
54 =head2 ClearSelection
55  
56 =cut
57  
58 12 my $buffer = shift ;
59 12 return($buffer->{SELECTION}->Clear()) ;
60 }
61  
62 #-------------------------------------------------------------------------------
63  
64 sub SetSelectionAnchor($$) # Expects line and character
65 40 ▶{
Subroutine SetSelectionAnchor: called CC=1 SCAR=0.0
Pod documented
66  
67 =head2 SetSelectionAnchor
68  
69 =cut
70  
71 40 my $buffer = shift ;
72 40 my ($line, $character) = @_ ;
73  
74 40 my ($original_line, $original_character) = $buffer->{SELECTION}->GetAnchor() ;
75  
76 40 my $undo_block = new Text::Editor::Vip::CommandBlock
77 (
78 $buffer
79 , "\$buffer->SetSelectionAnchor($line, $character) ;"
80 , ' #'
81 , "\$buffer->SetSelectionAnchor($original_line, $original_character) ;"
82 , ' #'
83 ) ;
84  
85 40 return($buffer->{SELECTION}->SetAnchor($line, $character)) ;
86 }
87  
88 #-------------------------------------------------------------------------------
89  
90 sub SetSelectionLine($$) # Expects line and character
91 130 ▶{
Subroutine SetSelectionLine: called CC=1 SCAR=0.0
Pod documented
92  
93 =head2 SetSelectionLine
94  
95 =cut
96  
97 130 my $buffer = shift ;
98 130 my ($line, $character) = @_ ;
99  
100 130 my ($original_line, $original_character) = $buffer->{SELECTION}->GetLine() ;
101  
102 130 my $undo_block = new Text::Editor::Vip::CommandBlock
103 (
104 $buffer
105 , "\$buffer->SetSelectionLine($line, $character) ;"
106 , ' #'
107 , "\$buffer->SetSelectionLine($original_line, $original_character) ;"
108 , ' #'
109 ) ;
110  
111 130 return($buffer->{SELECTION}->SetLine(@_)) ;
112 }
113  
114 #-------------------------------------------------------------------------------
115  
116 sub GetSelectionBoundaries
117 0 ▶{
Subroutine GetSelectionBoundaries: not called CC=1 SCAR=6.9
Pod documented
118  
119 =head2 GetSelectionBoundaries
120  
121 =cut
122  
123 0 my $buffer = shift ;
124 0 return($buffer->{SELECTION}->GetBoundaries()) ;
125 }
126  
127 #-------------------------------------------------------------------------------
128  
129 sub GetSelectionStartLine
130 1 ▶{
Subroutine GetSelectionStartLine: called CC=1 SCAR=0.0
Pod documented
131  
132 =head2 GetSelectionStartLine
133  
134 =cut
135  
136 1 my $buffer = shift ;
137 1 return($buffer->{SELECTION}->GetStartLine()) ;
138 }
139  
140 #-------------------------------------------------------------------------------
141  
142 sub GetSelectionStartCharacter
143 1 ▶{
Subroutine GetSelectionStartCharacter: called CC=1 SCAR=0.0
Pod documented
144  
145 =head2 GetSelectionStartCharacter
146  
147 =cut
148  
149 1 my $buffer = shift ;
150 1 return($buffer->{SELECTION}->GetStartCharacter()) ;
151 }
152  
153 #-------------------------------------------------------------------------------
154  
155 sub GetSelectionEndLine
156 1 ▶{
Subroutine GetSelectionEndLine: called CC=1 SCAR=0.0
Pod documented
157  
158 =head2 GetSelectionEndLine
159  
160 =cut
161  
162 1 my $buffer = shift ;
163 1 return($buffer->{SELECTION}->GetEndLine()) ;
164 }
165  
166 #-------------------------------------------------------------------------------
167  
168 sub GetSelectionEndCharacter
169 1 ▶{
Subroutine GetSelectionEndCharacter: called CC=1 SCAR=0.0
Pod documented
170  
171 =head2 GetSelectionEndCharacter
172  
173 =cut
174  
175 1 my $buffer = shift ;
176 1 return($buffer->{SELECTION}->GetEndCharacter()) ;
177 }
178  
179 #-------------------------------------------------------------------------------
180  
181 sub IsCharacterSelected($$) # Expects a line and a character index
182 7 ▶{
Subroutine IsCharacterSelected: called CC=1 SCAR=0.0
Pod documented
183  
184 =head2 IsCharacterSelected
185  
186 Returns 'true' if the character is within the boundaries of the selection.
187  
188 $buffer->IsCharacterSelected($line, $character) ;
189
190 =cut
191  
192 7 my $buffer = shift ;
193 7 return($buffer->{SELECTION}->IsCharacterSelected(@_)) ;
194 }
195  
196 #-------------------------------------------------------------------------------
197  
198 sub IsLineSelected($)
199 0 ▶{
Subroutine IsLineSelected: not called CC=1 SCAR=6.9
Pod undocumented
200  
201 =head2
202  
203 Returns 'true' if the line is within the boundaries of the selection.
204  
205 $buffer->IsLineSelected($line) ;
206
207 =cut
208  
209 0 my $buffer = shift ;
210 0 return($buffer->{SELECTION}->IsLineSelected(@_)) ;
211 }
212  
213 #-------------------------------------------------------------------------------
214  
215 sub SelectAll
216 9 ▶{
Subroutine SelectAll: called CC=1 SCAR=0.0
Pod documented
217  
218 =head2 SelectAll
219  
220 =cut
221  
222 9 my $buffer = shift ;
223  
224 9 my $undo_block = new Text::Editor::Vip::CommandBlock($buffer, "#\$buffer->SelectAll() ;", ' ', "# undo for \$buffer->SelectAll() ;", ' ') ;
225  
226 9 $buffer->SetSelectionAnchor(0, 0) ;
227 9 $buffer->SetSelectionLine
228 (
229 $buffer->GetNumberOfLines() - 1
230 , $buffer->GetLineLength($buffer->GetNumberOfLines() - 1)
231 ) ;
232 }
233  
234 #-------------------------------------------------------------------------------
235  
236 sub SetSelectionAnchorAtCurrentPosition
237 27 ▶{
Subroutine SetSelectionAnchorAtCurrentPosition: called CC=1 SCAR=0.0
Pod documented
238  
239 =head2 SetSelectionAnchorAtCurrentPosition
240  
241 =cut
242  
243 27 my $buffer = shift ;
244 27 $buffer->SetSelectionAnchor
245 (
246 $buffer->GetModificationLine()
247 , $buffer->GetModificationCharacter()
248 ) ;
249 }
250  
251 #-------------------------------------------------------------------------------
252  
253 sub ExtendSelection
254 118 ▶{
Subroutine ExtendSelection: called CC=1 SCAR=0.0
Pod documented
255  
256 =head2 ExtendSelection
257  
258 Extends the selection to the current modification position.
259  
260 =cut
261  
262 118 my $buffer = shift ;
263 118 $buffer->SetSelectionLine
264 (
265 $buffer->GetModificationLine()
266 , $buffer->GetModificationCharacter()
267 ) ;
268 }
269  
270 #-------------------------------------------------------------------------------
271  
272 sub ExtendSelectionToEndOfLine
273 4 ▶{
Subroutine ExtendSelectionToEndOfLine: called CC=2 SCAR=6.9
Pod documented
274  
275 =head2 ExtendSelectionToEndOfLine
276  
277 =cut
278  
279 4 my $buffer = shift ;
280 4 $buffer->ExpandedWithOrLoad('MoveToEndOfLineNoSelectionClear', 'Text::Editor::Vip::Buffer::Plugins::Movements') ;
281  
282 4 ▶$buffer->SetSelectionAnchorAtCurrentPosition() if $buffer->IsSelectionEmpty() ;
Branch: 1 branch
BranchTrueFalseTotal
if $buffer->IsSelectionEmpty 1 3 4
283 4 $buffer->MoveToEndOfLineNoSelectionClear() ;
284 4 $buffer->ExtendSelection() ;
285 }
286  
287 #-------------------------------------------------------------------------------
288  
289 sub ExtendSelectionToEndOfBuffer
290 2 ▶{
Subroutine ExtendSelectionToEndOfBuffer: called CC=2 SCAR=6.9
Pod documented
291  
292 =head2 ExtendSelectionToEndOfBuffer
293  
294 =cut
295  
296 2 my $buffer = shift ;
297 2 ▶$buffer->SetSelectionAnchorAtCurrentPosition() if $buffer->IsSelectionEmpty() ;
Branch: 1 branch
BranchTrueFalseTotal
if $buffer->IsSelectionEmpty 1 1 2
298  
299 2 my $number_of_lines = $buffer->GetNumberOfLines() ;
300  
301 2 $buffer->SetModificationLine($number_of_lines - 1) ;
302 2 $buffer->ExtendSelectionToEndOfLine() ;
303 }
304  
305 #-------------------------------------------------------------------------------
306  
307 sub ExtendSelectionToStartOfBuffer
308 2 ▶{
Subroutine ExtendSelectionToStartOfBuffer: called CC=2 SCAR=6.9
Pod documented
309  
310 =head2 ExtendSelectionToStartOfBuffer
311  
312 =cut
313  
314 2 my $buffer = shift ;
315 2 ▶$buffer->SetSelectionAnchorAtCurrentPosition() if $buffer->IsSelectionEmpty() ;
Branch: 1 branch
BranchTrueFalseTotal
if $buffer->IsSelectionEmpty 1 1 2
316  
317 2 $buffer->SetModificationPosition(0, 0) ;
318  
319 2 $buffer->ExtendSelection() ;
320 }
321  
322 #-------------------------------------------------------------------------------
323  
324 sub ExtendSelectionHome
325 4 ▶{
Subroutine ExtendSelectionHome: called CC=3 SCAR=11.0
Pod documented
326  
327 =head2 ExtendSelectionHome
328  
329 =cut
330  
331 4 my $buffer = shift ;
332 4 ▶$buffer->SetSelectionAnchorAtCurrentPosition() if $buffer->IsSelectionEmpty() ;
Branch: 1 branch
BranchTrueFalseTotal
if $buffer->IsSelectionEmpty 1 3 4
333  
334 4 $buffer->ExpandedWithOrLoad('GetFirstNonSpacePosition', 'Text::Editor::Vip::Buffer::Plugins::Movements') ;
335  
336 4 my $first_word_position = $buffer->GetFirstNonSpacePosition($buffer->GetModificationLine()) ;
337  
338 4 ▶if($first_word_position == $buffer->GetModificationCharacter())
Branch: 1 branch
BranchTrueFalseTotal
if ($first_word_position == $buffer->GetModificationCharacter) { } 2 2 4
339 {
340 2 $buffer->SetModificationCharacter(0) ;
341 }
342 else
343 {
344 2 $buffer->SetModificationCharacter($first_word_position) ;
345 }
346  
347 4 $buffer->ExtendSelection() ;
348 }
349  
350 #-----------------------------------------------------------------------
351  
352 sub ExtendSelectionLeft
353 6 ▶{
Subroutine ExtendSelectionLeft: called CC=3 SCAR=11.0
Pod documented
354  
355 =head2 ExtendSelectionLeft
356  
357 =cut
358  
359 6 my $buffer = shift ;
360 6 ▶$buffer->SetSelectionAnchorAtCurrentPosition() if $buffer->IsSelectionEmpty() ;
Branch: 1 branch
BranchTrueFalseTotal
if $buffer->IsSelectionEmpty 1 5 6
361  
362 6 ▶if(0 != $buffer->GetModificationCharacter())
Branch: 1 branch
BranchTrueFalseTotal
if (0 != $buffer->GetModificationCharacter) 5 1 6
363 {
364 5 $buffer->SetModificationCharacter($buffer->GetModificationCharacter() - 1) ;
365 }
366  
367 6 $buffer->ExtendSelection() ;
368 }
369  
370 #-----------------------------------------------------------------------
371  
372 sub ExtendSelectionRight
373 62 ▶{
Subroutine ExtendSelectionRight: called CC=2 SCAR=6.9
Pod documented
374  
375 =head2 ExtendSelectionRight
376  
377 =cut
378  
379 62 my $buffer = shift ;
380 62 ▶$buffer->SetSelectionAnchorAtCurrentPosition() if $buffer->IsSelectionEmpty() ;
Branch: 1 branch
BranchTrueFalseTotal
if $buffer->IsSelectionEmpty 2 60 62
381  
382 62 $buffer->SetModificationCharacter($buffer->GetModificationCharacter() + 1) ;
383 62 $buffer->ExtendSelection() ;
384 }
385  
386 #-----------------------------------------------------------------------
387  
388 sub ExtendSelectionUp
389 6 ▶{
Subroutine ExtendSelectionUp: called CC=3 SCAR=11.0
Pod documented
390  
391 =head2 ExtendSelectionUp
392  
393 =cut
394  
395 6 my $buffer = shift ;
396 6 ▶$buffer->SetSelectionAnchorAtCurrentPosition() if $buffer->IsSelectionEmpty() ;
Branch: 1 branch
BranchTrueFalseTotal
if $buffer->IsSelectionEmpty 2 4 6
397 6 $buffer->ExpandedWithOrLoad('MoveUpNoSelectionClea', 'Text::Editor::Vip::Buffer::Plugins::Display') ;
398  
399 6 my $modification_line = $buffer->GetModificationLine() ;
400  
401 6 ▶if($modification_line != 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($modification_line != 0) 4 2 6
402 {
403 4 $buffer->SetModificationCharacter
404 (
405 $buffer->GetCharacterPositionInText
406 (
407 $modification_line - 1
408 , $buffer->GetCharacterDisplayPosition
409 (
410 $modification_line
411 , $buffer->GetModificationCharacter()
412 )
413 )
414 ) ;
415  
416 4 $buffer->SetModificationLine($modification_line - 1) ;
417 }
418 #else
419 # at first line
420
421 6 $buffer->ExtendSelection() ;
422 }
423  
424 #-----------------------------------------------------------------------
425  
426 sub ExtendSelectionDown
427 11 ▶{
Subroutine ExtendSelectionDown: called CC=3 SCAR=11.0
Pod documented
428  
429 =head2 ExtendSelectionDown
430  
431 =cut
432  
433 11 my $buffer = shift ;
434 11 ▶$buffer->SetSelectionAnchorAtCurrentPosition() if $buffer->IsSelectionEmpty() ;
Branch: 1 branch
BranchTrueFalseTotal
if $buffer->IsSelectionEmpty 2 9 11
435  
436 11 $buffer->ExpandedWithOrLoad('GetCharacterDisplayPosition', 'Text::Editor::Vip::Buffer::Plugins::Display') ;
437  
438 11 my $modification_line = $buffer->GetModificationLine() ;
439  
440 11 ▶if($modification_line != ($buffer->GetNumberOfLines() - 1))
Branch: 1 branch
BranchTrueFalseTotal
if ($modification_line != $buffer->GetNumberOfLines - 1) 10 1 11
441 {
442 10 $buffer->SetModificationCharacter
443 (
444 $buffer->GetCharacterPositionInText
445 (
446 $modification_line + 1
447 , $buffer->GetCharacterDisplayPosition
448 (
449 $modification_line
450 , $buffer->GetModificationCharacter()
451 )
452 )
453 ) ;
454
455 10 $buffer->SetModificationLine($modification_line + 1) ;
456 }
457 #else
458 # at last line
459  
460 11 $buffer->ExtendSelection() ;
461 }
462  
463 #-------------------------------------------------------------------------------
464  
465 sub SelectWord
466 8 ▶{
Subroutine SelectWord: called CC=1 SCAR=0.0
Pod documented
467  
468 =head2 SelectWord
469  
470 Selects the word at the current position.
471  
472 =cut
473  
474 8 my $buffer = shift ;
475  
476 8 $buffer->ExpandedWithOrLoad('MoveToEndOfWordNoSelectionClear', 'Text::Editor::Vip::Buffer::Plugins::Movements') ;
477  
478 8 $buffer->MoveToPreviousWord() ;
479 8 $buffer->MoveToNextWord() ;
480 8 $buffer->SetSelectionAnchorAtCurrentPosition() ;
481 8 $buffer->MoveToEndOfWordNoSelectionClear() ;
482 8 $buffer->ExtendSelection() ;
483 }
484
485 #-----------------------------------------------------------------------
486  
487 sub ExtendSelectionToBeginingOfWord
488 9 ▶{
Subroutine ExtendSelectionToBeginingOfWord: called CC=2 SCAR=6.9
Pod documented
489  
490 =head2 ExtendSelectionToBeginingOfWord
491  
492 =cut
493  
494 9 my $buffer = shift ;
495 9 $buffer->ExpandedWithOrLoad('MoveToBeginingOfWordNoSelectionClear', 'Text::Editor::Vip::Buffer::Plugins::Movements') ;
496  
497 9 ▶$buffer->SetSelectionAnchorAtCurrentPosition() if $buffer->IsSelectionEmpty() ;
Branch: 1 branch
BranchTrueFalseTotal
if $buffer->IsSelectionEmpty 5 4 9
498 9 $buffer->MoveToBeginingOfWordNoSelectionClear() ;
499 9 $buffer->ExtendSelection() ;
500 }
501  
502 #-------------------------------------------------------------------------------
503  
504 sub ExtendSelectionToNextWord
505 4 ▶{
Subroutine ExtendSelectionToNextWord: called CC=2 SCAR=6.9
Pod documented
506  
507 =head2 ExtendSelectionToNextWord
508  
509 =cut
510  
511 4 my $buffer = shift ;
512 4 ▶$buffer->SetSelectionAnchorAtCurrentPosition() if $buffer->IsSelectionEmpty() ;
Branch: 1 branch
BranchTrueFalseTotal
if $buffer->IsSelectionEmpty 2 2 4
513 4 $buffer->ExpandedWithOrLoad('MoveToEndOfWordNoSelectionClear', 'Text::Editor::Vip::Buffer::Plugins::Movements') ;
514  
515 4 $buffer->MoveToEndOfWordNoSelectionClear() ;
516 4 $buffer->ExtendSelection() ;
517 }
518  
519 #-----------------------------------------------------------------------
520  
521 sub ExtendSelectionToPreviousWord
522 0 ▶{
Subroutine ExtendSelectionToPreviousWord: not called CC=2 SCAR=17.9
Pod documented
523  
524 =head2 ExtendSelectionToPreviousWord
525  
526 =cut
527  
528 0 my $buffer = shift ;
529 0 ▶$buffer->SetSelectionAnchorAtCurrentPosition() if $buffer->IsSelectionEmpty() ;
Branch: 1 branch
BranchTrueFalseTotal
if $buffer->IsSelectionEmpty 0 0 0
530 0 $buffer->ExpandedWithOrLoad('MoveToPreviousWordNoSelectionClear', 'Text::Editor::Vip::Buffer::Plugins::Movements') ;
531  
532 0 $buffer->MoveToPreviousWordNoSelectionClear() ;
533 0 $buffer->ExtendSelection() ;
534 }
535  
536 #-------------------------------------------------------------------------------
537  
538 5 1 ;
539  
540 =head1 AUTHOR
541  
542 Khemir Nadim ibn Hamouda
543 CPAN ID: NKH
544 mailto:nadim@khemir.net
545 http:// no web site
546  
547 =head1 COPYRIGHT
548  
549 This program is free software; you can redistribute
550 it and/or modify it under the same terms as Perl itself.
551  
552 The full text of the license can be found in the
553 LICENSE file included with this module.
554  
555 =cut
« blib/lib/Text/Editor/Vip/Buffer/Plugins/InsertDelete.pm ↑ Summary blib/lib/Text/Editor/Vip/Buffer.pm »