2000-06-06 05:53:49 +00:00
|
|
|
/**************************************************************************
|
2016-08-29 15:10:49 +00:00
|
|
|
* cut.c -- This file is part of GNU nano. *
|
2000-06-06 05:53:49 +00:00
|
|
|
* *
|
2018-01-24 09:13:28 +00:00
|
|
|
* Copyright (C) 1999-2011, 2013-2018 Free Software Foundation, Inc. *
|
2016-08-29 13:14:18 +00:00
|
|
|
* Copyright (C) 2014 Mark Majeres *
|
|
|
|
* Copyright (C) 2016 Benno Schulenberg *
|
|
|
|
* *
|
2016-08-29 15:10:49 +00:00
|
|
|
* GNU nano is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published *
|
|
|
|
* by the Free Software Foundation, either version 3 of the License, *
|
|
|
|
* or (at your option) any later version. *
|
2000-06-06 05:53:49 +00:00
|
|
|
* *
|
2016-08-29 15:10:49 +00:00
|
|
|
* GNU nano is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty *
|
|
|
|
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
|
|
|
* See the GNU General Public License for more details. *
|
2000-06-06 05:53:49 +00:00
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
2016-08-29 15:10:49 +00:00
|
|
|
* along with this program. If not, see http://www.gnu.org/licenses/. *
|
2000-06-06 05:53:49 +00:00
|
|
|
* *
|
|
|
|
**************************************************************************/
|
|
|
|
|
2005-12-08 02:47:10 +00:00
|
|
|
#include "proto.h"
|
2001-04-28 18:03:52 +00:00
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2019-01-01 16:29:08 +00:00
|
|
|
/* Delete the character under the cursor. */
|
|
|
|
void do_deletion(undo_type action)
|
|
|
|
{
|
|
|
|
#ifndef NANO_TINY
|
|
|
|
size_t old_amount = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
openfile->placewewant = xplustabs();
|
|
|
|
|
|
|
|
/* When in the middle of a line, delete the current character. */
|
|
|
|
if (openfile->current->data[openfile->current_x] != '\0') {
|
|
|
|
int char_len = parse_mbchar(openfile->current->data +
|
|
|
|
openfile->current_x, NULL, NULL);
|
|
|
|
size_t line_len = strlen(openfile->current->data +
|
|
|
|
openfile->current_x);
|
|
|
|
#ifndef NANO_TINY
|
|
|
|
/* If the type of action changed or the cursor moved to a different
|
|
|
|
* line, create a new undo item, otherwise update the existing item. */
|
|
|
|
if (action != openfile->last_action ||
|
|
|
|
openfile->current->lineno != openfile->current_undo->lineno)
|
|
|
|
add_undo(action);
|
|
|
|
else
|
|
|
|
update_undo(action);
|
|
|
|
|
|
|
|
if (ISSET(SOFTWRAP))
|
|
|
|
old_amount = number_of_chunks_in(openfile->current);
|
|
|
|
#endif
|
|
|
|
/* Move the remainder of the line "in", over the current character. */
|
|
|
|
charmove(&openfile->current->data[openfile->current_x],
|
|
|
|
&openfile->current->data[openfile->current_x + char_len],
|
|
|
|
line_len - char_len + 1);
|
|
|
|
#ifndef NANO_TINY
|
|
|
|
/* Adjust the mark if it is after the cursor on the current line. */
|
|
|
|
if (openfile->mark == openfile->current &&
|
|
|
|
openfile->mark_x > openfile->current_x)
|
|
|
|
openfile->mark_x -= char_len;
|
|
|
|
#endif
|
|
|
|
/* Otherwise, when not at end of buffer, join this line with the next. */
|
|
|
|
} else if (openfile->current != openfile->filebot) {
|
|
|
|
filestruct *joining = openfile->current->next;
|
|
|
|
|
|
|
|
/* If there is a magic line, and we're before it: don't eat it. */
|
|
|
|
if (joining == openfile->filebot && openfile->current_x != 0 &&
|
|
|
|
!ISSET(NO_NEWLINES)) {
|
|
|
|
#ifndef NANO_TINY
|
|
|
|
if (action == BACK)
|
|
|
|
add_undo(BACK);
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NANO_TINY
|
|
|
|
add_undo(action);
|
|
|
|
#endif
|
|
|
|
/* Add the contents of the next line to those of the current one. */
|
|
|
|
openfile->current->data = charealloc(openfile->current->data,
|
|
|
|
strlen(openfile->current->data) + strlen(joining->data) + 1);
|
|
|
|
strcat(openfile->current->data, joining->data);
|
|
|
|
|
|
|
|
#ifndef NANO_TINY
|
|
|
|
/* Adjust the mark if it was on the line that was "eaten". */
|
|
|
|
if (openfile->mark == joining) {
|
|
|
|
openfile->mark = openfile->current;
|
|
|
|
openfile->mark_x += openfile->current_x;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
unlink_node(joining);
|
|
|
|
renumber(openfile->current);
|
|
|
|
|
|
|
|
/* Two lines were joined, so we need to refresh the screen. */
|
|
|
|
refresh_needed = TRUE;
|
|
|
|
} else
|
|
|
|
/* We're at the end-of-file: nothing to do. */
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Adjust the file size, and remember it for a possible redo. */
|
|
|
|
openfile->totsize--;
|
|
|
|
#ifndef NANO_TINY
|
|
|
|
openfile->current_undo->newsize = openfile->totsize;
|
|
|
|
|
|
|
|
/* If the number of screen rows that a softwrapped line occupies
|
|
|
|
* has changed, we need a full refresh. */
|
|
|
|
if (ISSET(SOFTWRAP) && refresh_needed == FALSE &&
|
|
|
|
number_of_chunks_in(openfile->current) != old_amount)
|
|
|
|
refresh_needed = TRUE;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
set_modified();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Delete the character under the cursor. */
|
|
|
|
void do_delete(void)
|
|
|
|
{
|
|
|
|
#ifndef NANO_TINY
|
|
|
|
if (openfile->mark && ISSET(LET_THEM_ZAP))
|
|
|
|
zap_text();
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
do_deletion(DEL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Backspace over one character. That is, move the cursor left one
|
|
|
|
* character, and then delete the character under the cursor. */
|
|
|
|
void do_backspace(void)
|
|
|
|
{
|
|
|
|
#ifndef NANO_TINY
|
|
|
|
if (openfile->mark && ISSET(LET_THEM_ZAP))
|
|
|
|
zap_text();
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
if (openfile->current != openfile->fileage || openfile->current_x > 0) {
|
|
|
|
do_left();
|
|
|
|
do_deletion(BACK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NANO_TINY
|
|
|
|
/* Delete text from the cursor until the first start of a word to
|
|
|
|
* the right, or to the left when backward is true. */
|
|
|
|
void do_cutword(bool backward)
|
|
|
|
{
|
|
|
|
/* Remember the current cursor position. */
|
|
|
|
filestruct *is_current = openfile->current;
|
|
|
|
size_t is_current_x = openfile->current_x;
|
|
|
|
|
|
|
|
/* Remember where the cutbuffer is and then make it seem blank. */
|
|
|
|
filestruct *is_cutbuffer = cutbuffer;
|
|
|
|
filestruct *is_cutbottom = cutbottom;
|
|
|
|
cutbuffer = NULL;
|
|
|
|
cutbottom = NULL;
|
|
|
|
|
|
|
|
/* Move the cursor to a word start, to the left or to the right.
|
|
|
|
* If that word is on another line and the cursor was not already
|
|
|
|
* on the edge of the original line, then put the cursor on that
|
|
|
|
* edge instead, so that lines will not be joined unexpectedly. */
|
|
|
|
if (backward) {
|
|
|
|
do_prev_word(ISSET(WORD_BOUNDS));
|
|
|
|
if (openfile->current != is_current) {
|
|
|
|
if (is_current_x > 0) {
|
|
|
|
openfile->current = is_current;
|
|
|
|
openfile->current_x = 0;
|
|
|
|
} else
|
|
|
|
openfile->current_x = strlen(openfile->current->data);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
do_next_word(FALSE, ISSET(WORD_BOUNDS));
|
|
|
|
if (openfile->current != is_current &&
|
|
|
|
is_current->data[is_current_x] != '\0') {
|
|
|
|
openfile->current = is_current;
|
|
|
|
openfile->current_x = strlen(is_current->data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the mark at the start of that word. */
|
|
|
|
openfile->mark = openfile->current;
|
|
|
|
openfile->mark_x = openfile->current_x;
|
|
|
|
|
|
|
|
/* Put the cursor back where it was, so an undo will put it there too. */
|
|
|
|
openfile->current = is_current;
|
|
|
|
openfile->current_x = is_current_x;
|
|
|
|
|
|
|
|
/* Now kill the marked region and a word is gone. */
|
|
|
|
do_cut_text_void();
|
|
|
|
|
|
|
|
/* Discard the cut word and restore the cutbuffer. */
|
|
|
|
free_filestruct(cutbuffer);
|
|
|
|
cutbuffer = is_cutbuffer;
|
|
|
|
cutbottom = is_cutbottom;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Delete a word leftward. */
|
|
|
|
void do_cut_prev_word(void)
|
|
|
|
{
|
|
|
|
do_cutword(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Delete a word rightward. */
|
|
|
|
void do_cut_next_word(void)
|
|
|
|
{
|
|
|
|
do_cutword(FALSE);
|
|
|
|
}
|
|
|
|
#endif /* !NANO_TINY */
|
|
|
|
|
2006-04-24 19:44:04 +00:00
|
|
|
/* If we aren't on the last line of the file, move all the text of the
|
2006-05-21 20:03:43 +00:00
|
|
|
* current line, plus the newline at the end, into the cutbuffer. If we
|
|
|
|
* are, move all of the text of the current line into the cutbuffer. In
|
2005-11-09 02:23:54 +00:00
|
|
|
* both cases, set the current place we want to the beginning of the
|
|
|
|
* current line. */
|
2004-11-23 04:08:28 +00:00
|
|
|
void cut_line(void)
|
2002-07-19 01:08:59 +00:00
|
|
|
{
|
2017-12-29 18:27:33 +00:00
|
|
|
if (openfile->current != openfile->filebot)
|
|
|
|
extract_buffer(&cutbuffer, &cutbottom, openfile->current, 0,
|
|
|
|
openfile->current->next, 0);
|
|
|
|
else
|
|
|
|
extract_buffer(&cutbuffer, &cutbottom, openfile->current, 0,
|
|
|
|
openfile->current, strlen(openfile->current->data));
|
|
|
|
openfile->placewewant = 0;
|
2000-06-06 05:53:49 +00:00
|
|
|
}
|
|
|
|
|
2005-11-15 03:17:35 +00:00
|
|
|
#ifndef NANO_TINY
|
2006-05-21 20:03:43 +00:00
|
|
|
/* Move all currently marked text into the cutbuffer, and set the
|
|
|
|
* current place we want to where the text used to start. */
|
2016-12-31 15:36:14 +00:00
|
|
|
void cut_marked(bool *right_side_up)
|
2000-06-06 05:53:49 +00:00
|
|
|
{
|
2017-12-29 18:27:33 +00:00
|
|
|
filestruct *top, *bot;
|
|
|
|
size_t top_x, bot_x;
|
2001-06-21 23:58:47 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
mark_order((const filestruct **)&top, &top_x,
|
|
|
|
(const filestruct **)&bot, &bot_x, right_side_up);
|
2000-06-06 05:53:49 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
extract_buffer(&cutbuffer, &cutbottom, top, top_x, bot, bot_x);
|
|
|
|
openfile->placewewant = xplustabs();
|
2004-11-23 04:08:28 +00:00
|
|
|
}
|
2003-12-24 08:03:54 +00:00
|
|
|
|
2006-04-24 19:44:04 +00:00
|
|
|
/* If we aren't at the end of the current line, move all the text from
|
|
|
|
* the current cursor position to the end of the current line, not
|
2006-05-21 20:03:43 +00:00
|
|
|
* counting the newline at the end, into the cutbuffer. If we are, and
|
2006-04-24 19:44:04 +00:00
|
|
|
* we're not on the last line of the file, move the newline at the end
|
2006-05-21 20:03:43 +00:00
|
|
|
* into the cutbuffer, and set the current place we want to where the
|
2005-11-03 21:08:39 +00:00
|
|
|
* newline used to be. */
|
2004-11-23 04:08:28 +00:00
|
|
|
void cut_to_eol(void)
|
|
|
|
{
|
2017-12-29 18:27:33 +00:00
|
|
|
size_t data_len = strlen(openfile->current->data);
|
|
|
|
|
|
|
|
if (openfile->current_x < data_len)
|
|
|
|
/* If we're not at the end of the line, move all the text from
|
|
|
|
* the current position up to it, not counting the newline at
|
|
|
|
* the end, into the cutbuffer. */
|
|
|
|
extract_buffer(&cutbuffer, &cutbottom, openfile->current,
|
|
|
|
openfile->current_x, openfile->current, data_len);
|
|
|
|
else if (openfile->current != openfile->filebot) {
|
|
|
|
/* If we're at the end of the line, and it isn't the last line
|
|
|
|
* of the file, move all the text from the current position up
|
|
|
|
* to the beginning of the next line, i.e. the newline at the
|
|
|
|
* end, into the cutbuffer. */
|
|
|
|
extract_buffer(&cutbuffer, &cutbottom, openfile->current,
|
|
|
|
openfile->current_x, openfile->current->next, 0);
|
|
|
|
openfile->placewewant = xplustabs();
|
|
|
|
}
|
2000-06-06 05:53:49 +00:00
|
|
|
}
|
2006-05-21 20:03:43 +00:00
|
|
|
|
|
|
|
/* Move all the text from the current cursor position to the end of the
|
|
|
|
* file into the cutbuffer. */
|
|
|
|
void cut_to_eof(void)
|
|
|
|
{
|
2017-12-29 18:27:33 +00:00
|
|
|
extract_buffer(&cutbuffer, &cutbottom,
|
|
|
|
openfile->current, openfile->current_x,
|
|
|
|
openfile->filebot, strlen(openfile->filebot->data));
|
2006-05-21 20:03:43 +00:00
|
|
|
}
|
2005-11-15 03:17:35 +00:00
|
|
|
#endif /* !NANO_TINY */
|
2000-06-06 05:53:49 +00:00
|
|
|
|
2017-04-19 15:38:34 +00:00
|
|
|
/* Move text from the current buffer into the cutbuffer. If
|
|
|
|
* copy_text is TRUE, copy the text back into the buffer afterward.
|
2014-06-30 20:39:27 +00:00
|
|
|
* If cut_till_eof is TRUE, move all text from the current cursor
|
2018-10-24 02:25:22 +00:00
|
|
|
* position to the end of the file into the cutbuffer. If append
|
|
|
|
* is TRUE (when zapping), always append the cut to the cutbuffer. */
|
|
|
|
void do_cut_text(bool copy_text, bool marked, bool cut_till_eof, bool append)
|
2000-06-06 05:53:49 +00:00
|
|
|
{
|
2006-04-25 02:23:28 +00:00
|
|
|
#ifndef NANO_TINY
|
2017-12-29 18:27:33 +00:00
|
|
|
filestruct *cb_save = NULL;
|
|
|
|
/* The current end of the cutbuffer, before we add text to it. */
|
|
|
|
size_t cb_save_len = 0;
|
|
|
|
/* The length of the string at the current end of the cutbuffer,
|
|
|
|
* before we add text to it. */
|
|
|
|
bool old_no_newlines = ISSET(NO_NEWLINES);
|
|
|
|
bool right_side_up = TRUE;
|
|
|
|
/* There *is* no region, *or* it is marked forward. */
|
2006-04-25 02:23:28 +00:00
|
|
|
#endif
|
2017-12-29 18:27:33 +00:00
|
|
|
size_t was_totsize = openfile->totsize;
|
|
|
|
|
2018-06-02 15:57:19 +00:00
|
|
|
/* If cuts were not continuous, or when cutting a region, clear the slate. */
|
2018-10-24 02:25:22 +00:00
|
|
|
if (!append && (!keep_cutbuffer || marked || cut_till_eof)) {
|
2017-12-29 18:27:33 +00:00
|
|
|
free_filestruct(cutbuffer);
|
|
|
|
cutbuffer = NULL;
|
2018-06-02 15:57:19 +00:00
|
|
|
/* After a line cut, future line cuts should add to the cutbuffer. */
|
2018-07-10 13:31:04 +00:00
|
|
|
keep_cutbuffer = !marked && !cut_till_eof;
|
2017-12-29 18:27:33 +00:00
|
|
|
}
|
2000-08-07 14:58:26 +00:00
|
|
|
|
2006-04-25 02:23:28 +00:00
|
|
|
#ifndef NANO_TINY
|
2017-12-29 18:27:33 +00:00
|
|
|
if (copy_text) {
|
|
|
|
/* If the cutbuffer isn't empty, remember where it currently ends. */
|
|
|
|
if (cutbuffer != NULL) {
|
|
|
|
cb_save = cutbottom;
|
|
|
|
cb_save_len = strlen(cutbottom->data);
|
|
|
|
}
|
|
|
|
/* Don't add a magicline when moving text to the cutbuffer. */
|
|
|
|
SET(NO_NEWLINES);
|
2006-04-26 19:03:50 +00:00
|
|
|
}
|
2017-12-29 18:27:33 +00:00
|
|
|
|
|
|
|
if (cut_till_eof) {
|
|
|
|
/* Move all text up to the end of the file into the cutbuffer. */
|
|
|
|
cut_to_eof();
|
|
|
|
} else if (openfile->mark) {
|
|
|
|
/* Move the marked text to the cutbuffer, and turn the mark off. */
|
|
|
|
cut_marked(&right_side_up);
|
|
|
|
openfile->mark = NULL;
|
|
|
|
} else if (ISSET(CUT_FROM_CURSOR))
|
|
|
|
/* Move all text up to the end of the line into the cutbuffer. */
|
|
|
|
cut_to_eol();
|
|
|
|
else
|
2005-03-26 22:49:46 +00:00
|
|
|
#endif
|
2017-12-29 18:27:33 +00:00
|
|
|
/* Move the entire line into the cutbuffer. */
|
|
|
|
cut_line();
|
2000-06-06 05:53:49 +00:00
|
|
|
|
2006-04-25 02:23:28 +00:00
|
|
|
#ifndef NANO_TINY
|
2017-12-29 18:27:33 +00:00
|
|
|
if (copy_text) {
|
|
|
|
/* Copy the text that is in the cutbuffer (starting at its saved end,
|
|
|
|
* if there is one) back into the current buffer. This effectively
|
|
|
|
* uncuts the text we just cut. */
|
|
|
|
if (cutbuffer != NULL) {
|
|
|
|
if (cb_save != NULL) {
|
|
|
|
cb_save->data += cb_save_len;
|
|
|
|
copy_from_buffer(cb_save);
|
|
|
|
cb_save->data -= cb_save_len;
|
|
|
|
} else
|
|
|
|
copy_from_buffer(cutbuffer);
|
|
|
|
|
|
|
|
/* If the copied region was marked forward, put the new desired
|
|
|
|
* x position at its end; otherwise, leave it at its beginning. */
|
|
|
|
if (right_side_up)
|
|
|
|
openfile->placewewant = xplustabs();
|
|
|
|
}
|
|
|
|
/* Restore the magicline behavior now that we're done fiddling. */
|
|
|
|
if (!old_no_newlines)
|
|
|
|
UNSET(NO_NEWLINES);
|
|
|
|
} else
|
2014-03-17 14:15:57 +00:00
|
|
|
#endif /* !NANO_TINY */
|
2017-12-29 18:27:33 +00:00
|
|
|
/* Only set the modification flag if actually something was cut. */
|
|
|
|
if (openfile->totsize != was_totsize)
|
|
|
|
set_modified();
|
2006-04-25 02:23:28 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
refresh_needed = TRUE;
|
2000-06-06 05:53:49 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 15:38:34 +00:00
|
|
|
/* Move text from the current buffer into the cutbuffer. */
|
2006-04-25 02:23:28 +00:00
|
|
|
void do_cut_text_void(void)
|
|
|
|
{
|
2008-08-02 14:39:42 +00:00
|
|
|
#ifndef NANO_TINY
|
2018-09-26 14:42:23 +00:00
|
|
|
/* Only add a new undo item when the current item is not a CUT or when
|
|
|
|
* the current cut is not contiguous with the previous cutting. */
|
|
|
|
if (openfile->last_action != CUT || openfile->current_undo == NULL ||
|
|
|
|
openfile->current_undo->mark_begin_lineno != openfile->current->lineno ||
|
|
|
|
!keep_cutbuffer)
|
|
|
|
add_undo(CUT);
|
2018-10-24 02:25:22 +00:00
|
|
|
do_cut_text(FALSE, openfile->mark, FALSE, FALSE);
|
2017-12-29 18:27:33 +00:00
|
|
|
update_undo(CUT);
|
2018-07-10 13:31:04 +00:00
|
|
|
#else
|
2018-10-24 02:25:22 +00:00
|
|
|
do_cut_text(FALSE, FALSE, FALSE, FALSE);
|
2008-08-02 14:39:42 +00:00
|
|
|
#endif
|
2006-04-25 02:23:28 +00:00
|
|
|
}
|
|
|
|
|
2005-11-15 03:17:35 +00:00
|
|
|
#ifndef NANO_TINY
|
2017-04-19 15:38:34 +00:00
|
|
|
/* Move text from the current buffer into the cutbuffer, and copy it
|
|
|
|
* back into the buffer afterward. If the mark is set or the cursor
|
2014-06-18 19:04:35 +00:00
|
|
|
* was moved, blow away previous contents of the cutbuffer. */
|
2006-04-25 02:23:28 +00:00
|
|
|
void do_copy_text(void)
|
|
|
|
{
|
2018-08-20 17:31:23 +00:00
|
|
|
static filestruct *next_contiguous_line = NULL;
|
2017-12-29 18:27:33 +00:00
|
|
|
bool mark_is_set = (openfile->mark != NULL);
|
|
|
|
|
|
|
|
/* Remember the current viewport and cursor position. */
|
|
|
|
ssize_t is_edittop_lineno = openfile->edittop->lineno;
|
|
|
|
size_t is_firstcolumn = openfile->firstcolumn;
|
|
|
|
ssize_t is_current_lineno = openfile->current->lineno;
|
|
|
|
size_t is_current_x = openfile->current_x;
|
|
|
|
|
|
|
|
if (mark_is_set || openfile->current != next_contiguous_line)
|
2018-12-30 12:36:29 +00:00
|
|
|
keep_cutbuffer = FALSE;
|
2017-12-29 18:27:33 +00:00
|
|
|
|
2018-10-24 02:25:22 +00:00
|
|
|
do_cut_text(TRUE, mark_is_set, FALSE, FALSE);
|
2017-12-29 18:27:33 +00:00
|
|
|
|
|
|
|
/* If the mark was set, blow away the cutbuffer on the next copy. */
|
|
|
|
next_contiguous_line = (mark_is_set ? NULL : openfile->current);
|
|
|
|
|
|
|
|
/* If the mark was set, restore the viewport and cursor position. */
|
|
|
|
if (mark_is_set) {
|
|
|
|
openfile->edittop = fsfromline(is_edittop_lineno);
|
|
|
|
openfile->firstcolumn = is_firstcolumn;
|
|
|
|
openfile->current = fsfromline(is_current_lineno);
|
|
|
|
openfile->current_x = is_current_x;
|
|
|
|
}
|
2006-04-25 02:23:28 +00:00
|
|
|
}
|
|
|
|
|
2005-01-01 07:43:32 +00:00
|
|
|
/* Cut from the current cursor position to the end of the file. */
|
2014-06-30 20:39:27 +00:00
|
|
|
void do_cut_till_eof(void)
|
2005-01-01 07:43:32 +00:00
|
|
|
{
|
2017-12-29 18:27:33 +00:00
|
|
|
add_undo(CUT_TO_EOF);
|
2018-10-24 02:25:22 +00:00
|
|
|
do_cut_text(FALSE, FALSE, TRUE, FALSE);
|
2017-12-29 18:27:33 +00:00
|
|
|
update_undo(CUT_TO_EOF);
|
2005-01-01 07:43:32 +00:00
|
|
|
}
|
2018-10-24 02:25:22 +00:00
|
|
|
|
|
|
|
/* Erase text (current line or marked region), sending it into oblivion. */
|
|
|
|
void zap_text(void)
|
|
|
|
{
|
|
|
|
/* Remember the current cutbuffer so it can be restored after the zap. */
|
|
|
|
filestruct *was_cutbuffer = cutbuffer;
|
|
|
|
filestruct *was_cutbottom = cutbottom;
|
|
|
|
|
|
|
|
/* Add a new undo item only when the current item is not a ZAP or when
|
|
|
|
* the current zap is not contiguous with the previous zapping. */
|
|
|
|
if (openfile->last_action != ZAP || openfile->current_undo == NULL ||
|
|
|
|
openfile->current_undo->mark_begin_lineno != openfile->current->lineno ||
|
|
|
|
openfile->current_undo->xflags & (MARK_WAS_SET|WAS_MARKED_FORWARD))
|
|
|
|
add_undo(ZAP);
|
|
|
|
|
|
|
|
/* Use the cutbuffer from the ZAP undo item, so the cut can be undone. */
|
|
|
|
cutbuffer = openfile->current_undo->cutbuffer;
|
|
|
|
cutbottom = openfile->current_undo->cutbottom;
|
|
|
|
|
|
|
|
do_cut_text(FALSE, openfile->mark, FALSE, TRUE);
|
|
|
|
|
|
|
|
update_undo(ZAP);
|
|
|
|
|
|
|
|
cutbuffer = was_cutbuffer;
|
|
|
|
cutbottom = was_cutbottom;
|
|
|
|
}
|
2005-11-15 03:17:35 +00:00
|
|
|
#endif /* !NANO_TINY */
|
2005-01-01 07:43:32 +00:00
|
|
|
|
2017-04-19 15:38:34 +00:00
|
|
|
/* Copy text from the cutbuffer into the current buffer. */
|
2004-07-02 14:31:03 +00:00
|
|
|
void do_uncut_text(void)
|
2000-06-06 05:53:49 +00:00
|
|
|
{
|
2017-12-29 18:27:33 +00:00
|
|
|
ssize_t was_lineno = openfile->current->lineno;
|
|
|
|
/* The line number where we started the paste. */
|
|
|
|
size_t was_leftedge = 0;
|
|
|
|
/* The leftedge where we started the paste. */
|
2016-04-12 08:24:57 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* If the cutbuffer is empty, there is nothing to do. */
|
|
|
|
if (cutbuffer == NULL)
|
|
|
|
return;
|
2004-11-06 20:33:43 +00:00
|
|
|
|
2008-09-16 21:35:19 +00:00
|
|
|
#ifndef NANO_TINY
|
2017-12-29 18:27:33 +00:00
|
|
|
add_undo(PASTE);
|
2017-01-15 22:01:17 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
if (ISSET(SOFTWRAP))
|
|
|
|
was_leftedge = leftedge_for(xplustabs(), openfile->current);
|
2008-09-16 21:35:19 +00:00
|
|
|
#endif
|
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* Add a copy of the text in the cutbuffer to the current buffer
|
|
|
|
* at the current cursor position. */
|
|
|
|
copy_from_buffer(cutbuffer);
|
2000-06-06 05:53:49 +00:00
|
|
|
|
2014-05-25 19:41:49 +00:00
|
|
|
#ifndef NANO_TINY
|
2017-12-29 18:27:33 +00:00
|
|
|
update_undo(PASTE);
|
2014-05-25 19:41:49 +00:00
|
|
|
#endif
|
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* If we pasted less than a screenful, don't center the cursor. */
|
|
|
|
if (less_than_a_screenful(was_lineno, was_leftedge))
|
|
|
|
focusing = FALSE;
|
2016-04-12 08:24:57 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* Set the desired x position to where the pasted text ends. */
|
|
|
|
openfile->placewewant = xplustabs();
|
2000-06-06 05:53:49 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
set_modified();
|
|
|
|
refresh_needed = TRUE;
|
2000-06-06 05:53:49 +00:00
|
|
|
}
|