fix a UI bug where completions won't render

This commit is contained in:
Jacob Kim 2025-06-20 14:16:00 -07:00
parent 767a954951
commit 4bfbced10b
2 changed files with 5 additions and 17 deletions

View file

@ -4,7 +4,7 @@ import path from "path";
import satori from "satori";
// import puppeteer, { Browser, ScreenshotOptions } from "puppeteer";
import { BundledTheme, codeToHtml } from "shiki";
import { kebabOfStr } from "../util/text";
import { escapeForSVG, kebabOfStr } from "../util/text";
interface SyntaxHighlighterOptions {
themesDir?: string;
@ -259,7 +259,7 @@ export class SyntaxHighlighter {
// await tempPage.close();
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${dimensions.width}" height="${dimensions.height}">
<g><rect width="${dimensions.width}" height="${dimensions.height}" fill="${"#ff0000"}" />${guts}</g>
<g><rect width="${dimensions.width}" height="${dimensions.height}" fill="${backgroundColor}" />${guts}</g>
</svg>`;
console.log(svg);
@ -323,7 +323,7 @@ export class SyntaxHighlighter {
const spans = Array.from(line.childNodes)
.map((node) => {
if (node.nodeType === 3) {
return `<tspan xml:space="preserve">${node.textContent}</tspan>`;
return `<tspan xml:space="preserve">${escapeForSVG(node.textContent ?? "")}</tspan>`;
}
const el = node as HTMLElement;
@ -331,7 +331,7 @@ export class SyntaxHighlighter {
const colorMatch = style.match(/color:\s*(#[0-9a-fA-F]{6})/);
const fill = colorMatch ? ` fill="${colorMatch[1]}"` : "";
const content = el.textContent || "";
return `<tspan xml:space="preserve"${fill}>${content}</tspan>`;
return `<tspan xml:space="preserve"${fill}>${escapeForSVG(content)}</tspan>`;
})
.join("");

View file

@ -474,27 +474,15 @@ export class NextEditWindowManager {
// Get the position with offset
const offsetPosition = this.getOffsetPosition(editor, position);
const line = editor.document.lineAt(offsetPosition.line);
const endPos = line.range.end;
const zeroPos = new vscode.Position(0, 0);
const onePos = new vscode.Position(0, 1);
console.log("Line info:", {
lineNumber: offsetPosition.line,
lineLength: line.text.length,
offsetChar: offsetPosition.character,
endPos: endPos.character,
});
const range = new vscode.Range(offsetPosition, offsetPosition);
// Validate the range before applying
if (!this.isValidRange(editor, range)) {
console.error("Invalid range detected, skipping decoration");
// return;
return;
}
console.log("Applying decoration at range:", range.start, "to", range.end);
// Apply the decoration at the offset position
// editor.setDecorations(decoration, []);
editor.setDecorations(this.currentDecoration, [
{
range: new vscode.Range(offsetPosition, offsetPosition),