-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(ai): invoke OpenerService
for markdown links in chat UI
#14602
Conversation
4cecf16
to
bede94c
Compare
@sdirix Sorry for the force-push after requesting your review... Just saw another potential to simplify things. Now it is ready, I promise :-) |
No worries, I'm also guilty of this from time to time ;) |
const handleClick = (event: MouseEvent) => { | ||
if (event.target instanceof HTMLElement && event.target.tagName === 'A') { | ||
const href = event.target.getAttribute('href'); | ||
if (href) { | ||
open(openerService, new URI(href)); | ||
event.preventDefault(); | ||
} | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const handleClick = (event: MouseEvent) => { | |
if (event.target instanceof HTMLElement && event.target.tagName === 'A') { | |
const href = event.target.getAttribute('href'); | |
if (href) { | |
open(openerService, new URI(href)); | |
event.preventDefault(); | |
} | |
} | |
}; | |
const handleClick = (event: MouseEvent) => { | |
let target = event.target as HTMLElement; | |
while (target && target.tagName !== 'A') { | |
target = target.parentElement as HTMLElement; | |
} | |
if (target && target.tagName === 'A') { | |
const href = target.getAttribute('href'); | |
if (href) { | |
open(openerService, new URI(href)); | |
event.preventDefault(); | |
} | |
} | |
}; |
Should we support also links that have children? This could be useful for cases like <a><code>abc</code></a>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to already work. When I instruct the LLM with
Repeat exactly: [`test`](command:sample-command)
It then produces
<a href="command:sample-command"><code>test</code></a>
which is rendered as a clickable link
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but the opener handler isn't invoked, because the event.target
is the code
element.
So I think we should recursively move up to see if we are inside an A
element.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right! I overlooked that the command was not working properly as in both cases a similar styled popup was shown, the Javascript alert and the xdg-open alert 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me!
Fixes #14601 Contributed on behalf of STMicroelectronics.
bede94c
to
0e6cbe4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works even better now
What it does
Invoke Theia's
OpenerService
when users click a link in the chat UI. This enables registering custom implementations ofOpenHandler
for specific URIs used ashref
in markdown links.Fixes #14601
How to test
OpenHandler
is registered, e.g.[test](command:sample-command)
sample-command
is executed, as it is correctly handled by theCommandOpenHandler
Follow-ups
None
Breaking changes
Attribution
Contributed on behalf of STMicroelectronics.
Review checklist
Reminder for reviewers