mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-27 20:13:32 +01:00
Fix find on web not handling next properly
Fix #138275 Introduced bybbc10afedaThe root problembbc10afedafixed is that `window.find` starts after the current selection. If your document consists of `abc abcd` for example, the following happens: 1. Type `a` in the find box 1. The first `a` is correctly highlighted 1. Type `b` to refine the search 1. The search no longer sees the first `a`, so we skip ahead to the second `a`, which is unexpected To fix this, I added code to collapse the selection before continuing the search. However we were also collapsing the selection when you hit the next button, which just resulted in the same word being re-selected again instead of skipping ahead to the next word. This fix avoids collapsing the selection when you are simply pressing next
This commit is contained in:
@@ -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++) {
|
||||
|
||||
Reference in New Issue
Block a user