tweaks: add a different helping variable

This commit is contained in:
Benno Schulenberg 2020-02-19 19:06:04 +01:00
parent bb1a0bd86c
commit 76f1a4af4f
1 changed files with 12 additions and 13 deletions

View File

@ -1638,14 +1638,15 @@ void process_a_keystroke(void)
/* Insert the given short burst of bytes into the edit buffer. */ /* Insert the given short burst of bytes into the edit buffer. */
void inject(char *burst, size_t count) void inject(char *burst, size_t count)
{ {
size_t datalen = strlen(openfile->current->data); linestruct *thisline = openfile->current;
size_t datalen = strlen(thisline->data);
#ifndef NANO_TINY #ifndef NANO_TINY
size_t original_row = 0, old_amount = 0; size_t original_row = 0, old_amount = 0;
if (ISSET(SOFTWRAP)) { if (ISSET(SOFTWRAP)) {
if (openfile->current_y == editwinrows - 1) if (openfile->current_y == editwinrows - 1)
original_row = chunk_for(xplustabs(), openfile->current); original_row = chunk_for(xplustabs(), thisline);
old_amount = number_of_chunks_in(openfile->current); old_amount = number_of_chunks_in(thisline);
} }
#endif #endif
@ -1658,35 +1659,33 @@ void inject(char *burst, size_t count)
/* Only add a new undo item when the current item is not an ADD or when /* Only add a new undo item when the current item is not an ADD or when
* the current typing is not contiguous with the previous typing. */ * the current typing is not contiguous with the previous typing. */
if (openfile->last_action != ADD || if (openfile->last_action != ADD ||
openfile->current_undo->mark_begin_lineno != openfile->current->lineno || openfile->current_undo->mark_begin_lineno != thisline->lineno ||
openfile->current_undo->mark_begin_x != openfile->current_x) openfile->current_undo->mark_begin_x != openfile->current_x)
add_undo(ADD, NULL); add_undo(ADD, NULL);
#endif #endif
/* Make room for the new bytes and copy them into the line. */ /* Make room for the new bytes and copy them into the line. */
openfile->current->data = charealloc(openfile->current->data, thisline->data = charealloc(thisline->data, datalen + count + 1);
datalen + count + 1); memmove(thisline->data + openfile->current_x + count,
memmove(openfile->current->data + openfile->current_x + count, thisline->data + openfile->current_x,
openfile->current->data + openfile->current_x,
datalen - openfile->current_x + 1); datalen - openfile->current_x + 1);
strncpy(openfile->current->data + openfile->current_x, burst, count); strncpy(thisline->data + openfile->current_x, burst, count);
#ifndef NANO_TINY #ifndef NANO_TINY
/* When the mark is to the right of the cursor, compensate its position. */ /* When the mark is to the right of the cursor, compensate its position. */
if (openfile->current == openfile->mark && if (thisline == openfile->mark && openfile->current_x < openfile->mark_x)
openfile->current_x < openfile->mark_x)
openfile->mark_x += count; openfile->mark_x += count;
/* When the cursor is on the top row and not on the first chunk /* When the cursor is on the top row and not on the first chunk
* of a line, adding text there might change the preceding chunk * of a line, adding text there might change the preceding chunk
* and thus require an adjustment of firstcolumn. */ * and thus require an adjustment of firstcolumn. */
if (openfile->current == openfile->edittop && openfile->firstcolumn > 0) { if (thisline == openfile->edittop && openfile->firstcolumn > 0) {
ensure_firstcolumn_is_aligned(); ensure_firstcolumn_is_aligned();
refresh_needed = TRUE; refresh_needed = TRUE;
} }
#endif #endif
/* If text was added to the magic line, create a new magic line. */ /* If text was added to the magic line, create a new magic line. */
if (openfile->filebot == openfile->current && !ISSET(NO_NEWLINES)) { if (thisline == openfile->filebot && !ISSET(NO_NEWLINES)) {
new_magicline(); new_magicline();
if (margin > 0) if (margin > 0)
refresh_needed = TRUE; refresh_needed = TRUE;