diff --git a/src/baseclasses.js b/src/baseclasses.js index cc5476102..c54b86f6e 100644 --- a/src/baseclasses.js +++ b/src/baseclasses.js @@ -28,8 +28,8 @@ _.foldChildren = function(fold, fn) { _.keydown = function(e) { return this.parent.keydown(e); }; -_.textInput = function(e) { - return this.parent.textInput(e); +_.textInput = function(ch) { + return this.parent.textInput(ch); }; /** diff --git a/src/commands.js b/src/commands.js index 8342daf7e..0afc5c97f 100755 --- a/src/commands.js +++ b/src/commands.js @@ -295,9 +295,8 @@ _.keydown = function(e) { } return this.parent.keydown(e); }; -_.textInput = function(e) { +_.textInput = function(ch) { this.cursor.deleteSelection(); - var ch = e.data; if (ch !== '$') this.write(ch); else if (this.isEmpty()) @@ -418,8 +417,7 @@ _.keydown = function(e) { } return this.parent.keydown(e); }; -_.textInput = function(e) { - var ch = e.data; +_.textInput = function(ch) { if (ch.match(/[a-z]/i)) { this.cursor.deleteSelection(); this.cursor.insertNew(new VanillaSymbol(ch)); @@ -429,7 +427,7 @@ _.textInput = function(e) { if (ch === ' ' || (ch === '\\' && this.firstChild.isEmpty())) return; - this.cursor.parent.textInput(e); + this.cursor.parent.textInput(ch); }; _.renderCommand = function() { this.jQ = this.jQ.last(); diff --git a/src/rootelements.js b/src/rootelements.js index ea66e8a40..e75561edc 100755 --- a/src/rootelements.js +++ b/src/rootelements.js @@ -46,6 +46,14 @@ function createRoot(jQ, root, textbox, editable) { e.stopPropagation(); }); + //trigger virtual textInput event (see Wiki page "Keyboard Events") + function textInput() { + var text = textarea.val(); + if (!text) return; + textarea.val(''); + cursor.parent.textInput(text); + } + var lastKeydn = {}; //see Wiki page "Keyboard Events" jQ.bind('focus.mathquill blur.mathquill', function(e) { textarea.trigger(e); @@ -76,13 +84,7 @@ function createRoot(jQ, root, textbox, editable) { //after keypress event, trigger virtual textInput event if text was //input to textarea // (see Wiki page "Keyboard Events") - setTimeout(function() { - var text = textarea.val(); - if (!text) return; - textarea.val(''); - e.data = text; - cursor.parent.textInput(e); - }); + setTimeout(textInput); }).bind('mousedown.mathquill', function(e) { cursor.seek($(e.target), e.pageX, e.pageY).blink = $.noop; @@ -329,18 +331,17 @@ _.keydown = function(e) } return true; }; -_.textInput = function(e) { +_.textInput = function(ch) { if (!this.skipTextInput) - this.cursor.write(e.data); + this.cursor.write(ch); }; function RootMathCommand(cursor) { MathCommand.call(this, '$'); this.firstChild.cursor = cursor; - this.firstChild.textInput = function(e) { + this.firstChild.textInput = function(ch) { if (this.skipTextInput) return; - var ch = e.data; if (ch !== '$' || cursor.parent !== this) cursor.write(ch); else if (this.isEmpty()) { @@ -396,11 +397,10 @@ _.renderLatex = function(latex) { } }; _.keydown = RootMathBlock.prototype.keydown; -_.textInput = function(e) { +_.textInput = function(ch) { if (this.skipTextInput) return; this.cursor.deleteSelection(); - var ch = e.data; if (ch === '$') this.cursor.insertNew(new RootMathCommand(this.cursor)); else