diff --git a/src/vs/workbench/contrib/webview/browser/pre/main.js b/src/vs/workbench/contrib/webview/browser/pre/main.js index 16cc137a10b..ed2e896233c 100644 --- a/src/vs/workbench/contrib/webview/browser/pre/main.js +++ b/src/vs/workbench/contrib/webview/browser/pre/main.js @@ -989,15 +989,21 @@ onDomReady(() => { assertIsDefined(target.contentDocument).execCommand(data); }); + /** @type {string | undefined} */ + let lastFindValue = undefined; + hostMessaging.onMessage('find', (_event, data) => { const target = getActiveFrame(); if (!target) { return; } - // Reset selection so we start search after current find result - const selection = target.contentWindow.getSelection(); - selection.collapse(selection.anchorNode); + if (!data.previous && lastFindValue !== data.value) { + // Reset selection so we start search at the head of the last search + const selection = target.contentWindow.getSelection(); + selection.collapse(selection.anchorNode); + } + lastFindValue = data.value; const didFind = (/** @type {any} */ (target.contentWindow)).find( data.value, @@ -1016,6 +1022,8 @@ onDomReady(() => { return; } + lastFindValue = undefined; + if (!data.clearSelection) { const selection = target.contentWindow.getSelection(); for (let i = 0; i < selection.rangeCount; i++) {