mirror of
git://git.sv.gnu.org/nano.git
synced 2024-11-26 22:59:38 +03:00
inserting: prune some superfluous settings, and do one differently
When we don't set edittop in read_line(), we don't need to readjust it in read_file(), because in that particular case it will still be pointing at current. And since fileptr is a new, freshly created line, it can never be equal to filebot, so there is no point in comparing them. If more than one line was inserted at the beginning of the file, leave it up to the screen handling to set edittop to what it should be. Move the setting of fileage a bit down, to its sister setting: the line at current gets "connected" either to the top-of-file pointer or to the last line of the inserted file.
This commit is contained in:
parent
04013fb7fa
commit
dac0aa1d89
16
src/files.c
16
src/files.c
@ -708,8 +708,6 @@ filestruct *read_line(char *buf, size_t buf_len, filestruct *prevnode)
|
||||
freshline->next = openfile->fileage;
|
||||
openfile->fileage = freshline;
|
||||
freshline->lineno = 1;
|
||||
/* Make sure that our edit window stays on the first line. */
|
||||
openfile->edittop = freshline;
|
||||
} else {
|
||||
prevnode->next = freshline;
|
||||
freshline->next = NULL;
|
||||
@ -897,22 +895,18 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable, bool checkw
|
||||
current_len + 1);
|
||||
strncpy(openfile->current->data, fileptr->data, len);
|
||||
|
||||
/* Don't destroy fileage, edittop, or filebot! */
|
||||
if (fileptr == openfile->fileage)
|
||||
openfile->fileage = openfile->current;
|
||||
if (fileptr == openfile->edittop)
|
||||
openfile->edittop = openfile->current;
|
||||
if (fileptr == openfile->filebot)
|
||||
openfile->filebot = openfile->current;
|
||||
|
||||
/* Step back one line, and blow away the unterminated line,
|
||||
* since its text has been copied into current. */
|
||||
fileptr = fileptr->prev;
|
||||
delete_node(dropline);
|
||||
}
|
||||
|
||||
if (fileptr == NULL)
|
||||
/* After inserting a single unterminated line at the top,
|
||||
* readjust the top-of-file pointer. */
|
||||
openfile->fileage = openfile->current;
|
||||
else {
|
||||
/* Attach the line at current after the line at fileptr. */
|
||||
if (fileptr != NULL) {
|
||||
fileptr->next = openfile->current;
|
||||
openfile->current->prev = fileptr;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user