various miscellaneous cutting fixes
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3540 35c25a1d-7b9e-4130-9fde-d3aeb78583b8master
parent
83635c2155
commit
41b8972dc9
18
ChangeLog
18
ChangeLog
|
@ -93,6 +93,16 @@ CVS code -
|
||||||
- Rename variable editline to line, for consistency. (DLR)
|
- Rename variable editline to line, for consistency. (DLR)
|
||||||
- Change variable i from an int to a size_t in order to match
|
- Change variable i from an int to a size_t in order to match
|
||||||
selected, which it's compared against. (DLR)
|
selected, which it's compared against. (DLR)
|
||||||
|
- cut.c:
|
||||||
|
cut_to_eof()
|
||||||
|
- New function, containing the main functionality of
|
||||||
|
do_cut_till_end(). (DLR)
|
||||||
|
do_cut_text()
|
||||||
|
- Add parameter cut_till_end, to indicate when we're cutting
|
||||||
|
from the current cursor position to the end of the file, and
|
||||||
|
call cut_to_eof() when it's TRUE. (DLR)
|
||||||
|
do_cut_till_end()
|
||||||
|
- Convert to a wrapper for do_cut_text(). (DLR)
|
||||||
- files.c:
|
- files.c:
|
||||||
open_file()
|
open_file()
|
||||||
- Remove redundant wording in the error message when we try to
|
- Remove redundant wording in the error message when we try to
|
||||||
|
@ -180,6 +190,10 @@ CVS code -
|
||||||
do_input()
|
do_input()
|
||||||
- Remove redundant check for allow_funcs' being TRUE when we get
|
- Remove redundant check for allow_funcs' being TRUE when we get
|
||||||
KEY_MOUSE. (DLR)
|
KEY_MOUSE. (DLR)
|
||||||
|
- Don't blow away the cutbuffer when we get a shortcut and the
|
||||||
|
function associated with it is do_cut_till_end(). (DLR)
|
||||||
|
- Simplify the routine to preserve the cutbuffer when we call a
|
||||||
|
cutting or copying function associated with a shortcut. (DLR)
|
||||||
- nano.h:
|
- nano.h:
|
||||||
- Reorder the toggle #defines to match their corresponding order
|
- Reorder the toggle #defines to match their corresponding order
|
||||||
in toggle_init(). (DLR)
|
in toggle_init(). (DLR)
|
||||||
|
@ -199,10 +213,6 @@ CVS code -
|
||||||
do_yesno_prompt()
|
do_yesno_prompt()
|
||||||
- Handle the keys in a switch statement instead of a long if
|
- Handle the keys in a switch statement instead of a long if
|
||||||
block, for simplicity. (DLR)
|
block, for simplicity. (DLR)
|
||||||
- nano.c:
|
|
||||||
do_input()
|
|
||||||
- Don't blow away the cutbuffer when the shortcut we get is
|
|
||||||
do_cut_till_end(). (DLR)
|
|
||||||
- rcfile.c:
|
- rcfile.c:
|
||||||
parse_argument()
|
parse_argument()
|
||||||
- Rename variable ptr_bak to ptr_save, for consistency. (DLR)
|
- Rename variable ptr_bak to ptr_save, for consistency. (DLR)
|
||||||
|
|
61
src/cut.c
61
src/cut.c
|
@ -39,8 +39,8 @@ void cutbuffer_reset(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we aren't on the last line of the file, move all the text of the
|
/* If we aren't on the last line of the file, move all the text of the
|
||||||
* current line, plus the newline at the end, to the cutbuffer. If we
|
* current line, plus the newline at the end, into the cutbuffer. If we
|
||||||
* are, move all of the text of the current line to the cutbuffer. In
|
* are, move all of the text of the current line into the cutbuffer. In
|
||||||
* both cases, set the current place we want to the beginning of the
|
* both cases, set the current place we want to the beginning of the
|
||||||
* current line. */
|
* current line. */
|
||||||
void cut_line(void)
|
void cut_line(void)
|
||||||
|
@ -55,8 +55,8 @@ void cut_line(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
/* Move all currently marked text to the cutbuffer, and set the current
|
/* Move all currently marked text into the cutbuffer, and set the
|
||||||
* place we want to where the text used to start. */
|
* current place we want to where the text used to start. */
|
||||||
void cut_marked(void)
|
void cut_marked(void)
|
||||||
{
|
{
|
||||||
filestruct *top, *bot;
|
filestruct *top, *bot;
|
||||||
|
@ -71,9 +71,9 @@ void cut_marked(void)
|
||||||
|
|
||||||
/* If we aren't at the end of the current line, move all the text from
|
/* 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
|
* the current cursor position to the end of the current line, not
|
||||||
* counting the newline at the end, to the cutbuffer. If we are, and
|
* counting the newline at the end, into the cutbuffer. If we are, and
|
||||||
* we're not on the last line of the file, move the newline at the end
|
* we're not on the last line of the file, move the newline at the end
|
||||||
* to the cutbuffer, and set the current place we want to where the
|
* into the cutbuffer, and set the current place we want to where the
|
||||||
* newline used to be. */
|
* newline used to be. */
|
||||||
void cut_to_eol(void)
|
void cut_to_eol(void)
|
||||||
{
|
{
|
||||||
|
@ -84,27 +84,37 @@ void cut_to_eol(void)
|
||||||
if (openfile->current_x < data_len)
|
if (openfile->current_x < data_len)
|
||||||
/* If we're not at the end of the line, move all the text from
|
/* 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 current position up to it, not counting the newline at
|
||||||
* the end, to the cutbuffer. */
|
* the end, into the cutbuffer. */
|
||||||
move_to_filestruct(&cutbuffer, &cutbottom, openfile->current,
|
move_to_filestruct(&cutbuffer, &cutbottom, openfile->current,
|
||||||
openfile->current_x, openfile->current, data_len);
|
openfile->current_x, openfile->current, data_len);
|
||||||
else if (openfile->current != openfile->filebot) {
|
else if (openfile->current != openfile->filebot) {
|
||||||
/* If we're at the end of the line, and it isn't the last line
|
/* 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
|
* 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
|
* to the beginning of the next line, i.e, the newline at the
|
||||||
* end, to the cutbuffer. */
|
* end, into the cutbuffer. */
|
||||||
move_to_filestruct(&cutbuffer, &cutbottom, openfile->current,
|
move_to_filestruct(&cutbuffer, &cutbottom, openfile->current,
|
||||||
openfile->current_x, openfile->current->next, 0);
|
openfile->current_x, openfile->current->next, 0);
|
||||||
openfile->placewewant = xplustabs();
|
openfile->placewewant = xplustabs();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Move all the text from the current cursor position to the end of the
|
||||||
|
* file into the cutbuffer. */
|
||||||
|
void cut_to_eof(void)
|
||||||
|
{
|
||||||
|
move_to_filestruct(&cutbuffer, &cutbottom, openfile->current,
|
||||||
|
openfile->current_x, openfile->filebot,
|
||||||
|
strlen(openfile->filebot->data));
|
||||||
|
}
|
||||||
#endif /* !NANO_TINY */
|
#endif /* !NANO_TINY */
|
||||||
|
|
||||||
/* Move text from the current filestruct into the cutbuffer. If
|
/* Move text from the current filestruct into the cutbuffer. If
|
||||||
* copy_text is TRUE, copy the text back into the filestruct
|
* copy_text is TRUE, copy the text back into the filestruct afterward.
|
||||||
* afterward. */
|
* If cut_till_end is TRUE, move all text from the current cursor
|
||||||
|
* position to the end of the file into the cutbuffer. */
|
||||||
void do_cut_text(
|
void do_cut_text(
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
bool copy_text
|
bool copy_text, bool cut_till_end
|
||||||
#else
|
#else
|
||||||
void
|
void
|
||||||
#endif
|
#endif
|
||||||
|
@ -156,7 +166,11 @@ void do_cut_text(
|
||||||
keep_cutbuffer = TRUE;
|
keep_cutbuffer = TRUE;
|
||||||
|
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
if (openfile->mark_set) {
|
if (cut_till_end) {
|
||||||
|
/* If cut_till_end is TRUE, move all text up to the end of the
|
||||||
|
* file into the cutbuffer. */
|
||||||
|
cut_to_eof();
|
||||||
|
} else if (openfile->mark_set) {
|
||||||
/* If the mark is on, move the marked text to the cutbuffer, and
|
/* If the mark is on, move the marked text to the cutbuffer, and
|
||||||
* turn the mark off. */
|
* turn the mark off. */
|
||||||
cut_marked();
|
cut_marked();
|
||||||
|
@ -211,7 +225,7 @@ void do_cut_text_void(void)
|
||||||
{
|
{
|
||||||
do_cut_text(
|
do_cut_text(
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
FALSE
|
FALSE, FALSE
|
||||||
#endif
|
#endif
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -221,30 +235,13 @@ void do_cut_text_void(void)
|
||||||
* back into the filestruct afterward. */
|
* back into the filestruct afterward. */
|
||||||
void do_copy_text(void)
|
void do_copy_text(void)
|
||||||
{
|
{
|
||||||
do_cut_text(TRUE);
|
do_cut_text(TRUE, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Cut from the current cursor position to the end of the file. */
|
/* Cut from the current cursor position to the end of the file. */
|
||||||
void do_cut_till_end(void)
|
void do_cut_till_end(void)
|
||||||
{
|
{
|
||||||
assert(openfile->current != NULL && openfile->current->data != NULL);
|
do_cut_text(FALSE, TRUE);
|
||||||
|
|
||||||
check_statusblank();
|
|
||||||
|
|
||||||
move_to_filestruct(&cutbuffer, &cutbottom, openfile->current,
|
|
||||||
openfile->current_x, openfile->filebot,
|
|
||||||
strlen(openfile->filebot->data));
|
|
||||||
|
|
||||||
/* Leave the text in the cutbuffer, and mark the file as
|
|
||||||
* modified. */
|
|
||||||
set_modified();
|
|
||||||
|
|
||||||
/* Update the screen. */
|
|
||||||
edit_refresh();
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
dump_filestruct(cutbuffer);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
#endif /* !NANO_TINY */
|
#endif /* !NANO_TINY */
|
||||||
|
|
||||||
|
|
24
src/nano.c
24
src/nano.c
|
@ -1247,6 +1247,8 @@ int do_input(bool *meta_key, bool *func_key, bool *s_or_t, bool
|
||||||
/* The input buffer. */
|
/* The input buffer. */
|
||||||
static size_t kbinput_len = 0;
|
static size_t kbinput_len = 0;
|
||||||
/* The length of the input buffer. */
|
/* The length of the input buffer. */
|
||||||
|
bool cut_copy = FALSE;
|
||||||
|
/* Are we cutting or copying text? */
|
||||||
const shortcut *s;
|
const shortcut *s;
|
||||||
bool have_shortcut;
|
bool have_shortcut;
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
|
@ -1359,15 +1361,15 @@ int do_input(bool *meta_key, bool *func_key, bool *s_or_t, bool
|
||||||
* that we're done after running or trying to run their
|
* that we're done after running or trying to run their
|
||||||
* associated functions. */
|
* associated functions. */
|
||||||
default:
|
default:
|
||||||
/* Blow away the text in the cutbuffer if we aren't
|
/* If the function associated with this shortcut is
|
||||||
* cutting or copying text. */
|
* cutting or copying text, indicate this. */
|
||||||
if (s->func != do_cut_text_void
|
if (s->func == do_cut_text_void
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
&& s->func != do_copy_text && s->func !=
|
|| s->func == do_copy_text || s->func ==
|
||||||
do_cut_till_end
|
do_cut_till_end
|
||||||
#endif
|
#endif
|
||||||
)
|
)
|
||||||
cutbuffer_reset();
|
cut_copy = TRUE;
|
||||||
|
|
||||||
if (s->func != NULL) {
|
if (s->func != NULL) {
|
||||||
*ran_func = TRUE;
|
*ran_func = TRUE;
|
||||||
|
@ -1382,20 +1384,18 @@ int do_input(bool *meta_key, bool *func_key, bool *s_or_t, bool
|
||||||
}
|
}
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
else if (have_toggle) {
|
else if (have_toggle) {
|
||||||
/* Blow away the text in the cutbuffer, since we aren't
|
|
||||||
* cutting or copying text. */
|
|
||||||
cutbuffer_reset();
|
|
||||||
/* Toggle the flag associated with this shortcut. */
|
/* Toggle the flag associated with this shortcut. */
|
||||||
if (allow_funcs)
|
if (allow_funcs)
|
||||||
do_toggle(t);
|
do_toggle(t);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else
|
|
||||||
/* Blow away the text in the cutbuffer, since we aren't
|
|
||||||
* cutting or copying text. */
|
|
||||||
cutbuffer_reset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If we aren't cutting or copying text, blow away the text in the
|
||||||
|
* cutbuffer. */
|
||||||
|
if (!cut_copy)
|
||||||
|
cutbuffer_reset();
|
||||||
|
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -254,10 +254,11 @@ void cut_line(void);
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
void cut_marked(void);
|
void cut_marked(void);
|
||||||
void cut_to_eol(void);
|
void cut_to_eol(void);
|
||||||
|
void cut_to_eof(void);
|
||||||
#endif
|
#endif
|
||||||
void do_cut_text(
|
void do_cut_text(
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
bool copy_text
|
bool copy_text, bool cut_till_end
|
||||||
#else
|
#else
|
||||||
void
|
void
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue