Skip to content

Commit 49b923d

Browse files
committed
touch handler
1 parent 30565a6 commit 49b923d

File tree

7 files changed

+277
-41
lines changed

7 files changed

+277
-41
lines changed

.eslintrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575

7676
no-undef: 2,
7777
no-redeclare: 0,
78-
// no-unused-vars: 1,
78+
no-unused-vars: 1,
7979

8080
no-debugger: 2,
8181

@@ -88,7 +88,7 @@
8888
// no-useless-concat: 2,
8989
// no-eval: 2,
9090
// dot-notation: 2,
91-
// no-alert: 2,
91+
no-alert: 2,
9292
no-extra-semi: 2, // doesn't handle ;(function() {})() pattern
9393
// radix: 2,
9494
// no-invalid-this: 2,

experiments/cut_copy.html

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<html lang="en">
55
<head>
66
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
7+
<!--<meta name="viewport" content="width=device-width,height=device-height" />-->
78
<title>Text Events</title>
89
<meta name="author" content="Fabian Jakobs">
910

@@ -20,6 +21,10 @@
2021
width: 590px;
2122
height: 400px;
2223
}
24+
25+
#text {
26+
position: absolute;
27+
}
2328

2429
</style>
2530

@@ -70,6 +75,39 @@
7075
console.log(e.type, e.charCode, e.keyCode, e);
7176
}
7277

78+
addListener(canvas, "mousedown", function(e) {
79+
text.focus();
80+
e.preventDefault();
81+
}, false);
82+
83+
var pos;
84+
addListener(canvas, "touchstart", function(e) {
85+
text.value = ""
86+
pos = e.touches[0]
87+
text.focus();
88+
}, false);
89+
addListener(canvas, "contextmenu", function(e) {
90+
text.value = "xxxxx";
91+
var rect = canvas.getBoundingClientRect()
92+
// text.selectionStart = 0
93+
// text.selectionEnd = 20
94+
text.style.opacity = 0
95+
text.style.top = pos.clientY - 15 - rect.top + "px"
96+
text.style.left = pos.clientX - 15 - rect.left + "px"
97+
// canvas.style.fontSize = "300px"
98+
// text.readOnly = true
99+
// text.focus();
100+
text.style.width = "50px"
101+
text.style.height = "50px"
102+
text.select();
103+
setTimeout(function() {
104+
text.readOnly = false
105+
// text.style.top = pos.clientY - 5 + "px"
106+
// text.style.left = pos.clientY - 5 + "px"
107+
}, 100)
108+
//e.preventDefault();
109+
}, false);
110+
73111
addListener(text, "keydown", logKey, false);
74112
addListener(text, "keyup", logKey, false);
75113
addListener(text, "keypress", logKey, false);
@@ -78,8 +116,9 @@
78116
console.log(e.type, e.data, e);
79117
}, false);
80118

119+
var i = 0;
81120
function fillSelection() {
82-
text.value = "Juhu Kinners";
121+
text.value = "Juhu Kinners " + (i++);
83122
text.select();
84123
}
85124

kitchen-sink.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<html lang="en">
44
<head>
55
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
6+
<meta name="viewport" content="width=device-width,height=device-height" />
67
<title>Ace Kitchen Sink</title>
78
<meta name="author" content="Fabian Jakobs">
89
<!--

lib/ace/lib/event.js

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -118,30 +118,6 @@ exports.capture = function(el, eventHandler, releaseCaptureHandler) {
118118
return onMouseUp;
119119
};
120120

121-
exports.addTouchMoveListener = function (el, callback) {
122-
var startx, starty;
123-
exports.addListener(el, "touchstart", function (e) {
124-
var touches = e.touches;
125-
var touchObj = touches[0];
126-
startx = touchObj.clientX;
127-
starty = touchObj.clientY;
128-
});
129-
exports.addListener(el, "touchmove", function (e) {
130-
var touches = e.touches;
131-
if (touches.length > 1) return;
132-
133-
var touchObj = touches[0];
134-
135-
e.wheelX = startx - touchObj.clientX;
136-
e.wheelY = starty - touchObj.clientY;
137-
138-
startx = touchObj.clientX;
139-
starty = touchObj.clientY;
140-
141-
callback(e);
142-
});
143-
};
144-
145121
exports.addMouseWheelListener = function(el, callback) {
146122
if ("onmousewheel" in el) {
147123
exports.addListener(el, "mousewheel", function(e) {

lib/ace/mouse/default_handlers.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ function DefaultHandlers(mouseHandler) {
4545
editor.setDefaultHandler("tripleclick", this.onTripleClick.bind(mouseHandler));
4646
editor.setDefaultHandler("quadclick", this.onQuadClick.bind(mouseHandler));
4747
editor.setDefaultHandler("mousewheel", this.onMouseWheel.bind(mouseHandler));
48-
editor.setDefaultHandler("touchmove", this.onTouchMove.bind(mouseHandler));
4948

5049
var exports = ["select", "startSelect", "selectEnd", "selectAllEnd", "selectByWordsEnd",
5150
"selectByLinesEnd", "dragWait", "dragWaitEnd", "focusWait"];
@@ -290,10 +289,6 @@ function DefaultHandlers(mouseHandler) {
290289
return ev.stop();
291290
}
292291
};
293-
294-
this.onTouchMove = function(ev) {
295-
this.editor._emit("mousewheel", ev);
296-
};
297292

298293
}).call(DefaultHandlers.prototype);
299294

lib/ace/mouse/mouse_handler.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ var DefaultHandlers = require("./default_handlers").DefaultHandlers;
3737
var DefaultGutterHandler = require("./default_gutter_handler").GutterHandler;
3838
var MouseEvent = require("./mouse_event").MouseEvent;
3939
var DragdropHandler = require("./dragdrop_handler").DragdropHandler;
40+
var addTouchListeners = require("./touch_handler").addTouchListeners;
4041
var config = require("../config");
4142

4243
var MouseHandler = function(editor) {
@@ -67,7 +68,7 @@ var MouseHandler = function(editor) {
6768
editor.textInput && editor.textInput.getElement()
6869
].filter(Boolean), [400, 300, 250], this, "onMouseEvent");
6970
event.addMouseWheelListener(editor.container, this.onMouseWheel.bind(this, "mousewheel"));
70-
event.addTouchMoveListener(editor.container, this.onTouchMove.bind(this, "touchmove"));
71+
addTouchListeners(editor.container, editor);
7172

7273
var gutterEl = editor.renderer.$gutter;
7374
event.addListener(gutterEl, "mousedown", this.onMouseEvent.bind(this, "guttermousedown"));
@@ -121,14 +122,6 @@ var MouseHandler = function(editor) {
121122
this.editor._emit(name, mouseEvent);
122123
};
123124

124-
this.onTouchMove = function (name, e) {
125-
var mouseEvent = new MouseEvent(e, this.editor);
126-
mouseEvent.speed = 1;//this.$scrollSpeed * 2;
127-
mouseEvent.wheelX = e.wheelX;
128-
mouseEvent.wheelY = e.wheelY;
129-
this.editor._emit(name, mouseEvent);
130-
};
131-
132125
this.setState = function(state) {
133126
this.state = state;
134127
};

0 commit comments

Comments
 (0)