Commit 8854ddb7 authored by David Lawrence Ramsey's avatar David Lawrence Ramsey Committed by Benno Schulenberg
Browse files

undo: set and check 'xflags' in a bitwise manner

This allows multiple flags to be set, which will be needed for the
next commit.
No related merge requests found
Showing with 13 additions and 13 deletions
+13 -13
...@@ -659,7 +659,7 @@ void handle_comment_action(undo *u, bool undoing, bool add_comment) ...@@ -659,7 +659,7 @@ void handle_comment_action(undo *u, bool undoing, bool add_comment)
void undo_cut(undo *u) void undo_cut(undo *u)
{ {
/* Get to where we need to uncut from. */ /* Get to where we need to uncut from. */
if (u->xflags == WAS_WHOLE_LINE) if (u->xflags & WAS_WHOLE_LINE)
goto_line_posx(u->mark_begin_lineno, 0); goto_line_posx(u->mark_begin_lineno, 0);
else else
goto_line_posx(u->mark_begin_lineno, u->mark_begin_x); goto_line_posx(u->mark_begin_lineno, u->mark_begin_x);
...@@ -670,7 +670,7 @@ void undo_cut(undo *u) ...@@ -670,7 +670,7 @@ void undo_cut(undo *u)
copy_from_buffer(u->cutbuffer); copy_from_buffer(u->cutbuffer);
if (u->xflags != WAS_MARKED_FORWARD && u->type != PASTE) if (!(u->xflags & WAS_MARKED_FORWARD) && u->type != PASTE)
goto_line_posx(u->mark_begin_lineno, u->mark_begin_x); goto_line_posx(u->mark_begin_lineno, u->mark_begin_x);
} }
...@@ -689,7 +689,7 @@ void redo_cut(undo *u) ...@@ -689,7 +689,7 @@ void redo_cut(undo *u)
cutbottom = NULL; cutbottom = NULL;
openfile->mark = fsfromline(u->mark_begin_lineno); openfile->mark = fsfromline(u->mark_begin_lineno);
openfile->mark_x = (u->xflags == WAS_WHOLE_LINE) ? 0 : u->mark_begin_x; openfile->mark_x = (u->xflags & WAS_WHOLE_LINE) ? 0 : u->mark_begin_x;
do_cut_text(FALSE, TRUE, FALSE, u->type == ZAP); do_cut_text(FALSE, TRUE, FALSE, u->type == ZAP);
...@@ -724,7 +724,7 @@ void do_undo(void) ...@@ -724,7 +724,7 @@ void do_undo(void)
/* TRANSLATORS: The next thirteen strings describe actions /* TRANSLATORS: The next thirteen strings describe actions
* that are undone or redone. They are all nouns, not verbs. */ * that are undone or redone. They are all nouns, not verbs. */
undidmsg = _("text add"); undidmsg = _("text add");
if (u->xflags == WAS_FINAL_LINE && !ISSET(NO_NEWLINES)) if ((u->xflags & WAS_FINAL_LINE) && !ISSET(NO_NEWLINES))
remove_magicline(); remove_magicline();
data = charalloc(strlen(f->data) - strlen(u->strdata) + 1); data = charalloc(strlen(f->data) - strlen(u->strdata) + 1);
strncpy(data, f->data, u->begin); strncpy(data, f->data, u->begin);
...@@ -764,7 +764,7 @@ void do_undo(void) ...@@ -764,7 +764,7 @@ void do_undo(void)
/* When the join was done by a Backspace at the tail of the file, /* When the join was done by a Backspace at the tail of the file,
* and the nonewlines flag isn't set, do not re-add a newline that * and the nonewlines flag isn't set, do not re-add a newline that
* wasn't actually deleted; just position the cursor. */ * wasn't actually deleted; just position the cursor. */
if (u->xflags == WAS_FINAL_BACKSPACE && !ISSET(NO_NEWLINES)) { if ((u->xflags & WAS_FINAL_BACKSPACE) && !ISSET(NO_NEWLINES)) {
goto_line_posx(openfile->filebot->lineno, 0); goto_line_posx(openfile->filebot->lineno, 0);
break; break;
} }
...@@ -906,7 +906,7 @@ void do_redo(void) ...@@ -906,7 +906,7 @@ void do_redo(void)
switch (u->type) { switch (u->type) {
case ADD: case ADD:
redidmsg = _("text add"); redidmsg = _("text add");
if (u->xflags == WAS_FINAL_LINE && !ISSET(NO_NEWLINES)) if ((u->xflags & WAS_FINAL_LINE) && !ISSET(NO_NEWLINES))
new_magicline(); new_magicline();
data = charalloc(strlen(f->data) + strlen(u->strdata) + 1); data = charalloc(strlen(f->data) + strlen(u->strdata) + 1);
strncpy(data, f->data, u->begin); strncpy(data, f->data, u->begin);
...@@ -947,7 +947,7 @@ void do_redo(void) ...@@ -947,7 +947,7 @@ void do_redo(void)
/* When the join was done by a Backspace at the tail of the file, /* When the join was done by a Backspace at the tail of the file,
* and the nonewlines flag isn't set, do not join anything, as * and the nonewlines flag isn't set, do not join anything, as
* nothing was actually deleted; just position the cursor. */ * nothing was actually deleted; just position the cursor. */
if (u->xflags == WAS_FINAL_BACKSPACE && !ISSET(NO_NEWLINES)) { if ((u->xflags & WAS_FINAL_BACKSPACE) && !ISSET(NO_NEWLINES)) {
goto_line_posx(u->mark_begin_lineno, u->mark_begin_x); goto_line_posx(u->mark_begin_lineno, u->mark_begin_x);
break; break;
} }
...@@ -1369,7 +1369,7 @@ void add_undo(undo_type action) ...@@ -1369,7 +1369,7 @@ void add_undo(undo_type action)
case ADD: case ADD:
/* If a new magic line will be added, an undo should remove it. */ /* If a new magic line will be added, an undo should remove it. */
if (openfile->current == openfile->filebot) if (openfile->current == openfile->filebot)
u->xflags = WAS_FINAL_LINE; u->xflags |= WAS_FINAL_LINE;
u->wassize--; u->wassize--;
break; break;
case ENTER: case ENTER:
...@@ -1379,7 +1379,7 @@ void add_undo(undo_type action) ...@@ -1379,7 +1379,7 @@ void add_undo(undo_type action)
* backspace, as it won't actually have deleted anything. */ * backspace, as it won't actually have deleted anything. */
if (openfile->current->next == openfile->filebot && if (openfile->current->next == openfile->filebot &&
openfile->current->data[0] != '\0') openfile->current->data[0] != '\0')
u->xflags = WAS_FINAL_BACKSPACE; u->xflags |= WAS_FINAL_BACKSPACE;
case DEL: case DEL:
/* When not at the end of a line, store the deleted character, /* When not at the end of a line, store the deleted character,
* else purposely fall into the line-joining code. */ * else purposely fall into the line-joining code. */
...@@ -1420,11 +1420,11 @@ void add_undo(undo_type action) ...@@ -1420,11 +1420,11 @@ void add_undo(undo_type action)
if (openfile->mark) { if (openfile->mark) {
u->mark_begin_lineno = openfile->mark->lineno; u->mark_begin_lineno = openfile->mark->lineno;
u->mark_begin_x = openfile->mark_x; u->mark_begin_x = openfile->mark_x;
u->xflags = MARK_WAS_SET; u->xflags |= MARK_WAS_SET;
} else if (!ISSET(CUT_FROM_CURSOR)) { } else if (!ISSET(CUT_FROM_CURSOR)) {
/* The entire line is being cut regardless of the cursor position. */ /* The entire line is being cut regardless of the cursor position. */
u->begin = 0; u->begin = 0;
u->xflags = WAS_WHOLE_LINE; u->xflags |= WAS_WHOLE_LINE;
} }
break; break;
case PASTE: case PASTE:
...@@ -1553,7 +1553,7 @@ void update_undo(undo_type action) ...@@ -1553,7 +1553,7 @@ void update_undo(undo_type action)
free_filestruct(u->cutbuffer); free_filestruct(u->cutbuffer);
u->cutbuffer = copy_filestruct(cutbuffer); u->cutbuffer = copy_filestruct(cutbuffer);
} }
if (u->xflags == MARK_WAS_SET) { if (u->xflags & MARK_WAS_SET) {
/* If the "marking" operation was from right-->left or /* If the "marking" operation was from right-->left or
* bottom-->top, then swap the mark points. */ * bottom-->top, then swap the mark points. */
if ((u->lineno == u->mark_begin_lineno && u->begin < u->mark_begin_x) if ((u->lineno == u->mark_begin_lineno && u->begin < u->mark_begin_x)
...@@ -1567,7 +1567,7 @@ void update_undo(undo_type action) ...@@ -1567,7 +1567,7 @@ void update_undo(undo_type action)
u->lineno = u->mark_begin_lineno; u->lineno = u->mark_begin_lineno;
u->mark_begin_lineno = line; u->mark_begin_lineno = line;
} else } else
u->xflags = WAS_MARKED_FORWARD; u->xflags |= WAS_MARKED_FORWARD;
} else { } else {
/* Compute the end of the cut for the undo, using our copy. */ /* Compute the end of the cut for the undo, using our copy. */
u->cutbottom = u->cutbuffer; u->cutbottom = u->cutbuffer;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment