From 500b5e353907f7648216c460bb6c05054c6122ce Mon Sep 17 00:00:00 2001 From: Chris Allegretta Date: Thu, 21 Jun 2001 23:58:47 +0000 Subject: [PATCH] do_cut_text(): Moved the case of current == mark_beginbuf into cut_marke segment, so do_writeout could call it when writing selection to file. Added some NANO_SMALL ifdefs git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@689 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- BUGS | 5 ++--- ChangeLog | 3 +++ cut.c | 61 +++++++++++++++++++++++++++++++------------------------ files.c | 5 ++++- 4 files changed, 44 insertions(+), 30 deletions(-) diff --git a/BUGS b/BUGS index 76bea52a..7dd9a8b2 100644 --- a/BUGS +++ b/BUGS @@ -120,8 +120,7 @@ ** Open BUGS ** -Informal note - when using marked write to file, if there's only one -line of text hilighted, it writes the whole rest of the ifle to disk and -goes bonkers. Delete this message when fixed. +Informal note - when using marked write to file, the number of lines +written is off by one. Delete this message when fixed. $Id$ diff --git a/ChangeLog b/ChangeLog index 0a6962d0..0fefd52a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -70,6 +70,9 @@ Cvs code - - If the line is empty when using -k and wasn't already added, create a dummy line and add it to the cutbuffer (fixes bug #61) - Reset marked_cut if we blow away the cutbuffer. + - Moved the case of current == mark_beginbuf into cut_marked + segment, so do_writeout could call it when writing selection to + file. do_uncut_text() - Reset cutbuffer even if we're uncutting marked or cut to end text! - faq.html: diff --git a/cut.c b/cut.c index 591648f7..73a30630 100644 --- a/cut.c +++ b/cut.c @@ -68,6 +68,39 @@ void cut_marked_segment(filestruct * top, int top_x, filestruct * bot, { filestruct *tmp, *next, *botcopy; char *tmpstr; + int newsize; + + /* Special case for cutting part of one line */ + if (top == bot) { + int swap; + + tmp = copy_node(top); + newsize = abs(bot_x - top_x) + 1; + tmpstr = charalloc(newsize + 1); + + /* Make top_x always be before bot_x */ + if (top_x > bot_x) { + swap = top_x; + top_x = bot_x; + bot_x = swap; + } + + strncpy(tmpstr, &top->data[top_x], newsize); + + if (destructive) { + memmove(&top->data[top_x], &top->data[bot_x], + strlen(&top->data[bot_x]) + 1); + align(&top->data); + current_x = top_x; + update_cursor(); + } + tmpstr[newsize - 1] = 0; + tmp->data = tmpstr; + add_to_cutbuffer(tmp); + dump_buffer(cutbuffer); + + return; + } /* Set up the beginning of the cutbuffer */ tmp = copy_node(top); @@ -159,8 +192,7 @@ int do_cut_text(void) { filestruct *tmp, *fileptr = current; #ifndef NANO_SMALL - char *tmpstr; - int newsize, cuttingtoend = 0; + int cuttingtoend = 0; #endif @@ -218,30 +250,7 @@ int do_cut_text(void) } } if (ISSET(MARK_ISSET)) { - if (current->lineno == mark_beginbuf->lineno) { - tmp = copy_node(current); - newsize = abs(mark_beginx - current_x) + 1; - - tmpstr = charalloc(newsize + 1); - if (current_x < mark_beginx) { - strncpy(tmpstr, ¤t->data[current_x], newsize); - memmove(¤t->data[current_x], - ¤t->data[mark_beginx], - strlen(¤t->data[mark_beginx]) + 1); - } else { - strncpy(tmpstr, ¤t->data[mark_beginx], newsize); - memmove(¤t->data[mark_beginx], - ¤t->data[current_x], - strlen(¤t->data[current_x]) + 1); - current_x = mark_beginx; - update_cursor(); - } - tmpstr[newsize - 1] = 0; - tmp->data = tmpstr; - add_to_cutbuffer(tmp); - dump_buffer(cutbuffer); - align(¤t->data); - } else if (current->lineno < mark_beginbuf->lineno) + if (current->lineno <= mark_beginbuf->lineno) cut_marked_segment(current, current_x, mark_beginbuf, mark_beginx, 1); else diff --git a/files.c b/files.c index 503e0dde..f37d7a79 100644 --- a/files.c +++ b/files.c @@ -546,10 +546,12 @@ int do_writeout(char *path, int exiting, int append) } while (1) { +#ifndef NANO_SMALL if (ISSET(MARK_ISSET) && !exiting) i = statusq(1, writefile_list, WRITEFILE_LIST_LEN, "", _("%s Selection to File"), append ? _("Append") : _("Write")); else +#endif i = statusq(1, writefile_list, WRITEFILE_LIST_LEN, answer, _("File Name to %s"), append ? _("Append") : _("Write")); @@ -604,6 +606,7 @@ int do_writeout(char *path, int exiting, int append) filestruct *filebotbak = filebot; filestruct *cutback = cutbuffer; int oldmod = 0; + cutbuffer = NULL; /* Okay, since write_file changes the filename, back it up */ if (ISSET(MODIFIED)) @@ -611,7 +614,7 @@ int do_writeout(char *path, int exiting, int append) /* Now, non-destructively add the marked text to the cutbuffer, and write the file out using the cutbuffer ;) */ - if (current->lineno < mark_beginbuf->lineno) + if (current->lineno <= mark_beginbuf->lineno) cut_marked_segment(current, current_x, mark_beginbuf, mark_beginx, 0); else -- 2.39.5