nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit 8e91e26cc514b45568c1dad742a6ff352434322f
parent c2322f8563c28dcce0ed805c9d4b3f0c8178ba6a
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Thu, 28 Mar 2024 15:58:28 +0100

tweaks: reshuffle three fragments of code, moving related things together

And avoid calling xplustabs() twice in a row.

Diffstat:
Msrc/nano.c | 25+++++++++++++------------
1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/src/nano.c b/src/nano.c @@ -1496,10 +1496,6 @@ void inject(char *burst, size_t count) strncpy(thisline->data + openfile->current_x, burst, count); #ifndef NANO_TINY - /* When the mark is to the right of the cursor, compensate its position. */ - if (thisline == openfile->mark && openfile->current_x < openfile->mark_x) - openfile->mark_x += count; - /* 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 * and thus require an adjustment of firstcolumn. */ @@ -1507,7 +1503,17 @@ void inject(char *burst, size_t count) ensure_firstcolumn_is_aligned(); refresh_needed = TRUE; } + + /* When the mark is to the right of the cursor, compensate its position. */ + if (thisline == openfile->mark && openfile->current_x < openfile->mark_x) + openfile->mark_x += count; #endif + + openfile->current_x += count; + + openfile->totsize += mbstrlen(burst); + set_modified(); + /* If text was added to the magic line, create a new magic line. */ if (thisline == openfile->filebot && !ISSET(NO_NEWLINES)) { new_magicline(); @@ -1519,11 +1525,6 @@ void inject(char *burst, size_t count) update_line(thisline->next, 0); } - openfile->current_x += count; - - openfile->totsize += mbstrlen(burst); - set_modified(); - #ifndef NANO_TINY update_undo(ADD); #endif @@ -1533,20 +1534,20 @@ void inject(char *burst, size_t count) do_wrap(); #endif + openfile->placewewant = xplustabs(); + #ifndef NANO_TINY /* When softwrapping and the number of chunks in the current line changed, * or we were on the last row of the edit window and moved to a new chunk, * we need a full refresh. */ if (ISSET(SOFTWRAP) && (extra_chunks_in(openfile->current) != old_amount || (openfile->current_y == editwinrows - 1 && - chunk_for(xplustabs(), openfile->current) > original_row))) { + chunk_for(openfile->placewewant, openfile->current) > original_row))) { refresh_needed = TRUE; focusing = FALSE; } #endif - openfile->placewewant = xplustabs(); - #ifdef ENABLE_COLOR if (!refresh_needed) check_the_multis(openfile->current);