UX: minor fast edit tweaks (#14368)

UX: minor fast edit tweaks (#14368)

  • do not reduce opacity of disabled buttons if they are loading
  • replace ‘|’ by single quotes not double quotes
  • always start from index 0
  • reduces amount of work by checking row’s length
  • apply quotefix to fallback
  • do not add 1 to caretposition if index is 0
diff --git a/app/assets/javascripts/discourse/app/components/quote-button.js b/app/assets/javascripts/discourse/app/components/quote-button.js
index bf4a89b..fb943d9 100644
--- a/app/assets/javascripts/discourse/app/components/quote-button.js
+++ b/app/assets/javascripts/discourse/app/components/quote-button.js
@@ -34,7 +34,7 @@ function getQuoteTitle(element) {
 }
 
 function fixQuotes(str) {
-  return str.replace(/‘|’|„|“|«|»|”/g, '"');
+  return str.replace(/„|“|«|»|”/g, '"').replace(/‘|’/g, "'");
 }
 
 function regexSafeStr(str) {
@@ -353,18 +353,18 @@ export default Component.extend({
       const postModel = this.topic.postStream.findLoadedPost(postId);
       return ajax(`/posts/${postModel.id}`, { type: "GET", cache: false }).then(
         (result) => {
-          let bestIndex;
+          let bestIndex = 0;
           const rows = result.raw.split("\n");
 
           // selecting even a part of the text of a list item will include
           // "* " at the beginning of the buffer, we remove it to be able
           // to find it in row
-          const buffer = this.quoteState.buffer
-            .split("\n")[0]
-            .replace(/^\* /, "");
+          const buffer = fixQuotes(
+            this.quoteState.buffer.split("\n")[0].replace(/^\* /, "")
+          );
 
           rows.some((row, index) => {
-            if (row.includes(buffer)) {
+            if (row.length && row.includes(buffer)) {
               bestIndex = index;
               return true;
             }
@@ -372,26 +372,25 @@ export default Component.extend({
 
           this?.editPost(postModel);
 
-          if (bestIndex) {
-            afterTransition(document.querySelector("#reply-control"), () => {
-              const textarea = document.querySelector(".d-editor-input");
-              if (!textarea || this.isDestroyed || this.isDestroying) {
-                return;
-              }
-
-              // best index brings us to one row before as slice start from 1
-              // we add 1 to be at the beginning of next line
-              setCaretPosition(
-                textarea,
-                rows.slice(0, bestIndex).join("\n").length + 1
-              );
-
-              // ensures we correctly scroll to caret and reloads composer
-              // if we do another selection/edit
-              textarea.blur();
-              textarea.focus();
-            });
-          }
+          afterTransition(document.querySelector("#reply-control"), () => {
+            const textarea = document.querySelector(".d-editor-input");
+            if (!textarea || this.isDestroyed || this.isDestroying) {
+              return;
+            }
+
+            // best index brings us to one row before as slice start from 1
+            // we add 1 to be at the beginning of next line, unless we start from top
+            setCaretPosition(
+              textarea,
+              rows.slice(0, bestIndex).join("\n").length +
+                (bestIndex > 0 ? 1 : 0)
+            );
+
+            // ensures we correctly scroll to caret and reloads composer
+            // if we do another selection/edit
+            textarea.blur();
+            textarea.focus();
+          });
         }
       );
     }
diff --git a/app/assets/stylesheets/common/components/buttons.scss b/app/assets/stylesheets/common/components/buttons.scss
index 207eabd..689cc1a 100644
--- a/app/assets/stylesheets/common/components/buttons.scss
+++ b/app/assets/stylesheets/common/components/buttons.scss
@@ -58,7 +58,9 @@
   }
   &[disabled],
   &.disabled {
-    opacity: 0.4;
+    &:not(.is-loading) {
+      opacity: 0.4;
+    }
     &:hover {
       color: $text-color;
       background: $bg-color;

GitHub sha: 5a5b166b6d508bfe2a2276d78d7a84ec13552888

This commit appears in #14368 which was approved by pmusaraj. It was merged by jjaffeux.