diff --git a/src/global.c b/src/global.c index ce89eb71d98b755687c5b1959ae53964710f0f57..07976e50f4c73d1237ab614c101e9ff95482ceae 100644 --- a/src/global.c +++ b/src/global.c @@ -67,7 +67,9 @@ char *title = NULL; bool more_than_one = FALSE; /* Whether more than one buffer is or has been open. */ - +bool also_the_last = FALSE; + /* Whether indenting/commenting should include the last line of + * the marked region. */ int didfind = 0; /* Whether the last search found something. */ diff --git a/src/nano.c b/src/nano.c index de4d7a7a42d600c433c6e32b5c1792e0a22f1741..451d03ee7d8c1f50367ab1f5f9199f947397b19a 100644 --- a/src/nano.c +++ b/src/nano.c @@ -1698,13 +1698,16 @@ int do_input(bool allow_funcs) /* Execute the function of the shortcut. */ s->scfunc(); #ifndef NANO_TINY - /* If Shiftless movement occurred, discard a soft mark. */ - if (!shift_held && openfile->mark && - openfile->kind_of_mark == SOFTMARK && - (openfile->current_x != was_x || - openfile->current != was_current)) { - openfile->mark = NULL; - refresh_needed = TRUE; + /* When the marked region changes without Shift being held, + * discard a soft mark. And when the marked region covers a + * different set of lines, reset the "last line too" flag. */ + if (openfile->mark && (openfile->current != was_current || + openfile->current_x != was_x)) { + if (!shift_held && openfile->kind_of_mark == SOFTMARK) { + openfile->mark = NULL; + refresh_needed = TRUE; + } else if (openfile->current != was_current) + also_the_last = FALSE; } #endif #ifdef ENABLE_WRAPPING diff --git a/src/proto.h b/src/proto.h index 0a7106d89719c6e5c3106e451cdd445fbe1c3fa0..e5414c0662e36bb0f5d0d6e7b70f163ee3e9be06 100644 --- a/src/proto.h +++ b/src/proto.h @@ -54,6 +54,8 @@ extern char *title; extern bool more_than_one; +extern bool also_the_last; + extern int didfind; extern int controlleft; diff --git a/src/utils.c b/src/utils.c index 771f58aebf13f9bbc599987cea0a02a4f4c116d2..4ae36f4f8e078091d70d16337f9e454633cd1aea 100644 --- a/src/utils.c +++ b/src/utils.c @@ -541,8 +541,10 @@ void get_range(const filestruct **top, const filestruct **bot) mark_order(top, &top_x, bot, &bot_x, NULL); - if (bot_x == 0 && *bot != *top) + if (bot_x == 0 && *bot != *top && !also_the_last) *bot = (*bot)->prev; + else + also_the_last = TRUE; } }