Skip to content

Commit

Permalink
just pass in text input to textInput
Browse files Browse the repository at this point in the history
no need to pass in event object
  • Loading branch information
laughinghan committed Mar 27, 2011
1 parent 8e2370a commit bbf7a3a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/baseclasses.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

/**
Expand Down
8 changes: 3 additions & 5 deletions src/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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));
Expand All @@ -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();
Expand Down
26 changes: 13 additions & 13 deletions src/rootelements.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bbf7a3a

Please sign in to comment.