Browse Source

BugFix: in richer editor @ autocomplete doesn't really insert the user name into comment properly

Sam X. Chen 5 years ago
parent
commit
194b6ad46e
2 changed files with 29 additions and 6 deletions
  1. 28 6
      client/components/main/editor.js
  2. 1 0
      client/lib/textComplete.js

+ 28 - 6
client/components/main/editor.js

@@ -156,25 +156,47 @@ Template.editor.onRendered(() => {
         }
         }
         return undefined;
         return undefined;
       };
       };
+      let popupShown = false;
       inputs.each(function(idx, input) {
       inputs.each(function(idx, input) {
         mSummernotes[idx] = $(input).summernote({
         mSummernotes[idx] = $(input).summernote({
           placeholder,
           placeholder,
           callbacks: {
           callbacks: {
+            onKeydown(e) {
+              if (popupShown) {
+                e.preventDefault();
+              }
+            },
+            onKeyup(e) {
+              if (popupShown) {
+                e.preventDefault();
+              }
+            },
             onInit(object) {
             onInit(object) {
               const originalInput = this;
               const originalInput = this;
+              const setAutocomplete = function(jEditor) {
+                if (jEditor !== undefined) {
+                  jEditor.escapeableTextComplete(mentions).on({
+                    'textComplete:show'() {
+                      popupShown = true;
+                    },
+                    'textComplete:hide'() {
+                      popupShown = false;
+                    },
+                  });
+                }
+              };
               $(originalInput).on('submitted', function() {
               $(originalInput).on('submitted', function() {
                 // resetCommentInput has been called
                 // resetCommentInput has been called
                 if (!this.value) {
                 if (!this.value) {
                   const sn = getSummernote(this);
                   const sn = getSummernote(this);
-                  sn && sn.summernote('reset');
-                  object && object.editingArea.find('.note-placeholder').show();
+                  sn && sn.summernote('code', '');
+                  setAutocomplete(jEditor);
+                  //object && object.editingArea.find('.note-placeholder').show();
                 }
                 }
               });
               });
               const jEditor = object && object.editable;
               const jEditor = object && object.editable;
               const toolbar = object && object.toolbar;
               const toolbar = object && object.toolbar;
-              if (jEditor !== undefined) {
-                jEditor.escapeableTextComplete(mentions);
-              }
+              setAutocomplete(jEditor);
               if (toolbar !== undefined) {
               if (toolbar !== undefined) {
                 const fBtn = toolbar.find('.btn-fullscreen');
                 const fBtn = toolbar.find('.btn-fullscreen');
                 fBtn.on('click', function() {
                 fBtn.on('click', function() {
@@ -264,7 +286,7 @@ Template.editor.onRendered(() => {
                 const someNote = getSummernote(object);
                 const someNote = getSummernote(object);
                 const original = someNote.summernote('code');
                 const original = someNote.summernote('code');
                 const cleaned = cleanPastedHTML(original); //this is where to call whatever clean function you want. I have mine in a different file, called CleanPastedHTML.
                 const cleaned = cleanPastedHTML(original); //this is where to call whatever clean function you want. I have mine in a different file, called CleanPastedHTML.
-                someNote.summernote('reset'); //clear original
+                someNote.summernote('code', ''); //clear original
                 someNote.summernote('pasteHTML', cleaned); //this sets the displayed content editor to the cleaned pasted code.
                 someNote.summernote('pasteHTML', cleaned); //this sets the displayed content editor to the cleaned pasted code.
               };
               };
               setTimeout(function() {
               setTimeout(function() {

+ 1 - 0
client/lib/textComplete.js

@@ -45,6 +45,7 @@ $.fn.escapeableTextComplete = function(strategies, options, ...otherArgs) {
       });
       });
     },
     },
   });
   });
+  return this;
 };
 };
 
 
 EscapeActions.register('textcomplete', () => {}, () => dropdownMenuIsOpened, {
 EscapeActions.register('textcomplete', () => {}, () => dropdownMenuIsOpened, {