Skip to content

Commit

Permalink
First attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
AAClause committed Oct 25, 2020
1 parent 970a004 commit 381d954
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions addon/globalPlugins/brailleExtender/addoncfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
16 changes: 16 additions & 0 deletions addon/globalPlugins/brailleExtender/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
16 changes: 16 additions & 0 deletions addon/globalPlugins/brailleExtender/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -733,6 +748,7 @@ class AddonSettingsDialog(gui.settingsDialogs.MultiCategorySettingsDialog):
AdvancedInputModeDlg,
OneHandModeDlg,
RoleLabelsDlg,
AdvancedDlg,
]

def __init__(self, parent, initialCategory=None):
Expand Down

0 comments on commit 381d954

Please sign in to comment.