diff --git a/src/cut.c b/src/cut.c index 0f33e1d4..a701535d 100644 --- a/src/cut.c +++ b/src/cut.c @@ -108,6 +108,7 @@ void cut_to_eof(void) * is TRUE (when zapping), always append the cut to the cutbuffer. */ void do_cut_text(bool copy_text, bool marked, bool cut_till_eof, bool append) { + fprintf(stderr, "do_cut_text\n"); #ifndef NANO_TINY filestruct *cb_save = NULL; /* The current end of the cutbuffer, before we add text to it. */ @@ -117,9 +118,26 @@ void do_cut_text(bool copy_text, bool marked, bool cut_till_eof, bool append) bool old_no_newlines = ISSET(NO_NEWLINES); bool right_side_up = TRUE; /* There *is* no region, *or* it is marked forward. */ + bool bookmarked = FALSE;//openfile->current->bookmarked; + /* Whether current line is bookmarked. + No necesserily current line! It should the line + that will be removed! + */ #endif size_t was_totsize = openfile->totsize; + bool should_keep_bookmark = FALSE; + /*(openfile->mark && openfile->mark_x + );*/ + if(bookmarked) + fprintf(stderr, "Current line is bookmarked!\n"); + if(openfile->mark) + fprintf(stderr, "Text to be removed is marked!\n"); + if(openfile->mark && openfile->mark->bookmarked) + bookmarked = TRUE; + + filestruct *was_mark = openfile->mark; + /* If cuts were not continuous, or when cutting a region, clear the slate. */ if (!append && (!keep_cutbuffer || marked || cut_till_eof)) { free_filestruct(cutbuffer); @@ -146,13 +164,20 @@ void do_cut_text(bool copy_text, bool marked, bool cut_till_eof, bool append) /* Move the marked text to the cutbuffer, and turn the mark off. */ cut_marked(&right_side_up); openfile->mark = NULL; + should_keep_bookmark = TRUE; } else if (ISSET(CUT_FROM_CURSOR)) /* Move all text up to the end of the line into the cutbuffer. */ cut_to_eol(); else #endif + { + if (openfile->current->next) + bookmarked = openfile->current->next->bookmarked; + if (bookmarked) + should_keep_bookmark = TRUE; /* Move the entire line into the cutbuffer. */ cut_line(); + } #ifndef NANO_TINY if (copy_text) { @@ -182,6 +207,15 @@ void do_cut_text(bool copy_text, bool marked, bool cut_till_eof, bool append) set_modified(); refresh_needed = TRUE; + + /* Restore bookmark of current line if just part of it was cut. */ + /**/ + //if (marked) + //Should only keep bookmark if did not change line!!! + if (should_keep_bookmark /*&& was_mark == openfile->current*/) { + fprintf(stderr, "Will keep bookmark.\n"); + openfile->current->bookmarked = bookmarked;// + } } /* Move text from the current buffer into the cutbuffer. */ @@ -271,6 +305,8 @@ void zap_text(void) /* Copy text from the cutbuffer into the current buffer. */ void do_uncut_text(void) { + filestruct *was_current = openfile->current; + const bool bookmarked = openfile->current->bookmarked; ssize_t was_lineno = openfile->current->lineno; /* The line number where we started the paste. */ size_t was_leftedge = 0; @@ -302,6 +338,9 @@ void do_uncut_text(void) /* Set the desired x position to where the pasted text ends. */ openfile->placewewant = xplustabs(); + //openfile->current->bookmarked = bookmarked; + //was_current->bookmarked = bookmarked; + set_modified(); refresh_needed = TRUE; } diff --git a/src/nano.c b/src/nano.c index b84856e2..5df0bbfa 100644 --- a/src/nano.c +++ b/src/nano.c @@ -409,6 +409,7 @@ void ingraft_buffer(filestruct *somebuffer) { filestruct *top_save; size_t current_x_save = openfile->current_x; + const bool bookmarked = openfile->current->bookmarked; bool edittop_inside; #ifndef NANO_TINY bool right_side_up = FALSE, single_line = FALSE; @@ -442,6 +443,10 @@ void ingraft_buffer(filestruct *somebuffer) while (openfile->filebot->next != NULL) openfile->filebot = openfile->filebot->next; + /* Restore bookmark of current line. */ + if (bookmarked) + openfile->fileage->bookmarked = bookmarked; + /* Put the cursor at the end of the pasted text. */ openfile->current = openfile->filebot; openfile->current_x = strlen(openfile->filebot->data); diff --git a/src/text.c b/src/text.c index 7190de5e..997d8462 100644 --- a/src/text.c +++ b/src/text.c @@ -79,6 +79,7 @@ char *invocation_error(const char *name) /* Delete the character under the cursor. */ void do_deletion(undo_type action) { + bool bookmarked = openfile->current->bookmarked; #ifndef NANO_TINY size_t old_amount = 0; #endif @@ -119,6 +120,7 @@ void do_deletion(undo_type action) /* Adjust the file size. */ openfile->totsize--; } else if (openfile->current != openfile->filebot) { + bookmarked = bookmarked || openfile->current->next->bookmarked; /* We're at the end of a line and not at the end of the file: join * this line with the next. */ filestruct *joining = openfile->current->next; @@ -171,6 +173,8 @@ void do_deletion(undo_type action) refresh_needed = TRUE; #endif + openfile->current->bookmarked = bookmarked; + set_modified(); } @@ -658,6 +662,7 @@ void handle_comment_action(undo *u, bool undoing, bool add_comment) /* Undo a cut, or redo an uncut. */ void undo_cut(undo *u) { + fprintf(stderr, "undo_cut\n"); /* Get to where we need to uncut from. */ if (u->xflags == WAS_WHOLE_LINE) goto_line_posx(u->mark_begin_lineno, 0); @@ -668,10 +673,23 @@ void undo_cut(undo *u) if (!u->cutbuffer) return; + if(u->cutbuffer->bookmarked) + fprintf(stderr, "cutbuffer was bookmarked!\n"); + + bool bookmarked = u->cutbuffer->bookmarked; + + if (openfile->current->bookmarked) + fprintf(stderr, "Before recovering text: current line wass bookmarked!\n"); + copy_from_buffer(u->cutbuffer); if (u->xflags != WAS_MARKED_FORWARD && u->type != PASTE) goto_line_posx(u->mark_begin_lineno, u->mark_begin_x); + + openfile->current->bookmarked = bookmarked; + + if (openfile->current->bookmarked) + fprintf(stderr, "After recovering text: current line is bookmarked!\n"); } /* Redo a cut, or undo an uncut. */ @@ -775,6 +793,9 @@ void do_undo(void) free(f->data); f->data = data; splice_node(f, t); + bool aux = t->bookmarked; + t->bookmarked = f->bookmarked; + f->bookmarked = aux; renumber(t); goto_line_posx(u->lineno, u->begin); break;