wrapping: when autoindenting, use indentation of next line as example

When doing autoindentation, and the next line is not the start of
a new paragraph, then use the indentation of that line for the new
line, as it is more likely to have the desired indentation -- the
current line might be the start of the paragraph and thus could
have a deviant indentation.
master
Benno Schulenberg 2018-05-22 21:10:10 +02:00
parent d63d79b067
commit d00ab406bc
1 changed files with 10 additions and 3 deletions

View File

@ -1026,12 +1026,19 @@ void do_redo(void)
void do_enter(void) void do_enter(void)
{ {
filestruct *newnode = make_new_node(openfile->current); filestruct *newnode = make_new_node(openfile->current);
filestruct *sampleline = openfile->current;
size_t extra = 0; size_t extra = 0;
#ifndef NANO_TINY #ifndef NANO_TINY
bool allblanks = FALSE; bool allblanks = FALSE;
if (ISSET(AUTOINDENT)) { if (ISSET(AUTOINDENT)) {
extra = indent_length(openfile->current->data); /* If the next line is in this same paragraph, use its indentation
* as the model, as it is more likely to be what the user wants. */
if (openfile->current->next && inpar(openfile->current->next) &&
!begpar(openfile->current->next))
sampleline = openfile->current->next;
extra = indent_length(sampleline->data);
/* If we are breaking the line in the indentation, limit the new /* If we are breaking the line in the indentation, limit the new
* indentation to the current x position. */ * indentation to the current x position. */
@ -1047,8 +1054,8 @@ void do_enter(void)
openfile->current_x); openfile->current_x);
#ifndef NANO_TINY #ifndef NANO_TINY
if (ISSET(AUTOINDENT)) { if (ISSET(AUTOINDENT)) {
/* Copy the whitespace from the current line to the new one. */ /* Copy the whitespace from the sample line to the new one. */
strncpy(newnode->data, openfile->current->data, extra); strncpy(newnode->data, sampleline->data, extra);
/* If there were only blanks before the cursor, trim them. */ /* If there were only blanks before the cursor, trim them. */
if (allblanks) if (allblanks)
openfile->current_x = 0; openfile->current_x = 0;