mirror of
git://git.sv.gnu.org/nano.git
synced 2024-11-25 22:29:42 +03:00
moving: allow specifying negative numbers in "Go To Line"
The negatives are taken to mean: from the end of the file, and: from the end of the line. This fulfills https://savannah.gnu.org/bugs/?48248.
This commit is contained in:
parent
6bb30978fb
commit
1a4ec6c2d3
@ -518,7 +518,8 @@ Goes to the first line of the file.
|
||||
Goes to the last line of the file.
|
||||
.TP
|
||||
.B gotoline
|
||||
Goes to a specific line (and column if specified).
|
||||
Goes to a specific line (and column if specified). Negative numbers count
|
||||
from the end of the file (and end of the line).
|
||||
.TP
|
||||
.B gototext
|
||||
Switches from targeting a line number to searching for text.
|
||||
|
@ -1104,7 +1104,8 @@ Goes to the first line of the file.
|
||||
Goes to the last line of the file.
|
||||
|
||||
@item gotoline
|
||||
Goes to a specific line (and column if specified).
|
||||
Goes to a specific line (and column if specified). Negative numbers count
|
||||
from the end of the file (and end of the line).
|
||||
|
||||
@item gototext
|
||||
Switches from targeting a line number to searching for text.
|
||||
|
21
src/search.c
21
src/search.c
@ -932,11 +932,8 @@ void do_gotolinecolumn(ssize_t line, ssize_t column, bool use_answer,
|
||||
if (i > 0)
|
||||
return;
|
||||
|
||||
/* Do a bounds check. Display a warning on an out-of-bounds
|
||||
* line or column number only if we hit Enter at the statusbar
|
||||
* prompt. */
|
||||
if (!parse_line_column(answer, &line, &column) ||
|
||||
line < 1 || column < 1) {
|
||||
/* Try to extract one or two numbers from the user's response. */
|
||||
if (!parse_line_column(answer, &line, &column)) {
|
||||
statusbar(_("Invalid line or column number"));
|
||||
return;
|
||||
}
|
||||
@ -948,10 +945,24 @@ void do_gotolinecolumn(ssize_t line, ssize_t column, bool use_answer,
|
||||
column = openfile->placewewant + 1;
|
||||
}
|
||||
|
||||
/* Take a negative line number to mean: from the end of the file. */
|
||||
if (line < 0)
|
||||
line = openfile->filebot->lineno + line + 1;
|
||||
if (line < 1)
|
||||
line = 1;
|
||||
|
||||
/* Iterate to the requested line. */
|
||||
for (openfile->current = openfile->fileage; line > 1 &&
|
||||
openfile->current != openfile->filebot; line--)
|
||||
openfile->current = openfile->current->next;
|
||||
|
||||
/* Take a negative column number to mean: from the end of the line. */
|
||||
if (column < 0)
|
||||
column = strlenpt(openfile->current->data) + column + 2;
|
||||
if (column < 1)
|
||||
column = 1;
|
||||
|
||||
/* Set the x position that corresponds to the requested column. */
|
||||
openfile->current_x = actual_x(openfile->current->data, column - 1);
|
||||
openfile->placewewant = column - 1;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user