Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
}
}