From 32cae3bc82fb627d8db0511a39f991c99be307f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9-Abush=20Clause?= Date: Mon, 1 Jun 2020 23:25:19 +0200 Subject: [PATCH] First attempt --- addon/globalPlugins/brailleExtender/addoncfg.py | 3 +++ addon/globalPlugins/brailleExtender/patches.py | 16 ++++++++++++++++ addon/globalPlugins/brailleExtender/settings.py | 16 ++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/addon/globalPlugins/brailleExtender/addoncfg.py b/addon/globalPlugins/brailleExtender/addoncfg.py index 53d3cb16..dec67c7b 100644 --- a/addon/globalPlugins/brailleExtender/addoncfg.py +++ b/addon/globalPlugins/brailleExtender/addoncfg.py @@ -213,6 +213,9 @@ def getConfspec(): "enabled": "boolean(default=False)", "inputMethod": f"option({DOT_BY_DOT}, {BOTH_SIDES}, {ONE_SIDE}, default={ONE_SIDE})", }, + "advanced": { + "fixCursorPositions": "boolean(default=True)", + }, } def loadPreferedTables(): diff --git a/addon/globalPlugins/brailleExtender/patches.py b/addon/globalPlugins/brailleExtender/patches.py index 3a51f501..64df7386 100644 --- a/addon/globalPlugins/brailleExtender/patches.py +++ b/addon/globalPlugins/brailleExtender/patches.py @@ -114,6 +114,22 @@ def update(self): L{brailleCursorPos}, L{brailleSelectionStart} and L{brailleSelectionEnd} are similarly updated based on L{cursorPos}, L{selectionStart} and L{selectionEnd}, respectively. @postcondition: L{brailleCells}, L{brailleCursorPos}, L{brailleSelectionStart} and L{brailleSelectionEnd} are updated and ready for rendering. """ + if config.conf["brailleExtender"]["advanced"]["fixCursorPositions"]: + pattern = r"([^\ufe00-\ufe0f])[\ufe00-\ufe0f]\u20E3?" + matches = re.finditer(pattern, self.rawText) + posToRemove = [] + for match in matches: + posToRemove += list(range(match.start() + 1, match.end())) + self.rawText = re.sub(pattern, r"\1", self.rawText) + if isinstance(self.cursorPos, int): + adjustCursor = len(list(filter(lambda e: e<=self.cursorPos, posToRemove))) + self.cursorPos -= adjustCursor + if isinstance(self.selectionStart, int): + adjustCursor = len(list(filter(lambda e: e<=self.selectionStart, posToRemove))) + self.selectionStart -= adjustCursor + if isinstance(self.selectionEnd, int): + adjustCursor = len(list(filter(lambda e: e<=self.selectionEnd, posToRemove))) + self.selectionEnd -= adjustCursor mode = louis.dotsIO if config.conf["braille"]["expandAtCursor"] and self.cursorPos is not None: mode |= louis.compbrlAtCursor self.brailleCells, self.brailleToRawPos, self.rawToBraillePos, self.brailleCursorPos = louisHelper.translate( diff --git a/addon/globalPlugins/brailleExtender/settings.py b/addon/globalPlugins/brailleExtender/settings.py index 8e3f0c22..7fa4f4be 100644 --- a/addon/globalPlugins/brailleExtender/settings.py +++ b/addon/globalPlugins/brailleExtender/settings.py @@ -724,6 +724,21 @@ def onBrowseBtn(self, event): def askCreateQuickLaunch(): gui.messageBox(_("Please create or select a quick launch first"), '%s – %s' % (addonName, _("Error")), wx.OK|wx.ICON_ERROR) + +class AdvancedDlg(gui.settingsDialogs.SettingsPanel): + + # Translators: title of a dialog. + title = _("Advanced") + + def makeSettings(self, settingsSizer): + sHelper = gui.guiHelper.BoxSizerHelper(self, sizer=settingsSizer) + self.fixCursorPositions = sHelper.addItem(wx.CheckBox(self, label=_("Try to avoid &cursor positions issues with some characters such as variation selectors"))) + self.fixCursorPositions.SetValue(config.conf["brailleExtender"]["advanced"]["fixCursorPositions"]) + + def onSave(self): + config.conf["brailleExtender"]["advanced"]["fixCursorPositions"] = self.fixCursorPositions.IsChecked() + + class AddonSettingsDialog(gui.settingsDialogs.MultiCategorySettingsDialog): categoryClasses=[ GeneralDlg, @@ -733,6 +748,7 @@ class AddonSettingsDialog(gui.settingsDialogs.MultiCategorySettingsDialog): AdvancedInputModeDlg, OneHandModeDlg, RoleLabelsDlg, + AdvancedDlg, ] def __init__(self, parent, initialCategory=None):