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

filter: Statementstmt 98.9% 191 / 193 Branchbran 97.1% 68 / 70 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 30 / 30 Podpod 100% 25 / 25 totaltotal 98.7% 319 / 323 CC 37 SCAR 13.9
CC
37
Cov
98%
MoveToPreviousWordNoSelectionClear
10.1
MoveToNextWordNoSelectionClear
7.0
MoveToEndOfWordNoSelectionClear
5.0
CRAP 4.0
« blib/lib/Text/Editor/Vip/Buffer/DoUndoRedo.pm ↑ Summary blib/lib/Text/Editor/Vip/Buffer/Plugins/GetWord.pm »
1  
2 package Text::Editor::Vip::Buffer::Plugins::Movements;
3  
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use warnings ;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 BEGIN
8 4 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 4 ▶use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 $VERSION = 0.01;
13 4 @ISA = qw (Exporter);
14 4 @EXPORT = qw ();
15 4 @EXPORT_OK = qw ();
16 4 %EXPORT_TAGS = ();
17 }
18  
19 =head1 NAME
20  
21 Text::Editor::Vip::Buffer::Plugins::Movements- Add movement commands to Vip::Buffer
22  
23 =head1 SYNOPSIS
24  
25 use Text::Editor::Vip::Buffer
26
27 =head1 DESCRIPTION
28  
29 Add movement commands to Vip::Buffer. The commands use tab and a virtual buffer
30  
31 =head1 FUNCTIONS
32  
33 =cut
34  
35 #-------------------------------------------------------------------------------
36  
37 sub SetModificationPositionAtSelectionStart
38 2 ▶{
Subroutine SetModificationPositionAtSelectionStart: called CC=2 SCAR=6.9
Pod documented
39  
40 =head2 SetModificationPositionAtSelectionStart
41  
42 =cut
43  
44 2 my $buffer = shift ;
45  
46 2 ▶unless($buffer->{SELECTION}->IsEmpty())
Branch: 1 branch
BranchTrueFalseTotal
unless ($buffer->{"SELECTION"}->IsEmpty) 1 1 2
47 {
48 1 $buffer->SetModificationPosition($buffer->{SELECTION}->GetBoundaries()) ;
49 }
50 }
51  
52 #-------------------------------------------------------------------------------
53  
54 sub GetFirstNonSpacePosition
55 15 ▶{
Subroutine GetFirstNonSpacePosition: called CC=3 SCAR=11.0
Pod documented
56  
57 =head2 GetFirstNonSpacePosition
58  
59 Finds the first non space position at the B<line> argument or the current line if B<line> is not passed.
60  
61 =cut
62  
63 15 my $buffer = shift ;
64 15 my $line_index = shift ;
65  
66 15 ▶$line_index = $buffer->GetModificationLine() unless defined $line_index ;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line_index 1 14 15
67  
68 15 my $text = $buffer->GetLineText($line_index) ;
69
70 14 ▶if($text =~ /^([\t ]+)/)
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /^([\t ]+)/) { } 12 2 14
71 {
72 12 return(length($1)) ;
73 }
74 else
75 {
76 2 return(0) ;
77 }
78 }
79  
80 #-------------------------------------------------------------------------------
81  
82 sub MoveToTopOfBuffer
83 1 ▶{
Subroutine MoveToTopOfBuffer: called CC=1 SCAR=0.0
Pod documented
84  
85 =head2 MoveToTopOfBuffer
86  
87 Clears the buffer and Sets the modification position at 0,0.
88  
89 =cut
90  
91 1 my $buffer = shift ;
92 1 $buffer->{SELECTION}->Clear() ;
93 1 $buffer->SetModificationLine(0) ;
94 1 $buffer->SetModificationCharacter(0) ;
95 }
96  
97 #-------------------------------------------------------------------------------
98  
99 sub MoveToEndOfBuffer
100 1 ▶{
Subroutine MoveToEndOfBuffer: called CC=1 SCAR=0.0
Pod documented
101  
102 =head2 MoveToEndOfBuffer
103  
104 Clears the selection and sets the modification position after the last character of the last line.
105  
106 =cut
107  
108 1 my $buffer = shift ;
109 1 $buffer->{SELECTION}->Clear() ;
110 1 $buffer->SetModificationLine($buffer->GetNumberOfLines() - 1) ;
111 1 $buffer->MoveToEndOfLine() ;
112 }
113  
114 #-------------------------------------------------------------------------------
115  
116 sub MoveToEndOfLine
117 5 ▶{
Subroutine MoveToEndOfLine: called CC=2 SCAR=6.9
Pod documented
118  
119 =head2 MoveToEndOfLine
120  
121 Moves to the end of the line or the end of the selection if any.
122  
123 =cut
124  
125 5 my $buffer = shift ;
126  
127 5 ▶unless($buffer->{SELECTION}->IsEmpty())
Branch: 1 branch
BranchTrueFalseTotal
if ($buffer->{'SELECTION'}->IsEmpty) { } 3 2 5
128 {
129 2 $buffer->MoveToEndOfSelectionNoClear() ;
130 2 $buffer->{SELECTION}->Clear() ;
131 }
132 else
133 {
134 3 $buffer->MoveToEndOfLineNoSelectionClear() ;
135 }
136 }
137  
138 #-------------------------------------------------------------------------------
139  
140 sub MoveToEndOfSelectionNoClear
141 13 ▶{
Subroutine MoveToEndOfSelectionNoClear: called CC=2 SCAR=6.9
Pod documented
142  
143 =head2 MoveToEndOfSelectionNoClear
144  
145 Moves the modification to the end of the selection without clearing the selection.
146  
147 =cut
148  
149 13 my $buffer = shift ;
150  
151 13 ▶unless($buffer->{SELECTION}->IsEmpty())
Branch: 1 branch
BranchTrueFalseTotal
unless ($buffer->{"SELECTION"}->IsEmpty) 12 1 13
152 {
153 my (
154 12 $selection_start_line, $selection_start_character
155 , $selection_end_line, $selection_end_character
156 ) = $buffer->BoxSelection() ;
157
158 12 $buffer->SetModificationPosition($selection_end_line, $selection_end_character) ;
159 }
160 }
161  
162 #-------------------------------------------------------------------------------
163  
164 sub MoveToEndOfLineNoSelectionClear
165 11 ▶{
Subroutine MoveToEndOfLineNoSelectionClear: called CC=1 SCAR=0.0
Pod documented
166  
167 =head2 MoveToEndOfLineNoSelectionClear
168  
169 Moves to the end of the current line without clearing the selection (if any).
170  
171 =cut
172  
173 11 my $buffer = shift ;
174 11 $buffer->SetModificationCharacter
175 (
176 $buffer->GetLineLength
177 (
178 $buffer->GetModificationLine()
179 )
180 ) ;
181 }
182  
183 #-------------------------------------------------------------------------------
184  
185 sub MoveHome # jumping frog
186 5 ▶{
Subroutine MoveHome: called CC=3 SCAR=11.0
Pod documented
187  
188 =head2 MoveHome
189  
190 Moves the modification position to the begining of the line or to the first word (jumping frog style)
191  
192 =cut
193  
194 5 my $buffer = shift ;
195 5 my $first_non_space_position = $buffer->GetFirstNonSpacePosition($buffer->GetModificationLine()) ;
196  
197 5 ▶if($buffer->{SELECTION}->IsEmpty())
Branch: 1 branch
BranchTrueFalseTotal
if ($buffer->{'SELECTION'}->IsEmpty) { } 3 2 5
198 {
199 3 ▶ if($buffer->GetModificationCharacter() == $first_non_space_position)
Branch: 1 branch
BranchTrueFalseTotal
if ($buffer->GetModificationCharacter == $first_non_space_position) { } 1 2 3
200 {
201 1 $buffer->SetModificationCharacter(0) ;
202 }
203 else
204 {
205 2 $buffer->SetModificationCharacter($first_non_space_position) ;
206 }
207 }
208 else
209 {
210 2 $buffer->MoveToStartOfSelectionNoClear() ;
211 2 $buffer->{SELECTION}->Clear() ;
212 }
213 }
214  
215 #-------------------------------------------------------------------------------
216  
217 sub MoveToStartOfSelectionNoClear
218 13 ▶{
Subroutine MoveToStartOfSelectionNoClear: called CC=2 SCAR=6.9
Pod documented
219  
220 =head2 MoveToStartOfSelectionNoClear
221  
222 Sets the modification position at the start of the selection, if any, without clearing the selection.
223  
224 =cut
225  
226 13 my $buffer = shift ;
227  
228 13 ▶unless($buffer->{SELECTION}->IsEmpty())
Branch: 1 branch
BranchTrueFalseTotal
unless ($buffer->{"SELECTION"}->IsEmpty) 12 1 13
229 {
230 my (
231 12 $selection_start_line, $selection_start_character
232 , $selection_end_line, $selection_end_character
233 ) = $buffer->BoxSelection() ;
234
235 12 $buffer->SetModificationPosition($selection_start_line, $selection_start_character) ;
236 }
237 }
238  
239  
240 #-------------------------------------------------------------------------------
241  
242 sub MoveLeft
243 2 ▶{
Subroutine MoveLeft: called CC=1 SCAR=0.0
Pod documented
244  
245 =head2 MoveLeft
246  
247 Moves left, clearing the selection if any.
248  
249 =cut
250  
251 2 my $buffer = shift ;
252  
253 # position at begining of selection if any
254 2 $buffer->MoveLeftNoSelectionClear() ;
255 2 $buffer->{SELECTION}->Clear() ;
256 }
257  
258 #-------------------------------------------------------------------------------
259  
260 sub MoveLeftNoSelectionClear
261 10 ▶{
Subroutine MoveLeftNoSelectionClear: called CC=3 SCAR=11.0
Pod documented
262  
263 =head2 MoveLeftNoSelectionClear
264  
265 Moves left, no selection clearing is done.
266  
267 =cut
268  
269 10 my $buffer = shift ;
270  
271 10 ▶if($buffer->{SELECTION}->IsEmpty())
Branch: 1 branch
BranchTrueFalseTotal
if ($buffer->{'SELECTION'}->IsEmpty) { } 6 4 10
272 {
273 6 ▶ if(0 != $buffer->GetModificationCharacter())
Branch: 1 branch
BranchTrueFalseTotal
if (0 != $buffer->GetModificationCharacter) 4 2 6
274 {
275 4 $buffer->SetModificationCharacter($buffer->GetModificationCharacter() - 1) ;
276 }
277 #~ else
278 #~ {
279 #~ #uncomment to line wrap
280 #~ my $modification_line = $buffer->GetModificationLine() ;
281 #~ if(0 != $modification_line)
282 #~ {
283 #~ my $previous_line = $modification_line - 1 ;
284 #~ $buffer->SetModificationLine($previous_line) ;
285 #~ $buffer->SetModificationCharacter($buffer->GetLineLength($previous_line) ;
286 #~ }
287 #~ #else
288 #~ # begining of document
289 #~ }
290 }
291 else
292 {
293 4 $buffer->MoveToStartOfSelectionNoClear() ;
294 }
295 }
296  
297 #-------------------------------------------------------------------------------
298  
299 sub MoveRight
300 5 ▶{
Subroutine MoveRight: called CC=1 SCAR=0.0
Pod documented
301  
302 =head2 MoveRight
303  
304 Moves Right, clearing the selection if any.
305  
306 =cut
307  
308 5 my $buffer = shift ;
309  
310 # position at begining of selection if any
311 5 $buffer->MoveRightNoSelectionClear() ;
312 5 $buffer->{SELECTION}->Clear() ;
313 }
314  
315 #-------------------------------------------------------------------------------
316  
317 sub MoveRightNoSelectionClear
318 10 ▶{
Subroutine MoveRightNoSelectionClear: called CC=2 SCAR=6.9
Pod documented
319  
320 =head2 MoveRightNoSelectionClear
321  
322 Moves right without clearing the selection.
323  
324 =cut
325  
326 10 my $buffer = shift ;
327  
328 10 ▶if($buffer->{SELECTION}->IsEmpty())
Branch: 1 branch
BranchTrueFalseTotal
if ($buffer->{'SELECTION'}->IsEmpty) { } 6 4 10
329 {
330 # we don't limit the character position horizontaly
331
332 6 $buffer->SetModificationCharacter($buffer->GetModificationCharacter() + 1) ;
333
334 #~ #pseudo code to wrap
335 #~ if(current_character == end_of_line)
336 #~ {
337 #~ if(line != last_line)
338 #~ {
339 #~ line = line++ ;
340 #~ character = 0 ;
341 #~ }
342 #~ }
343 #~ else
344 #~ {
345 #~ current_character++ ;
346 #~ }
347 }
348 else
349 {
350 4 $buffer->MoveToEndOfSelectionNoClear() ;
351 }
352 }
353  
354 #-------------------------------------------------------------------------------
355  
356 sub MoveUp
357 6 ▶{
Subroutine MoveUp: called CC=1 SCAR=0.0
Pod documented
358  
359 =head2 MoveUp
360  
361 Moves up, clearing the selection.
362  
363 =cut
364  
365 6 my $buffer = shift ;
366  
367 6 $buffer->MoveUpNoSelectionClear() ;
368 6 $buffer->{SELECTION}->Clear() ;
369 }
370  
371 #-------------------------------------------------------------------------------
372  
373 sub MoveUpNoSelectionClear
374 12 ▶{
Subroutine MoveUpNoSelectionClear: called CC=3 SCAR=11.0
Pod documented
375  
376 =head2 MoveUpNoSelectionClear
377  
378 Moves up, without clearing the selection.
379  
380 =cut
381  
382 12 my $buffer = shift ;
383  
384 12 $buffer->ExpandedWithOrLoad('GetCharacterDisplayPosition', 'Text::Editor::Vip::Buffer::Plugins::Display') ;
385  
386 12 ▶if($buffer->{SELECTION}->IsEmpty())
Branch: 1 branch
BranchTrueFalseTotal
if ($buffer->{'SELECTION'}->IsEmpty) { } 8 4 12
387 {
388 8 my $modification_line = $buffer->GetModificationLine() ;
389
390 8 ▶ if($modification_line != 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($modification_line != 0) 6 2 8
391 {
392 6 $buffer->SetModificationCharacter
393 (
394 $buffer->GetCharacterPositionInText
395 (
396 $modification_line - 1
397 , $buffer->GetCharacterDisplayPosition
398 (
399 $modification_line
400 , $buffer->GetModificationCharacter()
401 )
402 )
403 ) ;
404
405 6 $buffer->SetModificationLine($modification_line - 1) ;
406 }
407 #else
408 # at first line
409 }
410 else
411 {
412 4 $buffer->MoveToStartOfSelectionNoClear() ;
413 }
414 }
415  
416 #-------------------------------------------------------------------------------
417  
418 sub MoveDown
419 5 ▶{
Subroutine MoveDown: called CC=1 SCAR=0.0
Pod documented
420  
421 =head2 MoveDown
422  
423 Moves the modification position down, clearing the selection.
424  
425 =cut
426  
427 5 my $buffer = shift ;
428 5 $buffer->MoveDownNoSelectionClear() ;
429 5 $buffer->{SELECTION}->Clear() ;
430 }
431  
432 #-------------------------------------------------------------------------------
433  
434 sub MoveDownNoSelectionClear
435 11 ▶{
Subroutine MoveDownNoSelectionClear: called CC=3 SCAR=11.0
Pod documented
436  
437 =head2 MoveDownNoSelectionClear
438  
439 Moves the modification position down, without clearing the selection. Moves to the end of the selection if any.
440  
441 =cut
442  
443 11 my $buffer = shift ;
444  
445 11 $buffer->ExpandedWithOrLoad('GetCharacterDisplayPosition', 'Text::Editor::Vip::Buffer::Plugins::Display') ;
446  
447 11 ▶if($buffer->{SELECTION}->IsEmpty())
Branch: 1 branch
BranchTrueFalseTotal
if ($buffer->{'SELECTION'}->IsEmpty) { } 7 4 11
448 {
449 7 my $modification_line = $buffer->GetModificationLine() ;
450
451 7 ▶ if($modification_line != ($buffer->GetNumberOfLines() - 1))
Branch: 1 branch
BranchTrueFalseTotal
if ($modification_line != $buffer->GetNumberOfLines - 1) 5 2 7
452 {
453 5 $buffer->SetModificationCharacter
454 (
455 $buffer->GetCharacterPositionInText
456 (
457 $modification_line + 1
458 , $buffer->GetCharacterDisplayPosition
459 (
460 $modification_line
461 , $buffer->GetModificationCharacter()
462 )
463 )
464 ) ;
465
466 5 $buffer->SetModificationLine($modification_line + 1) ;
467 }
468 #else
469 # at last line
470 }
471 else
472 {
473 4 $buffer->MoveToEndOfSelectionNoClear() ;
474 }
475 }
476  
477 #-------------------------------------------------------------------------------
478  
479 sub MoveToBeginingOfWord
480 4 ▶{
Subroutine MoveToBeginingOfWord: called CC=1 SCAR=0.0
Pod documented
481  
482 =head2 MoveToBeginingOfWord
483  
484 Moves the modification position to the begining of the current word, clearing the selection.
485  
486 =cut
487  
488 4 my $buffer = shift ;
489  
490 4 $buffer->{SELECTION}->Clear() ;
491 4 return($buffer->MoveToBeginingOfWordNoSelectionClear()) ;
492 }
493  
494 #-------------------------------------------------------------------------------
495  
496 sub MoveToBeginingOfWordNoSelectionClear
497 15 ▶{
Subroutine MoveToBeginingOfWordNoSelectionClear: called CC=3 SCAR=11.0
Pod documented
498  
499 =head2 MoveToBeginingOfWordNoSelectionClear
500  
501 Moves the modification position to the begining of the current word, without clearing the selection. Return 'true' if
502 the modification position was changed, 'false' if there was no current word.
503  
504 =cut
505  
506 15 my $buffer = shift ;
507  
508 15 $buffer->ExpandedWithOrLoad('GetAlphanumericFilter', 'Text::Editor::Vip::Buffer::Plugins::GetWord') ;
509  
510 15 my ($modification_line, $modification_character) = $buffer->GetModificationPosition() ;
511  
512 15 my $search_end ;
513 15 ▶if($modification_character > $buffer->GetLineLength())
Branch: 1 branch
BranchTrueFalseTotal
if ($modification_character > $buffer->GetLineLength) { } 4 11 15
514 {
515 4 $search_end = $buffer->GetLineLength() ;
516 }
517 else
518 {
519 11 $search_end = $modification_character ;
520 }
521  
522 15 my $character_regex = $buffer->GetAlphanumericFilter() ;
523 15 my $text = reverse(substr($buffer->GetLineText($modification_line), 0, $search_end)) ;
524  
525 15 ▶if($text =~ /^($character_regex)/)
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /^($character_regex)/) { } 11 4 15
526 {
527 #~ print "*** $modification_character, <$1> " . length($1) ."\n" ;
528 11 $buffer->SetModificationCharacter($search_end - length($1)) ;
529 11 return(1) ;
530 }
531 else
532 {
533 4 return(0) ;
534 }
535 }
536  
537 #-------------------------------------------------------------------------------
538  
539 sub MoveToEndOfWord
540 8 ▶{
Subroutine MoveToEndOfWord: called CC=1 SCAR=0.0
Pod documented
541  
542 =head2 MoveToEndOfWord
543  
544 Moves the modification position to the end of the current word, clearing the selection.
545  
546 =cut
547  
548 8 my $buffer = shift ;
549  
550 8 $buffer->MoveToEndOfWordNoSelectionClear() ;
551 8 $buffer->{SELECTION}->Clear() ;
552 }
553  
554 #-------------------------------------------------------------------------------
555  
556 sub MoveToEndOfWordNoSelectionClear
557 20 ▶{
Subroutine MoveToEndOfWordNoSelectionClear: called CC=5 SCAR=16.1
Pod documented
558  
559 =head2 MoveToEndOfWordNoSelectionClear
560  
561 Moves the modification position to the end of the current word, without clearing the selection. Return 'true' if
562 the modification position was changed, 'false' if there was no current word.
563  
564 =cut
565  
566 20 my $buffer = shift ;
567  
568 20 $buffer->ExpandedWithOrLoad('GetAlphanumericFilter', 'Text::Editor::Vip::Buffer::Plugins::GetWord') ;
569  
570 20 my ($modification_line, $modification_character) = $buffer->GetModificationPosition() ;
571  
572 20 my $search_start ;
573 20 ▶if($modification_character >= $buffer->GetLineLength())
Branch: 1 branch
BranchTrueFalseTotal
if ($modification_character >= $buffer->GetLineLength) { } 5 15 20
574 {
575 5 $search_start = $buffer->GetLineLength() ;
576 }
577 else
578 {
579 15 $search_start = $modification_character ;
580 }
581  
582 20 my $character_regex = $buffer->GetAlphanumericFilter() ;
583 20 my $text = substr($buffer->GetLineText($modification_line), $search_start) ;
584  
585 20 ▶if($text =~ /($character_regex)/)
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /($character_regex)/) { } 15 5 20
586 {
587 15 $buffer->SetModificationCharacter($modification_character + index($text, $1) + length($1)) ;
588 }
589 else
590 {
591 5 my $number_of_lines = $buffer->GetNumberOfLines() ;
592
593 5 ▶ for(my $current_line_index = $modification_line + 1 ; $current_line_index < $number_of_lines ; $current_line_index++)
Branch: 1 branch
BranchTrueFalseTotal
if ($current_line_index < $number_of_lines) 5 3 8
594 {
595 5 $text = $buffer->GetLineText($current_line_index) ;
596
597 5 ▶ if($text =~ /($character_regex)/)
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /($character_regex)/) 2 3 5
598 {
599 2 $buffer->SetModificationLine($current_line_index) ;
600 2 $buffer->SetModificationCharacter(index($text, $1) + length($1)) ;
601 2 last ;
602 }
603 }
604 }
605 }
606  
607 #-------------------------------------------------------------------------------
608  
609 sub MoveToNextWord
610 14 ▶{
Subroutine MoveToNextWord: called CC=1 SCAR=0.0
Pod documented
611  
612 =head2 MoveToNextWord
613  
614 Sets the modification position at the begining of the next word, potentialy on another line, and clears
615 the selection.
616  
617 =cut
618  
619 14 my $buffer = shift ;
620  
621 14 $buffer->MoveToNextWordNoSelectionClear() ;
622 14 $buffer->{SELECTION}->Clear() ;
623 }
624  
625 #-------------------------------------------------------------------------------
626  
627 sub MoveToNextWordNoSelectionClear
628 14 ▶{
Subroutine MoveToNextWordNoSelectionClear: called CC=7 SCAR=19.5
Pod documented
629  
630 =head2 MoveToNextWordNoSelectionClear
631  
632 Sets the modification position at the begining of the next word, potentialy on another line, without clearing
633 the selection.
634  
635 =cut
636  
637 14 my $buffer = shift ;
638  
639 14 $buffer->ExpandedWithOrLoad('GetAlphanumericFilter', 'Text::Editor::Vip::Buffer::Plugins::GetWord') ;
640  
641 14 my ($modification_line, $modification_character) = $buffer->GetModificationPosition() ;
642 14 my $text = $buffer->GetLineText($modification_line) ;
643  
644 14 my $character_regex = $buffer->GetAlphanumericFilter() ;
645  
646 14 my ($search_start, $skip_size) ;
647  
648 14 ▶if($modification_character >= $buffer->GetLineLength())
Branch: 1 branch
BranchTrueFalseTotal
if ($modification_character >= $buffer->GetLineLength) { } 1 13 14
649 {
650 1 $search_start = $buffer->GetLineLength() ;
651 1 $skip_size = 0 ;
652 }
653 else
654 {
655 13 ▶ if(substr($text, $modification_character) =~ /^($character_regex)/)
Branch: 1 branch
BranchTrueFalseTotal
if (substr($text, $modification_character) =~ /^($character_regex)/) { } 8 5 13
656 {
657 8 $skip_size = length($1);
658 8 $search_start = $modification_character + $skip_size ;
659 }
660 else
661 {
662 5 $skip_size = 0 ;
663 5 $search_start = $modification_character ;
664 }
665 }
666  
667 14 $text = substr($text, $search_start) ;
668  
669 14 ▶if($text =~ /\W($character_regex)/)
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /\W($character_regex)/) { } 10 4 14
670 {
671 10 $buffer->SetModificationCharacter($modification_character + index($text, $1) + $skip_size) ;
672 }
673 else
674 {
675 4 my $number_of_lines = $buffer->GetNumberOfLines() ;
676
677 4 ▶ for(my $current_line_index = $modification_line + 1 ; $current_line_index < $number_of_lines ; $current_line_index++)
Branch: 1 branch
BranchTrueFalseTotal
if ($current_line_index < $number_of_lines) 5 1 6
678 {
679 5 $text = $buffer->GetLineText($current_line_index) ;
680
681 5 ▶ if($text =~ /^($character_regex)/ || $text =~ /\W($character_regex)/)
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /^($character_regex)/ or $text =~ /\W($character_regex)/) 3 2 5
Condition100%3/3
$text =~ /^($character_regex)/ or $text =~ /\W($character_regex)/
l!l&&r!l&&!r
122
MC/DC100%2/2
$text =~ /^($character_regex)/ or $text =~ /\W($character_regex)/
$text =~ /^($character_regex)/ $text =~ /\W($character_regex)/
Truth table100%3/3
A or B
A= $text =~ /^($character_regex)/B= $text =~ /\W($character_regex)/
ABresult
1X1
011
000
682 {
683 3 $buffer->SetModificationLine($current_line_index) ;
684 3 $buffer->SetModificationCharacter(index($text, $1)) ;
685 3 last ;
686 }
687 }
688 }
689 }
690  
691 #-------------------------------------------------------------------------------
692  
693 sub MoveToPreviousWord
694 17 ▶{
Subroutine MoveToPreviousWord: called CC=1 SCAR=0.0
Pod documented
695  
696 =head2 MoveToPreviousWord
697  
698 Sets the modification position at the begining of the previous word, potentialy on another line, and clears
699 the selection.
700  
701 =cut
702  
703 17 my $buffer = shift ;
704  
705 17 $buffer->MoveToPreviousWordNoSelectionClear() ;
706 17 $buffer->{SELECTION}->Clear() ;
707 }
708  
709 #-------------------------------------------------------------------------------
710  
711 sub MoveToPreviousWordNoSelectionClear
712 17 ▶{
Subroutine MoveToPreviousWordNoSelectionClear: called CC=10 SCAR=23.1
Pod documented
713  
714 =head2 MoveToPreviousWordNoSelectionClear
715  
716 Sets the modification position at the begining of the previous word, potentialy on another line, without clearing
717 the selection.
718  
719 =cut
720  
721 17 my $buffer = shift ;
722 17 $buffer->ExpandedWithOrLoad('GetAlphanumericFilter', 'Text::Editor::Vip::Buffer::Plugins::GetWord') ;
723  
724 17 my $character_regex = $buffer->GetAlphanumericFilter() ;
725 17 my ($modification_line, $modification_character) = $buffer->GetModificationPosition() ;
726  
727 17 ▶if($modification_character >= $buffer->GetLineLength())
Branch: 1 branch
BranchTrueFalseTotal
if ($modification_character >= $buffer->GetLineLength) 1 16 17
728 {
729 1 $modification_character = $buffer->GetLineLength() ;
730
731 #handle case where we are after the line end and a word ends the line
732 1 my $text = $buffer->GetLineText($modification_line) ;
733
734 1 ▶ if(reverse(substr($text, 0, $modification_character)) =~ /^($character_regex)/)
Branch: 1 branch
BranchTrueFalseTotal
if (reverse(substr($text, 0, $modification_character)) =~ /^($character_regex)/) 1 0 1
735 {
736 1 $buffer->SetModificationCharacter($modification_character - length($1)) ;
737 1 return ;
738 }
739 }
740  
741 16 my $text = $buffer->GetLineText($modification_line) ;
742  
743 16 my ($search_end, $skip_size) = ($modification_character, 0) ;
744  
745 16 ▶if($modification_character <= 0)
Branch: 4 branches
BranchTrueFalseTotal
if ($modification_character <= 0) { } 6 10 16
elsif ($modification_character == $buffer->GetLineLength) { } 0 10 10
elsif (not substr($text, $modification_character, 1) =~ /$character_regex/) { } 2 8 10
elsif (reverse(substr($text, 0, $modification_character)) =~ /^($character_regex)/) { } 3 5 8
746 {
747 6 $search_end = 0 ;
748 6 $skip_size = 0 ;
749 }
750 elsif($modification_character == $buffer->GetLineLength())
751 {
752 #skip nothing if at end of line
753 0 $search_end = $modification_character ;
754 0 $skip_size = 0 ;
755 }
756 elsif(substr($text, $modification_character, 1) !~ /$character_regex/)
757 {
758 #skip nothing if at end of word
759 2 $search_end = $modification_character ;
760 2 $skip_size = 0 ;
761 }
762 elsif(reverse(substr($text, 0, $modification_character)) =~ /^($character_regex)/)
763 {
764 3 $skip_size = length($1);
765 3 $search_end = $modification_character - $skip_size ;
766 }
767  
768 16 $text = reverse substr($text, 0, $search_end) ;
769  
770 16 ▶if($text =~ /($character_regex)/)
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /($character_regex)/) { } 3 13 16
771 {
772 #~ print "search_end: $search_end skip size: $skip_size index: " . index($text, $1) . " length: " . length($1) . " '$1'\n" ;
773
774 3 $buffer->SetModificationCharacter($search_end - (index($text, $1) + length($1))) ;
775 }
776 else
777 {
778 13 ▶ for(my $current_line_index = $modification_line - 1 ; $current_line_index >= 0 ; $current_line_index--)
Branch: 1 branch
BranchTrueFalseTotal
if ($current_line_index >= 0) 7 8 15
779 {
780 7 $text = reverse $buffer->GetLineText($current_line_index) ;
781
782 7 ▶ if($text =~ /($character_regex)/)
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /($character_regex)/) 5 2 7
783 {
784 5 $buffer->SetModificationLine($current_line_index) ;
785 5 $buffer->SetModificationCharacter(length($text) - (index($text, $1) + length($1))) ;
786 5 last ;
787 }
788 }
789 }
790 }
791  
792 #-------------------------------------------------------------------------------
793  
794 4 1 ;
795  
796 =head1 AUTHOR
797  
798 Khemir Nadim ibn Hamouda
799 CPAN ID: NKH
800 mailto:nadim@khemir.net
801 http:// no web site
802  
803 =head1 COPYRIGHT
804  
805 This program is free software; you can redistribute
806 it and/or modify it under the same terms as Perl itself.
807  
808 The full text of the license can be found in the
809 LICENSE file included with this module.
810  
811 =cut
« blib/lib/Text/Editor/Vip/Buffer/DoUndoRedo.pm ↑ Summary blib/lib/Text/Editor/Vip/Buffer/Plugins/GetWord.pm »