Browse Source

fix: e2e test

Tienson Qin 3 years ago
parent
commit
f502de3ad4
2 changed files with 9 additions and 18 deletions
  1. 1 4
      e2e-tests/editor.spec.ts
  2. 8 14
      src/main/frontend/handler/editor.cljs

+ 1 - 4
e2e-tests/editor.spec.ts

@@ -220,10 +220,7 @@ test('undo and redo after starting an action should not destroy text #6267', asy
   await page.waitForTimeout(550) // Wait for 500ms autosave period to expire
 
   // Then type more, start an action prompt, and undo
-  await page.keyboard.type('text2 ')
-  for (const char of '[[') {
-    await page.keyboard.type(char)
-  }
+  await page.keyboard.type('text2 [[')
   await expect(page.locator(`[data-modal-name="page-search"]`)).toBeVisible()
   if (IsMac) {
     await page.keyboard.press('Meta+z')

+ 8 - 14
src/main/frontend/handler/editor.cljs

@@ -1766,19 +1766,11 @@
 (defn close-autocomplete-if-outside
   [input]
   (when (and input
-             (state/get-editor-action)
-             (not (wrapped-by? input page-ref/left-brackets page-ref/right-brackets)))
-    (let [value (gobj/get input "value")
-          pos (state/get-editor-last-pos)
-          current-pos (cursor/pos input)
-          between (gp-util/safe-subs value (min pos current-pos) (max pos current-pos))]
-      (when (and between
-                 (or
-                  (string/includes? between "[")
-                  (string/includes? between "]")
-                  (string/includes? between "(")
-                  (string/includes? between ")")))
-        (state/clear-editor-action!)))))
+             (contains? #{:page-search :page-search-hashtag :block-search} (state/get-editor-action))
+             (not (wrapped-by? input page-ref/left-brackets page-ref/right-brackets))
+             (not (wrapped-by? input block-ref/left-parens block-ref/right-parens))
+             (not (wrapped-by? input "#" "")))
+    (state/clear-editor-action!)))
 
 (defn resize-image!
   [block-id metadata full_text size]
@@ -2915,7 +2907,9 @@
                 (state/set-editor-show-block-commands!))
 
               :else
-              (close-autocomplete-if-outside input))))
+              nil)))
+
+        (close-autocomplete-if-outside input)
 
         (when-not (or (= k "Shift") is-processed?)
           (state/set-last-key-code! {:key-code key-code