Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/vs/base/browser/formattedTextRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ function _renderFormattedText(element: Node, treeNode: IFormatParseTree, actionH
child = document.createElement('code');
} else if (treeNode.type === FormatType.Action && actionHandler) {
const a = document.createElement('a');
a.setAttribute('data-content-index', String(treeNode.index));
Comment thread
maram-odoo marked this conversation as resolved.
actionHandler.disposables.add(DOM.addStandardDisposableListener(a, 'click', (event) => {
actionHandler.callback(String(treeNode.index), event);
}));
Expand Down
3 changes: 3 additions & 0 deletions src/vs/base/test/browser/formattedTextRenderer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ suite('FormattedTextRenderer', () => {
}
});
assert.strictEqual(result.innerHTML, '<a>action</a>');
assert.strictEqual(result.firstChild!.getAttribute('data-content-index'), '0');

const event: MouseEvent = document.createEvent('MouseEvent');
event.initEvent('click', true, true);
Expand All @@ -97,6 +98,7 @@ suite('FormattedTextRenderer', () => {
}
});
assert.strictEqual(result.innerHTML, '<i><b><a>action</a></b></i>');
assert.strictEqual(result.firstChild!.firstChild!.firstChild!.getAttribute('data-content-index'), '0');

const event: MouseEvent = document.createEvent('MouseEvent');
event.initEvent('click', true, true);
Expand All @@ -117,6 +119,7 @@ suite('FormattedTextRenderer', () => {
}
});
assert.strictEqual(result.innerHTML, '<code><i><b><a>action</a></b></i></code>');
assert.strictEqual(result.firstChild!.firstChild!.firstChild!.firstChild!.getAttribute('data-content-index'), '0');

const event: MouseEvent = document.createEvent('MouseEvent');
event.initEvent('click', true, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { $, addDisposableListener, getActiveWindow } from '../../../../../base/browser/dom.js';
import { IContentActionHandler, renderFormattedText } from '../../../../../base/browser/formattedTextRenderer.js';
import { StandardMouseEvent } from '../../../../../base/browser/mouseEvent.js';
import { StandardKeyboardEvent } from '../../../../../base/browser/keyboardEvent.js';
import { status } from '../../../../../base/browser/ui/aria/aria.js';
import { WorkbenchActionExecutedClassification, WorkbenchActionExecutedEvent } from '../../../../../base/common/actions.js';
import { Event } from '../../../../../base/common/event.js';
Expand Down Expand Up @@ -271,6 +272,18 @@ class EmptyTextEditorHintContentWidget extends Disposable implements IContentWid
// eslint-disable-next-line no-restricted-syntax
for (const anchor of hintElement.querySelectorAll('a')) {
anchor.style.cursor = 'pointer';
anchor.tabIndex = 0;
anchor.setAttribute('role', 'button');
anchor.addEventListener('keydown', (e: KeyboardEvent) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
e.stopPropagation();
const index = anchor.getAttribute('data-content-index');
if (index !== null) {
hintHandler.callback(index, new StandardKeyboardEvent(e));
}
}
});
}

return { hintElement, ariaLabel };
Expand Down