| 1 | |||
| 2 | package Text::Editor::Vip::Buffer::Plugins::PageUpDown; | ||
| 3 | |||
| 4 | use strict; | ||
| 5 | use warnings ; | ||
| 6 | |||
| 7 | BEGIN | ||
| 8 | { | ||
| 9 | use Exporter (); | ||
| 10 | |||
| 11 | use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); | ||
| 12 | $VERSION = 0.01; | ||
| 13 | @ISA = qw (Exporter); | ||
| 14 | @EXPORT = qw (); | ||
| 15 | @EXPORT_OK = qw (); | ||
| 16 | %EXPORT_TAGS = (); | ||
| 17 | } | ||
| 18 | |||
| 19 | die "Not yet ported to Vip!\n" : | ||
| 20 | |||
| 21 | =head1 NAME | ||
| 22 | |||
| 23 | Text::Editor::Vip::Buffer::Plugins::Movements- Add movement commands to Vip::Buffer | ||
| 24 | |||
| 25 | =head1 SYNOPSIS | ||
| 26 | |||
| 27 | use Text::Editor::Vip::Buffer | ||
| 28 | |||
| 29 | =head1 DESCRIPTION | ||
| 30 | |||
| 31 | Add page movement commands to Vip::Buffer. | ||
| 32 | |||
| 33 | =head1 FUNCTIONS | ||
| 34 | |||
| 35 | =cut | ||
| 36 | |||
| 37 | #------------------------------------------------------------------------------- | ||
| 38 | |||
| 39 | sub SetPageSize | ||
| 40 | { | ||
| 41 | |||
| 42 | =head2 SetPageSize | ||
| 43 | |||
| 44 | Sets the page size used. | ||
| 45 | |||
| 46 | =cut | ||
| 47 | |||
| 48 | $_[0]->{'Text::Editor::Vip::Buffer::Plugins::PageUpDown::Page_SIZE'} = $_[1] || 40; | ||
| 49 | } | ||
| 50 | |||
| 51 | #------------------------------------------------------------------------------- | ||
| 52 | |||
| 53 | sub GetPageSize | ||
| 54 | { | ||
| 55 | |||
| 56 | =head2 GetPageSize | ||
| 57 | |||
| 58 | Return the page size | ||
| 59 | |||
| 60 | =cut | ||
| 61 | |||
| 62 | return ($_[0]->{'Text::Editor::Vip::Buffer::Plugins::PageUpDown::PAGE_SIZE'} || 40) ; | ||
| 63 | } | ||
| 64 | |||
| 65 | #------------------------------------------------------------------------------- | ||
| 66 | |||
| 67 | sub PageUp | ||
| 68 | { | ||
| 69 | |||
| 70 | =head2 PageUp | ||
| 71 | |||
| 72 | =cut | ||
| 73 | |||
| 74 | $_[0]->ClearSelection() ; | ||
| 75 | $_[0]->PageUpNoSelectionClear() ; | ||
| 76 | } | ||
| 77 | |||
| 78 | #------------------------------------------------------------------------------- | ||
| 79 | |||
| 80 | sub PageUpNoSelectionClear | ||
| 81 | { | ||
| 82 | |||
| 83 | =head2 PageUpNoSelectionClear | ||
| 84 | |||
| 85 | =cut | ||
| 86 | |||
| 87 | my $buffer = shift ; | ||
| 88 | |||
| 89 | my $display_position = $buffer->GetCharacterDisplayPosition | ||
| 90 | ( | ||
| 91 | $buffer->GetModificationLine() | ||
| 92 | , $buffer->GetModificationCharacter() | ||
| 93 | ) ; | ||
| 94 | |||
| 95 | my $display_line_index = $buffer->GetDisplayLineIndex($buffer->GetModificationLine()) ; | ||
| 96 | |||
| 97 | #~ my $top_line_index = $buffer->GetTopLineIndex() ; | ||
| 98 | |||
| 99 | my $top_line_index = $buffer->GetTopLineIndex() ; | ||
| 100 | $top_line_index -= $buffer->GetPageSize() | ||
| 101 | $top_line_index = 0 unless $top_line_index >= 0 ; | ||
| 102 | |||
| 103 | #~ $buffer->SetTopLineIndex($top_line_index) ; | ||
| 104 | |||
| 105 | $buffer->SetModificationLine($top_line_index + $display_line_index) ; | ||
| 106 | $buffer->SetModificationCharacter | ||
| 107 | ( | ||
| 108 | $buffer->GetCharacterPositionInText($buffer->GetModificationLine(), $display_position) | ||
| 109 | ) ; | ||
| 110 | } | ||
| 111 | |||
| 112 | #------------------------------------------------------------------------------- | ||
| 113 | |||
| 114 | sub PageDown | ||
| 115 | { | ||
| 116 | |||
| 117 | =head2 PageDown | ||
| 118 | |||
| 119 | =cut | ||
| 120 | |||
| 121 | $_[0]->ClearSelection() ; | ||
| 122 | $_[0]->PageDownNoSelectionClear() ; | ||
| 123 | } | ||
| 124 | |||
| 125 | sub PageDownNoSelectionClear | ||
| 126 | { | ||
| 127 | |||
| 128 | =head2 PageDownNoSelectionClear | ||
| 129 | |||
| 130 | =cut | ||
| 131 | |||
| 132 | my $buffer = shift ; | ||
| 133 | my $display_line_index = $buffer->GetDisplayLineIndex($buffer->GetModificationLine()) ; | ||
| 134 | my $display_position = $buffer->GetCharacterDisplayPosition | ||
| 135 | ( | ||
| 136 | $buffer->GetModificationLine() | ||
| 137 | , $buffer->GetModificationCharacter() | ||
| 138 | ) ; | ||
| 139 | |||
| 140 | my $top_line_index = $buffer->GetTopLineIndex() ; | ||
| 141 | $top_line_index += $buffer->GetNumberOfLinesInDisplay() - 1 ; | ||
| 142 | $top_line_index = ($buffer->GetNumberOfLines() - 1) if $top_line_index >= $buffer->GetNumberOfLines() ; | ||
| 143 | |||
| 144 | $buffer->SetTopLineIndex($top_line_index) ; | ||
| 145 | $buffer->SetModificationLine($top_line_index + $display_line_index) ; | ||
| 146 | $buffer->SetModificationCharacter | ||
| 147 | ( | ||
| 148 | $buffer->GetCharacterPositionInText($buffer->GetModificationLine(), $display_position) | ||
| 149 | ) ; | ||
| 150 | } | ||
| 151 | |||
| 152 | #------------------------------------------------------------------------------- | ||
| 153 | |||
| 154 | sub ExtendSelectionPageUp | ||
| 155 | { | ||
| 156 | |||
| 157 | =head2 ExtendSelectionPageUp | ||
| 158 | |||
| 159 | =cut | ||
| 160 | |||
| 161 | my $buffer = shift ; | ||
| 162 | $buffer->ExpandedWithOrLoad('PageUpNoSelectionClear', 'Text::Editor::Vip::Buffer::Plugins::Movements') ; | ||
| 163 | |||
| 164 | $buffer->SetSelectionAnchorAtCurrentPosition() if $buffer->IsSelectionEmpty() ; | ||
| 165 | $buffer->PageUpNoSelectionClear() ; | ||
| 166 | $buffer->ExtendSelection() ; | ||
| 167 | } | ||
| 168 | |||
| 169 | #------------------------------------------------------------------------------- | ||
| 170 | |||
| 171 | sub ExtendSelectionPageDown | ||
| 172 | { | ||
| 173 | |||
| 174 | =head2 ExtendSelectionPageDown | ||
| 175 | |||
| 176 | =cut | ||
| 177 | |||
| 178 | my $buffer = shift ; | ||
| 179 | $buffer->ExpandedWithOrLoad('PageDownNoSelectionClear', 'Text::Editor::Vip::Buffer::Plugins::Movements') ; | ||
| 180 | |||
| 181 | $buffer->SetSelectionAnchorAtCurrentPosition() if $buffer->IsSelectionEmpty() ; | ||
| 182 | $buffer->PageDownNoSelectionClear() ; | ||
| 183 | $buffer->ExtendSelection() ; | ||
| 184 | } | ||
| 185 | |||
| 186 | #------------------------------------------------------------------------------- | ||
| 187 | |||
| 188 | =head1 AUTHOR | ||
| 189 | |||
| 190 | Khemir Nadim ibn Hamouda | ||
| 191 | CPAN ID: NKH | ||
| 192 | mailto:nadim@khemir.net | ||
| 193 | http:// no web site | ||
| 194 | |||
| 195 | =head1 COPYRIGHT | ||
| 196 | |||
| 197 | This program is free software; you can redistribute | ||
| 198 | it and/or modify it under the same terms as Perl itself. | ||
| 199 | |||
| 200 | The full text of the license can be found in the | ||
| 201 | LICENSE file included with this module. | ||
| 202 | |||
| 203 | =cut |