Commit 500b5e35 authored by Chris Allegretta's avatar Chris Allegretta
Browse files

do_cut_text(): Moved the case of current == mark_beginbuf into cut_marke ...

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
parent 40f45c86
Showing with 44 additions and 30 deletions
+44 -30
......@@ -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$
......@@ -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:
......
......@@ -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, &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)
if (current->lineno <= mark_beginbuf->lineno)
cut_marked_segment(current, current_x, mark_beginbuf,
mark_beginx, 1);
else
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment