From 52329d082f6278281f6f033472fe1c213e6ce2e9 Mon Sep 17 00:00:00 2001 From: Jona Date: Sun, 1 Mar 2026 12:37:25 -0500 Subject: [PATCH] fix: serialize save after blur commit for multiline edit (#75) --- media/main.js | 8 ++++++-- src/test/webview-edit-shortcuts.test.ts | 8 ++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/media/main.js b/media/main.js index 58079a4..a339fba 100644 --- a/media/main.js +++ b/media/main.js @@ -1760,8 +1760,12 @@ document.addEventListener('keydown', e => { if (editingCell && ((e.ctrlKey || e.metaKey) && e.key === 's')) { e.preventDefault(); - editingCell.blur(); - vscode.postMessage({ type: 'save' }); + const cellRef = editingCell; + cellRef && cellRef.blur(); + // Let blur's edit commit message flush first, then save. + setTimeout(() => { + vscode.postMessage({ type: 'save' }); + }, 0); } if (editingCell && e.key === 'Enter') { e.preventDefault(); diff --git a/src/test/webview-edit-shortcuts.test.ts b/src/test/webview-edit-shortcuts.test.ts index 750f88e..6ef0f5a 100644 --- a/src/test/webview-edit-shortcuts.test.ts +++ b/src/test/webview-edit-shortcuts.test.ts @@ -48,6 +48,14 @@ describe('Webview edit shortcuts', () => { assert.ok(webviewSource.includes('setSingleSelection(nextCell);')); }); + it('commits blur before save when using Ctrl/Cmd+S during edit', () => { + assert.ok(webviewSource.includes("if (editingCell && ((e.ctrlKey || e.metaKey) && e.key === 's')) {")); + assert.ok(webviewSource.includes("const cellRef = editingCell;")); + assert.ok(webviewSource.includes("cellRef && cellRef.blur();")); + assert.ok(webviewSource.includes("setTimeout(() => {")); + assert.ok(webviewSource.includes("vscode.postMessage({ type: 'save' });")); + }); + it('handles selection-mode paste as a grid operation', () => { assert.ok(webviewSource.includes("document.addEventListener('paste', e => {")); assert.ok(webviewSource.includes("type: 'pasteCells'"));