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
master
Chris Allegretta 2001-06-21 23:58:47 +00:00
parent 40f45c8689
commit 500b5e3539
4 changed files with 44 additions and 30 deletions

5
BUGS
View File

@ -120,8 +120,7 @@
** Open BUGS ** ** Open BUGS **
Informal note - when using marked write to file, if there's only one Informal note - when using marked write to file, the number of lines
line of text hilighted, it writes the whole rest of the ifle to disk and written is off by one. Delete this message when fixed.
goes bonkers. Delete this message when fixed.
$Id$ $Id$

View File

@ -70,6 +70,9 @@ Cvs code -
- If the line is empty when using -k and wasn't already added, - 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) create a dummy line and add it to the cutbuffer (fixes bug #61)
- Reset marked_cut if we blow away the cutbuffer. - 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() do_uncut_text()
- Reset cutbuffer even if we're uncutting marked or cut to end text! - Reset cutbuffer even if we're uncutting marked or cut to end text!
- faq.html: - faq.html:

61
cut.c
View File

@ -68,6 +68,39 @@ void cut_marked_segment(filestruct * top, int top_x, filestruct * bot,
{ {
filestruct *tmp, *next, *botcopy; filestruct *tmp, *next, *botcopy;
char *tmpstr; 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 */ /* Set up the beginning of the cutbuffer */
tmp = copy_node(top); tmp = copy_node(top);
@ -159,8 +192,7 @@ int do_cut_text(void)
{ {
filestruct *tmp, *fileptr = current; filestruct *tmp, *fileptr = current;
#ifndef NANO_SMALL #ifndef NANO_SMALL
char *tmpstr; int cuttingtoend = 0;
int newsize, cuttingtoend = 0;
#endif #endif
@ -218,30 +250,7 @@ int do_cut_text(void)
} }
} }
if (ISSET(MARK_ISSET)) { if (ISSET(MARK_ISSET)) {
if (current->lineno == mark_beginbuf->lineno) { 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, &current->data[current_x], newsize);
memmove(&current->data[current_x],
&current->data[mark_beginx],
strlen(&current->data[mark_beginx]) + 1);
} else {
strncpy(tmpstr, &current->data[mark_beginx], newsize);
memmove(&current->data[mark_beginx],
&current->data[current_x],
strlen(&current->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(&current->data);
} else if (current->lineno < mark_beginbuf->lineno)
cut_marked_segment(current, current_x, mark_beginbuf, cut_marked_segment(current, current_x, mark_beginbuf,
mark_beginx, 1); mark_beginx, 1);
else else

View File

@ -546,10 +546,12 @@ int do_writeout(char *path, int exiting, int append)
} }
while (1) { while (1) {
#ifndef NANO_SMALL
if (ISSET(MARK_ISSET) && !exiting) if (ISSET(MARK_ISSET) && !exiting)
i = statusq(1, writefile_list, WRITEFILE_LIST_LEN, "", i = statusq(1, writefile_list, WRITEFILE_LIST_LEN, "",
_("%s Selection to File"), append ? _("Append") : _("Write")); _("%s Selection to File"), append ? _("Append") : _("Write"));
else else
#endif
i = statusq(1, writefile_list, WRITEFILE_LIST_LEN, answer, i = statusq(1, writefile_list, WRITEFILE_LIST_LEN, answer,
_("File Name to %s"), append ? _("Append") : _("Write")); _("File Name to %s"), append ? _("Append") : _("Write"));
@ -604,6 +606,7 @@ int do_writeout(char *path, int exiting, int append)
filestruct *filebotbak = filebot; filestruct *filebotbak = filebot;
filestruct *cutback = cutbuffer; filestruct *cutback = cutbuffer;
int oldmod = 0; int oldmod = 0;
cutbuffer = NULL;
/* Okay, since write_file changes the filename, back it up */ /* Okay, since write_file changes the filename, back it up */
if (ISSET(MODIFIED)) 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 /* Now, non-destructively add the marked text to the
cutbuffer, and write the file out using the cutbuffer ;) */ 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, cut_marked_segment(current, current_x, mark_beginbuf,
mark_beginx, 0); mark_beginx, 0);
else else