diff --git a/README.md b/README.md index 609d0fa..47d6f42 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,9 @@ possible. It will save your reading position and restore it. - ' Followed by any lowercase letter, returns to the position which was - previously marked with that letter. + previously marked with that letter. Followed by another single quote, + returns to the position at which the last "large" movement command was + executed. - \[num\] % diff --git a/lib/App/termpub.pm b/lib/App/termpub.pm index 04e6cc0..103cddd 100644 --- a/lib/App/termpub.pm +++ b/lib/App/termpub.pm @@ -178,6 +178,7 @@ sub set_chapter { $self->history_index(0); } $self->title( $self->chapters->[$num]->title ); + $self->set_mark; $self->chapter($num); $self->line(0); $self->render_pad; diff --git a/lib/App/termpub/Pager.pm b/lib/App/termpub/Pager.pm index 3f980b1..ee0f9d6 100644 --- a/lib/App/termpub/Pager.pm +++ b/lib/App/termpub/Pager.pm @@ -81,6 +81,11 @@ sub get_position { }; } +sub set_mark { + my ( $self, $position ) = @_; + $self->positions->{"'"} = $position || $self->get_position; +} + sub mark_position { my $self = shift; my $c = getch(); @@ -93,9 +98,12 @@ sub mark_position { sub restore_position { my $self = shift; my $c = getch(); - if ( $c =~ /[a-z]/ ) { - return if !$self->positions->{$c}; + if ( $c =~ /[a-z']/ ) { + return if not exists $self->positions->{$c}; + my $old = $self->get_position; $self->goto_position( $self->positions->{$c} ); + $self->set_mark($old); + } return; } @@ -146,11 +154,13 @@ sub goto_line { sub goto_percent { my ( $self, $num ) = @_; $num ||= ( $self->prefix || 0 ); + $self->set_mark; $self->goto_line( int( $num * $self->pad_lines / 100 ) ); } sub goto_line_or_end { my $self = shift; + $self->set_mark; if ( $self->prefix ) { $self->goto_line; } @@ -180,12 +190,14 @@ sub prev_line { sub first_page { my $self = shift; + $self->set_mark; $self->line(0); $self->update_screen; } sub last_page { my $self = shift; + $self->set_mark; my $line = $self->pad_lines - $self->rows + 1; $self->line( $line >= 0 ? $line : 0 ); $self->update_screen; @@ -193,6 +205,7 @@ sub last_page { sub next_page { my $self = shift; + $self->set_mark; if ( $self->line + $self->rows <= $self->pad_lines ) { $self->line( $self->line + $self->rows ); $self->update_screen; @@ -203,6 +216,7 @@ sub next_page { sub prev_page { my $self = shift; + $self->set_mark; if ( $self->line == 0 && $self->chapter - 1 >= 0 ) { return 0; } diff --git a/script/termpub b/script/termpub index 96c5e07..e272f6c 100755 --- a/script/termpub +++ b/script/termpub @@ -90,7 +90,9 @@ letter. =item ' Followed by any lowercase letter, returns to the position which was -previously marked with that letter. +previously marked with that letter. Followed by another single quote, +returns to the position at which the last "large" movement command was +executed. =item [num] %