@@ -22,7 +22,7 @@ import { Registry } from 'vs/platform/registry/common/platform';
22
22
import { ICommandService } from 'vs/platform/commands/common/commands' ;
23
23
import { NEW_UNTITLED_FILE_COMMAND_ID } from 'vs/workbench/contrib/files/browser/fileConstants' ;
24
24
import { 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 ' ;
26
26
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys' ;
27
27
28
28
registerAccessibilityConfiguration ( ) ;
@@ -101,32 +101,44 @@ workbenchRegistry.registerWorkbenchContribution(EditorAccessibilityHelpContribut
101
101
102
102
class HoverAccessibleViewContribution extends Disposable {
103
103
static ID : 'hoverAccessibleViewContribution' ;
104
+ private _options : IAccessibleViewOptions = {
105
+ ariaLabel : localize ( 'hoverAccessibleView' , "Hover Accessible View" ) , language : 'typescript' , type : AccessibleViewType . View
106
+ } ;
104
107
constructor ( ) {
105
108
super ( ) ;
106
- this . _register ( AccessibleViewAction . addImplementation ( 90 , 'hover' , accessor => {
109
+ this . _register ( AccessibleViewAction . addImplementation ( 95 , 'hover' , accessor => {
107
110
const accessibleViewService = accessor . get ( IAccessibleViewService ) ;
108
111
const codeEditorService = accessor . get ( ICodeEditorService ) ;
109
112
const editor = codeEditorService . getActiveCodeEditor ( ) || codeEditorService . getFocusedCodeEditor ( ) ;
110
- if ( ! editor ) {
113
+ const editorHoverContent = editor ? ModesHoverController . get ( editor ) ?. getWidgetContent ( ) ?? undefined : undefined ;
114
+ if ( ! editorHoverContent ) {
111
115
return false ;
112
116
}
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.
116
132
return false ;
117
133
}
118
134
accessibleViewService . show ( {
119
135
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
127
139
} ) ;
128
140
return true ;
129
- } , EditorContextKeys . hoverFocused ) ) ;
141
+ } ) ) ;
130
142
}
131
143
}
132
144
0 commit comments