From d5444a0f4bf0236b200bdf45ad9cb38d7fa9da67 Mon Sep 17 00:00:00 2001 From: Anodynous Date: Sun, 7 Aug 2022 14:17:34 +0300 Subject: [PATCH 1/3] gui_none/add_translation: fix implementation Fix final mapping' strokes. --- plover/gui_none/add_translation.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/plover/gui_none/add_translation.py b/plover/gui_none/add_translation.py index 759fa6d5a..776837124 100644 --- a/plover/gui_none/add_translation.py +++ b/plover/gui_none/add_translation.py @@ -52,17 +52,16 @@ def trigger(self): elif self._status == 'strokes': self._engine.remove_dictionary_filter(self._stroke_filter) state = self._get_state()[0] - # Ignore add translation stroke. - state.translations = state.translations[1:] - strokes = [] - for t in state.translations: - strokes.extend(t.strokes) - if not strokes: + assert state.translations + if len(state.translations) == 1: # Abort add translation. self._pop_state(undo=True) self._status = None return - self._strokes = tuple(s.rtfcre for s in strokes) + self._strokes = tuple(s.rtfcre + # Ignore add translation strokes. + for t in state.translations[:-1] + for s in t.strokes) self._clear_state(undo=True) self._translation = '' self._status = 'translations' @@ -70,8 +69,6 @@ def trigger(self): self._engine.hook_connect('send_backspaces', self.send_backspaces) elif self._status == 'translations': state = self._get_state()[0] - # Ignore add translation stroke. - state.translations = state.translations[1:] self._engine.hook_disconnect('send_string', self.send_string) self._engine.hook_disconnect('send_backspaces', self.send_backspaces) self._translation = self._translation.strip() From 630899c6437b997455cd06c8a1a9f40afcddb0e1 Mon Sep 17 00:00:00 2001 From: Benoit Pierre Date: Tue, 9 Aug 2022 00:19:34 +0200 Subject: [PATCH 2/3] gui_none/add_translation: small cleanups --- plover/gui_none/add_translation.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/plover/gui_none/add_translation.py b/plover/gui_none/add_translation.py index 776837124..96c55173a 100644 --- a/plover/gui_none/add_translation.py +++ b/plover/gui_none/add_translation.py @@ -1,4 +1,3 @@ - from plover.engine import StartingStrokeState @@ -28,9 +27,8 @@ def _clear_state(self, undo=False): def _push_state(self): self._translator_states.insert(0, self._get_state()) - def _pop_state(self, undo=False): - if undo: - self._engine.clear_translator_state(True) + def _pop_state(self): + self._engine.clear_translator_state(True) self._set_state(*self._translator_states.pop(0)) @staticmethod @@ -55,7 +53,7 @@ def trigger(self): assert state.translations if len(state.translations) == 1: # Abort add translation. - self._pop_state(undo=True) + self._pop_state() self._status = None return self._strokes = tuple(s.rtfcre @@ -64,14 +62,13 @@ def trigger(self): for s in t.strokes) self._clear_state(undo=True) self._translation = '' - self._status = 'translations' self._engine.hook_connect('send_string', self.send_string) self._engine.hook_connect('send_backspaces', self.send_backspaces) + self._status = 'translations' elif self._status == 'translations': state = self._get_state()[0] self._engine.hook_disconnect('send_string', self.send_string) self._engine.hook_disconnect('send_backspaces', self.send_backspaces) - self._translation = self._translation.strip() - self._engine.add_translation(self._strokes, self._translation) - self._pop_state(undo=True) + self._engine.add_translation(self._strokes, self._translation.strip()) + self._pop_state() self._status = None From 68785507510257bb2ee2405f20d6773e16fbde40 Mon Sep 17 00:00:00 2001 From: Anodynous Date: Sun, 7 Aug 2022 21:57:16 +0300 Subject: [PATCH 3/3] add news entry --- news.d/bugfix/1546.ui.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 news.d/bugfix/1546.ui.md diff --git a/news.d/bugfix/1546.ui.md b/news.d/bugfix/1546.ui.md new file mode 100644 index 000000000..34f5b4ddb --- /dev/null +++ b/news.d/bugfix/1546.ui.md @@ -0,0 +1 @@ +Fix `{PLOVER:ADD_TRANSLATION}` implementation when using the headless GUI (`-g none`).