text: retain a bookmark when two lines are joined or something is cut

Also, do not copy the bookmark into the cutbuffer, so it will not get
pasted elsewhere.
This commit is contained in:
Benno Schulenberg
2020-03-28 17:06:47 +01:00
parent 9fb0beca1d
commit 732cf88786
3 changed files with 11 additions and 1 deletions

View File

@@ -87,6 +87,8 @@ void do_deletion(undo_type action)
openfile->mark = openfile->current;
openfile->mark_x += openfile->current_x;
}
openfile->current->bookmarked |= joining->bookmarked;
#endif
unlink_node(joining);
renumber_from(openfile->current);
@@ -246,9 +248,14 @@ void extract_segment(linestruct *top, size_t top_x, linestruct *bot, size_t bot_
bool same_line = (openfile->mark == top);
bool post_marked = (openfile->mark && (openfile->mark->lineno > top->lineno ||
(same_line && openfile->mark_x > top_x)));
bool was_bookmarked = top->bookmarked;
if (top == bot && top_x == bot_x)
return;
if (top != bot)
for (linestruct *line = top->next; line != bot->next; line = line->next)
was_bookmarked |= line->bookmarked;
#endif
if (top == bot) {
@@ -318,6 +325,8 @@ void extract_segment(linestruct *top, size_t top_x, linestruct *bot, size_t bot_
openfile->current_x = top_x;
#ifndef NANO_TINY
openfile->current->bookmarked = was_bookmarked;
if (post_marked || same_line)
openfile->mark = openfile->current;
if (post_marked)

View File

@@ -151,7 +151,7 @@ linestruct *copy_node(const linestruct *src)
#endif
dst->lineno = src->lineno;
#ifndef NANO_TINY
dst->bookmarked = src->bookmarked;
dst->bookmarked = FALSE;
#endif
return dst;

View File

@@ -535,6 +535,7 @@ void do_undo(void)
line->data = charealloc(line->data, strlen(line->data) +
strlen(&u->strdata[regain_from_x]) + 1);
strcat(line->data, &u->strdata[regain_from_x]);
line->bookmarked |= line->next->bookmarked;
unlink_node(line->next);
renumber_from(line);
goto_line_posx(u->head_lineno, original_x);