Skip to content

Commit 961377a

Browse files
committed
Implement diff indication
1 parent 282cfec commit 961377a

4 files changed

Lines changed: 72 additions & 2 deletions

File tree

addon/globalPlugins/devHelper/__init__.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,30 @@
1+
from pathlib import Path
2+
3+
import addonHandler
4+
import api
15
import characterProcessing
6+
import globalCommands
27
import globalPluginHandler
38
import languageHandler
9+
import nvwave
10+
import scriptHandler
411
import speech
12+
import textInfos
13+
14+
SOUNDS_DIR = Path(__file__).parent / "media"
15+
DIFF_SOUNDS = {
16+
"-": "diffLineDeleted.wav",
17+
"+": "diffLineInserted.wav",
18+
}
19+
DIFF_SOUNDS = {k: str(SOUNDS_DIR / v) for k, v in DIFF_SOUNDS.items()}
520

621
SPACE = characterProcessing.processSpeechSymbol(languageHandler.getLanguage(), " ")
722
end_utterance_command = speech.commands.EndUtteranceCommand()
823

24+
# We need this to get translations fromNVDA standard catalog.
25+
gettext = _
26+
addonHandler.initTranslation()
27+
928

1029
def get_spelling_speech_decorator(func):
1130
def wrapper(*args, **kwargs):
@@ -63,3 +82,56 @@ def terminate(self):
6382
speech.speech._getSpellingSpeechWithoutCharMode = (
6483
self._speech_speech__getSpellingSpeechWithoutCharMode
6584
)
85+
86+
@scriptHandler.script(
87+
description=gettext(
88+
# Translators: Input help mode message for move review cursor to previous line command.
89+
"Moves the review cursor to the previous line of the current navigator object and speaks it",
90+
),
91+
resumeSayAllMode=speech.sayAll.CURSOR.REVIEW,
92+
category=globalCommands.SCRCAT_TEXTREVIEW,
93+
gestures=("kb:numpad7", "kb(laptop):NVDA+upArrow", "ts(text):flickUp"),
94+
)
95+
def script_review_previous_line(self, gesture):
96+
result = globalCommands.commands.script_review_previousLine(gesture)
97+
self.report_diff_line_status()
98+
return result
99+
100+
@scriptHandler.script(
101+
description=gettext(
102+
# Translators: Input help mode message for read current line under review cursor command.
103+
"Reports the line of the current navigator object where the review cursor is situated. "
104+
"If this key is pressed twice, the current line will be spelled. "
105+
"Pressing three times will spell the line using character descriptions.",
106+
),
107+
category=globalCommands.SCRCAT_TEXTREVIEW,
108+
gestures=("kb:numpad8", "kb(laptop):NVDA+shift+."),
109+
speakOnDemand=True,
110+
)
111+
def script_review_currentLine(self, gesture):
112+
result = globalCommands.commands.script_review_currentLine(gesture)
113+
if scriptHandler.getLastScriptRepeatCount() == 0:
114+
self.report_diff_line_status()
115+
return result
116+
117+
@scriptHandler.script(
118+
description=gettext(
119+
# Translators: Input help mode message for move review cursor to next line command.
120+
"Moves the review cursor to the next line of the current navigator object and speaks it",
121+
),
122+
resumeSayAllMode=speech.sayAll.CURSOR.REVIEW,
123+
category=globalCommands.SCRCAT_TEXTREVIEW,
124+
gestures=("kb:numpad9", "kb(laptop):NVDA+downArrow", "ts(text):flickDown"),
125+
)
126+
def script_review_nextLine(self, gesture):
127+
result = globalCommands.commands.script_review_nextLine(gesture)
128+
self.report_diff_line_status()
129+
return result
130+
131+
def report_diff_line_status(self):
132+
info = api.getReviewPosition().copy()
133+
info.expand(textInfos.UNIT_LINE)
134+
text = info.text
135+
if not text or text[0] not in DIFF_SOUNDS:
136+
return
137+
nvwave.playWaveFile(DIFF_SOUNDS[text[0]])
173 KB
Binary file not shown.
67.5 KB
Binary file not shown.

readme.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ This addon detects 2 or more consecutive spaces, and folds them into a short seq
1818
For example "space space space space space" becomes "5 space".
1919

2020
### Diff indication
21-
Not in upstream for now, I'll add it later.
22-
2321
When navigating through an object using numpad7 or numpad9, the addon checks for a diff character at the beginning of the line.
2422

2523
The space is ignored, for the plus or minus a sound is played, to make addition/deletion easy to identify.

0 commit comments

Comments
 (0)