From d40d7aa03920301cf83a25c4d198eb17a4155910 Mon Sep 17 00:00:00 2001
From: Julia Radzhabova <julia.radzhabova@onlyoffice.com>
Date: Fri, 24 Jul 2020 14:32:06 +0300
Subject: [PATCH] [DE] Sort autocorrection list

---
 apps/common/main/lib/view/AutoCorrectDialog.js | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/apps/common/main/lib/view/AutoCorrectDialog.js b/apps/common/main/lib/view/AutoCorrectDialog.js
index 0240434ec..ae05d0f8f 100644
--- a/apps/common/main/lib/view/AutoCorrectDialog.js
+++ b/apps/common/main/lib/view/AutoCorrectDialog.js
@@ -103,7 +103,7 @@ define([
             ].join('');
 
             this.options.tpl = _.template(this.template)(this.options);
-            this.mathStore = this.options.mathStore || [];
+            this.mathStore = this.options.mathStore || new Common.UI.DataViewStore();
             this.api = this.options.api;
 
             var path = this.appPrefix + "settings-math-correct";
@@ -127,7 +127,7 @@ define([
             this.mathList = new Common.UI.ListView({
                 el: $window.find('#auto-correct-math-list'),
                 store: this.mathStore,
-                simpleAddMode: true,
+                simpleAddMode: false,
                 template: _.template(['<div class="listview inner" style=""></div>'].join('')),
                 itemTemplate: _.template([
                     '<div id="<%= id %>" class="list-item" style="pointer-events:none;width: 100%;display:flex;">',
@@ -318,6 +318,15 @@ define([
         onResetList: function(clear) {
             if (this.mathStore.length>0 && !clear) return;
 
+            if (this.mathStore.length==0) {
+                this.mathStore.comparator = function(item1, item2) {
+                    var n1 = item1.get('replaced').toLowerCase(),
+                        n2 = item2.get('replaced').toLowerCase();
+                    if (n1==n2) return 0;
+                    return (n1<n2) ? -1 : 1;
+                };
+            }
+
             if (clear) {
                 // remove storage data
                 var path = this.appPrefix + "settings-math-correct";