Skip to content

Commit 7b63732

Browse files
authored
Merge 61e2ad9 into 3f89b60
2 parents 3f89b60 + 61e2ad9 commit 7b63732

7 files changed

Lines changed: 136 additions & 12 deletions

File tree

source/config/configSpec.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@
212212
reportLineNumber = boolean(default=False)
213213
# 0: Off, 1: Speech, 2: Tones, 3: Both Speech and Tones
214214
reportLineIndentation = integer(0, 3, default=0)
215+
ignoreBlankLinesForReportLineIndentation = boolean(default=False)
215216
reportParagraphIndentation = boolean(default=False)
216217
reportTables = boolean(default=true)
217218
includeLayoutTables = boolean(default=False)

source/globalCommands.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def script_reportCurrentSelection(self,gesture):
273273
speech.speakMessage(_("No selection"))
274274
else:
275275
speech.speakTextSelected(info.text)
276-
276+
277277
@script(
278278
# Translators: Input help mode message for report date and time command.
279279
description=_("If pressed once, reports the current time. If pressed twice, reports the current date"),
@@ -622,6 +622,23 @@ def script_toggleReportLineIndentation(self, gesture: inputCore.InputGesture):
622622
# {mode} will be replaced with the mode; i.e. Off, Speech, Tones or Both Speech and Tones.
623623
ui.message(_("Report line indentation {mode}").format(mode=state.displayString))
624624

625+
@script(
626+
# Translators: Input help mode message for toggle ignore blank lines for line indentation reporting command.
627+
description=_("Toggles on and off the ignoring of blank lines for line indentation reporting"),
628+
category=SCRCAT_DOCUMENTFORMATTING
629+
)
630+
def script_toggleignoreBlankLinesForReportLineIndentation(self, gesture: inputCore.InputGesture) -> None:
631+
ignore = config.conf['documentFormatting']['ignoreBlankLinesForReportLineIndentation']
632+
config.conf['documentFormatting']['ignoreBlankLinesForReportLineIndentation'] = not ignore
633+
if ignore:
634+
# Translators: The message announced when toggling off the ignore blank lines for line indentation
635+
# reporting document formatting setting.
636+
ui.message(_("Ignore blank lines for line indentation reporting off"))
637+
else:
638+
# Translators: The message announced when toggling on the ignore blank lines for line indentation
639+
# reporting document formatting setting.
640+
ui.message(_("Ignore blank lines for line indentation reporting on"))
641+
625642
@script(
626643
# Translators: Input help mode message for toggle report paragraph indentation command.
627644
description=_("Toggles on and off the reporting of paragraph indentation"),

source/gui/settingsDialogs.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2389,15 +2389,24 @@ def makeSettings(self, settingsSizer):
23892389
self.lineIndentationCombo
23902390
)
23912391
self.lineIndentationCombo.SetSelection(config.conf['documentFormatting']['reportLineIndentation'])
2392+
2393+
# Translators: This is the label of a checkbox in the document formatting settings panel
2394+
# If this option is selected, NVDA will ignore blank lines for line indentation reporting
2395+
ignoreBlankLinesText = _("Ignore &blank lines for line indentation reporting")
2396+
ignoreBlankLinesCheckBox = wx.CheckBox(pageAndSpaceBox, label=ignoreBlankLinesText)
2397+
self.ignoreBlankLinesForReportLineIndentationCheckbox = pageAndSpaceGroup.addItem(ignoreBlankLinesCheckBox)
2398+
self.ignoreBlankLinesForReportLineIndentationCheckbox.SetValue(
2399+
config.conf["documentFormatting"]["ignoreBlankLinesForReportLineIndentation"]
2400+
)
23922401

2393-
# Translators: This message is presented in the document formatting settings panelue
2402+
# Translators: This message is presented in the document formatting settings panel
23942403
# If this option is selected, NVDA will report paragraph indentation if available.
23952404
paragraphIndentationText = _("&Paragraph indentation")
23962405
_paragraphIndentationCheckBox = wx.CheckBox(pageAndSpaceBox, label=paragraphIndentationText)
23972406
self.paragraphIndentationCheckBox = pageAndSpaceGroup.addItem(_paragraphIndentationCheckBox)
23982407
self.paragraphIndentationCheckBox.SetValue(config.conf["documentFormatting"]["reportParagraphIndentation"])
23992408

2400-
# Translators: This message is presented in the document formatting settings panelue
2409+
# Translators: This message is presented in the document formatting settings panel
24012410
# If this option is selected, NVDA will report line spacing if available.
24022411
lineSpacingText=_("&Line spacing")
24032412
_lineSpacingCheckBox = wx.CheckBox(pageAndSpaceBox, label=lineSpacingText)
@@ -2541,6 +2550,8 @@ def onSave(self):
25412550
config.conf["documentFormatting"]["reportPage"]=self.pageCheckBox.IsChecked()
25422551
config.conf["documentFormatting"]["reportLineNumber"]=self.lineNumberCheckBox.IsChecked()
25432552
config.conf["documentFormatting"]["reportLineIndentation"] = self.lineIndentationCombo.GetSelection()
2553+
ignoreBlankLines = self.ignoreBlankLinesForReportLineIndentationCheckbox.IsChecked()
2554+
config.conf["documentFormatting"]["ignoreBlankLinesForReportLineIndentation"] = ignoreBlankLines
25442555
config.conf["documentFormatting"]["reportParagraphIndentation"]=self.paragraphIndentationCheckBox.IsChecked()
25452556
config.conf["documentFormatting"]["reportLineSpacing"]=self.lineSpacingCheckBox.IsChecked()
25462557
config.conf["documentFormatting"]["reportTables"]=self.tablesCheckBox.IsChecked()

source/speech/speech.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1540,7 +1540,17 @@ def getTextInfoSpeech( # noqa: C901
15401540
if autoLanguageSwitching and newLanguage!=lastLanguage:
15411541
relativeSpeechSequence.append(LangChangeCommand(newLanguage))
15421542
lastLanguage=newLanguage
1543-
if reportIndentation and speakTextInfoState and allIndentation!=speakTextInfoState.indentationCache:
1543+
if (
1544+
reportIndentation
1545+
and speakTextInfoState
1546+
and(
1547+
# either not ignoring blank lines
1548+
not formatConfig['ignoreBlankLinesForReportLineIndentation']
1549+
# or line isn't completely blank
1550+
or any(isinstance(t, str) and not all(c in LINE_END_CHARS for c in t) for t in textWithFields)
1551+
)
1552+
and allIndentation != speakTextInfoState.indentationCache
1553+
):
15441554
indentationSpeech=getIndentationSpeech(allIndentation, formatConfig)
15451555
if autoLanguageSwitching and speechSequence[-1].lang is not None:
15461556
# Indentation must be spoken in the default language,
@@ -1604,6 +1614,10 @@ def getTextInfoSpeech( # noqa: C901
16041614
return True
16051615

16061616

1617+
# for checking a line is completely blank, i.e. doesn't even contain spaces
1618+
LINE_END_CHARS = frozenset(('\r', '\n'))
1619+
1620+
16071621
def _isControlEndFieldCommand(command: Union[str, textInfos.FieldCommand]):
16081622
return isinstance(command, textInfos.FieldCommand) and command.command == "controlEnd"
16091623

tests/system/robot/symbolPronunciationTests.py

Lines changed: 81 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ class EndSpeech(_enum.Enum):
7676
NONE = None
7777

7878

79+
class ReportLineIndentation(_enum.Enum):
80+
"""Line indentation reporting options. Should match config.configFlags.ReportLineIndentation
81+
"""
82+
OFF = 0
83+
SPEECH = 1
84+
85+
7986
def _pressKeyAndCollectSpeech(key: str, numberOfTimes: int) -> _typing.List[str]:
8087
actual = []
8188
for _ in range(numberOfTimes):
@@ -500,7 +507,7 @@ def test_symbolInSpeechUI():
500507
_notepad.prepareNotepad((
501508
"t" # Character doesn't matter, we just want to invoke "Right" speech UI.
502509
))
503-
_setSymbolLevel(SymLevel.ALL)
510+
_setConfig(SymLevel.ALL)
504511
spy = _NvdaLib.getSpyLib()
505512
expected = "shouldn't sub tick symbol"
506513
spy.override_translationString(EndSpeech.RIGHT.value, expected)
@@ -527,7 +534,7 @@ def test_symbolInSpeechUI():
527534
)
528535

529536
# Show that with symbol level None, the speech UI symbols are not substituted.
530-
_setSymbolLevel(SymLevel.NONE)
537+
_setConfig(SymLevel.NONE)
531538
actual = _pressKeyAndCollectSpeech(Move.REVIEW_CHAR.value, numberOfTimes=1)
532539
_builtIn.should_be_equal(
533540
actual,
@@ -536,20 +543,35 @@ def test_symbolInSpeechUI():
536543
)
537544

538545

539-
def _setSymbolLevel(symbolLevel: SymLevel) -> None:
546+
def _setConfig(
547+
symbolLevel: SymLevel,
548+
reportLineIndentation: ReportLineIndentation = ReportLineIndentation.OFF,
549+
ignoreBlankLinesForReportLineIndentation: bool = False
550+
) -> None:
540551
spy = _NvdaLib.getSpyLib()
541-
SYMBOL_LEVEL_KEY = ["speech", "symbolLevel"]
542-
spy.set_configValue(SYMBOL_LEVEL_KEY, symbolLevel.value)
543-
_builtIn.log(message=f"Doing test at symbol level: {symbolLevel}")
552+
spy.set_configValue(["documentFormatting", "reportLineIndentation"], reportLineIndentation.value)
553+
spy.set_configValue(
554+
["documentFormatting", "ignoreBlankLinesForReportLineIndentation"],
555+
ignoreBlankLinesForReportLineIndentation
556+
)
557+
spy.set_configValue(["speech", "symbolLevel"], symbolLevel.value)
558+
message = (
559+
f"Doing test at symbol level: {symbolLevel}"
560+
f", line indentation reporting: {reportLineIndentation}"
561+
f", ignore blank lines for line indentation reporting: {ignoreBlankLinesForReportLineIndentation}"
562+
)
563+
_builtIn.log(message=message)
544564

545565

546566
def _doTest(
547567
navKey: Move,
548568
expectedSpeech: _typing.List[str],
549569
reportedAfterLast: EndSpeech,
550570
symbolLevel: SymLevel,
571+
reportLineIndentation: ReportLineIndentation = ReportLineIndentation.OFF,
572+
ignoreBlankLinesForReportLineIndentation: bool = False
551573
) -> None:
552-
_setSymbolLevel(symbolLevel)
574+
_setConfig(symbolLevel, reportLineIndentation, ignoreBlankLinesForReportLineIndentation)
553575

554576
actual = _pressKeyAndCollectSpeech(navKey.value, numberOfTimes=len(expectedSpeech))
555577
_builtIn.should_be_equal(
@@ -600,7 +622,7 @@ def test_tableHeaders():
600622
</table>
601623
"""
602624
)
603-
_setSymbolLevel(SymLevel.ALL)
625+
_setConfig(SymLevel.ALL)
604626
# Expected to be in browse mode
605627
actualSpeech = _chrome.getSpeechAfterKey("downArrow")
606628
_asserts.strings_match(
@@ -669,3 +691,54 @@ def test_tableHeaders():
669691
"Don tick t column 3\nc", # note symbols ARE replaced in column name
670692
]
671693
)
694+
695+
696+
def test_ignoreBlankLinesForReportLineIndentation():
697+
""" Test line indentation reporting with ignoreBlankLinesForReportLineIndentation off and then on
698+
"""
699+
_notepad.prepareNotepad('\n'.join([
700+
'', # blank line
701+
'def foo',
702+
'\thello',
703+
'', # blank line
704+
'\tworld',
705+
'', # blank line
706+
'def bar'
707+
]))
708+
709+
def _doTestIgnoreBlankLines(ignoreBlankLines: bool, expectedSpeech: _typing.List[str]) -> None:
710+
_doTest(
711+
navKey=Move.REVIEW_LINE,
712+
reportedAfterLast=EndSpeech.BOTTOM,
713+
symbolLevel=SymLevel.ALL,
714+
reportLineIndentation=ReportLineIndentation.SPEECH,
715+
ignoreBlankLinesForReportLineIndentation=ignoreBlankLines,
716+
expectedSpeech=expectedSpeech
717+
)
718+
719+
_doTestIgnoreBlankLines(
720+
ignoreBlankLines=False,
721+
expectedSpeech=[
722+
'def foo',
723+
'tab hello',
724+
'no indent blank',
725+
'tab world',
726+
'no indent blank',
727+
'def bar'
728+
]
729+
)
730+
731+
_NvdaLib.getSpeechAfterKey(Move.REVIEW_HOME.value) # reset to start position
732+
733+
_doTestIgnoreBlankLines(
734+
ignoreBlankLines=True,
735+
expectedSpeech=[
736+
'def foo',
737+
'tab hello',
738+
'blank',
739+
'world',
740+
'blank',
741+
'no indent def bar'
742+
]
743+
)
744+

tests/system/robot/symbolPronunciationTests.robot

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,7 @@ tableHeaderSymbols
6767
[Documentation] Ensure symbols announced as expected in table headers.
6868
[Tags] table
6969
test_tableHeaders
70+
71+
ignoreBlankLinesForReportLineIndentation
72+
[Documentation] Ensure indentation announced as expected when ignore blank lines for line indentation reporting is on/off.
73+
test_ignoreBlankLinesForReportLineIndentation

user_docs/en/userGuide.t2t

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,6 +2076,7 @@ You can configure reporting of:
20762076
- Page numbers
20772077
- Line numbers
20782078
- Line indentation reporting [(Off, Speech, Tones, Both Speech and Tones) #DocumentFormattingSettingsLineIndentation]
2079+
- Ignore blank lines for line indentation reporting
20792080
- Paragraph indentation (e.g. hanging indent, first line indent)
20802081
- Line spacing (single, double, etc.)
20812082
- Alignment
@@ -2118,6 +2119,9 @@ The tone will increase in pitch every space, and for a tab, it will increase in
21182119
- Both Speech and Tones: This option reads indentation using both of the above methods.
21192120
-
21202121

2122+
If you tick the "Ignore blank lines for line indentation reporting" checkbox, then indentation changes won't be reported for blank lines.
2123+
This may be useful when reading a document where blank lines are used to separate indented bloks of text, such as in programming source code.
2124+
21212125
+++ Document Navigation +++[DocumentNavigation]
21222126
This category allows you to adjust various aspects of document navigation.
21232127

0 commit comments

Comments
 (0)