MDL-44225 atto_equation: Set focus after adding equation from toolbar

This commit is contained in:
Andrew Nicols 2014-03-08 01:01:10 +08:00 committed by Damyon Wiese
parent a279604330
commit 9ee8a359c9
4 changed files with 43 additions and 4 deletions

View File

@ -322,8 +322,21 @@ M.atto_equation = M.atto_equation || {
value = value.substring(0, this.lastcursorpos) + tex + value.substring(this.lastcursorpos, value.length);
input.set('value', value);
M.atto_equation.update_preview(false, elementid);
input.focus();
var focusPoint = this.lastcursorpos + tex.length,
realInput = input.getDOMNode();
if (typeof realInput.selectionStart === "number") {
// Modern browsers have selectionStart and selectionEnd to control the cursor position.
realInput.selectionStart = realInput.selectionEnd = focusPoint;
} else if (typeof realInput.createTextRange !== "undefined") {
// Legacy browsers (IE<=9) use createTextRange().
var range = realInput.createTextRange();
range.moveToPoint(focusPoint);
range.select();
}
// Focus must be set before updating the preview for the cursor box to be in the correct location.
M.atto_equation.update_preview(false, elementid);
},
/**

View File

@ -322,8 +322,21 @@ M.atto_equation = M.atto_equation || {
value = value.substring(0, this.lastcursorpos) + tex + value.substring(this.lastcursorpos, value.length);
input.set('value', value);
M.atto_equation.update_preview(false, elementid);
input.focus();
var focusPoint = this.lastcursorpos + tex.length,
realInput = input.getDOMNode();
if (typeof realInput.selectionStart === "number") {
// Modern browsers have selectionStart and selectionEnd to control the cursor position.
realInput.selectionStart = realInput.selectionEnd = focusPoint;
} else if (typeof realInput.createTextRange !== "undefined") {
// Legacy browsers (IE<=9) use createTextRange().
var range = realInput.createTextRange();
range.moveToPoint(focusPoint);
range.select();
}
// Focus must be set before updating the preview for the cursor box to be in the correct location.
M.atto_equation.update_preview(false, elementid);
},
/**

View File

@ -320,8 +320,21 @@ M.atto_equation = M.atto_equation || {
value = value.substring(0, this.lastcursorpos) + tex + value.substring(this.lastcursorpos, value.length);
input.set('value', value);
M.atto_equation.update_preview(false, elementid);
input.focus();
var focusPoint = this.lastcursorpos + tex.length,
realInput = input.getDOMNode();
if (typeof realInput.selectionStart === "number") {
// Modern browsers have selectionStart and selectionEnd to control the cursor position.
realInput.selectionStart = realInput.selectionEnd = focusPoint;
} else if (typeof realInput.createTextRange !== "undefined") {
// Legacy browsers (IE<=9) use createTextRange().
var range = realInput.createTextRange();
range.moveToPoint(focusPoint);
range.select();
}
// Focus must be set before updating the preview for the cursor box to be in the correct location.
M.atto_equation.update_preview(false, elementid);
},
/**