From d4dfd44491e99a3b18cc9ceb3eb27e2a968b8ba6 Mon Sep 17 00:00:00 2001 From: Shamim Rezaie Date: Tue, 10 Aug 2021 05:45:51 +1000 Subject: [PATCH] MDL-56773 atto_equation: The equation editor should always be rtl Also re-applied the border that was added to the preview area as part of MDL-44778. The class name that's used no longer exists. --- lib/editor/atto/plugins/equation/styles.css | 4 ---- .../atto/plugins/equation/tests/behat/equation.feature | 2 ++ .../moodle-atto_equation-button-debug.js | 5 +++-- .../moodle-atto_equation-button-min.js | 4 ++-- .../moodle-atto_equation-button.js | 5 +++-- lib/editor/atto/plugins/equation/yui/src/button/js/button.js | 5 +++-- 6 files changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/editor/atto/plugins/equation/styles.css b/lib/editor/atto/plugins/equation/styles.css index 8df2d6bc67e..3cac262f071 100644 --- a/lib/editor/atto/plugins/equation/styles.css +++ b/lib/editor/atto/plugins/equation/styles.css @@ -9,7 +9,3 @@ padding: 5px; min-width: 206px; } - -.atto_form .atto_equation_preview { - margin-bottom: 0; /* Turn off the margin-bottom from the class "well" */ -} diff --git a/lib/editor/atto/plugins/equation/tests/behat/equation.feature b/lib/editor/atto/plugins/equation/tests/behat/equation.feature index eaf0d09ecbf..fff9e8f9a97 100644 --- a/lib/editor/atto/plugins/equation/tests/behat/equation.feature +++ b/lib/editor/atto/plugins/equation/tests/behat/equation.feature @@ -13,6 +13,7 @@ Feature: Atto equation editor And I select the text in the "Description" Atto editor And I click on "Show more buttons" "button" And I click on "Equation editor" "button" + And the "class" attribute of "Edit equation using" "field" should contain "text-ltr" And I set the field "Edit equation using" to " = 1 \div 0" And I click on "\infty" "button" And I click on "Save equation" "button" @@ -31,6 +32,7 @@ Feature: Atto equation editor And I select the text in the "Description" Atto editor And I click on "Show more buttons" "button" And I click on "Equation editor" "button" + And the "class" attribute of "Edit equation using" "field" should contain "text-ltr" Then the field "Edit equation using" matches value " \pi " And I click on "Save equation" "button" And the field "Description" matches value "

\( \pi \)

" diff --git a/lib/editor/atto/plugins/equation/yui/build/moodle-atto_equation-button/moodle-atto_equation-button-debug.js b/lib/editor/atto/plugins/equation/yui/build/moodle-atto_equation-button/moodle-atto_equation-button-debug.js index 26506612b8e..b80060c71f5 100644 --- a/lib/editor/atto/plugins/equation/yui/build/moodle-atto_equation-button/moodle-atto_equation-button-debug.js +++ b/lib/editor/atto/plugins/equation/yui/build/moodle-atto_equation-button/moodle-atto_equation-button-debug.js @@ -59,10 +59,11 @@ var COMPONENTNAME = 'atto_equation', '
' + '{{{library}}}' + '' + - '
' + '' + - '
' + '
{{get_string "cursorinfo" component}}
' + '
' + diff --git a/lib/editor/atto/plugins/equation/yui/build/moodle-atto_equation-button/moodle-atto_equation-button-min.js b/lib/editor/atto/plugins/equation/yui/build/moodle-atto_equation-button/moodle-atto_equation-button-min.js index 9978c135056..3e06277438b 100644 --- a/lib/editor/atto/plugins/equation/yui/build/moodle-atto_equation-button/moodle-atto_equation-button-min.js +++ b/lib/editor/atto/plugins/equation/yui/build/moodle-atto_equation-button/moodle-atto_equation-button-min.js @@ -1,2 +1,2 @@ -YUI.add("moodle-atto_equation-button",function(r,t){var s="atto_equation",l={EQUATION_TEXT:"atto_equation_equation",EQUATION_PREVIEW:"atto_equation_preview",SUBMIT:"atto_equation_submit",LIBRARY:"atto_equation_library",LIBRARY_GROUPS:"atto_equation_groups",LIBRARY_GROUP_PREFIX:"atto_equation_group"},u={LIBRARY:"."+l.LIBRARY,LIBRARY_GROUP:"."+l.LIBRARY_GROUPS+" > div > div",EQUATION_TEXT:"."+l.EQUATION_TEXT,EQUATION_PREVIEW:"."+l.EQUATION_PREVIEW,SUBMIT:"."+l.SUBMIT,LIBRARY_BUTTON:"."+l.LIBRARY+" button"},c={START:"\\(",END:"\\)"},n='{{{library}}}
{{get_string "cursorinfo" component}}

',d='
{{#each library}}
{{#split "\n" elements}}{{/split}}
{{/each}}
';r.namespace("M.atto_equation").Button=r.Base.create("button",r.M.editor_atto.EditorPlugin,[],{_currentSelection:null,_lastCursorPos:0,_content:null,_sourceEquation:null,_groupFocus:null,_equationPatterns:[/\$\$([\S\s]+?)\$\$/,/\\\(([\S\s]+?)\\\)/,/\\\[([\S\s]+?)\\\]/,/\[tex\]([\S\s]+?)\[\/tex\]/],initializer:function(){this._groupFocus={},this.get("texfilteractive")&&(this.addButton({icon:"e/math",callback:this._displayDialogue}),this.get("host").on("atto:selectionchanged",function(){this._resolveEquation()?this.highlightButtons():this.unHighlightButtons()},this),this.editor.all("tex").each(function(t){var e=r.Node.create(""+c.START+" "+t.get("text")+" "+c.END+"");t.replace(e)}))},_displayDialogue:function(){var t,e,i;this._currentSelection=this.get("host").getSelection(),!1!==this._currentSelection&&(t=this._resolveEquation(),e=this.getDialogue({headerContent:M.util.get_string("pluginname",s),focusAfterHide:!0,width:600,focusOnShowSelector:u.LIBRARY_BUTTON}),i=this._getDialogueContent(),e.set("bodyContent",i),e.show(),require(["core/event"],function(t){t.notifyFilterContentUpdated(e.get("boundingBox").getDOMNode())}),t&&i.one(u.EQUATION_TEXT).set("text",t),this._updatePreview(!1))},_resolveEquation:function(){var c,t=this.get("host").getSelectionParentNode(),d=this.get("host").getSelection(),h=!1;return!!this.get("host").isActive()&&(!!t&&(!(!d||0===d.length)&&(this.sourceEquation=null,d=d[0],c=r.one(t).get("text"),r.Array.find(this._equationPatterns,function(u){var t=c.match(new RegExp(u.source,"g"));if(t&&t.length)return r.Array.find(t,function(t){for(var e,i,n,o,a,s,r,l=0;-1!==c.indexOf(t,l);){if(i=(e=c.indexOf(t,l))+t.length,n=d.startOffset>=e&&d.startOffsete,n&&o&&(a=t.match(u))&&a.length)return r=(s=c.indexOf(a[1],e))+a[1].length,h=a[1],this.sourceEquation={startOuterPosition:e,endOuterPosition:i,outerMatch:t,startInnerPosition:s,endInnerPosition:r,innerMatch:a},!0;l=i}},this)},this),!1!==h&&(h=h.trim()),h)))},_setEquation:function(t){var e,i,n,o,a;o=this.get("host"),t.preventDefault(),this.getDialogue({focusAfterHide:null}).hide(),""!==(n=t.currentTarget.ancestor(".atto_form").one("textarea").get("value"))&&(o.setSelection(this._currentSelection),this.sourceEquation?(n=" "+n+" ",a=(i=(e=r.one(o.getSelectionParentNode())).get("text")).slice(0,this.sourceEquation.startInnerPosition)+n+i.slice(this.sourceEquation.endInnerPosition),e.set("text",a)):(n=c.START+" "+n+" "+c.END,o.insertContentAtFocusPoint(n)),this.markUpdated())},_throttle:function(i,n){var o=null;return function(){var t=this,e=arguments;clearTimeout(o),o=setTimeout(function(){i.apply(t,e)},n)}},_updatePreview:function(t){var e,i,n,o=this._content.one(u.EQUATION_TEXT),a=o.get("value"),s=o.get("selectionStart");for(t&&t.preventDefault(),s=s||0;"\\"===a.charAt(s)&&0<=s;)--s;if(i=/[a-zA-Z\{]/,0!==s&&"{"!=a.charAt(s-1))for(;i.test(a.charAt(s))&&s=o.size()&&(s=0),e=o.item(s),this._setGroupTabFocus(n,e),e.focus()},_setGroupTabFocus:function(t,e){var i=t.generateID();"undefined"!=typeof this._groupFocus[i]&&this._groupFocus[i].setAttribute("tabindex","-1"),(this._groupFocus[i]=e).setAttribute("tabindex",0),t.setAttribute("aria-activedescendant",e.generateID())},_selectLibraryItem:function(t){var e,i,n,o,a,s=t.currentTarget.getAttribute("data-tex"),r=0;t.preventDefault(),this._setGroupTabFocus(t.currentTarget.get("parentNode"),t.currentTarget)," "!==(i=(e=(n=t.currentTarget.ancestor(".atto_form").one("textarea")).get("value")).substring(0,this._lastCursorPos)).charAt(i.length-1)&&(i+=" "),r=(i+=s).length," "!==e.charAt(this._lastCursorPos)&&(i+=" "),i+=e.substring(this._lastCursorPos,e.length),n.set("value",i),n.focus(),"number"==typeof(o=n.getDOMNode()).selectionStart?o.selectionStart=o.selectionEnd=r:"undefined"!=typeof o.createTextRange&&((a=o.createTextRange()).moveToPoint(r),a.select()),this._updatePreview(!1)},_getLibraryContent:function(){var t,e,i,n=r.Handlebars.compile(d),o=this.get("library"),a="";return r.Handlebars.registerHelper("split",function(t,e,i){var n,o,a;if(void 0===t||void 0===e)return"";for(a="",n=e.trim().split(t);0 div > div",EQUATION_TEXT:"."+u.EQUATION_TEXT,EQUATION_PREVIEW:"."+u.EQUATION_PREVIEW,SUBMIT:"."+u.SUBMIT,LIBRARY_BUTTON:"."+u.LIBRARY+" button"},c={START:"\\(",END:"\\)"},n='
{{{library}}}
{{get_string "cursorinfo" component}}

',d='
{{#each library}}
{{#split "\n" elements}}{{/split}}
{{/each}}
';r.namespace("M.atto_equation").Button=r.Base.create("button",r.M.editor_atto.EditorPlugin,[],{_currentSelection:null,_lastCursorPos:0,_content:null,_sourceEquation:null,_groupFocus:null,_equationPatterns:[/\$\$([\S\s]+?)\$\$/,/\\\(([\S\s]+?)\\\)/,/\\\[([\S\s]+?)\\\]/,/\[tex\]([\S\s]+?)\[\/tex\]/],initializer:function(){this._groupFocus={},this.get("texfilteractive")&&(this.addButton({icon:"e/math",callback:this._displayDialogue}),this.get("host").on("atto:selectionchanged",function(){this._resolveEquation()?this.highlightButtons():this.unHighlightButtons()},this),this.editor.all("tex").each(function(t){var e=r.Node.create(""+c.START+" "+t.get("text")+" "+c.END+"");t.replace(e)}))},_displayDialogue:function(){var t,e,i;this._currentSelection=this.get("host").getSelection(),!1!==this._currentSelection&&(t=this._resolveEquation(),e=this.getDialogue({headerContent:M.util.get_string("pluginname",s),focusAfterHide:!0,width:600,focusOnShowSelector:l.LIBRARY_BUTTON}),i=this._getDialogueContent(),e.set("bodyContent",i),e.show(),require(["core/event"],function(t){t.notifyFilterContentUpdated(e.get("boundingBox").getDOMNode())}),t&&i.one(l.EQUATION_TEXT).set("text",t),this._updatePreview(!1))},_resolveEquation:function(){var c,t=this.get("host").getSelectionParentNode(),d=this.get("host").getSelection(),h=!1;return!!this.get("host").isActive()&&(!!t&&(!(!d||0===d.length)&&(this.sourceEquation=null,d=d[0],c=r.one(t).get("text"),r.Array.find(this._equationPatterns,function(l){var t=c.match(new RegExp(l.source,"g"));if(t&&t.length)return r.Array.find(t,function(t){for(var e,i,n,o,a,s,r,u=0;-1!==c.indexOf(t,u);){if(i=(e=c.indexOf(t,u))+t.length,n=d.startOffset>=e&&d.startOffsete,n&&o&&(a=t.match(l))&&a.length)return r=(s=c.indexOf(a[1],e))+a[1].length,h=a[1],this.sourceEquation={startOuterPosition:e,endOuterPosition:i,outerMatch:t,startInnerPosition:s,endInnerPosition:r,innerMatch:a},!0;u=i}},this)},this),!1!==h&&(h=h.trim()),h)))},_setEquation:function(t){var e,i,n,o,a;o=this.get("host"),t.preventDefault(),this.getDialogue({focusAfterHide:null}).hide(),""!==(n=t.currentTarget.ancestor(".atto_form").one("textarea").get("value"))&&(o.setSelection(this._currentSelection),this.sourceEquation?(n=" "+n+" ",a=(i=(e=r.one(o.getSelectionParentNode())).get("text")).slice(0,this.sourceEquation.startInnerPosition)+n+i.slice(this.sourceEquation.endInnerPosition),e.set("text",a)):(n=c.START+" "+n+" "+c.END,o.insertContentAtFocusPoint(n)),this.markUpdated())},_throttle:function(i,n){var o=null;return function(){var t=this,e=arguments;clearTimeout(o),o=setTimeout(function(){i.apply(t,e)},n)}},_updatePreview:function(t){var e,i,n,o=this._content.one(l.EQUATION_TEXT),a=o.get("value"),s=o.get("selectionStart");for(t&&t.preventDefault(),s=s||0;"\\"===a.charAt(s)&&0<=s;)--s;if(i=/[a-zA-Z\{]/,0!==s&&"{"!=a.charAt(s-1))for(;i.test(a.charAt(s))&&s=o.size()&&(s=0),e=o.item(s),this._setGroupTabFocus(n,e),e.focus()},_setGroupTabFocus:function(t,e){var i=t.generateID();"undefined"!=typeof this._groupFocus[i]&&this._groupFocus[i].setAttribute("tabindex","-1"),(this._groupFocus[i]=e).setAttribute("tabindex",0),t.setAttribute("aria-activedescendant",e.generateID())},_selectLibraryItem:function(t){var e,i,n,o,a,s=t.currentTarget.getAttribute("data-tex"),r=0;t.preventDefault(),this._setGroupTabFocus(t.currentTarget.get("parentNode"),t.currentTarget)," "!==(i=(e=(n=t.currentTarget.ancestor(".atto_form").one("textarea")).get("value")).substring(0,this._lastCursorPos)).charAt(i.length-1)&&(i+=" "),r=(i+=s).length," "!==e.charAt(this._lastCursorPos)&&(i+=" "),i+=e.substring(this._lastCursorPos,e.length),n.set("value",i),n.focus(),"number"==typeof(o=n.getDOMNode()).selectionStart?o.selectionStart=o.selectionEnd=r:"undefined"!=typeof o.createTextRange&&((a=o.createTextRange()).moveToPoint(r),a.select()),this._updatePreview(!1)},_getLibraryContent:function(){var t,e,i,n=r.Handlebars.compile(d),o=this.get("library"),a="";return r.Handlebars.registerHelper("split",function(t,e,i){var n,o,a;if(void 0===t||void 0===e)return"";for(a="",n=e.trim().split(t);0' + '{{{library}}}' + '' + - '
' + '' + - '
' + '
{{get_string "cursorinfo" component}}
' + '
' + diff --git a/lib/editor/atto/plugins/equation/yui/src/button/js/button.js b/lib/editor/atto/plugins/equation/yui/src/button/js/button.js index 472e76068d2..e118b879123 100644 --- a/lib/editor/atto/plugins/equation/yui/src/button/js/button.js +++ b/lib/editor/atto/plugins/equation/yui/src/button/js/button.js @@ -57,10 +57,11 @@ var COMPONENTNAME = 'atto_equation', '
' + '{{{library}}}' + '' + - '
' + '' + - '
' + '
{{get_string "cursorinfo" component}}
' + '
' +