mirror of
https://github.com/voideditor/void
synced 2026-05-24 09:58:23 +00:00
add native updateEditorInset() function
This commit is contained in:
parent
dd48db0ed3
commit
4a9962a7fc
4 changed files with 41 additions and 1 deletions
|
|
@ -12,19 +12,25 @@ import { CtrlKWebviewProvider } from './providers/CtrlKWebviewProvider';
|
|||
|
||||
// this comes from vscode.proposed.editorInsets.d.ts
|
||||
declare module 'vscode' {
|
||||
|
||||
export interface WebviewEditorInset {
|
||||
readonly editor: vscode.TextEditor;
|
||||
readonly line: number;
|
||||
readonly height: number;
|
||||
readonly webview: vscode.Webview;
|
||||
readonly handle: number;
|
||||
readonly onDidDispose: Event<void>;
|
||||
dispose(): void;
|
||||
}
|
||||
|
||||
export namespace window {
|
||||
export function createWebviewTextEditorInset(editor: vscode.TextEditor, line: number, height: number, options?: vscode.WebviewOptions): WebviewEditorInset;
|
||||
export function updateWebviewTextEditorInset(handle: number, line: number, height: number): WebviewEditorInset;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
const roundRangeToLines = (selection: vscode.Selection) => {
|
||||
let endLine = selection.end.character === 0 ? selection.end.line - 1 : selection.end.line // e.g. if the user triple clicks, it selects column=0, line=line -> column=0, line=line+1
|
||||
return new vscode.Range(selection.start.line, 0, endLine, Number.MAX_SAFE_INTEGER)
|
||||
|
|
|
|||
|
|
@ -826,6 +826,10 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
|
|||
// checkProposedApiEnabled(extension, 'editorInsets'); // Void commented this out
|
||||
return extHostEditorInsets.createWebviewEditorInset(editor, line, height, options, extension);
|
||||
},
|
||||
// Void created this function:
|
||||
updateWebviewTextEditorInset(handle: number, line: number, height: number): vscode.WebviewEditorInset {
|
||||
return extHostEditorInsets.updateEditorInset(handle, line, height);
|
||||
},
|
||||
createTerminal(nameOrOptions?: vscode.TerminalOptions | vscode.ExtensionTerminalOptions | string, shellPath?: string, shellArgs?: readonly string[] | string): vscode.Terminal {
|
||||
if (typeof nameOrOptions === 'object') {
|
||||
if ('pty' in nameOrOptions) {
|
||||
|
|
|
|||
|
|
@ -99,11 +99,11 @@ export class ExtHostEditorInsets implements ExtHostEditorInsetsShape {
|
|||
};
|
||||
|
||||
const inset = new class implements vscode.WebviewEditorInset {
|
||||
|
||||
readonly editor: vscode.TextEditor = editor;
|
||||
readonly line: number = line;
|
||||
readonly height: number = height;
|
||||
readonly webview: vscode.Webview = webview;
|
||||
readonly handle: number = handle;
|
||||
readonly onDidDispose: vscode.Event<void> = onDidDispose.event;
|
||||
|
||||
dispose(): void {
|
||||
|
|
@ -125,6 +125,34 @@ export class ExtHostEditorInsets implements ExtHostEditorInsetsShape {
|
|||
return inset;
|
||||
}
|
||||
|
||||
|
||||
updateEditorInset(handle: number, line: number, height: number): vscode.WebviewEditorInset {
|
||||
const _inset = this._insets.get(handle);
|
||||
|
||||
if (!_inset) {
|
||||
throw new Error(`Inset with handle ${handle} not found`);
|
||||
}
|
||||
|
||||
const { editor, onDidReceiveMessage, inset: { webview, onDidDispose, dispose } } = _inset
|
||||
|
||||
const inset = new class implements vscode.WebviewEditorInset {
|
||||
readonly editor: vscode.TextEditor = editor;
|
||||
readonly line: number = line;
|
||||
readonly height: number = height;
|
||||
readonly webview: vscode.Webview = webview;
|
||||
readonly handle: number = handle;
|
||||
readonly onDidDispose: vscode.Event<void> = onDidDispose;
|
||||
dispose = dispose
|
||||
};
|
||||
|
||||
this._insets.set(handle, { editor, inset: inset, onDidReceiveMessage });
|
||||
// _inset?.onDidReceiveMessage.fire({});
|
||||
|
||||
return inset
|
||||
}
|
||||
|
||||
|
||||
|
||||
$onDidDispose(handle: number): void {
|
||||
const value = this._insets.get(handle);
|
||||
if (value) {
|
||||
|
|
|
|||
|
|
@ -12,11 +12,13 @@ declare module 'vscode' {
|
|||
readonly line: number;
|
||||
readonly height: number;
|
||||
readonly webview: Webview;
|
||||
readonly handle: number;
|
||||
readonly onDidDispose: Event<void>;
|
||||
dispose(): void;
|
||||
}
|
||||
|
||||
export namespace window {
|
||||
export function createWebviewTextEditorInset(editor: TextEditor, line: number, height: number, options?: WebviewOptions): WebviewEditorInset;
|
||||
export function updateWebviewTextEditorInset(handle: number, line: number, height: number): WebviewEditorInset;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue