3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
+ import { localize } from 'vs/nls' ;
6
7
import * as DOM from 'vs/base/browser/dom' ;
7
8
import { Disposable , DisposableStore } from 'vs/base/common/lifecycle' ;
9
+ import { ServicesAccessor } from 'vs/editor/browser/editorExtensions' ;
10
+ import { Categories } from 'vs/platform/action/common/actionCommonCategories' ;
11
+ import { Action2 , MenuId , registerAction2 } from 'vs/platform/actions/common/actions' ;
12
+ import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
13
+ import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey' ;
14
+ import { IContextMenuService } from 'vs/platform/contextview/browser/contextView' ;
8
15
import { INotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookBrowser' ;
9
16
import { INotebookCellList } from 'vs/workbench/contrib/notebook/browser/view/notebookRenderingCommon' ;
10
17
import { NotebookCellOutlineProvider , OutlineEntry } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookOutlineProvider' ;
11
18
import { CellKind } from 'vs/workbench/contrib/notebook/common/notebookCommon' ;
12
19
20
+ export class ToggleNotebookStickyScroll extends Action2 {
21
+
22
+ constructor ( ) {
23
+ super ( {
24
+ id : 'notebook.action.toggleNotebookStickyScroll' ,
25
+ title : {
26
+ value : localize ( 'toggleStickyScroll' , "Toggle Notebook Sticky Scroll" ) ,
27
+ mnemonicTitle : localize ( { key : 'mitoggleStickyScroll' , comment : [ '&& denotes a mnemonic' ] } , "&&Toggle Notebook Sticky Scroll" ) ,
28
+ original : 'Toggle Notebook Sticky Scroll' ,
29
+ } ,
30
+ category : Categories . View ,
31
+ toggled : {
32
+ condition : ContextKeyExpr . equals ( 'config.notebook.stickyScroll.enabled' , true ) ,
33
+ title : localize ( 'notebookStickyScroll' , "Notebook Sticky Scroll" ) ,
34
+ mnemonicTitle : localize ( { key : 'miNotebookStickyScroll' , comment : [ '&& denotes a mnemonic' ] } , "&&Notebook Sticky Scroll" ) ,
35
+ } ,
36
+ menu : [
37
+ { id : MenuId . CommandPalette } ,
38
+ { id : MenuId . NotebookStickyScrollContext }
39
+ ]
40
+ } ) ;
41
+ }
42
+
43
+ override async run ( accessor : ServicesAccessor ) : Promise < void > {
44
+ const configurationService = accessor . get ( IConfigurationService ) ;
45
+ const newValue = ! configurationService . getValue ( 'notebook.stickyScroll.enabled' ) ;
46
+ return configurationService . updateValue ( 'notebook.stickyScroll.enabled' , newValue ) ;
47
+ }
48
+ }
49
+
13
50
class NotebookStickyLine extends Disposable {
14
51
constructor (
15
52
public readonly element : HTMLElement ,
@@ -56,11 +93,11 @@ export class NotebookStickyScroll extends Disposable {
56
93
private readonly domNode : HTMLElement ,
57
94
private readonly notebookEditor : INotebookEditor ,
58
95
private readonly notebookOutline : NotebookCellOutlineProvider ,
59
- private readonly notebookCellList : INotebookCellList
96
+ private readonly notebookCellList : INotebookCellList ,
97
+ @IContextMenuService private readonly _contextMenuService : IContextMenuService ,
60
98
) {
61
99
super ( ) ;
62
100
63
-
64
101
if ( this . notebookEditor . notebookOptions . getLayoutConfiguration ( ) . stickyScroll ) {
65
102
this . init ( ) ;
66
103
}
@@ -73,6 +110,17 @@ export class NotebookStickyScroll extends Disposable {
73
110
this . setTop ( ) ;
74
111
}
75
112
} ) ) ;
113
+
114
+ this . _register ( DOM . addDisposableListener ( this . domNode , DOM . EventType . CONTEXT_MENU , async ( event : MouseEvent ) => {
115
+ this . onContextMenu ( event ) ;
116
+ } ) ) ;
117
+ }
118
+
119
+ private onContextMenu ( event : MouseEvent ) {
120
+ this . _contextMenuService . showContextMenu ( {
121
+ menuId : MenuId . NotebookStickyScrollContext ,
122
+ getAnchor : ( ) => event ,
123
+ } ) ;
76
124
}
77
125
78
126
private updateConfig ( ) {
@@ -388,3 +436,5 @@ export class NotebookStickyScroll extends Disposable {
388
436
super . dispose ( ) ;
389
437
}
390
438
}
439
+
440
+ registerAction2 ( ToggleNotebookStickyScroll ) ;
0 commit comments