Bug 1250398 - Disable APZ for source editors. r=gl draft
authorJ. Ryan Stinnett <jryans@gmail.com>
Fri, 19 Feb 2016 20:08:10 -0600
changeset 335045 188533c48d7b3288ef3756cab76b0a42b4b7873b
parent 334723 675f335b6b44b0a85aa8a8d5066cbeaaf3d1bc64
child 515057 eae5276432d58824b54888cba13e40dd842e30c6
push id11703
push userbmo:jryans@gmail.com
push dateFri, 26 Feb 2016 20:52:47 +0000
reviewersgl
bugs1250398
milestone47.0a1
Bug 1250398 - Disable APZ for source editors. r=gl MozReview-Commit-ID: JmUuoobDr7y
devtools/client/sourceeditor/editor.js
--- a/devtools/client/sourceeditor/editor.js
+++ b/devtools/client/sourceeditor/editor.js
@@ -297,16 +297,40 @@ Editor.prototype = {
 
       win.CodeMirror.commands.save = () => this.emit("saveRequested");
 
       // Create a CodeMirror instance add support for context menus,
       // overwrite the default controller (otherwise items in the top and
       // context menus won't work).
 
       cm = win.CodeMirror(win.document.body, this.config);
+
+      // Disable APZ for source editors. It currently causes the line numbers to
+      // "tear off" and swim around on top of the content. Bug 1160601 tracks
+      // finding a solution that allows APZ to work with CodeMirror.
+      cm.getScrollerElement().addEventListener("wheel", ev => {
+        // By handling the wheel events ourselves, we force the platform to
+        // scroll synchronously, like it did before APZ. However, we lose smooth
+        // scrolling for users with mouse wheels. This seems acceptible vs.
+        // doing nothing and letting the gutter slide around.
+        ev.preventDefault();
+
+        let { deltaX, deltaY } = ev;
+
+        if (ev.deltaMode == ev.DOM_DELTA_LINE) {
+          deltaX *= cm.defaultCharWidth();
+          deltaY *= cm.defaultTextHeight();
+        } else if (ev.deltaMode == ev.DOM_DELTA_PAGE) {
+          deltaX *= cm.getWrapperElement().clientWidth;
+          deltaY *= cm.getWrapperElement().clientHeight;
+        }
+
+        cm.getScrollerElement().scrollBy(deltaX, deltaY);
+      });
+
       cm.getWrapperElement().addEventListener("contextmenu", ev => {
         ev.preventDefault();
 
         if (!this.config.contextMenu) {
           return;
         }
 
         let popup = this.config.contextMenu;