tweaks: change do_para_end() to not step beyond end of paragraph
Not stepping beyond the last line of the paragraph means that the length of the paragraph is always the difference in line numbers (between first and last line of the paragraph) plus one.master
parent
9a77c997e2
commit
e2c61d83ef
26
src/move.c
26
src/move.c
|
@ -180,10 +180,8 @@ void do_para_begin(filestruct **line)
|
|||
*line = (*line)->prev;
|
||||
}
|
||||
|
||||
/* Move down to the last line of the current paragraph; then move down
|
||||
* one line farther if there is such a line. Return FALSE when we could
|
||||
* step one line further, and TRUE otherwise. */
|
||||
bool do_para_end(filestruct **line)
|
||||
/* Move down to the last line of the first found paragraph. */
|
||||
void do_para_end(filestruct **line)
|
||||
{
|
||||
while ((*line)->next != NULL && !inpar(*line))
|
||||
*line = (*line)->next;
|
||||
|
@ -191,13 +189,6 @@ bool do_para_end(filestruct **line)
|
|||
while ((*line)->next != NULL && inpar((*line)->next) &&
|
||||
!begpar((*line)->next, 0))
|
||||
*line = (*line)->next;
|
||||
|
||||
if ((*line)->next != NULL) {
|
||||
*line = (*line)->next;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Move up to first start of a paragraph before the current line. */
|
||||
|
@ -211,15 +202,20 @@ void do_para_begin_void(void)
|
|||
edit_redraw(was_current, CENTERING);
|
||||
}
|
||||
|
||||
/* Move down to just after the first end of a paragraph. */
|
||||
/* Move down to just after the first found end of a paragraph. */
|
||||
void do_para_end_void(void)
|
||||
{
|
||||
filestruct *was_current = openfile->current;
|
||||
|
||||
if (do_para_end(&openfile->current))
|
||||
openfile->current_x = strlen(openfile->current->data);
|
||||
else
|
||||
do_para_end(&openfile->current);
|
||||
|
||||
/* Step beyond the last line of the paragraph, if possible;
|
||||
* otherwise, move to the end of the line. */
|
||||
if (openfile->current->next != NULL) {
|
||||
openfile->current = openfile->current->next;
|
||||
openfile->current_x = 0;
|
||||
} else
|
||||
openfile->current_x = strlen(openfile->current->data);
|
||||
|
||||
edit_redraw(was_current, CENTERING);
|
||||
}
|
||||
|
|
|
@ -361,7 +361,7 @@ void do_page_up(void);
|
|||
void do_page_down(void);
|
||||
#ifdef ENABLE_JUSTIFY
|
||||
void do_para_begin(filestruct **line);
|
||||
bool do_para_end(filestruct **line);
|
||||
void do_para_end(filestruct **line);
|
||||
void do_para_begin_void(void);
|
||||
void do_para_end_void(void);
|
||||
#endif
|
||||
|
|
20
src/text.c
20
src/text.c
|
@ -2051,23 +2051,17 @@ bool find_paragraph(filestruct **firstline, bool *touched_eof,
|
|||
|
||||
*firstline = line;
|
||||
|
||||
/* Now move down to just beyond the end of the paragraph, if possible. */
|
||||
*touched_eof = do_para_end(&line);
|
||||
/* Move down to the last line of the paragraph. */
|
||||
do_para_end(&line);
|
||||
|
||||
/* If the search for end-of-paragraph stopped at end-of-file, and we're
|
||||
* not in a paragraph, it means that there aren't any paragraphs left. */
|
||||
if (*touched_eof && !inpar(line))
|
||||
/* When not in a paragraph now, there aren't any paragraphs left. */
|
||||
if (!inpar(line))
|
||||
return FALSE;
|
||||
|
||||
/* Determine the length of the quoting part, and the number of lines
|
||||
* in the found paragraph. */
|
||||
/* We found a paragraph; determine length of quoting and number of lines. */
|
||||
*quotelen = quote_length((*firstline)->data);
|
||||
*parlen = line->lineno - (*firstline)->lineno;
|
||||
|
||||
/* When the last line of the buffer is part of the found paragraph,
|
||||
* it means the paragraph is one line longer than computed. */
|
||||
if (*touched_eof)
|
||||
(*parlen)++;
|
||||
*parlen = line->lineno - (*firstline)->lineno + 1;
|
||||
*touched_eof = (line->next == NULL);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue