From 2bb74973121a0933237bed60eb0c0037e465bff9 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 11 May 2015 16:37:53 +0800 Subject: [PATCH] Handle when in-page entries are cleared --- atom/browser/api/lib/navigation-controller.coffee | 28 +++++++++++++---------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/atom/browser/api/lib/navigation-controller.coffee b/atom/browser/api/lib/navigation-controller.coffee index 9c3159c..82c4ab4 100644 --- a/atom/browser/api/lib/navigation-controller.coffee +++ b/atom/browser/api/lib/navigation-controller.coffee @@ -14,22 +14,28 @@ class NavigationController @history = [] @currentIndex = -1 @pendingIndex = -1 + @inPageIndex = -1 @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. @currentIndex = @pendingIndex @pendingIndex = -1 - @history[@currentIndex] = {url, inPage} + @history[@currentIndex] = url else if replaceEntry # Non-user initialized navigation. - @history[@currentIndex] = {url, inPage} + @history[@currentIndex] = url else # Normal navigation. @history = @history.slice 0, @currentIndex + 1 # Clear history. currentEntry = @history[@currentIndex] - if currentEntry?.url isnt url or currentEntry?.inPage isnt inPage + if currentEntry?.url isnt url @currentIndex++ - @history.push {url, inPage} + @history.push url loadUrl: (url, options={}) -> @pendingIndex = -1 @@ -39,7 +45,7 @@ class NavigationController if @currentIndex is -1 '' else - @history[@currentIndex].url + @history[@currentIndex] stop: -> @pendingIndex = -1 @@ -68,20 +74,18 @@ class NavigationController goBack: -> return unless @canGoBack() @pendingIndex = @getActiveIndex() - 1 - pendingEntry = @history[@pendingIndex] - if pendingEntry.inPage + if @inPageIndex > -1 and @pendingIndex >= @inPageIndex @webContents._goBack() else - @webContents._loadUrl pendingEntry.url, {} + @webContents._loadUrl @history[@pendingIndex], {} goForward: -> return unless @canGoForward() @pendingIndex = @getActiveIndex() + 1 - pendingEntry = @history[@pendingIndex] - if pendingEntry.inPage + if @inPageIndex > -1 and @pendingIndex >= @inPageIndex @webContents._goForward() else - @webContents._loadUrl pendingEntry.url, {} + @webContents._loadUrl @history[@pendingIndex], {} goToIndex: (index) -> return unless @canGoToIndex index -- 2.7.4