moving the textarea over the cursor belongs to the renderer
This commit is contained in:
parent
1a87012957
commit
9db4c1d1f4
3 changed files with 26 additions and 26 deletions
|
|
@ -56,7 +56,7 @@ var Editor =function(renderer, session) {
|
|||
this.container = container;
|
||||
this.renderer = renderer;
|
||||
|
||||
this.textInput = new TextInput(container, this);
|
||||
this.textInput = new TextInput(renderer.getTextAreaContainer(), this);
|
||||
this.keyBinding = new KeyBinding(this);
|
||||
var self = this;
|
||||
event.addListener(container, "mousedown", function(e) {
|
||||
|
|
@ -281,6 +281,11 @@ var Editor =function(renderer, session) {
|
|||
|
||||
this.onCursorChange = function(e) {
|
||||
this.$highlightBrackets();
|
||||
|
||||
// move text input over the cursor
|
||||
// this is required for iOS and IME
|
||||
this.renderer.moveTextAreaToCursor(this.textInput.getElement());
|
||||
|
||||
this.renderer.updateCursor(this.getCursorPosition(), this.$overwrite);
|
||||
|
||||
if (!this.$blockScrolling && (!e || !e.blockScrolling)) {
|
||||
|
|
|
|||
|
|
@ -43,35 +43,13 @@ var TextInput = function(parentNode, host) {
|
|||
|
||||
var text = document.createElement("textarea");
|
||||
var style = text.style;
|
||||
style.position = "fixed";
|
||||
style.left = "-10000px";
|
||||
style.top = "-10000px";
|
||||
parentNode.appendChild(text);
|
||||
|
||||
// move text input over the cursor
|
||||
// this is required for iOS and IME
|
||||
style.left = "0px";
|
||||
style.top = "0px";
|
||||
style.position = "absolute";
|
||||
style.zIndex = -1;
|
||||
style.opacity = 0;
|
||||
style.border = "none";
|
||||
style.width = "10px";
|
||||
style.height = "30px";
|
||||
|
||||
var changeCursor = function() {
|
||||
if (host.renderer.isMockRenderer) return;
|
||||
|
||||
var cursor = host.getCursorPosition();
|
||||
var pos = host.renderer.textToScreenCoordinates(cursor.row, cursor.column);
|
||||
var epos = parentNode.getBoundingClientRect();
|
||||
style.left = (pos.pageX - epos.left - 6) + "px";
|
||||
style.top = (pos.pageY - epos.top + 52) + "px";
|
||||
};
|
||||
|
||||
host.addEventListener("changeSession", function(e) {
|
||||
if (e.oldSession)
|
||||
e.oldSession.getSelection().removeEventListener("changeCursor", changeCursor);
|
||||
e.session.getSelection().addEventListener("changeCursor", changeCursor);
|
||||
});
|
||||
parentNode.appendChild(text);
|
||||
|
||||
var PLACEHOLDER = String.fromCharCode(0);
|
||||
sendText();
|
||||
|
|
@ -182,6 +160,10 @@ var TextInput = function(parentNode, host) {
|
|||
this.blur = function() {
|
||||
text.blur();
|
||||
};
|
||||
|
||||
this.getElement = function() {
|
||||
return text;
|
||||
};
|
||||
};
|
||||
|
||||
exports.TextInput = TextInput;
|
||||
|
|
|
|||
|
|
@ -291,6 +291,19 @@ var VirtualRenderer = function(container, theme) {
|
|||
this.getMouseEventTarget = function() {
|
||||
return this.content;
|
||||
};
|
||||
|
||||
this.getTextAreaContainer = function() {
|
||||
return this.scroller;
|
||||
};
|
||||
|
||||
this.moveTextAreaToCursor = function(textarea) {
|
||||
var pos = this.$cursorLayer.getPixelPosition();
|
||||
if (!pos)
|
||||
return;
|
||||
|
||||
textarea.style.left = (pos.left + this.$padding) + "px";
|
||||
textarea.style.top = pos.top + "px";
|
||||
};
|
||||
|
||||
this.getFirstVisibleRow = function() {
|
||||
return (this.layerConfig || {}).firstRow || 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue