Skip to content

Commit

Permalink
MDL-44225 atto_equation: Set focus after adding equation from toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols authored and Damyon Wiese committed Mar 26, 2014
1 parent a279604 commit 9ee8a35
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},

/**
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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);
},

/**
Expand Down
15 changes: 14 additions & 1 deletion lib/editor/atto/plugins/equation/yui/src/button/js/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},

/**
Expand Down

0 comments on commit 9ee8a35

Please sign in to comment.