diff --git a/index.ts b/index.ts index 7e9906b0..2afff2d5 100644 --- a/index.ts +++ b/index.ts @@ -552,6 +552,9 @@ export class ModalEditor extends CustomEditor { private readonly cursorShapeRuntime: CursorShapeRuntime | null; private lastCursorShapeSequence: CursorShapeSequence | null = null; + private lastLineCacheKey: { line: string; width: number; label: string } = { line: "", width: 0, label: "" }; + private lastLineCacheResult: string = ""; + // Unnamed register private unnamedRegister: string = ""; private clipboardMirrorPolicy: ClipboardMirrorPolicy = DEFAULT_CLIPBOARD_MIRROR_POLICY; @@ -3021,7 +3024,15 @@ export class ModalEditor extends CustomEditor { const last = lines.length - 1; const lastLine = lines[last]; if (lastLine && visibleWidth(lastLine) >= visibleWidth(rawLabel)) { - lines[last] = truncateToWidth(lastLine, width - visibleWidth(rawLabel), "") + label; + const contentWidth = width - visibleWidth(rawLabel); + const k = this.lastLineCacheKey; + if (lastLine !== k.line || contentWidth !== k.width || label !== k.label) { + k.line = lastLine; + k.width = contentWidth; + k.label = label; + this.lastLineCacheResult = truncateToWidth(lastLine, contentWidth, "") + label; + } + lines[last] = this.lastLineCacheResult; } else { lines[last] = label; }