diff --git a/packages/editor/src/browser/editor-command.ts b/packages/editor/src/browser/editor-command.ts index 17d025fc6e707..9ac8bdd8bf180 100644 --- a/packages/editor/src/browser/editor-command.ts +++ b/packages/editor/src/browser/editor-command.ts @@ -150,6 +150,14 @@ export namespace EditorCommands { category: CommonCommands.VIEW_CATEGORY, label: 'Toggle Word Wrap' }); + /** + * Command that toggles sticky scroll. + */ + export const TOGGLE_STICKY_SCROLL = Command.toLocalizedCommand({ + id: 'editor.action.toggleStickyScroll', + category: CommonCommands.VIEW_CATEGORY, + label: 'Toggle Sticky Scroll', + }, 'theia/editor/toggleStickyScroll', EDITOR_CATEGORY_KEY); /** * Command that re-opens the last closed editor. */ @@ -265,6 +273,7 @@ export class EditorCommandContribution implements CommandContribution { registry.registerCommand(EditorCommands.TOGGLE_MINIMAP); registry.registerCommand(EditorCommands.TOGGLE_RENDER_WHITESPACE); registry.registerCommand(EditorCommands.TOGGLE_WORD_WRAP); + registry.registerCommand(EditorCommands.TOGGLE_STICKY_SCROLL); registry.registerCommand(EditorCommands.REOPEN_CLOSED_EDITOR); registry.registerCommand(CommonCommands.AUTO_SAVE, { diff --git a/packages/editor/src/browser/editor-menu.ts b/packages/editor/src/browser/editor-menu.ts index 20f1ee7b6252c..9a635ca7cf67b 100644 --- a/packages/editor/src/browser/editor-menu.ts +++ b/packages/editor/src/browser/editor-menu.ts @@ -173,6 +173,10 @@ export class EditorMenuContribution implements MenuContribution { commandId: EditorCommands.TOGGLE_RENDER_WHITESPACE.id, order: '3' }); + registry.registerMenuAction(CommonMenus.VIEW_TOGGLE, { + commandId: EditorCommands.TOGGLE_STICKY_SCROLL.id, + order: '4' + }); registry.registerMenuAction(CommonMenus.FILE_CLOSE, { commandId: CommonCommands.CLOSE_MAIN_TAB.id, label: nls.localizeByDefault('Close Editor'), diff --git a/packages/editor/src/browser/editor-navigation-contribution.ts b/packages/editor/src/browser/editor-navigation-contribution.ts index 5ac7b8d07ff46..c1920baa2e166 100644 --- a/packages/editor/src/browser/editor-navigation-contribution.ts +++ b/packages/editor/src/browser/editor-navigation-contribution.ts @@ -100,6 +100,11 @@ export class EditorNavigationContribution implements Disposable, FrontendApplica execute: () => this.toggleWordWrap(), isEnabled: () => true, }); + this.commandRegistry.registerHandler(EditorCommands.TOGGLE_STICKY_SCROLL.id, { + execute: () => this.toggleStickyScroll(), + isEnabled: () => true, + isToggled: () => this.isStickyScrollEnabled() + }); this.commandRegistry.registerHandler(EditorCommands.REOPEN_CLOSED_EDITOR.id, { execute: () => this.reopenLastClosedEditor() }); @@ -188,6 +193,14 @@ export class EditorNavigationContribution implements Disposable, FrontendApplica } } + /** + * Toggle the display of sticky scroll in the editor. + */ + protected async toggleStickyScroll(): Promise { + const value: boolean | undefined = this.preferenceService.get('editor.stickyScroll.enabled'); + this.preferenceService.set('editor.stickyScroll.enabled', !value, PreferenceScope.User); + } + /** * Toggle the display of minimap in the editor. */ @@ -312,4 +325,7 @@ export class EditorNavigationContribution implements Disposable, FrontendApplica return !!this.preferenceService.get(EditorNavigationContribution.MOUSE_NAVIGATION_PREFERENCE); } + private isStickyScrollEnabled(): boolean { + return !!this.preferenceService.get('editor.stickyScroll.enabled'); + } }