diff --git a/news.d/bugfix/1547.core.md b/news.d/bugfix/1547.core.md new file mode 100644 index 000000000..b4b9885f4 --- /dev/null +++ b/news.d/bugfix/1547.core.md @@ -0,0 +1 @@ +Fix possible exception when calling `Engine.clear_translator_state(undo=True)`. diff --git a/plover/engine.py b/plover/engine.py index b3682fb68..5ac8371fa 100644 --- a/plover/engine.py +++ b/plover/engine.py @@ -527,7 +527,8 @@ def translator_state(self, state): def clear_translator_state(self, undo=False): if undo: state = self._translator.get_state() - self._formatter.format(state.translations, (), None) + if state.translations: + self._formatter.format(state.translations, (), None) self._translator.clear_state() @property diff --git a/test/test_engine.py b/test/test_engine.py index 086224f0e..6c835a794 100644 --- a/test/test_engine.py +++ b/test/test_engine.py @@ -264,3 +264,6 @@ def test_engine_running_state(engine): # Running state is kept throughout. engine.set_output(True) assert engine.translator_state == running_state + +def test_undo_and_clear_empty_translator_state(engine): + engine.clear_translator_state(undo=True)