Skip to content

Commit

Permalink
editor: add toggle sticky scroll command (#11926)
Browse files Browse the repository at this point in the history
The commit adds support for the `toggle sticky scroll` command and menu in the framework in order to toggle sticky scroll in monaco editors.
  • Loading branch information
EstFoisy authored Dec 9, 2022
1 parent 4440abd commit 1446bca
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/editor/src/browser/editor-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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, {
Expand Down
4 changes: 4 additions & 0 deletions packages/editor/src/browser/editor-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
16 changes: 16 additions & 0 deletions packages/editor/src/browser/editor-navigation-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
});
Expand Down Expand Up @@ -188,6 +193,14 @@ export class EditorNavigationContribution implements Disposable, FrontendApplica
}
}

/**
* Toggle the display of sticky scroll in the editor.
*/
protected async toggleStickyScroll(): Promise<void> {
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.
*/
Expand Down Expand Up @@ -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');
}
}

0 comments on commit 1446bca

Please sign in to comment.