Skip to content

Commit

Permalink
Mark and restore special mark '
Browse files Browse the repository at this point in the history
  • Loading branch information
mdom committed Feb 2, 2019
1 parent d9df9cc commit 2850716
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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\] %

Expand Down
1 change: 1 addition & 0 deletions lib/App/termpub.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 16 additions & 2 deletions lib/App/termpub/Pager.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -180,19 +190,22 @@ 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;
}

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;
Expand All @@ -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;
}
Expand Down
4 changes: 3 additions & 1 deletion script/termpub
Original file line number Diff line number Diff line change
Expand Up @@ -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] %
Expand Down

0 comments on commit 2850716

Please sign in to comment.