@@ -22,7 +22,7 @@ import { Registry } from 'vs/platform/registry/common/platform';
2222import { ICommandService } from 'vs/platform/commands/common/commands' ;
2323import { NEW_UNTITLED_FILE_COMMAND_ID } from 'vs/workbench/contrib/files/browser/fileConstants' ;
2424import { ModesHoverController } from 'vs/editor/contrib/hover/browser/hover' ;
25- import { withNullAsUndefined } from 'vs/base/common/types ' ;
25+ import { IContextViewService } from 'vs/platform/contextview/browser/contextView ' ;
2626import { EditorContextKeys } from 'vs/editor/common/editorContextKeys' ;
2727
2828registerAccessibilityConfiguration ( ) ;
@@ -101,32 +101,44 @@ workbenchRegistry.registerWorkbenchContribution(EditorAccessibilityHelpContribut
101101
102102class HoverAccessibleViewContribution extends Disposable {
103103 static ID : 'hoverAccessibleViewContribution' ;
104+ private _options : IAccessibleViewOptions = {
105+ ariaLabel : localize ( 'hoverAccessibleView' , "Hover Accessible View" ) , language : 'typescript' , type : AccessibleViewType . View
106+ } ;
104107 constructor ( ) {
105108 super ( ) ;
106109 this . _register ( AccessibleViewAction . addImplementation ( 90 , 'hover' , accessor => {
107110 const accessibleViewService = accessor . get ( IAccessibleViewService ) ;
108111 const codeEditorService = accessor . get ( ICodeEditorService ) ;
109112 const editor = codeEditorService . getActiveCodeEditor ( ) || codeEditorService . getFocusedCodeEditor ( ) ;
110- if ( ! editor ) {
113+ const editorHoverContent = editor ? ModesHoverController . get ( editor ) ?. getWidgetContent ( ) ?? undefined : undefined ;
114+ if ( ! editorHoverContent ) {
111115 return false ;
112116 }
113- const controller = ModesHoverController . get ( editor ) ;
114- const content = withNullAsUndefined ( controller ?. getWidgetContent ( ) ) ;
115- if ( ! controller || ! content ) {
117+ accessibleViewService . show ( {
118+ verbositySettingKey : 'hover' ,
119+ provideContent ( ) { return editorHoverContent ; } ,
120+ onClose ( ) { } ,
121+ options : this . _options
122+ } ) ;
123+ return true ;
124+ } , EditorContextKeys . hoverFocused ) ) ;
125+ this . _register ( AccessibleViewAction . addImplementation ( 90 , 'extension-hover' , accessor => {
126+ const accessibleViewService = accessor . get ( IAccessibleViewService ) ;
127+ const contextViewService = accessor . get ( IContextViewService ) ;
128+ const contextViewElement = contextViewService . getContextViewElement ( ) ;
129+ const extensionHoverContent = contextViewElement ?. textContent ?? undefined ;
130+ if ( contextViewElement . classList . contains ( 'accessible-view-container' ) || ! extensionHoverContent ) {
131+ // The accessible view, itself, uses the context view service to display the text. We don't want to read that.
116132 return false ;
117133 }
118134 accessibleViewService . show ( {
119135 verbositySettingKey : 'hover' ,
120- provideContent ( ) { return content ; } ,
121- onClose ( ) {
122- controller . focus ( ) ;
123- } ,
124- options : {
125- ariaLabel : localize ( 'hoverAccessibleView' , "Hover Accessible View" ) , language : 'typescript' , type : AccessibleViewType . View
126- }
136+ provideContent ( ) { return extensionHoverContent ; } ,
137+ onClose ( ) { } ,
138+ options : this . _options
127139 } ) ;
128140 return true ;
129- } , EditorContextKeys . hoverFocused ) ) ;
141+ } ) ) ;
130142 }
131143}
132144
0 commit comments