input: do not auto-indent when something is pasted into nano from outside

Also, do not break overlong lines and do not convert tabs to spaces,
nor interpret a <Tab> as an indent command (when the mark is on).
In other words: accept an outside paste as literally as possible.

This fulfills https://savannah.gnu.org/bugs/?40060.
Requested-by: Egmont Koblinger <egmont@gmail.com>

And fulfills https://savannah.gnu.org/bugs/?57527.
Requested-by: Sébastien Desreux <seb@h-k.fr>
Requested-by: Hans Ecke <hecke@gxt.com>

Original-idea-by: Brand Huntsman <alpha@qzx.com>
This commit is contained in:
Benno Schulenberg 2020-01-05 14:21:46 +01:00
parent f705a9674b
commit 7d483987ce
3 changed files with 13 additions and 6 deletions

View File

@ -78,6 +78,9 @@ static linestruct *hindline;
static linestruct *filetail;
/* What was the bottom line of the buffer. */
static bool pasting_from_outside = FALSE;
/* Whether a bracketed paste is in progress. */
/* Create a new linestruct node. Note that we do not set prevnode->next. */
linestruct *make_new_node(linestruct *prevnode)
{
@ -1493,6 +1496,9 @@ void do_input(void)
}
#endif
if (bracketed_paste)
pasting_from_outside = TRUE;
/* Check for a shortcut in the main list. */
shortcut = get_shortcut(&input);
@ -1534,6 +1540,7 @@ void do_input(void)
* at once, filtering out any ASCII control codes. */
puddle[depth] = '\0';
inject(puddle, depth, TRUE);
pasting_from_outside = FALSE;
/* Empty the input buffer. */
free(puddle);
@ -1699,7 +1706,7 @@ void inject(char *output, size_t output_len, bool filtering)
#ifdef ENABLE_WRAPPING
/* If text gets wrapped, the edit window needs a refresh. */
if (ISSET(BREAK_LONG_LINES) && do_wrap())
if (ISSET(BREAK_LONG_LINES) && !pasting_from_outside && do_wrap())
refresh_needed = TRUE;
#endif
}

View File

@ -68,12 +68,12 @@ void do_mark(void)
void do_tab(void)
{
#ifdef ENABLE_COLOR
if (openfile->syntax && openfile->syntax->tab)
if (openfile->syntax && openfile->syntax->tab && !bracketed_paste)
inject(openfile->syntax->tab, strlen(openfile->syntax->tab), FALSE);
else
#endif
#ifndef NANO_TINY
if (ISSET(TABS_TO_SPACES)) {
if (ISSET(TABS_TO_SPACES) && !bracketed_paste) {
char *spaces = charalloc(tabsize + 1);
size_t length = tabsize - (xplustabs() % tabsize);
@ -853,7 +853,7 @@ void do_enter(void)
linestruct *sampleline = openfile->current;
bool allblanks = FALSE;
if (ISSET(AUTOINDENT)) {
if (ISSET(AUTOINDENT) && !bracketed_paste) {
#ifdef ENABLE_JUSTIFY
/* When doing automatic long-line wrapping and the next line is
* in this same paragraph, use its indentation as the model. */
@ -875,7 +875,7 @@ void do_enter(void)
strcpy(&newnode->data[extra], openfile->current->data +
openfile->current_x);
#ifndef NANO_TINY
if (ISSET(AUTOINDENT)) {
if (ISSET(AUTOINDENT) && !bracketed_paste) {
/* Copy the whitespace from the sample line to the new one. */
strncpy(newnode->data, sampleline->data, extra);
/* If there were only blanks before the cursor, trim them. */

View File

@ -657,7 +657,7 @@ int parse_kbinput(WINDOW *win)
#ifndef NANO_TINY
/* When <Tab> is pressed while the mark is on, do an indent. */
if (retval == TAB_CODE && openfile->mark && currmenu == MMAIN &&
openfile->mark != openfile->current)
!bracketed_paste && openfile->mark != openfile->current)
return INDENT_KEY;
#endif