Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding keyboard control for navigation through sticky scroll lines #174670

Merged
merged 45 commits into from
Mar 1, 2023
Merged
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
eb72100
work in progress
aiday-mar Feb 16, 2023
20cc79c
added code in order to make individual sticky lines grey
aiday-mar Feb 16, 2023
f931df6
adding changes
aiday-mar Feb 16, 2023
badba6f
Adding code in order to have context keys
aiday-mar Feb 17, 2023
49df40b
changing the code
aiday-mar Feb 17, 2023
7881f8c
adding code in order not to move the cursor when sticky scroll is foc…
aiday-mar Feb 17, 2023
2df6275
Simplifying the code
aiday-mar Feb 17, 2023
520b67e
removing unecessary code
aiday-mar Feb 17, 2023
b4191bc
converting to an arrow function in order to avoid error
aiday-mar Feb 17, 2023
b1b4dd8
removing a console log
aiday-mar Feb 17, 2023
1317642
removing the stickyScrollLinesEnabled boolean
aiday-mar Feb 17, 2023
ccc0603
removing a comment
aiday-mar Feb 17, 2023
f7d61a6
removing space
aiday-mar Feb 17, 2023
6fdf23e
settig back tasks.json to what it was
aiday-mar Feb 17, 2023
eedbcda
saving the default tasks.json
aiday-mar Feb 17, 2023
ee51d0b
Cleaned the code and also added an on hover listener on the sticky sc…
aiday-mar Feb 17, 2023
425f9fa
removing a useless variable
aiday-mar Feb 17, 2023
3e06bc3
when clicking on escape comming out of the focus
aiday-mar Feb 17, 2023
3ef249e
writing out all the classes as interfaces
aiday-mar Feb 17, 2023
7e4d695
Changed the left arrow to an Enter key code
aiday-mar Feb 17, 2023
25b143e
Merge branch 'main' into aiday/issue169107
aiday-mar Feb 17, 2023
2675b8c
also preventing the user from typing on the left and on the right whe…
aiday-mar Feb 17, 2023
89bbb96
added back the css for when the sticky scroll widget is focused
aiday-mar Feb 17, 2023
35a1d39
instead of using notEqualsTo(true) use isEqualTo(false)
aiday-mar Feb 17, 2023
344be96
removing the dependence on the context key
aiday-mar Feb 20, 2023
df04e7b
removed the servcice
aiday-mar Feb 20, 2023
048a71d
making the sticky scroll focused context key a property of the contro…
aiday-mar Feb 20, 2023
b4f59bf
assigning the context key to a property of the class in order to not …
aiday-mar Feb 20, 2023
9aa0aef
adding some changes
aiday-mar Feb 21, 2023
2e4540f
added some console messages in order to better understand the focus t…
aiday-mar Feb 22, 2023
476a144
adding code to the widget so that it remembers the sticky line on whi…
aiday-mar Feb 22, 2023
26616be
work in progress
aiday-mar Feb 22, 2023
40f6279
refactoring the code and using the focus tracker
aiday-mar Feb 23, 2023
1d8625b
renamed toggle focus sticky scroll to focus sticky scroll
aiday-mar Feb 28, 2023
dc79c61
removing the keybindings
aiday-mar Feb 28, 2023
b444d6d
adding the ondidfocus listener on the focus tracker
aiday-mar Feb 28, 2023
6f3a796
adding changes from review
aiday-mar Feb 28, 2023
f8bb5c8
adding changes from review
aiday-mar Feb 28, 2023
8994c08
adding last changes
aiday-mar Feb 28, 2023
19ebffa
setting the attribute to be a list for the root dom node
aiday-mar Feb 28, 2023
150e817
removed the unecessary call to blur()
aiday-mar Feb 28, 2023
ad7d621
adding changes so that the focus persist on the scrolling
aiday-mar Feb 28, 2023
3dfcc87
making line number distinction before and after the rendering of the …
aiday-mar Feb 28, 2023
d3086e5
removing unecessary code
aiday-mar Feb 28, 2023
96a563d
disposing when clicking on the sticky scroll and revealing some other…
aiday-mar Feb 28, 2023
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
Next Next commit
work in progress
  • Loading branch information
aiday-mar committed Feb 16, 2023
commit eb7210055093e89b68e41b0354273db037761588
29 changes: 29 additions & 0 deletions src/vs/editor/contrib/stickyScroll/browser/stickyScrollActions.ts
Original file line number Diff line number Diff line change
@@ -4,11 +4,13 @@
*--------------------------------------------------------------------------------------------*/

import { ServicesAccessor } from 'vs/editor/browser/editorExtensions';
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
import { localize } from 'vs/nls';
import { Categories } from 'vs/platform/action/common/actionCommonCategories';
import { Action2, MenuId } from 'vs/platform/actions/common/actions';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { IStickyScrollFocusService } from './stickyScrollServices';

export class ToggleStickyScroll extends Action2 {

@@ -40,3 +42,30 @@ export class ToggleStickyScroll extends Action2 {
return configurationService.updateValue('editor.stickyScroll.enabled', newValue);
}
}

export class FocusStickyScroll extends Action2 {

constructor() {
super({
id: 'editor.action.focusStickyScroll',
title: {
value: localize('focusStickyScroll', "Focus Sticky Scroll"),
mnemonicTitle: localize({ key: 'mifocusStickyScroll', comment: ['&& denotes a mnemonic'] }, "&&Focus Sticky Scroll"),
original: 'Focus Sticky Scroll',
},
category: Categories.View,
// Add code in order to make the focus option appear only when sticky scroll is enabled
menu: [
{ id: MenuId.CommandPalette },
{ id: MenuId.StickyScrollContext }
]
});
}

run(accessor: ServicesAccessor): void {
const stickyScrollFocusService = accessor.get(IStickyScrollFocusService);
const codeEditorService = accessor.get(ICodeEditorService);
const editor = codeEditorService.getFocusedCodeEditor() || codeEditorService.getActiveCodeEditor();
stickyScrollFocusService.focus(editor);
}
}
Original file line number Diff line number Diff line change
@@ -4,9 +4,11 @@
*--------------------------------------------------------------------------------------------*/

import { EditorContributionInstantiation, registerEditorContribution } from 'vs/editor/browser/editorExtensions';
import { ToggleStickyScroll } from 'vs/editor/contrib/stickyScroll/browser/stickyScrollActions';
import { ToggleStickyScroll, FocusStickyScroll } from 'vs/editor/contrib/stickyScroll/browser/stickyScrollActions';
import { StickyScrollController } from 'vs/editor/contrib/stickyScroll/browser/stickyScrollController';
import { registerAction2 } from 'vs/platform/actions/common/actions';

registerEditorContribution(StickyScrollController.ID, StickyScrollController, EditorContributionInstantiation.AfterFirstRender);
registerAction2(ToggleStickyScroll);
registerAction2(FocusStickyScroll);

Original file line number Diff line number Diff line change
@@ -60,6 +60,17 @@ export class StickyScrollController extends Disposable implements IEditorContrib
return this._widgetState;
}

public static get(editor: ICodeEditor): StickyScrollController | null {
return editor.getContribution<StickyScrollController>(StickyScrollController.ID);
}

public focus(): void {
// Mark the last sticky line as being foused, by changing the background color
if (this._stickyScrollWidget.getDomNode().hasChildNodes()) {
const childNodes = this._stickyScrollWidget.getDomNode().childNodes;
}
}

private _onContextMenu(event: MouseEvent) {
this._contextMenuService.showContextMenu({
menuId: MenuId.StickyScrollContext,
@@ -108,7 +119,6 @@ export class StickyScrollController extends Disposable implements IEditorContrib
const layoutInfo = this._editor.getLayoutInfo();
const width = layoutInfo.width - layoutInfo.minimap.minimapCanvasOuterWidth - layoutInfo.verticalScrollbarWidth;
this._stickyScrollWidget.getDomNode().style.width = `${width}px`;

// make sure sticky scroll doesn't take up more than 25% of the editor
const theoreticalLines = layoutInfo.height / this._editor.getOption(EditorOption.lineHeight);
this._maxStickyLines = Math.round(theoreticalLines * .25);
29 changes: 29 additions & 0 deletions src/vs/editor/contrib/stickyScroll/browser/stickyScrollServices.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/


import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { InstantiationType, registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { StickyScrollController } from 'vs/editor/contrib/stickyScroll/browser/stickyScrollController';

export interface IStickyScrollFocusService {
focus(): void;
}

export class StickyScrollFocusService {
focus(editor: ICodeEditor): void {
const stickyScrollController = StickyScrollController.get(editor);
if (stickyScrollController) {
stickyScrollController.focus();
}
}
}

export const IStickyScrollFocusService = createDecorator<IStickyScrollFocusService>('IStickyScrollFocusService');

// Unsure what instantiation type to use
registerSingleton(IStickyScrollFocusService, StickyScrollFocusService, InstantiationType.Eager);