move gutter mouse event code to the mouse_handler
This commit is contained in:
parent
653a88ff30
commit
680ae0e8a2
4 changed files with 29 additions and 70 deletions
|
|
@ -86,30 +86,6 @@ var Editor = function(renderer, session) {
|
|||
|
||||
oop.implement(this, EventEmitter);
|
||||
|
||||
this.$forwardEvents = {
|
||||
gutterclick: 1,
|
||||
gutterdblclick: 1
|
||||
};
|
||||
|
||||
this.$originalAddEventListener = this.addEventListener;
|
||||
this.$originalRemoveEventListener = this.removeEventListener;
|
||||
|
||||
this.addEventListener = function(eventName, callback) {
|
||||
if (this.$forwardEvents[eventName]) {
|
||||
return this.renderer.addEventListener(eventName, callback);
|
||||
} else {
|
||||
return this.$originalAddEventListener(eventName, callback);
|
||||
}
|
||||
};
|
||||
|
||||
this.removeEventListener = function(eventName, callback) {
|
||||
if (this.$forwardEvents[eventName]) {
|
||||
return this.renderer.removeEventListener(eventName, callback);
|
||||
} else {
|
||||
return this.$originalRemoveEventListener(eventName, callback);
|
||||
}
|
||||
};
|
||||
|
||||
this.setKeyboardHandler = function(keyboardHandler) {
|
||||
this.keyBinding.setKeyboardHandler(keyboardHandler);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -56,6 +56,14 @@ function FoldHandler(editor) {
|
|||
event.preventDefault();
|
||||
}
|
||||
});
|
||||
|
||||
editor.on("gutterclick", function(e) {
|
||||
if (e.domEvent.target.className.indexOf("ace_fold-widget") != -1) {
|
||||
var row = e.getDocumentPosition().row;
|
||||
editor.session.onFoldWidgetClick(row, e.domEvent);
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
exports.FoldHandler = FoldHandler;
|
||||
|
|
|
|||
|
|
@ -56,13 +56,19 @@ var MouseHandler = function(editor) {
|
|||
});
|
||||
|
||||
var mouseTarget = editor.renderer.getMouseEventTarget();
|
||||
event.addListener(mouseTarget, "mousedown", this.onMouseDown.bind(this));
|
||||
event.addListener(mouseTarget, "click", this.onMouseClick.bind(this));
|
||||
event.addListener(mouseTarget, "mousemove", this.onMouseMove.bind(this));
|
||||
event.addMultiMouseDownListener(mouseTarget, 0, 2, 500, this.onMouseDoubleClick.bind(this));
|
||||
event.addMultiMouseDownListener(mouseTarget, 0, 3, 600, this.onMouseTripleClick.bind(this));
|
||||
event.addMultiMouseDownListener(mouseTarget, 0, 4, 600, this.onMouseQuadClick.bind(this));
|
||||
event.addMouseWheelListener(editor.container, this.onMouseWheel.bind(this));
|
||||
event.addListener(mouseTarget, "mousedown", this.onMouseEvent.bind(this, "mousedown"));
|
||||
event.addListener(mouseTarget, "click", this.onMouseEvent.bind(this, "click"));
|
||||
event.addListener(mouseTarget, "mousemove", this.onMouseMove.bind(this, "mousemove"));
|
||||
event.addMultiMouseDownListener(mouseTarget, 0, 2, 500, this.onMouseEvent.bind(this, "dblclick"));
|
||||
event.addMultiMouseDownListener(mouseTarget, 0, 3, 600, this.onMouseEvent.bind(this, "tripleclick"));
|
||||
event.addMultiMouseDownListener(mouseTarget, 0, 4, 600, this.onMouseEvent.bind(this, "quadclick"));
|
||||
event.addMouseWheelListener(editor.container, this.onMouseWheel.bind(this, "mousewheel"));
|
||||
|
||||
var gutterEl = editor.renderer.$gutter;
|
||||
event.addListener(gutterEl, "mousedown", this.onMouseEvent.bind(this, "guttermousedown"));
|
||||
event.addListener(gutterEl, "click", this.onMouseEvent.bind(this, "gutterclick"));
|
||||
event.addListener(gutterEl, "dblclick", this.onMouseEvent.bind(this, "gutterdblclick"));
|
||||
event.addListener(gutterEl, "mousemove", this.onMouseMove.bind(this, "gutter"));
|
||||
};
|
||||
|
||||
(function() {
|
||||
|
|
@ -76,42 +82,26 @@ var MouseHandler = function(editor) {
|
|||
return this.$scrollSpeed;
|
||||
};
|
||||
|
||||
this.onMouseDown = function(e) {
|
||||
this.editor._dispatchEvent("mousedown", new MouseEvent(e, this.editor));
|
||||
this.onMouseEvent = function(name, e) {
|
||||
this.editor._dispatchEvent(name, new MouseEvent(e, this.editor));
|
||||
};
|
||||
|
||||
this.onMouseClick = function(e) {
|
||||
this.editor._dispatchEvent("click", new MouseEvent(e, this.editor));
|
||||
};
|
||||
|
||||
this.onMouseMove = function(e) {
|
||||
this.onMouseMove = function(name, e) {
|
||||
// optimization, because mousemove doesn't have a default handler.
|
||||
var listeners = this.editor._eventRegistry && this.editor._eventRegistry.mousemove;
|
||||
if (!listeners || !listeners.length)
|
||||
return;
|
||||
|
||||
this.editor._dispatchEvent("mousemove", new MouseEvent(e, this.editor));
|
||||
this.editor._dispatchEvent(name, new MouseEvent(e, this.editor));
|
||||
};
|
||||
|
||||
this.onMouseDoubleClick = function(e) {
|
||||
this.editor._dispatchEvent("dblclick", new MouseEvent(e, this.editor));
|
||||
};
|
||||
|
||||
this.onMouseTripleClick = function(e) {
|
||||
this.editor._dispatchEvent("tripleclick", new MouseEvent(e, this.editor));
|
||||
};
|
||||
|
||||
this.onMouseQuadClick = function(e) {
|
||||
this.editor._dispatchEvent("quadclick", new MouseEvent(e, this.editor));
|
||||
};
|
||||
|
||||
this.onMouseWheel = function(e) {
|
||||
this.onMouseWheel = function(name, e) {
|
||||
var mouseEvent = new MouseEvent(e, this.editor);
|
||||
mouseEvent.speed = this.$scrollSpeed * 2;
|
||||
mouseEvent.wheelX = e.wheelX;
|
||||
mouseEvent.wheelY = e.wheelY;
|
||||
|
||||
this.editor._dispatchEvent("mousewheel", mouseEvent);
|
||||
this.editor._dispatchEvent(name, mouseEvent);
|
||||
};
|
||||
|
||||
}).call(MouseHandler.prototype);
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ var VirtualRenderer = function(container, theme) {
|
|||
this.scroller.appendChild(this.content);
|
||||
|
||||
this.$gutterLayer = new GutterLayer(this.$gutter);
|
||||
this.$gutterLayer.on("changeGutterWidth", this.onResize.bind(this, true));
|
||||
this.$gutterLayer.on("changeGutterWidth", this.onResize.bind(this, true));
|
||||
|
||||
this.$markerBack = new MarkerLayer(this.content);
|
||||
|
||||
|
|
@ -120,8 +120,6 @@ var VirtualRenderer = function(container, theme) {
|
|||
|
||||
_self.$loop.schedule(_self.CHANGE_FULL);
|
||||
});
|
||||
event.addListener(this.$gutter, "click", this.$onGutterClick.bind(this));
|
||||
event.addListener(this.$gutter, "dblclick", this.$onGutterClick.bind(this));
|
||||
|
||||
this.$size = {
|
||||
width: 0,
|
||||
|
|
@ -249,7 +247,7 @@ var VirtualRenderer = function(container, theme) {
|
|||
|
||||
var gutterWidth = this.showGutter ? this.$gutter.offsetWidth : 0;
|
||||
this.scroller.style.left = gutterWidth + "px";
|
||||
size.scrollerWidth = Math.max(0, width - gutterWidth - this.scrollBar.getWidth())
|
||||
size.scrollerWidth = Math.max(0, width - gutterWidth - this.scrollBar.getWidth());
|
||||
this.scroller.style.width = size.scrollerWidth + "px";
|
||||
|
||||
if (this.session.getUseWrapMode() && this.adjustWrapLimit() || force)
|
||||
|
|
@ -265,19 +263,6 @@ var VirtualRenderer = function(container, theme) {
|
|||
return this.session.adjustWrapLimit(limit);
|
||||
};
|
||||
|
||||
this.$onGutterClick = function(e) {
|
||||
var pageY = event.getDocumentY(e);
|
||||
var row = this.screenToTextCoordinates(0, pageY).row;
|
||||
|
||||
if (e.target.className.indexOf('ace_fold-widget') != -1)
|
||||
return this.session.onFoldWidgetClick(row, e);
|
||||
|
||||
this._dispatchEvent("gutter" + e.type, {
|
||||
row: row,
|
||||
htmlEvent: e
|
||||
});
|
||||
};
|
||||
|
||||
this.setShowInvisibles = function(showInvisibles) {
|
||||
if (this.$textLayer.setShowInvisibles(showInvisibles))
|
||||
this.$loop.schedule(this.CHANGE_TEXT);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue