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;
|
*line = (*line)->prev;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Move down to the last line of the current paragraph; then move down
|
/* Move down to the last line of the first found paragraph. */
|
||||||
* one line farther if there is such a line. Return FALSE when we could
|
void do_para_end(filestruct **line)
|
||||||
* step one line further, and TRUE otherwise. */
|
|
||||||
bool do_para_end(filestruct **line)
|
|
||||||
{
|
{
|
||||||
while ((*line)->next != NULL && !inpar(*line))
|
while ((*line)->next != NULL && !inpar(*line))
|
||||||
*line = (*line)->next;
|
*line = (*line)->next;
|
||||||
|
@ -191,13 +189,6 @@ bool do_para_end(filestruct **line)
|
||||||
while ((*line)->next != NULL && inpar((*line)->next) &&
|
while ((*line)->next != NULL && inpar((*line)->next) &&
|
||||||
!begpar((*line)->next, 0))
|
!begpar((*line)->next, 0))
|
||||||
*line = (*line)->next;
|
*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. */
|
/* 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);
|
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)
|
void do_para_end_void(void)
|
||||||
{
|
{
|
||||||
filestruct *was_current = openfile->current;
|
filestruct *was_current = openfile->current;
|
||||||
|
|
||||||
if (do_para_end(&openfile->current))
|
do_para_end(&openfile->current);
|
||||||
openfile->current_x = strlen(openfile->current->data);
|
|
||||||
else
|
/* 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;
|
openfile->current_x = 0;
|
||||||
|
} else
|
||||||
|
openfile->current_x = strlen(openfile->current->data);
|
||||||
|
|
||||||
edit_redraw(was_current, CENTERING);
|
edit_redraw(was_current, CENTERING);
|
||||||
}
|
}
|
||||||
|
|
|
@ -361,7 +361,7 @@ void do_page_up(void);
|
||||||
void do_page_down(void);
|
void do_page_down(void);
|
||||||
#ifdef ENABLE_JUSTIFY
|
#ifdef ENABLE_JUSTIFY
|
||||||
void do_para_begin(filestruct **line);
|
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_begin_void(void);
|
||||||
void do_para_end_void(void);
|
void do_para_end_void(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
20
src/text.c
20
src/text.c
|
@ -2051,23 +2051,17 @@ bool find_paragraph(filestruct **firstline, bool *touched_eof,
|
||||||
|
|
||||||
*firstline = line;
|
*firstline = line;
|
||||||
|
|
||||||
/* Now move down to just beyond the end of the paragraph, if possible. */
|
/* Move down to the last line of the paragraph. */
|
||||||
*touched_eof = do_para_end(&line);
|
do_para_end(&line);
|
||||||
|
|
||||||
/* If the search for end-of-paragraph stopped at end-of-file, and we're
|
/* When not in a paragraph now, there aren't any paragraphs left. */
|
||||||
* not in a paragraph, it means that there aren't any paragraphs left. */
|
if (!inpar(line))
|
||||||
if (*touched_eof && !inpar(line))
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
/* Determine the length of the quoting part, and the number of lines
|
/* We found a paragraph; determine length of quoting and number of lines. */
|
||||||
* in the found paragraph. */
|
|
||||||
*quotelen = quote_length((*firstline)->data);
|
*quotelen = quote_length((*firstline)->data);
|
||||||
*parlen = line->lineno - (*firstline)->lineno;
|
*parlen = line->lineno - (*firstline)->lineno + 1;
|
||||||
|
*touched_eof = (line->next == NULL);
|
||||||
/* 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)++;
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue