]> khamidou — GitHub mirrors - electron.git/commitdiff
Make history.go work
authorCheng Zhao <zcbenz@gmail.com>
Mon, 11 May 2015 08:44:01 +0000 (16:44 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 11 May 2015 08:44:01 +0000 (16:44 +0800)
atom/browser/api/atom_api_web_contents.cc
atom/browser/api/atom_api_web_contents.h
atom/browser/api/lib/navigation-controller.coffee
atom/renderer/lib/override.coffee

index ddb05cfdfeaa3da81bfa1064182466cc877a8f4b..e228a064f4138d22403c8df08e705b07e9b40da0 100644 (file)
@@ -454,6 +454,11 @@ void WebContents::GoForward() {
   web_contents()->GetController().GoForward();
 }
 
+void WebContents::GoToOffset(int offset) {
+  atom::AtomBrowserClient::SuppressRendererProcessRestartForOnce();
+  web_contents()->GetController().GoToOffset(offset);
+}
+
 int WebContents::GetRoutingID() const {
   return web_contents()->GetRoutingID();
 }
@@ -624,6 +629,7 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder(
         .SetMethod("_reloadIgnoringCache", &WebContents::ReloadIgnoringCache)
         .SetMethod("_goBack", &WebContents::GoBack)
         .SetMethod("_goForward", &WebContents::GoForward)
+        .SetMethod("_goToOffset", &WebContents::GoToOffset)
         .SetMethod("getRoutingId", &WebContents::GetRoutingID)
         .SetMethod("getProcessId", &WebContents::GetProcessID)
         .SetMethod("isCrashed", &WebContents::IsCrashed)
index aa0ee8d6f68339235cedaf0d2f31d20e8f11b5fb..e75cfb0267f0b784b82727fbe969578eda1099f6 100644 (file)
@@ -55,7 +55,7 @@ class WebContents : public mate::EventEmitter,
   void ReloadIgnoringCache();
   void GoBack();
   void GoForward();
-  void GoToIndex();
+  void GoToOffset(int offset);
   int GetRoutingID() const;
   int GetProcessID() const;
   bool IsCrashed() const;
index 82c4ab4da747b8388dab766e68604e3f9d2f4dee..f7945e07bf401b26a24057ed98afd71b609278e5 100644 (file)
@@ -94,7 +94,12 @@ class NavigationController
 
   goToOffset: (offset) ->
     return unless @canGoToOffset offset
-    @goToIndex @currentIndex + offset
+    pendingIndex = @currentIndex + offset
+    if @inPageIndex > -1 and pendingIndex >= @inPageIndex
+      @pendingIndex = pendingIndex
+      @webContents._goToOffset offset
+    else
+      @goToIndex pendingIndex
 
   getActiveIndex: ->
     if @pendingIndex is -1 then @currentIndex else @pendingIndex
index 1bc1e612c5c297447b2fb50a09a4db80847a6c03..1ca6e692ba21148b35bef0dcd7eca9f9d1973356 100644 (file)
@@ -87,3 +87,4 @@ sendHistoryOperation = (args...) ->
   ipc.send 'ATOM_SHELL_NAVIGATION_CONTROLLER', args...
 window.history.back = -> sendHistoryOperation 'goBack'
 window.history.forward = -> sendHistoryOperation 'goForward'
+window.history.go = (offset) -> sendHistoryOperation 'goToOffset', offset