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.container = container;
|
||||||
this.renderer = renderer;
|
this.renderer = renderer;
|
||||||
|
|
||||||
this.textInput = new TextInput(container, this);
|
this.textInput = new TextInput(renderer.getTextAreaContainer(), this);
|
||||||
this.keyBinding = new KeyBinding(this);
|
this.keyBinding = new KeyBinding(this);
|
||||||
var self = this;
|
var self = this;
|
||||||
event.addListener(container, "mousedown", function(e) {
|
event.addListener(container, "mousedown", function(e) {
|
||||||
|
|
@ -281,6 +281,11 @@ var Editor =function(renderer, session) {
|
||||||
|
|
||||||
this.onCursorChange = function(e) {
|
this.onCursorChange = function(e) {
|
||||||
this.$highlightBrackets();
|
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);
|
this.renderer.updateCursor(this.getCursorPosition(), this.$overwrite);
|
||||||
|
|
||||||
if (!this.$blockScrolling && (!e || !e.blockScrolling)) {
|
if (!this.$blockScrolling && (!e || !e.blockScrolling)) {
|
||||||
|
|
|
||||||
|
|
@ -43,35 +43,13 @@ var TextInput = function(parentNode, host) {
|
||||||
|
|
||||||
var text = document.createElement("textarea");
|
var text = document.createElement("textarea");
|
||||||
var style = text.style;
|
var style = text.style;
|
||||||
style.position = "fixed";
|
style.position = "absolute";
|
||||||
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.zIndex = -1;
|
style.zIndex = -1;
|
||||||
style.opacity = 0;
|
style.opacity = 0;
|
||||||
|
style.border = "none";
|
||||||
style.width = "10px";
|
style.width = "10px";
|
||||||
style.height = "30px";
|
style.height = "30px";
|
||||||
|
parentNode.appendChild(text);
|
||||||
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);
|
|
||||||
});
|
|
||||||
|
|
||||||
var PLACEHOLDER = String.fromCharCode(0);
|
var PLACEHOLDER = String.fromCharCode(0);
|
||||||
sendText();
|
sendText();
|
||||||
|
|
@ -182,6 +160,10 @@ var TextInput = function(parentNode, host) {
|
||||||
this.blur = function() {
|
this.blur = function() {
|
||||||
text.blur();
|
text.blur();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.getElement = function() {
|
||||||
|
return text;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.TextInput = TextInput;
|
exports.TextInput = TextInput;
|
||||||
|
|
|
||||||
|
|
@ -291,6 +291,19 @@ var VirtualRenderer = function(container, theme) {
|
||||||
this.getMouseEventTarget = function() {
|
this.getMouseEventTarget = function() {
|
||||||
return this.content;
|
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() {
|
this.getFirstVisibleRow = function() {
|
||||||
return (this.layerConfig || {}).firstRow || 0;
|
return (this.layerConfig || {}).firstRow || 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue