[ty] Fix Escape handler in playground (#21397)

This commit is contained in:
Micha Reiser 2025-11-12 08:54:14 +01:00 committed by GitHub
parent 725ae69773
commit 19c7994e90
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -70,13 +70,16 @@ export default function Editor({
const serverRef = useRef<PlaygroundServer | null>(null);
if (serverRef.current != null) {
serverRef.current.update({
files,
workspace,
onOpenFile,
onVendoredFileChange,
onBackToUserFile,
});
serverRef.current.update(
{
files,
workspace,
onOpenFile,
onVendoredFileChange,
onBackToUserFile,
},
isViewingVendoredFile,
);
}
// Update the diagnostics in the editor.
@ -200,6 +203,7 @@ class PlaygroundServer
private rangeSemanticTokensDisposable: IDisposable;
private signatureHelpDisposable: IDisposable;
private documentHighlightDisposable: IDisposable;
private inVendoredFileCondition: editor.IContextKey<boolean>;
// Cache for vendored file handles
private vendoredFileHandles = new Map<string, FileHandle>();
@ -249,8 +253,16 @@ class PlaygroundServer
this.documentHighlightDisposable =
monaco.languages.registerDocumentHighlightProvider("python", this);
this.inVendoredFileCondition = editor.createContextKey<boolean>(
"inVendoredFile",
false,
);
// Register Esc key command
editor.addCommand(monaco.KeyCode.Escape, this.props.onBackToUserFile);
editor.addCommand(
monaco.KeyCode.Escape,
() => this.props.onBackToUserFile(),
"inVendoredFile",
);
}
triggerCharacters: string[] = ["."];
@ -452,8 +464,9 @@ class PlaygroundServer
return undefined;
}
update(props: PlaygroundServerProps) {
update(props: PlaygroundServerProps, isViewingVendoredFile: boolean) {
this.props = props;
this.inVendoredFileCondition.set(isViewingVendoredFile);
}
private getOrCreateVendoredFileHandle(vendoredPath: string): FileHandle {