Compare commits
9 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
09b74839dc | ||
|
|
271780542a | ||
|
|
9197bbdba9 | ||
|
|
ad1ac504b4 | ||
|
|
c01deb9798 | ||
|
|
444b392226 | ||
|
|
aed8ec2580 | ||
|
|
291306f699 | ||
|
|
b0e6c5941c |
15 changed files with 515 additions and 71 deletions
|
|
@ -248,12 +248,12 @@ if (!Array.prototype.indexOf)
|
||||||
if (len === 0)
|
if (len === 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
var n = 0, zero = n;
|
var n = 0;
|
||||||
if (arguments.length > 0) {
|
if (arguments.length > 0) {
|
||||||
n = Number(arguments[1]);
|
n = Number(arguments[1]);
|
||||||
if (n !== n)
|
if (n !== n)
|
||||||
n = 0;
|
n = 0;
|
||||||
else if (n !== 0 && n !== (1 / zero) && n !== -(1 / zero))
|
else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0))
|
||||||
n = (n > 0 || -1) * Math.floor(Math.abs(n));
|
n = (n > 0 || -1) * Math.floor(Math.abs(n));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -288,13 +288,13 @@ if (!Array.prototype.lastIndexOf)
|
||||||
if (len === 0)
|
if (len === 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
var n = len, zero = false | 0;
|
var n = len;
|
||||||
if (arguments.length > 0)
|
if (arguments.length > 0)
|
||||||
{
|
{
|
||||||
n = Number(arguments[1]);
|
n = Number(arguments[1]);
|
||||||
if (n !== n)
|
if (n !== n)
|
||||||
n = 0;
|
n = 0;
|
||||||
else if (n !== 0 && n !== (1 / zero) && n !== -(1 / zero))
|
else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0))
|
||||||
n = (n > 0 || -1) * Math.floor(Math.abs(n));
|
n = (n > 0 || -1) * Math.floor(Math.abs(n));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -4078,7 +4078,7 @@ var lang = require("pilot/lang");
|
||||||
var useragent = require("pilot/useragent");
|
var useragent = require("pilot/useragent");
|
||||||
var TextInput = require("ace/keyboard/textinput").TextInput;
|
var TextInput = require("ace/keyboard/textinput").TextInput;
|
||||||
var MouseHandler = require("ace/mouse_handler").MouseHandler;
|
var MouseHandler = require("ace/mouse_handler").MouseHandler;
|
||||||
//var TouchHandler = require("ace/touch_handler").TouchHandler;
|
var TouchHandler = require("ace/touch_handler").TouchHandler;
|
||||||
var KeyBinding = require("ace/keyboard/keybinding").KeyBinding;
|
var KeyBinding = require("ace/keyboard/keybinding").KeyBinding;
|
||||||
var EditSession = require("ace/edit_session").EditSession;
|
var EditSession = require("ace/edit_session").EditSession;
|
||||||
var Search = require("ace/search").Search;
|
var Search = require("ace/search").Search;
|
||||||
|
|
@ -4095,11 +4095,10 @@ var Editor =function(renderer, session) {
|
||||||
this.keyBinding = new KeyBinding(this);
|
this.keyBinding = new KeyBinding(this);
|
||||||
|
|
||||||
// TODO detect touch event support
|
// TODO detect touch event support
|
||||||
if (useragent.isIPad) {
|
if (useragent.isIPad)
|
||||||
//this.$mouseHandler = new TouchHandler(this);
|
this.$mouseHandler = new TouchHandler(this);
|
||||||
} else {
|
else
|
||||||
this.$mouseHandler = new MouseHandler(this);
|
this.$mouseHandler = new MouseHandler(this);
|
||||||
}
|
|
||||||
|
|
||||||
this.$selectionMarker = null;
|
this.$selectionMarker = null;
|
||||||
this.$highlightLineMarker = null;
|
this.$highlightLineMarker = null;
|
||||||
|
|
@ -5476,6 +5475,8 @@ var TextInput = function(parentNode, host) {
|
||||||
|
|
||||||
var text = document.createElement("textarea");
|
var text = document.createElement("textarea");
|
||||||
text.style.left = "-10000px";
|
text.style.left = "-10000px";
|
||||||
|
if (useragent.isIPad)
|
||||||
|
text.style.position = "absolute";
|
||||||
parentNode.appendChild(text);
|
parentNode.appendChild(text);
|
||||||
|
|
||||||
var PLACEHOLDER = String.fromCharCode(0);
|
var PLACEHOLDER = String.fromCharCode(0);
|
||||||
|
|
@ -5491,11 +5492,18 @@ var TextInput = function(parentNode, host) {
|
||||||
if (value) {
|
if (value) {
|
||||||
if (value.charCodeAt(value.length-1) == PLACEHOLDER.charCodeAt(0)) {
|
if (value.charCodeAt(value.length-1) == PLACEHOLDER.charCodeAt(0)) {
|
||||||
value = value.slice(0, -1);
|
value = value.slice(0, -1);
|
||||||
if (value)
|
if (value.length)
|
||||||
host.onTextInput(value);
|
host.onTextInput(value);
|
||||||
} else
|
}
|
||||||
|
if (value.charCodeAt(0) == PLACEHOLDER.charCodeAt(0)) {
|
||||||
|
value = value.slice(1, value.length);
|
||||||
|
if (value.length)
|
||||||
host.onTextInput(value);
|
host.onTextInput(value);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
host.onTextInput(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
copied = false;
|
copied = false;
|
||||||
|
|
||||||
|
|
@ -5815,6 +5823,129 @@ var MouseHandler = function(editor) {
|
||||||
}).call(MouseHandler.prototype);
|
}).call(MouseHandler.prototype);
|
||||||
|
|
||||||
exports.MouseHandler = MouseHandler;
|
exports.MouseHandler = MouseHandler;
|
||||||
|
});/* ***** BEGIN LICENSE BLOCK *****
|
||||||
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version
|
||||||
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
* http://www.mozilla.org/MPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* License.
|
||||||
|
*
|
||||||
|
* The Original Code is Ajax.org Code Editor (ACE).
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is
|
||||||
|
* Ajax.org B.V.
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
* Fabian Jakobs <fabian AT ajax DOT org>
|
||||||
|
*
|
||||||
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||||
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||||
|
* of those above. If you wish to allow use of your version of this file only
|
||||||
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||||
|
* use your version of this file under the terms of the MPL, indicate your
|
||||||
|
* decision by deleting the provisions above and replace them with the notice
|
||||||
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||||
|
* the provisions above, a recipient may use your version of this file under
|
||||||
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||||
|
*
|
||||||
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
define('ace/touch_handler', function(require, exports, module) {
|
||||||
|
|
||||||
|
var event = require("pilot/event");
|
||||||
|
|
||||||
|
var TouchHandler = function(editor) {
|
||||||
|
this.editor = editor;
|
||||||
|
event.addListener(editor.container, "click", function(e) {
|
||||||
|
// does this only work on click?
|
||||||
|
editor.focus();
|
||||||
|
});
|
||||||
|
var mouseTarget = editor.renderer.getMouseEventTarget();
|
||||||
|
mouseTarget.ontouchstart = this.onTouchStart.bind(this);
|
||||||
|
mouseTarget.ontouchmove = this.onTouchMove.bind(this);
|
||||||
|
mouseTarget.ontouchend = this.onTouchEnd.bind(this);
|
||||||
|
};
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
this.$scrollSpeed = 1;
|
||||||
|
this.setScrollSpeed = function(speed) {
|
||||||
|
this.$scrollSpeed = speed;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.getScrollSpeed = function() {
|
||||||
|
return this.$scrollSpeed;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.onTouchMove = function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
if (e.touches.length == 1) {
|
||||||
|
this.$moveCursor(e.touches[0]);
|
||||||
|
}
|
||||||
|
else if (e.touches.length == 2) {
|
||||||
|
if (!this.$scroll)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var touch = e.touches[0];
|
||||||
|
var diffX = this.$scroll.pageX - touch.pageX;
|
||||||
|
var diffY = this.$scroll.pageY - touch.pageY;
|
||||||
|
this.editor.renderer.scrollBy(diffX, diffY);
|
||||||
|
|
||||||
|
this.$scroll = {
|
||||||
|
pageX: touch.pageX,
|
||||||
|
pageY: touch.pageY,
|
||||||
|
ts: new Date().getTime()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.$moveCursor = function(touch) {
|
||||||
|
var pageX = touch.pageX;
|
||||||
|
var pageY = touch.pageY;
|
||||||
|
|
||||||
|
var editor = this.editor;
|
||||||
|
var pos = editor.renderer.screenToTextCoordinates(pageX, pageY);
|
||||||
|
pos.row = Math.max(0, Math.min(pos.row, editor.session.getLength()-1));
|
||||||
|
|
||||||
|
editor.moveCursorToPosition(pos);
|
||||||
|
editor.renderer.scrollCursorIntoView();
|
||||||
|
};
|
||||||
|
|
||||||
|
this.onTouchEnd = function(e) {
|
||||||
|
//if (e.touches.length == 1) {
|
||||||
|
console.log("focus")
|
||||||
|
editor.focus();
|
||||||
|
//e.preventDefault();
|
||||||
|
//}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.onTouchStart = function(e) {
|
||||||
|
if (e.touches.length == 1) {
|
||||||
|
this.$moveCursor(e.touches[0]);
|
||||||
|
}
|
||||||
|
else if (e.touches.length == 2) {
|
||||||
|
e.preventDefault();
|
||||||
|
var touch = e.touches[0];
|
||||||
|
this.$scroll = {
|
||||||
|
pageX: touch.pageX,
|
||||||
|
pageY: touch.pageY
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}).call(TouchHandler.prototype);
|
||||||
|
|
||||||
|
exports.TouchHandler = TouchHandler;
|
||||||
});/* ***** BEGIN LICENSE BLOCK *****
|
});/* ***** BEGIN LICENSE BLOCK *****
|
||||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
*
|
*
|
||||||
|
|
@ -6469,8 +6600,7 @@ canon.addCommand({
|
||||||
canon.addCommand({
|
canon.addCommand({
|
||||||
name: "inserttext",
|
name: "inserttext",
|
||||||
exec: function(env, args, request) {
|
exec: function(env, args, request) {
|
||||||
env.editor.insert(lang.stringRepeat(args.text || "",
|
env.editor.insert(lang.stringRepeat(args.text || "", args.times || 1));
|
||||||
args.times || 1));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -10150,7 +10280,9 @@ var VirtualRenderer = function(container, theme) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.getTextAreaContainer = function() {
|
this.getTextAreaContainer = function() {
|
||||||
return this.container;
|
// Let's make it play nice wit iPad. Otherwise the default padding of
|
||||||
|
// the container will make the cursor shift to the left.
|
||||||
|
return useragent.isIPad ? this.content : this.container;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.moveTextAreaToCursor = function(textarea) {
|
this.moveTextAreaToCursor = function(textarea) {
|
||||||
|
|
@ -10158,15 +10290,32 @@ var VirtualRenderer = function(container, theme) {
|
||||||
if (useragent.isIE)
|
if (useragent.isIE)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var pos = this.$cursorLayer.getPixelPosition();
|
if (!this.layerConfig)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var pos, left, top;
|
||||||
|
if (useragent.isIPad) {
|
||||||
|
pos = this.$cursorLayer.getPixelPosition(true);
|
||||||
|
if (!pos)
|
||||||
|
return;
|
||||||
|
|
||||||
|
left = pos.left + this.$padding// - 3;
|
||||||
|
top = pos.top;
|
||||||
|
} else {
|
||||||
|
pos = this.$cursorLayer.getPixelPosition();
|
||||||
if (!pos)
|
if (!pos)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var bounds = this.content.getBoundingClientRect();
|
var bounds = this.content.getBoundingClientRect();
|
||||||
var offset = (this.layerConfig && this.layerConfig.offset) || 0;
|
var offset = this.layerConfig.offset;
|
||||||
|
|
||||||
textarea.style.left = (bounds.left + pos.left + this.$padding) + "px";
|
left = bounds.left + pos.left + this.$padding;
|
||||||
textarea.style.top = (bounds.top + pos.top - this.scrollTop + offset) + "px";
|
top = bounds.top + pos.top - this.scrollTop + offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
textarea.style.left = left + "px";
|
||||||
|
textarea.style.top = top + "px";
|
||||||
|
textarea.style.lineHeight = this.layerConfig.lineHeight + "px";
|
||||||
};
|
};
|
||||||
|
|
||||||
this.getFirstVisibleRow = function() {
|
this.getFirstVisibleRow = function() {
|
||||||
|
|
@ -10975,7 +11124,8 @@ var Text = function(parentEl) {
|
||||||
},
|
},
|
||||||
|
|
||||||
this.$measureSizes = function() {
|
this.$measureSizes = function() {
|
||||||
var n = 1000;
|
var n = 500;
|
||||||
|
var probe = "Xy";
|
||||||
if (!this.$measureNode) {
|
if (!this.$measureNode) {
|
||||||
var measureNode = this.$measureNode = document.createElement("div");
|
var measureNode = this.$measureNode = document.createElement("div");
|
||||||
var style = measureNode.style;
|
var style = measureNode.style;
|
||||||
|
|
@ -10991,7 +11141,7 @@ var Text = function(parentEl) {
|
||||||
// in FF 3.6 monospace fonts can have a fixed sub pixel width.
|
// in FF 3.6 monospace fonts can have a fixed sub pixel width.
|
||||||
// that's why we have to measure many characters
|
// that's why we have to measure many characters
|
||||||
// Note: characterWidth can be a float!
|
// Note: characterWidth can be a float!
|
||||||
measureNode.innerHTML = lang.stringRepeat("Xy", n);
|
dom.setInnerText(measureNode, lang.stringRepeat(probe, n));
|
||||||
document.body.insertBefore(measureNode, document.body.firstChild);
|
document.body.insertBefore(measureNode, document.body.firstChild);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -11001,9 +11151,10 @@ var Text = function(parentEl) {
|
||||||
style[prop] = value;
|
style[prop] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//console.log(this.$measureNode.offsetWidth / (n * probe.length))
|
||||||
var size = {
|
var size = {
|
||||||
height: this.$measureNode.offsetHeight,
|
height: this.$measureNode.offsetHeight,
|
||||||
width: this.$measureNode.offsetWidth / (n * 2)
|
width: this.$measureNode.offsetWidth / (n * probe.length)
|
||||||
};
|
};
|
||||||
return size;
|
return size;
|
||||||
};
|
};
|
||||||
|
|
@ -11270,6 +11421,7 @@ exports.Text = Text;
|
||||||
define('ace/layer/cursor', function(require, exports, module) {
|
define('ace/layer/cursor', function(require, exports, module) {
|
||||||
|
|
||||||
var dom = require("pilot/dom");
|
var dom = require("pilot/dom");
|
||||||
|
var useragent = require("pilot/useragent");
|
||||||
|
|
||||||
var Cursor = function(parentEl) {
|
var Cursor = function(parentEl) {
|
||||||
this.element = document.createElement("div");
|
this.element = document.createElement("div");
|
||||||
|
|
@ -11309,6 +11461,8 @@ var Cursor = function(parentEl) {
|
||||||
|
|
||||||
this.showCursor = function() {
|
this.showCursor = function() {
|
||||||
this.isVisible = true;
|
this.isVisible = true;
|
||||||
|
|
||||||
|
if (!useragent.isIPad)
|
||||||
this.element.appendChild(this.cursor);
|
this.element.appendChild(this.cursor);
|
||||||
|
|
||||||
var cursor = this.cursor;
|
var cursor = this.cursor;
|
||||||
|
|
@ -11363,7 +11517,7 @@ var Cursor = function(parentEl) {
|
||||||
this.cursor.style.width = config.characterWidth + "px";
|
this.cursor.style.width = config.characterWidth + "px";
|
||||||
this.cursor.style.height = config.lineHeight + "px";
|
this.cursor.style.height = config.lineHeight + "px";
|
||||||
|
|
||||||
if (this.isVisible) {
|
if (this.isVisible && !useragent.isIPad) {
|
||||||
this.element.appendChild(this.cursor);
|
this.element.appendChild(this.cursor);
|
||||||
}
|
}
|
||||||
this.restartTimer();
|
this.restartTimer();
|
||||||
|
|
@ -11632,7 +11786,6 @@ define("text!ace/css/editor.css", ".ace_editor {" +
|
||||||
"" +
|
"" +
|
||||||
".ace_editor textarea {" +
|
".ace_editor textarea {" +
|
||||||
" position: fixed;" +
|
" position: fixed;" +
|
||||||
" z-index: -1;" +
|
|
||||||
" width: 10px;" +
|
" width: 10px;" +
|
||||||
" height: 30px;" +
|
" height: 30px;" +
|
||||||
" opacity: 0;" +
|
" opacity: 0;" +
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
70
demo/ipad.js
Normal file
70
demo/ipad.js
Normal file
|
|
@ -0,0 +1,70 @@
|
||||||
|
/* ***** BEGIN LICENSE BLOCK *****
|
||||||
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version
|
||||||
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
* http://www.mozilla.org/MPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* License.
|
||||||
|
*
|
||||||
|
* The Original Code is Mozilla Skywriter.
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is
|
||||||
|
* Mozilla.
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
* Fabian Jakobs <fabian AT ajax DOT org>
|
||||||
|
*
|
||||||
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||||
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||||
|
* of those above. If you wish to allow use of your version of this file only
|
||||||
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||||
|
* use your version of this file under the terms of the MPL, indicate your
|
||||||
|
* decision by deleting the provisions above and replace them with the notice
|
||||||
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||||
|
* the provisions above, a recipient may use your version of this file under
|
||||||
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||||
|
*
|
||||||
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
|
||||||
|
define(function(require, exports, module) {
|
||||||
|
|
||||||
|
var Dom = require("pilot/dom");
|
||||||
|
var Event = require("pilot/event");
|
||||||
|
|
||||||
|
var Editor = require("ace/editor").Editor;
|
||||||
|
var EditSession = require("ace/edit_session").EditSession;
|
||||||
|
var UndoManager = require("ace/undomanager").UndoManager;
|
||||||
|
var Renderer = require("ace/virtual_renderer").VirtualRenderer;
|
||||||
|
var JavaScriptMode = require("ace/mode/javascript").Mode;
|
||||||
|
|
||||||
|
exports.launch = function(el, text) {
|
||||||
|
if (typeof(el) == "string") {
|
||||||
|
el = document.getElementById(el);
|
||||||
|
}
|
||||||
|
|
||||||
|
var editor = new Editor(new Renderer(el, "ace/theme/twilight"));
|
||||||
|
|
||||||
|
var doc = new EditSession(text);
|
||||||
|
doc.setMode(new JavaScriptMode());
|
||||||
|
doc.setUndoManager(new UndoManager());
|
||||||
|
editor.setSession(doc);
|
||||||
|
|
||||||
|
editor.resize();
|
||||||
|
Event.addListener(window, "resize", function() {
|
||||||
|
editor.resize();
|
||||||
|
});
|
||||||
|
|
||||||
|
return editor;
|
||||||
|
};
|
||||||
|
|
||||||
|
});
|
||||||
62
ipad.html
Normal file
62
ipad.html
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
||||||
|
"http://www.w3.org/TR/html4/strict.dtd">
|
||||||
|
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||||
|
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||||
|
<meta name="viewport" content="user-scalable=no, width=device-width">
|
||||||
|
<meta name="author" content="Fabian Jakobs">
|
||||||
|
|
||||||
|
<title>Ace on iPad</title>
|
||||||
|
|
||||||
|
<link href='http://fonts.googleapis.com/css?family=Droid+Sans+Mono' rel='stylesheet' type='text/css'>
|
||||||
|
|
||||||
|
<style type="text/css" media="screen">
|
||||||
|
body {
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
#editor {
|
||||||
|
margin: 0;
|
||||||
|
position: absolute;
|
||||||
|
font-family: 'Droid Sans Mono';
|
||||||
|
font-size: 14px;
|
||||||
|
top: 0;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
-webkit-user-select: none;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="editor">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="demo/require.js" type="text/javascript" charset="utf-8"></script>
|
||||||
|
<script>
|
||||||
|
|
||||||
|
require({
|
||||||
|
paths: {
|
||||||
|
demo: "../demo",
|
||||||
|
ace: "../lib/ace",
|
||||||
|
pilot: "../support/pilot/lib/pilot"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
require(["demo/ipad"], function(demo) {
|
||||||
|
var text = 'function foo(items) {\n\
|
||||||
|
for (var i=0; i<items.length; i++) {\n\
|
||||||
|
alert(items[i] + "juhu");\n\
|
||||||
|
}\n\
|
||||||
|
}';
|
||||||
|
for (var i=0; i<500; i++)
|
||||||
|
text += "\njuhu " + i;
|
||||||
|
|
||||||
|
demo.launch("editor", text);
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
@ -253,8 +253,7 @@ canon.addCommand({
|
||||||
canon.addCommand({
|
canon.addCommand({
|
||||||
name: "inserttext",
|
name: "inserttext",
|
||||||
exec: function(env, args, request) {
|
exec: function(env, args, request) {
|
||||||
env.editor.insert(lang.stringRepeat(args.text || "",
|
env.editor.insert(lang.stringRepeat(args.text || "", args.times || 1));
|
||||||
args.times || 1));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,6 @@
|
||||||
|
|
||||||
.ace_editor textarea {
|
.ace_editor textarea {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
z-index: -1;
|
|
||||||
width: 10px;
|
width: 10px;
|
||||||
height: 30px;
|
height: 30px;
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ var lang = require("pilot/lang");
|
||||||
var useragent = require("pilot/useragent");
|
var useragent = require("pilot/useragent");
|
||||||
var TextInput = require("ace/keyboard/textinput").TextInput;
|
var TextInput = require("ace/keyboard/textinput").TextInput;
|
||||||
var MouseHandler = require("ace/mouse_handler").MouseHandler;
|
var MouseHandler = require("ace/mouse_handler").MouseHandler;
|
||||||
//var TouchHandler = require("ace/touch_handler").TouchHandler;
|
var TouchHandler = require("ace/touch_handler").TouchHandler;
|
||||||
var KeyBinding = require("ace/keyboard/keybinding").KeyBinding;
|
var KeyBinding = require("ace/keyboard/keybinding").KeyBinding;
|
||||||
var EditSession = require("ace/edit_session").EditSession;
|
var EditSession = require("ace/edit_session").EditSession;
|
||||||
var Search = require("ace/search").Search;
|
var Search = require("ace/search").Search;
|
||||||
|
|
@ -65,11 +65,10 @@ var Editor =function(renderer, session) {
|
||||||
this.keyBinding = new KeyBinding(this);
|
this.keyBinding = new KeyBinding(this);
|
||||||
|
|
||||||
// TODO detect touch event support
|
// TODO detect touch event support
|
||||||
if (useragent.isIPad) {
|
if (useragent.isIPad)
|
||||||
//this.$mouseHandler = new TouchHandler(this);
|
this.$mouseHandler = new TouchHandler(this);
|
||||||
} else {
|
else
|
||||||
this.$mouseHandler = new MouseHandler(this);
|
this.$mouseHandler = new MouseHandler(this);
|
||||||
}
|
|
||||||
|
|
||||||
this.$selectionMarker = null;
|
this.$selectionMarker = null;
|
||||||
this.$highlightLineMarker = null;
|
this.$highlightLineMarker = null;
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,13 @@ var TextInput = function(parentNode, host) {
|
||||||
|
|
||||||
var text = document.createElement("textarea");
|
var text = document.createElement("textarea");
|
||||||
text.style.left = "-10000px";
|
text.style.left = "-10000px";
|
||||||
|
// We have too many moving parts in the iPad, so we set the text
|
||||||
|
// positioning to absolute to be able to calculate the precise position for
|
||||||
|
// cursor. Otherwise the cursor position would be relative to the screen
|
||||||
|
// coordinates (position: fixed).
|
||||||
|
if (useragent.isIPad)
|
||||||
|
text.style.position = "absolute";
|
||||||
|
|
||||||
parentNode.appendChild(text);
|
parentNode.appendChild(text);
|
||||||
|
|
||||||
var PLACEHOLDER = String.fromCharCode(0);
|
var PLACEHOLDER = String.fromCharCode(0);
|
||||||
|
|
@ -59,11 +66,18 @@ var TextInput = function(parentNode, host) {
|
||||||
if (value) {
|
if (value) {
|
||||||
if (value.charCodeAt(value.length-1) == PLACEHOLDER.charCodeAt(0)) {
|
if (value.charCodeAt(value.length-1) == PLACEHOLDER.charCodeAt(0)) {
|
||||||
value = value.slice(0, -1);
|
value = value.slice(0, -1);
|
||||||
if (value)
|
if (value.length)
|
||||||
host.onTextInput(value);
|
host.onTextInput(value);
|
||||||
} else
|
}
|
||||||
|
if (value.charCodeAt(0) == PLACEHOLDER.charCodeAt(0)) {
|
||||||
|
value = value.slice(1, value.length);
|
||||||
|
if (value.length)
|
||||||
host.onTextInput(value);
|
host.onTextInput(value);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
host.onTextInput(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
copied = false;
|
copied = false;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@
|
||||||
define(function(require, exports, module) {
|
define(function(require, exports, module) {
|
||||||
|
|
||||||
var dom = require("pilot/dom");
|
var dom = require("pilot/dom");
|
||||||
|
var useragent = require("pilot/useragent");
|
||||||
|
|
||||||
var Cursor = function(parentEl) {
|
var Cursor = function(parentEl) {
|
||||||
this.element = document.createElement("div");
|
this.element = document.createElement("div");
|
||||||
|
|
@ -78,6 +79,8 @@ var Cursor = function(parentEl) {
|
||||||
|
|
||||||
this.showCursor = function() {
|
this.showCursor = function() {
|
||||||
this.isVisible = true;
|
this.isVisible = true;
|
||||||
|
|
||||||
|
if (!useragent.isIPad)
|
||||||
this.element.appendChild(this.cursor);
|
this.element.appendChild(this.cursor);
|
||||||
|
|
||||||
var cursor = this.cursor;
|
var cursor = this.cursor;
|
||||||
|
|
@ -132,7 +135,7 @@ var Cursor = function(parentEl) {
|
||||||
this.cursor.style.width = config.characterWidth + "px";
|
this.cursor.style.width = config.characterWidth + "px";
|
||||||
this.cursor.style.height = config.lineHeight + "px";
|
this.cursor.style.height = config.lineHeight + "px";
|
||||||
|
|
||||||
if (this.isVisible) {
|
if (this.isVisible && !useragent.isIPad) {
|
||||||
this.element.appendChild(this.cursor);
|
this.element.appendChild(this.cursor);
|
||||||
}
|
}
|
||||||
this.restartTimer();
|
this.restartTimer();
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,8 @@ var Text = function(parentEl) {
|
||||||
},
|
},
|
||||||
|
|
||||||
this.$measureSizes = function() {
|
this.$measureSizes = function() {
|
||||||
var n = 1000;
|
var n = 500;
|
||||||
|
var probe = "Xy";
|
||||||
if (!this.$measureNode) {
|
if (!this.$measureNode) {
|
||||||
var measureNode = this.$measureNode = document.createElement("div");
|
var measureNode = this.$measureNode = document.createElement("div");
|
||||||
var style = measureNode.style;
|
var style = measureNode.style;
|
||||||
|
|
@ -109,7 +110,7 @@ var Text = function(parentEl) {
|
||||||
// in FF 3.6 monospace fonts can have a fixed sub pixel width.
|
// in FF 3.6 monospace fonts can have a fixed sub pixel width.
|
||||||
// that's why we have to measure many characters
|
// that's why we have to measure many characters
|
||||||
// Note: characterWidth can be a float!
|
// Note: characterWidth can be a float!
|
||||||
measureNode.innerHTML = lang.stringRepeat("Xy", n);
|
dom.setInnerText(measureNode, lang.stringRepeat(probe, n));
|
||||||
document.body.insertBefore(measureNode, document.body.firstChild);
|
document.body.insertBefore(measureNode, document.body.firstChild);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -119,9 +120,10 @@ var Text = function(parentEl) {
|
||||||
style[prop] = value;
|
style[prop] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//console.log(this.$measureNode.offsetWidth / (n * probe.length))
|
||||||
var size = {
|
var size = {
|
||||||
height: this.$measureNode.offsetHeight,
|
height: this.$measureNode.offsetHeight,
|
||||||
width: this.$measureNode.offsetWidth / (n * 2)
|
width: this.$measureNode.offsetWidth / (n * probe.length)
|
||||||
};
|
};
|
||||||
return size;
|
return size;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
124
lib/ace/touch_handler.js
Normal file
124
lib/ace/touch_handler.js
Normal file
|
|
@ -0,0 +1,124 @@
|
||||||
|
/* ***** BEGIN LICENSE BLOCK *****
|
||||||
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version
|
||||||
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
* http://www.mozilla.org/MPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* License.
|
||||||
|
*
|
||||||
|
* The Original Code is Ajax.org Code Editor (ACE).
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is
|
||||||
|
* Ajax.org B.V.
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
* Fabian Jakobs <fabian AT ajax DOT org>
|
||||||
|
*
|
||||||
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||||
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||||
|
* of those above. If you wish to allow use of your version of this file only
|
||||||
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||||
|
* use your version of this file under the terms of the MPL, indicate your
|
||||||
|
* decision by deleting the provisions above and replace them with the notice
|
||||||
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||||
|
* the provisions above, a recipient may use your version of this file under
|
||||||
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||||
|
*
|
||||||
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
define(function(require, exports, module) {
|
||||||
|
|
||||||
|
var event = require("pilot/event");
|
||||||
|
|
||||||
|
var TouchHandler = function(editor) {
|
||||||
|
this.editor = editor;
|
||||||
|
event.addListener(editor.container, "click", function(e) {
|
||||||
|
// does this only work on click?
|
||||||
|
editor.focus();
|
||||||
|
});
|
||||||
|
var mouseTarget = editor.renderer.getMouseEventTarget();
|
||||||
|
mouseTarget.ontouchstart = this.onTouchStart.bind(this);
|
||||||
|
mouseTarget.ontouchmove = this.onTouchMove.bind(this);
|
||||||
|
mouseTarget.ontouchend = this.onTouchEnd.bind(this);
|
||||||
|
};
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
this.$scrollSpeed = 1;
|
||||||
|
this.setScrollSpeed = function(speed) {
|
||||||
|
this.$scrollSpeed = speed;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.getScrollSpeed = function() {
|
||||||
|
return this.$scrollSpeed;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.onTouchMove = function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
if (e.touches.length == 1) {
|
||||||
|
this.$moveCursor(e.touches[0]);
|
||||||
|
}
|
||||||
|
else if (e.touches.length == 2) {
|
||||||
|
if (!this.$scroll)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var touch = e.touches[0];
|
||||||
|
var diffX = this.$scroll.pageX - touch.pageX;
|
||||||
|
var diffY = this.$scroll.pageY - touch.pageY;
|
||||||
|
this.editor.renderer.scrollBy(diffX, diffY);
|
||||||
|
|
||||||
|
this.$scroll = {
|
||||||
|
pageX: touch.pageX,
|
||||||
|
pageY: touch.pageY,
|
||||||
|
ts: new Date().getTime()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.$moveCursor = function(touch) {
|
||||||
|
var pageX = touch.pageX;
|
||||||
|
var pageY = touch.pageY;
|
||||||
|
|
||||||
|
var editor = this.editor;
|
||||||
|
var pos = editor.renderer.screenToTextCoordinates(pageX, pageY);
|
||||||
|
pos.row = Math.max(0, Math.min(pos.row, editor.session.getLength()-1));
|
||||||
|
|
||||||
|
editor.moveCursorToPosition(pos);
|
||||||
|
editor.renderer.scrollCursorIntoView();
|
||||||
|
};
|
||||||
|
|
||||||
|
this.onTouchEnd = function(e) {
|
||||||
|
//if (e.touches.length == 1) {
|
||||||
|
console.log("focus")
|
||||||
|
editor.focus();
|
||||||
|
//e.preventDefault();
|
||||||
|
//}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.onTouchStart = function(e) {
|
||||||
|
if (e.touches.length == 1) {
|
||||||
|
this.$moveCursor(e.touches[0]);
|
||||||
|
}
|
||||||
|
else if (e.touches.length == 2) {
|
||||||
|
e.preventDefault();
|
||||||
|
var touch = e.touches[0];
|
||||||
|
this.$scroll = {
|
||||||
|
pageX: touch.pageX,
|
||||||
|
pageY: touch.pageY
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}).call(TouchHandler.prototype);
|
||||||
|
|
||||||
|
exports.TouchHandler = TouchHandler;
|
||||||
|
});
|
||||||
|
|
@ -298,7 +298,9 @@ var VirtualRenderer = function(container, theme) {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.getTextAreaContainer = function() {
|
this.getTextAreaContainer = function() {
|
||||||
return this.container;
|
// Let's make it play nice wit iPad. Otherwise the default padding of
|
||||||
|
// the container will make the cursor shift to the left.
|
||||||
|
return useragent.isIPad ? this.content : this.container;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.moveTextAreaToCursor = function(textarea) {
|
this.moveTextAreaToCursor = function(textarea) {
|
||||||
|
|
@ -306,15 +308,32 @@ var VirtualRenderer = function(container, theme) {
|
||||||
if (useragent.isIE)
|
if (useragent.isIE)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var pos = this.$cursorLayer.getPixelPosition();
|
if (!this.layerConfig)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var pos, left, top;
|
||||||
|
if (useragent.isIPad) {
|
||||||
|
pos = this.$cursorLayer.getPixelPosition(true);
|
||||||
|
if (!pos)
|
||||||
|
return;
|
||||||
|
|
||||||
|
left = pos.left + this.$padding - 3;
|
||||||
|
top = pos.top;
|
||||||
|
} else {
|
||||||
|
pos = this.$cursorLayer.getPixelPosition();
|
||||||
if (!pos)
|
if (!pos)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var bounds = this.content.getBoundingClientRect();
|
var bounds = this.content.getBoundingClientRect();
|
||||||
var offset = (this.layerConfig && this.layerConfig.offset) || 0;
|
var offset = this.layerConfig.offset;
|
||||||
|
|
||||||
textarea.style.left = (bounds.left + pos.left + this.$padding) + "px";
|
left = bounds.left + pos.left + this.$padding;
|
||||||
textarea.style.top = (bounds.top + pos.top - this.scrollTop + offset) + "px";
|
top = bounds.top + pos.top - this.scrollTop + offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
textarea.style.left = left + "px";
|
||||||
|
textarea.style.top = top + "px";
|
||||||
|
textarea.style.lineHeight = this.layerConfig.lineHeight + "px";
|
||||||
};
|
};
|
||||||
|
|
||||||
this.getFirstVisibleRow = function() {
|
this.getFirstVisibleRow = function() {
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit c0cab19cbb5d44df98bae0060c782a6f30464afe
|
Subproject commit 67a380309e5b139a9603334ad9d9f917659f04bc
|
||||||
Loading…
Add table
Add a link
Reference in a new issue