Merge pull request #1502 from ajaxorg/scrolling_issues

fix several small issues on mac
This commit is contained in:
Ruben Daniels 2013-07-06 03:48:01 -07:00
commit 65713e974b
4 changed files with 69 additions and 12 deletions

View file

@ -80,6 +80,39 @@ exports.handler = {
data.lastEvent = "keypress";
}
},
// on mac, with some keyboard layouts (e.g swedish) ^ starts composition, we don't need it in normal mode
updateMacCompositionHandlers: function(editor, enable) {
var onCompositionUpdateOverride = function(text) {
if (util.currentMode !== "insert") {
var el = this.textInput.getElement();
el.blur();
el.focus();
el.value = text;
} else {
this.onCompositionUpdateOrig(text);
}
};
var onCompositionStartOverride = function(text) {
if (util.currentMode === "insert") {
this.onCompositionStartOrig(text);
}
}
if (enable) {
if (!editor.onCompositionUpdateOrig) {
editor.onCompositionUpdateOrig = editor.onCompositionUpdate;
editor.onCompositionUpdate = onCompositionUpdateOverride;
editor.onCompositionStartOrig = editor.onCompositionStart;
editor.onCompositionStart = onCompositionStartOverride;
}
} else {
if (editor.onCompositionUpdateOrig) {
editor.onCompositionUpdate = editor.onCompositionUpdateOrig;
editor.onCompositionUpdateOrig = null;
editor.onCompositionStart = editor.onCompositionStartOrig;
editor.onCompositionStartOrig = null;
}
}
},
handleKeyboard: function(data, hashId, key, keyCode, e) {
// ignore command keys (shift, ctrl etc.)
@ -132,12 +165,15 @@ exports.handler = {
if (util.currentMode !== "insert")
cmds.coreCommands.stop.exec(editor);
editor.$vimModeHandler = this;
this.updateMacCompositionHandlers(editor, true);
},
detach: function(editor) {
editor.removeListener("click", exports.onCursorMove);
util.noMode(editor);
util.currentMode = "normal";
this.updateMacCompositionHandlers(editor, false);
},
actions: cmds.actions,

View file

@ -83,6 +83,18 @@ var actions = exports.actions = {
case "b":
editor.renderer.alignCursor(null, 1);
break;
case "c":
editor.session.onFoldWidgetClick(range.start.row, {domEvent:{target :{}}});
break;
case "o":
editor.session.onFoldWidgetClick(range.start.row, {domEvent:{target :{}}});
break;
case "C":
editor.session.foldAll();
break;
case "O":
editor.session.unfold();
break;
}
}
},

View file

@ -141,9 +141,9 @@ else {
}
exports.addMouseWheelListener = function(el, callback) {
var factor = 8;
var listener = function(e) {
if (e.wheelDelta !== undefined) {
if ("onmousewheel" in el) {
var factor = 8;
exports.addListener(el, "mousewheel", function(e) {
if (e.wheelDeltaX !== undefined) {
e.wheelX = -e.wheelDeltaX / factor;
e.wheelY = -e.wheelDeltaY / factor;
@ -151,8 +151,16 @@ exports.addMouseWheelListener = function(el, callback) {
e.wheelX = 0;
e.wheelY = -e.wheelDelta / factor;
}
}
else {
callback(e);
});
} else if ("onwheel" in el) {
exports.addListener(el, "wheel", function(e) {
e.wheelX = (e.deltaX || 0) * 5;
e.wheelY = (e.deltaY || 0) * 5;
callback(e);
});
} else {
exports.addListener(el, "DOMMouseScroll", function(e) {
if (e.axis && e.axis == e.HORIZONTAL_AXIS) {
e.wheelX = (e.detail || 0) * 5;
e.wheelY = 0;
@ -160,11 +168,9 @@ exports.addMouseWheelListener = function(el, callback) {
e.wheelX = 0;
e.wheelY = (e.detail || 0) * 5;
}
}
callback(e);
};
exports.addListener(el, "DOMMouseScroll", listener);
exports.addListener(el, "mousewheel", listener);
callback(e);
});
}
};
exports.addMultiMouseDownListener = function(el, timeouts, eventHandler, callbackName) {

View file

@ -727,7 +727,8 @@ var VirtualRenderer = function(container, theme) {
changes & this.CHANGE_SIZE ||
changes & this.CHANGE_TEXT ||
changes & this.CHANGE_LINES ||
changes & this.CHANGE_SCROLL
changes & this.CHANGE_SCROLL ||
changes & this.CHANGE_H_SCROLL
)
this.$computeLayerConfig();
@ -1269,7 +1270,9 @@ var VirtualRenderer = function(container, theme) {
if (deltaY > 0 && this.session.getScrollTop() + this.$size.scrollerHeight
- this.layerConfig.maxHeight < -1 + this.scrollMargin.bottom)
return true;
// todo: handle horizontal scrolling
// todo: better handle horizontal scrolling
if (deltaX)
return true;
};
this.pixelToScreenCoordinates = function(x, y) {