From 3abafa76ec9761e017fb88cfee5e4ef8f5e28324 Mon Sep 17 00:00:00 2001 From: Mathew Pareles Date: Wed, 15 Jan 2025 18:14:09 -0800 Subject: [PATCH] fix cmd+k tabbing --- .../void/browser/inlineDiffsService.ts | 42 ++++++++++++++++++- .../src/quick-edit-tsx/QuickEditChat.tsx | 2 +- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/vs/workbench/contrib/void/browser/inlineDiffsService.ts b/src/vs/workbench/contrib/void/browser/inlineDiffsService.ts index a678bf58..d6f38cfb 100644 --- a/src/vs/workbench/contrib/void/browser/inlineDiffsService.ts +++ b/src/vs/workbench/contrib/void/browser/inlineDiffsService.ts @@ -61,6 +61,43 @@ registerColor('void.sweepIdxBG', configOfBG(sweepIdxBG), '', true); + + +const getLeadingWhitespacePx = (editor: ICodeEditor, startLine: number): number => { + + const model = editor.getModel(); + if (!model) { + return 0; + } + + // Get the line content, defaulting to empty string if line doesn't exist + const lineContent = model.getLineContent(startLine) || ''; + + // Find the first non-whitespace character + const firstNonWhitespaceIndex = lineContent.search(/\S/); + + // Extract leading whitespace, handling case where line is all whitespace + const leadingWhitespace = firstNonWhitespaceIndex === -1 + ? lineContent + : lineContent.slice(0, firstNonWhitespaceIndex); + + // Get font information from editor render options + const { tabSize: numSpacesInTab } = model.getFormattingOptions(); + const spaceWidth = editor.getOption(EditorOption.fontInfo).spaceWidth; + const tabWidth = numSpacesInTab * spaceWidth; + + let paddingLeft = 0; + for (const char of leadingWhitespace) { + if (char === '\t') { + paddingLeft += tabWidth + } else if (char === ' ') { + paddingLeft += spaceWidth; + } + } + + return paddingLeft; +}; + // similar to ServiceLLM export type StartApplyingOpts = { featureName: 'Ctrl+K'; @@ -400,10 +437,14 @@ class InlineDiffsService extends Disposable implements IInlineDiffsService { let viewZone_: IViewZone | null = null const textAreaRef: { current: HTMLTextAreaElement | null } = { current: null } + + const paddingLeft = getLeadingWhitespacePx(editor, ctrlKZone.startLine) + const itemId = this._consistentEditorItemService.addToEditor(editor, () => { const domNode = document.createElement('div'); domNode.style.zIndex = '1' domNode.style.height = 'auto' + domNode.style.paddingLeft = `${paddingLeft}px` const viewZone: IViewZone = { afterLineNumber: ctrlKZone.startLine - 1, domNode: domNode, @@ -418,7 +459,6 @@ class InlineDiffsService extends Disposable implements IInlineDiffsService { zoneId = accessor.addZone(viewZone) }) - // mount react this._instantiationService.invokeFunction(accessor => { mountCtrlK(domNode, accessor, { diff --git a/src/vs/workbench/contrib/void/browser/react/src/quick-edit-tsx/QuickEditChat.tsx b/src/vs/workbench/contrib/void/browser/react/src/quick-edit-tsx/QuickEditChat.tsx index 2088de01..9b32cf56 100644 --- a/src/vs/workbench/contrib/void/browser/react/src/quick-edit-tsx/QuickEditChat.tsx +++ b/src/vs/workbench/contrib/void/browser/react/src/quick-edit-tsx/QuickEditChat.tsx @@ -80,7 +80,7 @@ export const QuickEditChat = ({ const keybindingString = accessor.get('IKeybindingService').lookupKeybinding(VOID_CTRL_K_ACTION_ID)?.getLabel() - return
+ return