From: Benno Schulenberg Date: Tue, 8 Dec 2015 16:02:05 +0000 (+0000) Subject: Letting also unlink_node() update 'filebot', instead of doing it in X-Git-Tag: v2.5.1~53 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=a64bfbee8bf4647c2a8f6d14bf271d259209bc86;p=nano.git Letting also unlink_node() update 'filebot', instead of doing it in four different places. It is not a problem that the history routines also use these functions, as history nodes will never equal filebot. git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5491 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/ChangeLog b/ChangeLog index c71c7fde..d514f9a8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,6 @@ 2015-12-08 Benno Schulenberg - * src/nano.c (splice_node): Make this function update 'filebot', - instead of doing it in four different places. + * src/nano.c (splice_node, unlink_node): Let these functions update + 'filebot', instead of doing it in four different places each. 2015-12-07 Benno Schulenberg * src/winio.c (edit_draw): Quit the loop when there is no end match. diff --git a/src/nano.c b/src/nano.c index 310616ed..18302e70 100644 --- a/src/nano.c +++ b/src/nano.c @@ -110,7 +110,7 @@ void splice_node(filestruct *afterthis, filestruct *newnode) openfile->filebot = newnode; } -/* Unlink a node from the rest of the filestruct and delete it. */ +/* Disconnect a node from a linked list of filestructs and delete it. */ void unlink_node(filestruct *fileptr) { assert(fileptr != NULL); @@ -120,10 +120,14 @@ void unlink_node(filestruct *fileptr) if (fileptr->next != NULL) fileptr->next->prev = fileptr->prev; + /* Update filebot when removing a node at the end of file. */ + if (openfile && openfile->filebot == fileptr) + openfile->filebot = fileptr->prev; + delete_node(fileptr); } -/* Delete a node from the filestruct. */ +/* Free the data structures in the given node. */ void delete_node(filestruct *fileptr) { assert(fileptr != NULL && fileptr->data != NULL); diff --git a/src/text.c b/src/text.c index d1871da4..da8900c2 100644 --- a/src/text.c +++ b/src/text.c @@ -144,8 +144,6 @@ void do_deletion(undo_type action) openfile->mark_begin_x += openfile->current_x; } #endif - if (openfile->filebot == foo) - openfile->filebot = openfile->current; unlink_node(foo); renumber(openfile->current); @@ -566,8 +564,6 @@ void do_undo(void) f->data = charealloc(f->data, strlen(f->data) + strlen(&f->next->data[u->mark_begin_x]) + 1); strcat(f->data, &f->next->data[u->mark_begin_x]); - if (openfile->filebot == f->next) - openfile->filebot = f; unlink_node(f->next); goto_line_posx(u->lineno, u->begin); break; @@ -707,8 +703,6 @@ void do_redo(void) } f->data = charealloc(f->data, strlen(f->data) + strlen(u->strdata) + 1); strcat(f->data, u->strdata); - if (f->next == openfile->filebot) - openfile->filebot = f; unlink_node(f->next); renumber(f); goto_line_posx(u->mark_begin_lineno, u->mark_begin_x); @@ -2098,11 +2092,9 @@ void do_justify(bool full_justify) strcat(openfile->current->data, next_line->data + indent_len); - /* Don't destroy edittop or filebot! */ + /* Don't destroy edittop! */ if (next_line == openfile->edittop) openfile->edittop = openfile->current; - if (next_line == openfile->filebot) - openfile->filebot = openfile->current; #ifndef NANO_TINY /* Adjust the mark coordinates to compensate for the change