nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 3/3] text: retain a bookmark when two lines are joined or somethi


From: Benno Schulenberg
Subject: [PATCH 3/3] text: retain a bookmark when two lines are joined or something is pasted
Date: Sun, 5 Apr 2020 19:37:11 +0200

Also, do not copy the bookmark into the cutbuffer.
---
 src/cut.c  | 8 ++++++++
 src/nano.c | 2 +-
 src/text.c | 1 +
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/cut.c b/src/cut.c
index 6ca0bfbb..446e3351 100644
--- a/src/cut.c
+++ b/src/cut.c
@@ -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);
@@ -249,6 +251,7 @@ void extract_segment(linestruct *top, size_t top_x, 
linestruct *bot, size_t bot_
                                                (openfile->mark != top || 
openfile->mark_x >= top_x) &&
                                                (openfile->mark != bot || 
openfile->mark_x <= bot_x));
        bool same_line = (openfile->mark == top);
+       bool was_bookmarked = top->bookmarked | bot->bookmarked;
 
        if (top == bot && top_x == bot_x)
                return;
@@ -302,6 +305,8 @@ void extract_segment(linestruct *top, size_t top_x, 
linestruct *bot, size_t bot_
        } else if (same_line)
                /* Update the pointer to this partially cut line. */
                openfile->mark = openfile->current;
+
+       openfile->current->bookmarked = was_bookmarked;
 #endif
 
        /* Glue the texts before and after the extraction together. */
@@ -331,6 +336,7 @@ void ingraft_buffer(linestruct *topline)
        /* Remember whether mark and cursor are on the same line, and their 
order. */
        bool right_side_up = (openfile->mark && mark_is_before_cursor());
        bool same_line = (openfile->mark == openfile->current);
+       bool was_bookmarked = openfile->current->bookmarked;
 #endif
        size_t was_x = openfile->current_x;
 
@@ -364,6 +370,8 @@ void ingraft_buffer(linestruct *topline)
                } else
                        openfile->mark = openfile->filetop;
        }
+
+       openfile->filetop->bookmarked = was_bookmarked;
 #endif
 
        /* Add the number of characters in the copied text to the file size. */
diff --git a/src/nano.c b/src/nano.c
index 1c7f8102..d734bdb8 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -166,7 +166,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;
diff --git a/src/text.c b/src/text.c
index b9251d2d..ca2d4584 100644
--- a/src/text.c
+++ b/src/text.c
@@ -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);
-- 
2.25.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]