Skip to content

Commit 1446bca

Browse files
authored
editor: add toggle sticky scroll command (#11926)
The commit adds support for the `toggle sticky scroll` command and menu in the framework in order to toggle sticky scroll in monaco editors.
1 parent 4440abd commit 1446bca

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

packages/editor/src/browser/editor-command.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,14 @@ export namespace EditorCommands {
150150
category: CommonCommands.VIEW_CATEGORY,
151151
label: 'Toggle Word Wrap'
152152
});
153+
/**
154+
* Command that toggles sticky scroll.
155+
*/
156+
export const TOGGLE_STICKY_SCROLL = Command.toLocalizedCommand({
157+
id: 'editor.action.toggleStickyScroll',
158+
category: CommonCommands.VIEW_CATEGORY,
159+
label: 'Toggle Sticky Scroll',
160+
}, 'theia/editor/toggleStickyScroll', EDITOR_CATEGORY_KEY);
153161
/**
154162
* Command that re-opens the last closed editor.
155163
*/
@@ -265,6 +273,7 @@ export class EditorCommandContribution implements CommandContribution {
265273
registry.registerCommand(EditorCommands.TOGGLE_MINIMAP);
266274
registry.registerCommand(EditorCommands.TOGGLE_RENDER_WHITESPACE);
267275
registry.registerCommand(EditorCommands.TOGGLE_WORD_WRAP);
276+
registry.registerCommand(EditorCommands.TOGGLE_STICKY_SCROLL);
268277
registry.registerCommand(EditorCommands.REOPEN_CLOSED_EDITOR);
269278

270279
registry.registerCommand(CommonCommands.AUTO_SAVE, {

packages/editor/src/browser/editor-menu.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ export class EditorMenuContribution implements MenuContribution {
173173
commandId: EditorCommands.TOGGLE_RENDER_WHITESPACE.id,
174174
order: '3'
175175
});
176+
registry.registerMenuAction(CommonMenus.VIEW_TOGGLE, {
177+
commandId: EditorCommands.TOGGLE_STICKY_SCROLL.id,
178+
order: '4'
179+
});
176180
registry.registerMenuAction(CommonMenus.FILE_CLOSE, {
177181
commandId: CommonCommands.CLOSE_MAIN_TAB.id,
178182
label: nls.localizeByDefault('Close Editor'),

packages/editor/src/browser/editor-navigation-contribution.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ export class EditorNavigationContribution implements Disposable, FrontendApplica
100100
execute: () => this.toggleWordWrap(),
101101
isEnabled: () => true,
102102
});
103+
this.commandRegistry.registerHandler(EditorCommands.TOGGLE_STICKY_SCROLL.id, {
104+
execute: () => this.toggleStickyScroll(),
105+
isEnabled: () => true,
106+
isToggled: () => this.isStickyScrollEnabled()
107+
});
103108
this.commandRegistry.registerHandler(EditorCommands.REOPEN_CLOSED_EDITOR.id, {
104109
execute: () => this.reopenLastClosedEditor()
105110
});
@@ -188,6 +193,14 @@ export class EditorNavigationContribution implements Disposable, FrontendApplica
188193
}
189194
}
190195

196+
/**
197+
* Toggle the display of sticky scroll in the editor.
198+
*/
199+
protected async toggleStickyScroll(): Promise<void> {
200+
const value: boolean | undefined = this.preferenceService.get('editor.stickyScroll.enabled');
201+
this.preferenceService.set('editor.stickyScroll.enabled', !value, PreferenceScope.User);
202+
}
203+
191204
/**
192205
* Toggle the display of minimap in the editor.
193206
*/
@@ -312,4 +325,7 @@ export class EditorNavigationContribution implements Disposable, FrontendApplica
312325
return !!this.preferenceService.get(EditorNavigationContribution.MOUSE_NAVIGATION_PREFERENCE);
313326
}
314327

328+
private isStickyScrollEnabled(): boolean {
329+
return !!this.preferenceService.get('editor.stickyScroll.enabled');
330+
}
315331
}

0 commit comments

Comments
 (0)