From 5c1aef3ccf4991b3ddb7b1032fe1d6a96ac98a82 Mon Sep 17 00:00:00 2001 From: C9 Date: Sat, 24 Nov 2012 05:28:39 -0500 Subject: [PATCH 1/3] First run test of iOS scrolling --- demo/kitchen-sink/demo.js | 75 +++++++++++++++++++++++++++++++++++- demo/kitchen-sink/styles.css | 15 ++++++++ kitchen-sink.html | 8 ++++ 3 files changed, 96 insertions(+), 2 deletions(-) diff --git a/demo/kitchen-sink/demo.js b/demo/kitchen-sink/demo.js index 29be01be..7a2008e8 100644 --- a/demo/kitchen-sink/demo.js +++ b/demo/kitchen-sink/demo.js @@ -177,8 +177,6 @@ var keybindings = { }) }; - - /*********** manage layout ***************************/ var consoleHeight = 20; function onResize() { @@ -395,6 +393,79 @@ bindCheckbox("highlight_token", function(checked) { } }); +bindCheckbox("mobile_mode", function(checked) { + //var editor = env.editor; + /** Mobile test **/ + if (checked) { + var editorElement = document.getElementById("editor"); + var editorElementChild = editorElement.childNodes[0]; + + var left = editorElement.offsetLeft; + var height = editorElement.style.height; + var totalHeight = env.editor.session.getLength() * env.editor.renderer.lineHeight; + var width = document.documentElement.clientWidth - left; + + var mobileScrollDiv = document.createElement("div"); + mobileScrollDiv.id = "scrolldiv_container"; + mobileScrollDiv.style.width = width + "px"; + //mobileScrollDiv.style.left = left + "px"; + mobileScrollDiv.style.height = height; + + var mobileScrollDivChild = document.createElement("div"); + mobileScrollDivChild.id = "scrolldiv_child"; + mobileScrollDivChild.style.height = totalHeight + "px"; + mobileScrollDiv.appendChild(mobileScrollDivChild); + editorElement.appendChild(mobileScrollDiv); + + var movementDiff = 0, lastMovementPos = 0; + var timeDiff = 0, lastTime = 0; + document.addEventListener("touchmove", function(e) { + //console.log(" TOUCHMOVE", e, mobileScrollDiv.scrollTop); + movementDiff = mobileScrollDiv.scrollTop - lastMovementPos; + lastMovementPos = mobileScrollDiv.scrollTop; + + timeDiff = e.timeStamp - lastTime; + lastTime = e.timeStamp; + }); + var movingTimer; + document.addEventListener("touchstart", function(e) { + if (e.target.className.split(" ").indexOf("ace_content") !== -1) { + if (movingTimer) + clearInterval(movingTimer); + + //console.log("touchstart", e); + } + }, false); + document.addEventListener("touchend", function(e) { + if (e.target.className.split(" ").indexOf("ace_content") !== -1) { + //console.log("TOUCH END", e); + //console.log(movementDiff, timeDiff); + var position = mobileScrollDiv.scrollTop; + //var velocity = (movementDiff/timeDiff) * 4; + var velocity = movementDiff; + movingTimer = setInterval(function() { + position += velocity; + velocity *= 0.94; + //console.log(velocity); + env.editor.session.setScrollTop(position); + if (Math.abs(velocity) < 4) + clearInterval(movingTimer); + }, 5); + } + }, false); + + mobileScrollDiv.onscroll = function(e) { + //console.log("Scrolling", e, mobileScrollDiv.scrollTop); + env.editor.session.setScrollTop(mobileScrollDiv.scrollTop); + }; + } + else { + var mobileScrollDiv = document.getElementById("scrolldiv_container"); + if (mobileScrollDiv) + mobileScrollDiv.parentNode.removeChild(mobileScrollDiv); + } +}); + /************** dragover ***************************/ event.addListener(container, "dragover", function(e) { return event.preventDefault(e); diff --git a/demo/kitchen-sink/styles.css b/demo/kitchen-sink/styles.css index ec3578aa..d525fce1 100644 --- a/demo/kitchen-sink/styles.css +++ b/demo/kitchen-sink/styles.css @@ -40,4 +40,19 @@ body { #controls td + td { text-align: left; +} + +#scrolldiv_container { + position: absolute; + top: 0px; + left: 0px; + z-index: 9999; + -webkit-overflow-scrolling: touch; + overflow-y: scroll; + pointer-events: none; +} + +#scrolldiv_child { + -webkit-transform: translateZ(0px); + pointer-events: none; } \ No newline at end of file diff --git a/kitchen-sink.html b/kitchen-sink.html index 96dc9c37..9164cbbe 100644 --- a/kitchen-sink.html +++ b/kitchen-sink.html @@ -245,6 +245,14 @@ + + + + + + + + From 81508772f378f44715a17ccd51b63c2a86c4028a Mon Sep 17 00:00:00 2001 From: C9 Date: Fri, 30 Nov 2012 04:58:21 -0500 Subject: [PATCH 2/3] Initial support for scrolling --- demo/kitchen-sink/demo.js | 26 +++++-- kitchen-sink.html | 3 +- lib/ace/css/editor.css | 16 +++++ lib/ace/layer/mobilescroll.js | 129 ++++++++++++++++++++++++++++++++++ lib/ace/virtual_renderer.js | 8 +++ 5 files changed, 174 insertions(+), 8 deletions(-) create mode 100644 lib/ace/layer/mobilescroll.js diff --git a/demo/kitchen-sink/demo.js b/demo/kitchen-sink/demo.js index 7a2008e8..3f9eaafc 100644 --- a/demo/kitchen-sink/demo.js +++ b/demo/kitchen-sink/demo.js @@ -394,11 +394,9 @@ bindCheckbox("highlight_token", function(checked) { }); bindCheckbox("mobile_mode", function(checked) { - //var editor = env.editor; /** Mobile test **/ if (checked) { var editorElement = document.getElementById("editor"); - var editorElementChild = editorElement.childNodes[0]; var left = editorElement.offsetLeft; var height = editorElement.style.height; @@ -407,7 +405,7 @@ bindCheckbox("mobile_mode", function(checked) { var mobileScrollDiv = document.createElement("div"); mobileScrollDiv.id = "scrolldiv_container"; - mobileScrollDiv.style.width = width + "px"; + mobileScrollDiv.style.width = (width+30) + "px"; //mobileScrollDiv.style.left = left + "px"; mobileScrollDiv.style.height = height; @@ -419,6 +417,8 @@ bindCheckbox("mobile_mode", function(checked) { var movementDiff = 0, lastMovementPos = 0; var timeDiff = 0, lastTime = 0; + var waitingForLastScroll = false; + document.addEventListener("touchmove", function(e) { //console.log(" TOUCHMOVE", e, mobileScrollDiv.scrollTop); movementDiff = mobileScrollDiv.scrollTop - lastMovementPos; @@ -430,24 +430,30 @@ bindCheckbox("mobile_mode", function(checked) { var movingTimer; document.addEventListener("touchstart", function(e) { if (e.target.className.split(" ").indexOf("ace_content") !== -1) { - if (movingTimer) - clearInterval(movingTimer); + clearInterval(movingTimer); + waitingForLastScroll = false; + movementDiff = 0, lastMovementPos = 0; + timeDiff = 0, lastTime = 0; //console.log("touchstart", e); } }, false); document.addEventListener("touchend", function(e) { if (e.target.className.split(" ").indexOf("ace_content") !== -1) { + waitingForLastScroll = true; + //console.log("TOUCH END", e); //console.log(movementDiff, timeDiff); var position = mobileScrollDiv.scrollTop; //var velocity = (movementDiff/timeDiff) * 4; var velocity = movementDiff; + movingTimer = setInterval(function() { position += velocity; - velocity *= 0.94; + velocity *= 0.949; //console.log(velocity); env.editor.session.setScrollTop(position); + mobileScrollDiv.scrollTop = position; if (Math.abs(velocity) < 4) clearInterval(movingTimer); }, 5); @@ -456,7 +462,13 @@ bindCheckbox("mobile_mode", function(checked) { mobileScrollDiv.onscroll = function(e) { //console.log("Scrolling", e, mobileScrollDiv.scrollTop); - env.editor.session.setScrollTop(mobileScrollDiv.scrollTop); + if (waitingForLastScroll === false) { + env.editor.session.setScrollTop(mobileScrollDiv.scrollTop); + } + // Set the top of the scrolldiv to what the editor scrolltop is + /*else { + mobileScrollDiv.scrollTop = env.editor.session.getScrollTop(); + }*/ }; } else { diff --git a/kitchen-sink.html b/kitchen-sink.html index 9164cbbe..dc205075 100644 --- a/kitchen-sink.html +++ b/kitchen-sink.html @@ -5,6 +5,7 @@ Ace Kitchen Sink +