Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Track presence of internal find state
Browse files Browse the repository at this point in the history
Auditors: @jkup

The trick to this was to keep track in our app state when electron has find state defined.  When it is not defined always do the findFirst call
  • Loading branch information
bbondy committed Aug 27, 2016
1 parent bb4ac34 commit 313d743
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
3 changes: 2 additions & 1 deletion docs/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ WindowStore
searchString: string, // the string being searched
caseSensitivity: boolean, // whether we are doing a case sensitive search
numberOfMatches: number, // Total number of matches on the page
activeMatchOrdinal: number // The current ordinal of the match
activeMatchOrdinal: number, // The current ordinal of the match
internalFindStatePresent: boolean // true if a find-first (ie findNext: false) call has been made
}
unloaded: boolean, // true if the tab is unloaded

Expand Down
6 changes: 3 additions & 3 deletions js/actions/webviewActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const webviewActions = {
}
},

findInPage: function (searchString, caseSensitivity, forward, webview) {
findInPage: function (searchString, caseSensitivity, forward, findNext, webview) {
webview = webview || getWebview()
if (!webview) {
return
Expand All @@ -92,8 +92,8 @@ const webviewActions = {
if (searchString) {
webview.findInPage(searchString, {
matchCase: caseSensitivity,
forward: forward !== undefined ? forward : true,
findNext: forward !== undefined
forward,
findNext
})
} else {
webview.stopFindInPage('clearSelection')
Expand Down
6 changes: 3 additions & 3 deletions js/components/findbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ class FindBar extends ImmutableComponent {
}

onFindFirst () {
this.props.onFind(this.searchString, this.isCaseSensitive)
this.props.onFind(this.searchString, this.isCaseSensitive, true, false)
}

onFindNext () {
this.props.onFind(this.searchString, this.isCaseSensitive, true)
this.props.onFind(this.searchString, this.isCaseSensitive, true, this.props.findDetail.get('internalFindStatePresent'))
}

onFindPrev () {
this.props.onFind(this.searchString, this.isCaseSensitive, false)
this.props.onFind(this.searchString, this.isCaseSensitive, false, this.props.findDetail.get('internalFindStatePresent'))
}

/**
Expand Down
2 changes: 1 addition & 1 deletion js/components/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ class Frame extends ImmutableComponent {
}
const searchString = this.props.findDetail && this.props.findDetail.get('searchString')
if (searchString) {
webviewActions.findInPage(searchString, this.props.findDetail && this.props.findDetail.get('caseSensitivity') || undefined, forward, this.webview)
webviewActions.findInPage(searchString, this.props.findDetail && this.props.findDetail.get('caseSensitivity') || undefined, forward, this.props.findDetail.get('internalFindStatePresent'), this.webview)
}
}

Expand Down
12 changes: 10 additions & 2 deletions js/components/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -634,10 +634,18 @@ class Main extends ImmutableComponent {
const activeFrame = FrameStateUtil.getActiveFrame(this.props.windowState)
windowActions.setFindbarShown(activeFrame, false)
webviewActions.stopFindInPage()
windowActions.setFindDetail(this.frame, Immutable.fromJS({
internalFindStatePresent: false
}))
}

onFind (searchString, caseSensitivity, forward) {
webviewActions.findInPage(searchString, caseSensitivity, forward)
onFind (searchString, caseSensitivity, forward, findNext) {
webviewActions.findInPage(searchString, caseSensitivity, forward, findNext)
if (!findNext) {
windowActions.setFindDetail(this.frame, Immutable.fromJS({
internalFindStatePresent: true
}))
}
}

onTabContextMenu (e) {
Expand Down

0 comments on commit 313d743

Please sign in to comment.