Skip to content

Commit

Permalink
Add find keyboard binding for help view (#6526)
Browse files Browse the repository at this point in the history
  • Loading branch information
timtmok authored Feb 28, 2025
1 parent 1a472a2 commit 9daa8aa
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
17 changes: 16 additions & 1 deletion src/vs/workbench/contrib/positronHelp/browser/helpEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Disposable } from '../../../../base/common/lifecycle.js';
import { Emitter, Event } from '../../../../base/common/event.js';
import { IThemeService } from '../../../../platform/theme/common/themeService.js';
import { PositronHelpFocused } from '../../../common/contextkeys.js';
import { IContextKeyService } from '../../../../platform/contextkey/common/contextkey.js';
import { IContextKey, IContextKeyService } from '../../../../platform/contextkey/common/contextkey.js';
import { isLocalhost } from './utils.js';
import { ExtensionIdentifier } from '../../../../platform/extensions/common/extensions.js';
import { KeyEvent } from '../../webview/browser/webviewMessages.js';
Expand Down Expand Up @@ -270,6 +270,11 @@ export class HelpEntry extends Disposable implements IHelpEntry, WebviewFindDele
*/
private _claimTimeout?: NodeJS.Timeout;

/**
* The helpFocusedContextKey to track when the help overlay webview is focused.
*/
private helpFocusedContextKey: IContextKey<boolean>;

/**
* Gets or sets the dispose timeout. This timeout is used to schedule the disposal of the help
* overlay webview.
Expand Down Expand Up @@ -349,6 +354,8 @@ export class HelpEntry extends Disposable implements IHelpEntry, WebviewFindDele
// Reload the help overlay webview.
this._helpOverlayWebview?.reload();
}));

this.helpFocusedContextKey = PositronHelpFocused.bindTo(this._contextKeyService);
}

/**
Expand Down Expand Up @@ -620,6 +627,14 @@ export class HelpEntry extends Disposable implements IHelpEntry, WebviewFindDele
helpOverlayWebview.claim(element, DOM.getWindow(element), undefined);
helpOverlayWebview.layoutWebviewOverElement(element);

helpOverlayWebview.onDidFocus(() => {
this.helpFocusedContextKey.set(true);
});

helpOverlayWebview.onDidBlur(() => {
this.helpFocusedContextKey.set(false);
});

// Run logic for animating cases.
ensureWebviewSizeCorrectWhenAnimating();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import { SyncDescriptor } from '../../../../platform/instantiation/common/descri
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
import { ViewPaneContainer } from '../../../browser/parts/views/viewPaneContainer.js';
import { PositronHelpView } from './positronHelpView.js';
import { POSITRON_HELP_VIEW_ID } from './positronHelpService.js';
import { POSITRON_HELP_COPY } from './positronHelpIdentifiers.js';
import { IPositronHelpService, POSITRON_HELP_VIEW_ID } from './positronHelpService.js';
import { POSITRON_HELP_COPY, POSITRON_HELP_FIND } from './positronHelpIdentifiers.js';
import { ICommandAndKeybindingRule, KeybindingWeight, KeybindingsRegistry } from '../../../../platform/keybinding/common/keybindingsRegistry.js';
import { IWorkbenchContribution, WorkbenchPhase, registerWorkbenchContribution2 } from '../../../common/contributions.js';
import { ViewContainer, IViewContainersRegistry, ViewContainerLocation, Extensions as ViewContainerExtensions, IViewsRegistry } from '../../../common/views.js';
Expand Down Expand Up @@ -77,7 +77,15 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
handler: accessor => { }
} satisfies ICommandAndKeybindingRule);


KeybindingsRegistry.registerCommandAndKeybindingRule({
id: POSITRON_HELP_FIND,
weight: KeybindingWeight.WorkbenchContrib,
primary: KeyMod.CtrlCmd | KeyCode.KeyF,
when: PositronHelpFocused,
handler: accessor => {
accessor.get(IPositronHelpService).find();
}
} satisfies ICommandAndKeybindingRule);

class PositronHelpContribution extends Disposable implements IWorkbenchContribution {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@

// Identifiers.
export const POSITRON_HELP_COPY = 'positron.help.copy';
export const POSITRON_HELP_FIND = 'positron.help.find';
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ export interface IPositronHelpService {
* Navigates forward.
*/
navigateForward(): void;

/**
* Show the find widget.
*/
find(): void;
}

/**
Expand Down Expand Up @@ -384,6 +389,13 @@ class PositronHelpService extends Disposable implements IPositronHelpService {
}
}

/**
* Show the find widget.
*/
find() {
this.currentHelpEntry.showFind();
}

//#endregion IPositronHelpService

//#region Private Methods
Expand Down

0 comments on commit 9daa8aa

Please sign in to comment.