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

fix: adding escape command in order to focus out of the sticky scroll #178020

Merged
merged 5 commits into from
Mar 22, 2023
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
44 changes: 27 additions & 17 deletions src/vs/editor/contrib/stickyScroll/browser/stickyScrollActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class ToggleStickyScroll extends Action2 {
}
}

const weight = KeybindingWeight.EditorContrib + 10000;
const weight = KeybindingWeight.EditorContrib;

export class FocusStickyScroll extends EditorAction2 {

Expand All @@ -66,10 +66,7 @@ export class FocusStickyScroll extends EditorAction2 {
}

runEditorCommand(_accessor: ServicesAccessor, editor: ICodeEditor) {
const stickyScrollController = StickyScrollController.get(editor);
if (stickyScrollController) {
stickyScrollController.focus();
}
StickyScrollController.get(editor)?.focus();
}
}

Expand All @@ -90,10 +87,7 @@ export class SelectNextStickyScrollLine extends EditorAction2 {
}

runEditorCommand(_accessor: ServicesAccessor, editor: ICodeEditor) {
const stickyScrollController = StickyScrollController.get(editor);
if (stickyScrollController) {
stickyScrollController.focusNext();
}
StickyScrollController.get(editor)?.focusNext();
}
}

Expand All @@ -114,10 +108,7 @@ export class SelectPreviousStickyScrollLine extends EditorAction2 {
}

runEditorCommand(_accessor: ServicesAccessor, editor: ICodeEditor) {
const stickyScrollController = StickyScrollController.get(editor);
if (stickyScrollController) {
stickyScrollController.focusPrevious();
}
StickyScrollController.get(editor)?.focusPrevious();
}
}

Expand All @@ -138,9 +129,28 @@ export class GoToStickyScrollLine extends EditorAction2 {
}

runEditorCommand(_accessor: ServicesAccessor, editor: ICodeEditor) {
const stickyScrollController = StickyScrollController.get(editor);
if (stickyScrollController) {
stickyScrollController.goToFocused();
}
StickyScrollController.get(editor)?.goToFocused();
}
}

export class SelectEditor extends EditorAction2 {

constructor() {
super({
id: 'editor.action.selectEditor',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not the best person to ask but not sure the ideal name for this, should a contrib be registering unprefixed editor.action.* commands?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll talk with the team about it

title: {
value: localize('selectEditor.title', "Select Editor"),
original: 'Select Editor'
},
precondition: ContextKeyExpr.has('config.editor.stickyScroll.enabled'),
keybinding: {
weight,
aiday-mar marked this conversation as resolved.
Show resolved Hide resolved
primary: KeyCode.Escape
}
});
}

runEditorCommand(_accessor: ServicesAccessor, editor: ICodeEditor) {
StickyScrollController.get(editor)?.selectEditor();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/

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

Expand All @@ -14,3 +14,4 @@ registerAction2(FocusStickyScroll);
registerAction2(SelectPreviousStickyScrollLine);
registerAction2(SelectNextStickyScrollLine);
registerAction2(GoToStickyScrollLine);
registerAction2(SelectEditor);
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface IStickyScrollController {
goToFocused(): void;
findScrollWidgetState(): StickyScrollWidgetState;
dispose(): void;
selectEditor(): void;
}

export class StickyScrollController extends Disposable implements IEditorContribution, IStickyScrollController {
Expand Down Expand Up @@ -172,6 +173,10 @@ export class StickyScrollController extends Disposable implements IEditorContrib
}
}

public selectEditor(): void {
this._editor.focus();
}

// True is next, false is previous
private _focusNav(direction: boolean): void {
this._focusedStickyElementIndex = direction ? this._focusedStickyElementIndex + 1 : this._focusedStickyElementIndex - 1;
Expand Down