Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't jump to the next finding if the caret is placed somewhere else #17

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions src/findInPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ function removeElement () {
function creatEventHandler () {
this[documentKeydown] = (function (e) {
if (!this[hasOpened]) return

var selection = window.getSelection()
if(selection.focusNode && selection.focusNode !== this[findBox]) return

onKeydown.call(this, e)
}).bind(this)
this[events].push({ ele: document, name: 'keydown', fn: this[documentKeydown] })
Expand Down Expand Up @@ -359,7 +363,8 @@ function focusInput (doBlur = false) {
}

function wrapInput (inputEle, caseEle, timeout = 50) {
inputEle.type = 'password'
// inputEle.type = 'password'
inputEle.style['visibility'] = 'hidden'
caseEle.style['visibility'] = 'hidden'

setTimeout(() => {
Expand All @@ -370,13 +375,20 @@ function wrapInput (inputEle, caseEle, timeout = 50) {
}, timeout)
}
function unwrapInput (inputEle, caseEle) {
inputEle.type = 'text'
// inputEle.type = 'text'
inputEle.style['visibility'] = 'visible'
caseEle.style['visibility'] = 'visible'
}

function onInput () {
setTimeout(() => {
this.previousInputTimeouts = this.previousInputTimeouts || []
this.previousInputTimeouts.push(setTimeout(() => {
if (this[inComposition]) return

while(this.previousInputTimeouts.length) {
clearTimeout(this.previousInputTimeouts.shift())
}

this[action] = 'input'
let text = this[findInput].value
if (text && text !== this[lastText]) {
Expand All @@ -389,15 +401,20 @@ function onInput () {
lockNext.call(this)
focusInput.call(this, true)
}
}, 50)
}, 50))
}

function onKeydown (e) {
if (this[inComposition] || !e) return
let text;
switch (e.code) {
case 'Enter':
text = this[findInput].value
if (!text) return
e.shiftKey ? findKeep.call(this, false) : findKeep.call(this, true)
break
case 'NumpadEnter':
let text = this[findInput].value
text = this[findInput].value
if (!text) return
e.shiftKey ? findKeep.call(this, false) : findKeep.call(this, true)
break
Expand Down