33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6+ import { localize } from 'vs/nls' ;
67import * as DOM from 'vs/base/browser/dom' ;
78import { 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' ;
815import { INotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookBrowser' ;
916import { INotebookCellList } from 'vs/workbench/contrib/notebook/browser/view/notebookRenderingCommon' ;
1017import { NotebookCellOutlineProvider , OutlineEntry } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookOutlineProvider' ;
1118import { CellKind } from 'vs/workbench/contrib/notebook/common/notebookCommon' ;
1219
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+
1350class NotebookStickyLine extends Disposable {
1451 constructor (
1552 public readonly element : HTMLElement ,
@@ -56,11 +93,11 @@ export class NotebookStickyScroll extends Disposable {
5693 private readonly domNode : HTMLElement ,
5794 private readonly notebookEditor : INotebookEditor ,
5895 private readonly notebookOutline : NotebookCellOutlineProvider ,
59- private readonly notebookCellList : INotebookCellList
96+ private readonly notebookCellList : INotebookCellList ,
97+ @IContextMenuService private readonly _contextMenuService : IContextMenuService ,
6098 ) {
6199 super ( ) ;
62100
63-
64101 if ( this . notebookEditor . notebookOptions . getLayoutConfiguration ( ) . stickyScroll ) {
65102 this . init ( ) ;
66103 }
@@ -73,6 +110,17 @@ export class NotebookStickyScroll extends Disposable {
73110 this . setTop ( ) ;
74111 }
75112 } ) ) ;
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+ } ) ;
76124 }
77125
78126 private updateConfig ( ) {
@@ -388,3 +436,5 @@ export class NotebookStickyScroll extends Disposable {
388436 super . dispose ( ) ;
389437 }
390438}
439+
440+ registerAction2 ( ToggleNotebookStickyScroll ) ;
0 commit comments