Compare commits

...

3 Commits

Author SHA1 Message Date
Andrew df646b34e2 amend 2024-10-31 20:31:45 -07:00
Andrew 5e41a555dc add inset-update test 2024-10-31 20:31:07 -07:00
mp 4a9962a7fc add native updateEditorInset() function 2024-10-31 19:24:44 -07:00
6 changed files with 47 additions and 9 deletions
-8
View File
@@ -6024,14 +6024,6 @@
"node": ">=10"
}
},
"node_modules/monaco-editor": {
"version": "0.52.0",
"resolved": "https://registry.npmjs.org/monaco-editor/-/monaco-editor-0.52.0.tgz",
"integrity": "sha512-OeWhNpABLCeTqubfqLMXGsqf6OmPU6pHM85kF3dhy6kq5hnhuVS1p3VrEW/XhWHc71P2tHyS5JFySD8mgs1crw==",
"dev": true,
"license": "MIT",
"peer": true
},
"node_modules/ms": {
"version": "2.1.3",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
@@ -234,6 +234,12 @@ export class DiffProvider implements vscode.CodeLensProvider {
updateWebviewHTML(inset.webview, this._extensionUri, { jsOutLocation: 'dist/webviews/diffline/index.js', cssOutLocation: 'dist/webviews/styles.css' },
{ text }
)
setTimeout(() => {
console.log('updating!')
vscode.window.updateWebviewTextEditorInset(inset.handle, line + 2, height)
}, 2000)
return inset
})
@@ -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) {
+2
View File
@@ -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;
}
}