mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-17 19:27:11 +00:00
[ty] Fix Escape handler in playground (#21397)
This commit is contained in:
parent
725ae69773
commit
19c7994e90
1 changed files with 22 additions and 9 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue