From d3be78cca2196c7ec5411424815bf82381df7111 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 12 Sep 2018 20:02:57 +1000 Subject: [PATCH] Only commit undo groups when buffer was modified This fixes an interaction with kak-lsp that would trigger undo group commit when setting a buffer option value. --- src/context.cc | 7 ++++++- src/context.hh | 1 + test/regression/0-spurious-undo-group-on-external/cmd | 1 + test/regression/0-spurious-undo-group-on-external/in | 1 + test/regression/0-spurious-undo-group-on-external/out | 1 + test/regression/0-spurious-undo-group-on-external/rc | 2 ++ 6 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 test/regression/0-spurious-undo-group-on-external/cmd create mode 100644 test/regression/0-spurious-undo-group-on-external/in create mode 100644 test/regression/0-spurious-undo-group-on-external/out create mode 100644 test/regression/0-spurious-undo-group-on-external/rc diff --git a/src/context.cc b/src/context.cc index 03cf1586..b3b82938 100644 --- a/src/context.cc +++ b/src/context.cc @@ -211,7 +211,11 @@ Vector Context::selections_content() const void Context::begin_edition() { if (m_edition_level >= 0) + { + if (m_edition_level == 0) + m_edition_timestamp = buffer().timestamp(); ++m_edition_level; + } } void Context::end_edition() @@ -220,7 +224,8 @@ void Context::end_edition() return; kak_assert(m_edition_level != 0); - if (m_edition_level == 1) + if (m_edition_level == 1 and + buffer().timestamp() != m_edition_timestamp) buffer().commit_undo_group(); --m_edition_level; diff --git a/src/context.hh b/src/context.hh index e1924a21..14543946 100644 --- a/src/context.hh +++ b/src/context.hh @@ -134,6 +134,7 @@ private: void begin_edition(); void end_edition(); int m_edition_level = 0; + size_t m_edition_timestamp = 0; friend struct ScopedEdition; diff --git a/test/regression/0-spurious-undo-group-on-external/cmd b/test/regression/0-spurious-undo-group-on-external/cmd new file mode 100644 index 00000000..0fe9192e --- /dev/null +++ b/test/regression/0-spurious-undo-group-on-external/cmd @@ -0,0 +1 @@ +Abarbazu diff --git a/test/regression/0-spurious-undo-group-on-external/in b/test/regression/0-spurious-undo-group-on-external/in new file mode 100644 index 00000000..257cc564 --- /dev/null +++ b/test/regression/0-spurious-undo-group-on-external/in @@ -0,0 +1 @@ +foo diff --git a/test/regression/0-spurious-undo-group-on-external/out b/test/regression/0-spurious-undo-group-on-external/out new file mode 100644 index 00000000..257cc564 --- /dev/null +++ b/test/regression/0-spurious-undo-group-on-external/out @@ -0,0 +1 @@ +foo diff --git a/test/regression/0-spurious-undo-group-on-external/rc b/test/regression/0-spurious-undo-group-on-external/rc new file mode 100644 index 00000000..7b43b8bc --- /dev/null +++ b/test/regression/0-spurious-undo-group-on-external/rc @@ -0,0 +1,2 @@ +decl int my_option +hook global InsertChar r %{ eval -buffer %val{buffile} %{ eval "set buffer my_option 1" } }