From 6a3a53f421a6868ca041352ac04c91e67886b458 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ji=C5=99=C3=AD=20Techet?= Date: Thu, 23 Jun 2016 18:10:50 +0200 Subject: [PATCH] Fix undo of line end type change At the moment undo of line end type change only undos the changes made in the document but the different line ending settings remains active. This patch fixes the issue by combining the line end scintilla undo action with a new UNDO_EOL action responsible for updating the line ending settings. Fixes #409 --- src/callbacks.c | 7 +++++++ src/document.c | 38 ++++++++++++++++++++++++++++++++++++++ src/documentprivate.h | 1 + 3 files changed, 46 insertions(+) diff --git a/src/callbacks.c b/src/callbacks.c index 0848c7f0c..f0d6b7ca9 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -497,8 +497,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); } diff --git a/src/document.c b/src/document.c index ff3f5e859..ed7fb770d 100644 --- a/src/document.c +++ b/src/document.c @@ -2953,6 +2953,25 @@ void document_undo(GeanyDocument *doc) g_free(action->data); break; } + case UNDO_EOL: + { + undo_action *next_action; + + 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: { UndoReloadData *data = (UndoReloadData*)action->data; @@ -3017,9 +3036,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: @@ -3044,6 +3072,16 @@ void document_redo(GeanyDocument *doc) g_free(action->data); break; } + case UNDO_EOL: + { + document_undo_add_internal(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); + break; + } case UNDO_RELOAD: { UndoReloadData *data = (UndoReloadData*)action->data; diff --git a/src/documentprivate.h b/src/documentprivate.h index 16d517a73..47496c1f1 100644 --- a/src/documentprivate.h +++ b/src/documentprivate.h @@ -35,6 +35,7 @@ enum UNDO_ENCODING, UNDO_BOM, UNDO_RELOAD, + UNDO_EOL, UNDO_ACTIONS_MAX }; -- 2.11.4.GIT