Skip to content

Commit 089b35e

Browse files
authored
Merge 8827af2 into 42dbabc
2 parents 42dbabc + 8827af2 commit 089b35e

2 files changed

Lines changed: 24 additions & 10 deletions

File tree

source/globalCommands.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3630,8 +3630,8 @@ def script_reloadPlugins(self, gesture):
36303630

36313631
@script(
36323632
description=_(
3633-
# Translators: input help mode message for Report destination URL of navigator link command
3634-
"Report the destination URL of the link in the navigator object. "
3633+
# Translators: input help mode message for Report destination URL of a link command
3634+
"Report the destination URL of the link at the position of caret or focus. "
36353635
"If pressed twice, shows the URL in a window for easier review."
36363636
),
36373637
gesture="kb:NVDA+k",
@@ -3640,25 +3640,39 @@ def script_reloadPlugins(self, gesture):
36403640
def script_reportLinkDestination(
36413641
self, gesture: inputCore.InputGesture, forceBrowseable: bool = False
36423642
) -> None:
3643-
"""Generates a ui.message or ui.browseableMessage of a link's destination, if the navigator
3644-
object is a link, or an element with an included link such as a graphic.
3643+
"""Generates a ui.message or ui.browseableMessage of a link's destination, if focus or caret is
3644+
positioned on a link, or an element with an included link such as a graphic.
36453645
@param forceBrowseable: skips the press once check, and displays the browseableMessage version.
36463646
"""
3647-
obj = api.getNavigatorObject()
3647+
try:
3648+
ti: textInfos.TextInfo = api.getCaretPosition()
3649+
except RuntimeError:
3650+
log.debugWarning("Unable to get the caret position.", exc_info=True)
3651+
ti: textInfos.TextInfo = api.getFocusObject().makeTextInfo(textInfos.POSITION_FIRST)
3652+
ti.expand(textInfos.UNIT_CHARACTER)
3653+
obj: NVDAObject = ti.NVDAObjectAtStart
36483654
presses = scriptHandler.getLastScriptRepeatCount()
36493655
if (
36503656
obj.role == controlTypes.role.Role.LINK # If it's a link, or
36513657
or controlTypes.state.State.LINKED in obj.states # if it isn't a link but contains one
36523658
):
3659+
linkDestination = obj.value
3660+
if linkDestination is None:
3661+
# Translators: Informs the user that the link has no destination
3662+
ui.message(_("Link has no apparent destination"))
3663+
return
36533664
if (
36543665
presses == 1 # If pressed twice, or
36553666
or forceBrowseable # if a browseable message is preferred unconditionally
36563667
):
36573668
# Translators: Informs the user that the window contains the destination of the
36583669
# link with given title
3659-
ui.browseableMessage(obj.value, title=_("Destination of: {name}").format(name=obj.name))
3670+
ui.browseableMessage(
3671+
linkDestination,
3672+
title=_("Destination of: {name}").format(name=obj.name)
3673+
)
36603674
elif presses == 0: # One press
3661-
ui.message(obj.value) # Speak the link
3675+
ui.message(linkDestination) # Speak the link
36623676
else: # Some other number of presses
36633677
return # Do nothing
36643678
else:
@@ -3667,8 +3681,8 @@ def script_reportLinkDestination(
36673681

36683682
@script(
36693683
description=_(
3670-
# Translators: input help mode message for Report URL of navigator link in a window command
3671-
"Reports the destination URL of the link in the navigator object in a window, "
3684+
# Translators: input help mode message for Report URL of a link in a window command
3685+
"shows the destination URL of the link at the position of caret or focus in a window, "
36723686
"instead of just speaking it. May be preferred by braille users."
36733687
),
36743688
category=SCRCAT_TOOLS

user_docs/en/userGuide.t2t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ The actual commands will not execute while in input help mode.
222222
| Read status bar | ``NVDA+end`` | ``NVDA+shift+end`` | Reports the Status Bar if NVDA finds one. Pressing twice will spell the information. Pressing three times will copy it to the clipboard |
223223
| Read time | ``NVDA+f12`` | ``NVDA+f12`` | Pressing once reports the current time, pressing twice reports the date |
224224
| Report text formatting | ``NVDA+f`` | ``NVDA+f`` | Reports text formatting. Pressing twice shows the information in a window |
225-
| Report link destination | ``NVDA+k`` | ``NVDA+k`` | Pressing once speaks the destination URL of the link in the [navigator object #ObjectNavigation]. Pressing twice shows it in a window for more careful review |
225+
| Report link destination | ``NVDA+k`` | ``NVDA+k`` | Pressing once speaks the destination URL of the link at the current focus or caret position. Pressing twice shows it in a window for more careful review |
226226

227227
+++ Toggle which information NVDA reads +++[ToggleWhichInformationNVDAReads]
228228
|| Name | Desktop key | Laptop key | Description |

0 commit comments

Comments
 (0)