Skip to content

Commit

Permalink
Merge pull request #527 from techee/eol_undo
Browse files Browse the repository at this point in the history
Fix undo of line end type change
  • Loading branch information
b4n committed Jun 23, 2016
2 parents fda8979 + d097e8c commit 586e64b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 8 deletions.
7 changes: 7 additions & 0 deletions src/callbacks.c
Expand Up @@ -487,8 +487,15 @@ static void convert_eol(gint mode)

g_return_if_fail(doc != NULL);

/* sci_convert_eols() adds UNDO_SCINTILLA action in on_editor_notify().
* It is added to the undo stack before sci_convert_eols() finishes
* so after adding UNDO_EOL, UNDO_EOL will be at the top of the stack
* and UNDO_SCINTILLA below it. */
sci_convert_eols(doc->editor->sci, mode);
document_undo_add(doc, UNDO_EOL, GINT_TO_POINTER(sci_get_eol_mode(doc->editor->sci)));

sci_set_eol_mode(doc->editor->sci, mode);

ui_update_statusbar(doc, -1);
}

Expand Down
50 changes: 42 additions & 8 deletions src/document.c
Expand Up @@ -3036,12 +3036,29 @@ void document_undo(GeanyDocument *doc)
document_redo_add(doc, UNDO_ENCODING, g_strdup(doc->encoding));

document_set_encoding(doc, (const gchar*)action->data);
g_free(action->data);

ignore_callback = TRUE;
encodings_select_radio_item((const gchar*)action->data);
ignore_callback = FALSE;
ui_update_statusbar(doc, -1);
ui_document_show_hide(doc);
break;
}
case UNDO_EOL:
{
undo_action *next_action;

g_free(action->data);
document_redo_add(doc, UNDO_EOL, GINT_TO_POINTER(sci_get_eol_mode(doc->editor->sci)));

sci_set_eol_mode(doc->editor->sci, GPOINTER_TO_INT(action->data));

ui_update_statusbar(doc, -1);
ui_document_show_hide(doc);

/* When undoing, UNDO_EOL is always followed by UNDO_SCINTILLA
* which undos the line endings in the editor and should be
* performed together with UNDO_EOL. */
next_action = g_trash_stack_peek(&doc->priv->undo_actions);
if (next_action && next_action->type == UNDO_SCINTILLA)
document_undo(doc);
break;
}
case UNDO_RELOAD:
Expand Down Expand Up @@ -3108,9 +3125,18 @@ void document_redo(GeanyDocument *doc)
{
case UNDO_SCINTILLA:
{
undo_action *next_action;

document_undo_add_internal(doc, UNDO_SCINTILLA, NULL);

sci_redo(doc->editor->sci);

/* When redoing an EOL change, the UNDO_SCINTILLA which changes
* the line ends in the editor is followed by UNDO_EOL
* which should be performed together with UNDO_SCINTILLA. */
next_action = g_trash_stack_peek(&doc->priv->redo_actions);
if (next_action != NULL && next_action->type == UNDO_EOL)
document_redo(doc);
break;
}
case UNDO_BOM:
Expand All @@ -3127,12 +3153,20 @@ void document_redo(GeanyDocument *doc)
document_undo_add_internal(doc, UNDO_ENCODING, g_strdup(doc->encoding));

document_set_encoding(doc, (const gchar*)action->data);
g_free(action->data);

ignore_callback = TRUE;
encodings_select_radio_item((const gchar*)action->data);
ignore_callback = FALSE;
ui_update_statusbar(doc, -1);
ui_document_show_hide(doc);
break;
}
case UNDO_EOL:
{
document_undo_add_internal(doc, UNDO_EOL, GINT_TO_POINTER(sci_get_eol_mode(doc->editor->sci)));

g_free(action->data);
sci_set_eol_mode(doc->editor->sci, GPOINTER_TO_INT(action->data));

ui_update_statusbar(doc, -1);
ui_document_show_hide(doc);
break;
}
case UNDO_RELOAD:
Expand Down
1 change: 1 addition & 0 deletions src/documentprivate.h
Expand Up @@ -35,6 +35,7 @@ enum
UNDO_ENCODING,
UNDO_BOM,
UNDO_RELOAD,
UNDO_EOL,
UNDO_ACTIONS_MAX
};

Expand Down

0 comments on commit 586e64b

Please sign in to comment.