Handle when in-page entries are cleared
This commit is contained in:
parent
82ffa4d2b1
commit
2bb7497312
1 changed files with 16 additions and 12 deletions
|
@ -14,22 +14,28 @@ class NavigationController
|
||||||
@history = []
|
@history = []
|
||||||
@currentIndex = -1
|
@currentIndex = -1
|
||||||
@pendingIndex = -1
|
@pendingIndex = -1
|
||||||
|
@inPageIndex = -1
|
||||||
|
|
||||||
@webContents.on 'navigation-entry-commited', (event, url, inPage, replaceEntry) =>
|
@webContents.on 'navigation-entry-commited', (event, url, inPage, replaceEntry) =>
|
||||||
console.log 'navigation-entry-commited', url, inPage, replaceEntry
|
if @inPageIndex > -1 and not inPage
|
||||||
|
# Navigated to a new page, clear in-page mark.
|
||||||
|
@inPageIndex = -1
|
||||||
|
else if @inPageIndex is -1 and inPage
|
||||||
|
# Started in-page navigations.
|
||||||
|
@inPageIndex = @currentIndex
|
||||||
|
|
||||||
if @pendingIndex >= 0 # Go to index.
|
if @pendingIndex >= 0 # Go to index.
|
||||||
@currentIndex = @pendingIndex
|
@currentIndex = @pendingIndex
|
||||||
@pendingIndex = -1
|
@pendingIndex = -1
|
||||||
@history[@currentIndex] = {url, inPage}
|
@history[@currentIndex] = url
|
||||||
else if replaceEntry # Non-user initialized navigation.
|
else if replaceEntry # Non-user initialized navigation.
|
||||||
@history[@currentIndex] = {url, inPage}
|
@history[@currentIndex] = url
|
||||||
else # Normal navigation.
|
else # Normal navigation.
|
||||||
@history = @history.slice 0, @currentIndex + 1 # Clear history.
|
@history = @history.slice 0, @currentIndex + 1 # Clear history.
|
||||||
currentEntry = @history[@currentIndex]
|
currentEntry = @history[@currentIndex]
|
||||||
if currentEntry?.url isnt url or currentEntry?.inPage isnt inPage
|
if currentEntry?.url isnt url
|
||||||
@currentIndex++
|
@currentIndex++
|
||||||
@history.push {url, inPage}
|
@history.push url
|
||||||
|
|
||||||
loadUrl: (url, options={}) ->
|
loadUrl: (url, options={}) ->
|
||||||
@pendingIndex = -1
|
@pendingIndex = -1
|
||||||
|
@ -39,7 +45,7 @@ class NavigationController
|
||||||
if @currentIndex is -1
|
if @currentIndex is -1
|
||||||
''
|
''
|
||||||
else
|
else
|
||||||
@history[@currentIndex].url
|
@history[@currentIndex]
|
||||||
|
|
||||||
stop: ->
|
stop: ->
|
||||||
@pendingIndex = -1
|
@pendingIndex = -1
|
||||||
|
@ -68,20 +74,18 @@ class NavigationController
|
||||||
goBack: ->
|
goBack: ->
|
||||||
return unless @canGoBack()
|
return unless @canGoBack()
|
||||||
@pendingIndex = @getActiveIndex() - 1
|
@pendingIndex = @getActiveIndex() - 1
|
||||||
pendingEntry = @history[@pendingIndex]
|
if @inPageIndex > -1 and @pendingIndex >= @inPageIndex
|
||||||
if pendingEntry.inPage
|
|
||||||
@webContents._goBack()
|
@webContents._goBack()
|
||||||
else
|
else
|
||||||
@webContents._loadUrl pendingEntry.url, {}
|
@webContents._loadUrl @history[@pendingIndex], {}
|
||||||
|
|
||||||
goForward: ->
|
goForward: ->
|
||||||
return unless @canGoForward()
|
return unless @canGoForward()
|
||||||
@pendingIndex = @getActiveIndex() + 1
|
@pendingIndex = @getActiveIndex() + 1
|
||||||
pendingEntry = @history[@pendingIndex]
|
if @inPageIndex > -1 and @pendingIndex >= @inPageIndex
|
||||||
if pendingEntry.inPage
|
|
||||||
@webContents._goForward()
|
@webContents._goForward()
|
||||||
else
|
else
|
||||||
@webContents._loadUrl pendingEntry.url, {}
|
@webContents._loadUrl @history[@pendingIndex], {}
|
||||||
|
|
||||||
goToIndex: (index) ->
|
goToIndex: (index) ->
|
||||||
return unless @canGoToIndex index
|
return unless @canGoToIndex index
|
||||||
|
|
Loading…
Add table
Reference in a new issue