Skip to content

Commit

Permalink
Count \t (a tab) as a blank character. Closes #6.
Browse files Browse the repository at this point in the history
  • Loading branch information
trypsynth committed Sep 5, 2022
1 parent 65461c1 commit 58a7098
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions addon/globalPlugins/indent_nav.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ def mylog(*arg, **kwarg):
pass


# Adapted from NVDA's speech module to count tabs as blank characters.
BLANK_CHUNK_CHARS = frozenset((" ", "\n", "\r", "\t", "\0", u"\xa0"))
def isBlank(text):
return not text or set(text) <= BLANK_CHUNK_CHARS


def myAssert(condition):
if not condition:
Expand Down Expand Up @@ -409,7 +414,7 @@ class EditableIndentNav(NVDAObject):
scriptCategory = _("IndentNav")
beeper = Beeper()
def getIndentLevel(self, s):
if speech.isBlank(s):
if isBlank(s):
return 0
indent = speech.splitTextIndentation(s)[0]
return len(indent.replace("\t", " " * 4))
Expand Down Expand Up @@ -492,7 +497,7 @@ def moveInEditable(self, increment, errorMessage, unbounded=False, op=operator.e
# Get the current indentation level
text = lm.getText()
indentationLevel = self.getIndentLevel(text)
onEmptyLine = speech.isBlank(text)
onEmptyLine = isBlank(text)

# Scan each line until we hit the end of the indentation block, the end of the edit area, or find a line with the same indentation level
found = False
Expand All @@ -505,7 +510,7 @@ def moveInEditable(self, increment, errorMessage, unbounded=False, op=operator.e
newIndentation = self.getIndentLevel(text)

# Skip over empty lines if we didn't start on one.
if not onEmptyLine and speech.isBlank(text):
if not onEmptyLine and isBlank(text):
continue

if op(newIndentation, indentationLevel):
Expand Down Expand Up @@ -589,7 +594,7 @@ def selectIndentationBlock(self, selectMultiple=False, successMessage=""):
text = lm.getText()
originalTextInfo = lm.getTextInfo()
indentationLevel = self.getIndentLevel(text)
onEmptyLine = speech.isBlank(text)
onEmptyLine = isBlank(text)
if onEmptyLine:
return self.endOfDocument(_("Nothing to select"))
# Scan each line forward as long as indentation level is greater than current
Expand All @@ -604,7 +609,7 @@ def selectIndentationBlock(self, selectMultiple=False, successMessage=""):
text = lm.getText()
newIndentation = self.getIndentLevel(text)

if speech.isBlank(text):
if isBlank(text):
continue

if newIndentation < indentationLevel:
Expand Down Expand Up @@ -648,14 +653,14 @@ def script_indentPaste(self, gesture):
if 0 == line.move(textInfos.UNIT_CHARACTER, -1, "end"):
break
lineLevel = self.getIndentLevel(line.text.rstrip("\r\n") + "a")
if not speech.isBlank(line.text):
if not isBlank(line.text):
ui.message(_("Cannot indent-paste: current line is not empty!"))
return
text = clipboardBackup
textLevel = min([
self.getIndentLevel(s)
for s in text.splitlines()
if not speech.isBlank(s)
if not isBlank(s)
])
useTabs = '\t' in text or '\t' in line.text
delta = lineLevel - textLevel
Expand Down

0 comments on commit 58a7098

Please sign in to comment.