From 4338f565fae81d718edaadfa18d00f683597d236 Mon Sep 17 00:00:00 2001
From: Marijn Haverbeke <marijnh@gmail.com>
Date: Fri, 18 Feb 2011 12:47:55 +0100
Subject: [PATCH] add blockDocumentScroll option

---
 lib/codemirror.js | 15 +++++++++------
 manual.html       |  5 +++++
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/lib/codemirror.js b/lib/codemirror.js
index a7e4f519..dd86e2b4 100644
--- a/lib/codemirror.js
+++ b/lib/codemirror.js
@@ -418,13 +418,15 @@ var CodeMirror = (function() {
     connect(div, "paste", function(){input.focus(); fastPoll();});
     connect(input, "paste", fastPoll);
 
-    function stopScroll(e) {
-      var up = e.e.detail ? e.e.detail < 0 : e.e.wheelDelta > 0;
-      if (up ? div.scrollTop == 0 : div.scrollTop + div.clientHeight >= div.scrollHeight)
-        e.stop();
+    if (options.blockDocumentScroll) {
+      function stopScroll(e) {
+        var up = e.e.detail ? e.e.detail < 0 : e.e.wheelDelta > 0;
+        if (up ? div.scrollTop == 0 : div.scrollTop + div.clientHeight >= div.scrollHeight)
+          e.stop();
+      }
+      connect(div, "mousewheel", stopScroll);
+      connect(div, "DOMMouseScroll", stopScroll);
     }
-    connect(div, "mousewheel", stopScroll);
-    connect(div, "DOMMouseScroll", stopScroll);
 
     if (document.activeElement == input) onFocus();
     else onBlur();
@@ -1526,6 +1528,7 @@ var CodeMirror = (function() {
     enterMode: "indent",
     electricChars: true,
     keyHook: null,
+    blockDocumentScroll: true,
     lineNumbers: false,
     gutter: false,
     firstLineNumber: 1,
diff --git a/manual.html b/manual.html
index 74f52424..eea79a43 100644
--- a/manual.html
+++ b/manual.html
@@ -173,6 +173,11 @@
       indentation (only works if the mode supports indentation).
       Default is true.</dd>
 
+      <dt id="option_blockDocumentScroll"><code>blockDocumentScroll (boolean)</code></dt>
+      <dd>When true (the default) using the scroll wheel inside the
+      editor will only cause the editor to scroll, not the document
+      around it.</dd>
+
       <dt id="option_lineNumbers"><code>lineNumbers (boolean)</code></dt>
       <dd>Whether to show line numbers to the left of the editor.</dd>
 
-- 
GitLab