don't autojump to first match when opening search
This commit is contained in:
parent
89431615b3
commit
2ed936af00
|
@ -22,6 +22,7 @@ onDOMready().then(() => {
|
||||||
const RX_MAYBE_REGEXP = /^\s*\/(.+?)\/([simguy]*)\s*$/;
|
const RX_MAYBE_REGEXP = /^\s*\/(.+?)\/([simguy]*)\s*$/;
|
||||||
|
|
||||||
const state = {
|
const state = {
|
||||||
|
firstRun: true,
|
||||||
// used for case-sensitive matching directly
|
// used for case-sensitive matching directly
|
||||||
find: '',
|
find: '',
|
||||||
// used when /re/ is detected or for case-insensitive matching
|
// used when /re/ is detected or for case-insensitive matching
|
||||||
|
@ -241,6 +242,7 @@ onDOMready().then(() => {
|
||||||
} else {
|
} else {
|
||||||
showTally(0, 0);
|
showTally(0, 0);
|
||||||
}
|
}
|
||||||
|
state.firstRun = false;
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -559,6 +561,7 @@ onDOMready().then(() => {
|
||||||
|
|
||||||
function createDialog(type) {
|
function createDialog(type) {
|
||||||
state.originalFocus = document.activeElement;
|
state.originalFocus = document.activeElement;
|
||||||
|
state.firstRun = true;
|
||||||
|
|
||||||
const dialog = state.dialog = template.searchReplaceDialog.cloneNode(true);
|
const dialog = state.dialog = template.searchReplaceDialog.cloneNode(true);
|
||||||
Object.assign(dialog, DIALOG_PROPS.dialog);
|
Object.assign(dialog, DIALOG_PROPS.dialog);
|
||||||
|
@ -766,7 +769,7 @@ onDOMready().then(() => {
|
||||||
|
|
||||||
// scrolls the editor to reveal the match
|
// scrolls the editor to reveal the match
|
||||||
function makeMatchVisible(cm, searchCursor) {
|
function makeMatchVisible(cm, searchCursor) {
|
||||||
const canFocus = !state.dialog || !state.dialog.contains(document.activeElement);
|
const canFocus = !state.firstRun && (!state.dialog || !state.dialog.contains(document.activeElement));
|
||||||
state.cm = cm;
|
state.cm = cm;
|
||||||
|
|
||||||
// scroll within the editor
|
// scroll within the editor
|
||||||
|
@ -779,12 +782,11 @@ onDOMready().then(() => {
|
||||||
unclosedOp: !cm.curOp,
|
unclosedOp: !cm.curOp,
|
||||||
});
|
});
|
||||||
if (!cm.curOp) cm.startOperation();
|
if (!cm.curOp) cm.startOperation();
|
||||||
if (canFocus) cm.setSelection(searchCursor.pos.from, searchCursor.pos.to);
|
if (!state.firstRun) {
|
||||||
cm.scrollIntoView(searchCursor.pos, SCROLL_REVEAL_MIN_PX);
|
editor.scrollToEditor(cm);
|
||||||
|
cm.setSelection(searchCursor.pos.from, searchCursor.pos.to);
|
||||||
// scroll to the editor itself
|
cm.scrollIntoView(searchCursor.pos, SCROLL_REVEAL_MIN_PX);
|
||||||
editor.scrollToEditor(cm);
|
}
|
||||||
|
|
||||||
// focus or expose as the current search target
|
// focus or expose as the current search target
|
||||||
clearMarker();
|
clearMarker();
|
||||||
if (canFocus) {
|
if (canFocus) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user