Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: hash tags enclosed in double brackets is broken #9030

Merged
merged 2 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions e2e-tests/editor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ test('hashtag search page auto-complete', async ({ page, block }) => {
await block.mustFill("done")
})

test('hashtag search #[[ page auto-complete', async ({ page, block }) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙌

await createRandomPage(page)

await block.activeEditing(0)

await page.type('textarea >> nth=0', '#[[', { delay: 100 })
await page.waitForSelector('text="Search for a page"', { state: 'visible' })
await page.keyboard.press('Escape', { delay: 50 })
})

test('disappeared children #4814', async ({ page, block }) => {
await createRandomPage(page)

Expand Down
5 changes: 3 additions & 2 deletions src/main/frontend/commands.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,9 @@
{:keys [last-pattern postfix-fn backward-pos end-pattern backward-truncate-number command]
:as _option}]
(when-let [input (gdom/getElement id)]
(let [last-pattern (when-not backward-truncate-number
(or last-pattern (state/get-editor-command-trigger)))
(let [last-pattern (when-not (= last-pattern :skip-check)
(when-not backward-truncate-number
(or last-pattern (state/get-editor-command-trigger))))
edit-content (gobj/get input "value")
current-pos (cursor/pos input)
current-pos (or
Expand Down
115 changes: 63 additions & 52 deletions src/main/frontend/handler/editor.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2915,66 +2915,77 @@
:else
nil))))

(defn- input-page-ref?
[k current-pos blank-selected? last-key-code]
(and blank-selected?
(contains? keycode/left-square-brackets-keys k)
(= (:key last-key-code) k)
(> current-pos 0)))

(defn- default-case-for-keyup-handler
[input current-pos k code is-processed? c]
(let [last-key-code (state/get-last-key-code)
blank-selected? (string/blank? (util/get-selected-text))
non-enter-processed? (and is-processed? ;; #3251
(not= code keycode/enter-code)) ;; #3459
editor-action (state/get-editor-action)]
(when (and (not editor-action) (not non-enter-processed?))
(cond
;; When you type text inside square brackets
(and (not (contains? #{"ArrowDown" "ArrowLeft" "ArrowRight" "ArrowUp" "Escape"} k))
(wrapped-by? input page-ref/left-brackets page-ref/right-brackets))
(let [orig-pos (cursor/get-caret-pos input)
value (gobj/get input "value")
square-pos (string/last-index-of (subs value 0 (:pos orig-pos)) page-ref/left-brackets)
pos (+ square-pos 2)
_ (state/set-editor-last-pos! pos)
pos (assoc orig-pos :pos pos)
command-step (if (= \# (util/nth-safe value (dec square-pos)))
:editor/search-page-hashtag
:editor/search-page)]
(commands/handle-step [command-step])
(state/set-editor-action-data! {:pos pos}))

;; Handle non-ascii square brackets
(and blank-selected?
(contains? keycode/left-square-brackets-keys k)
(= (:key last-key-code) k)
(> current-pos 0)
(not (wrapped-by? input page-ref/left-brackets page-ref/right-brackets)))
(do
(commands/handle-step [:editor/input page-ref/left-and-right-brackets {:backward-truncate-number 2
(if (and (= editor-action :page-search-hashtag)
(input-page-ref? k current-pos blank-selected? last-key-code))
(do
(commands/handle-step [:editor/input page-ref/right-brackets {:last-pattern :skip-check
:backward-pos 2}])
(commands/handle-step [:editor/search-page])
(state/set-editor-action-data! {:pos (cursor/get-caret-pos input)}))
(when (and (not editor-action) (not non-enter-processed?))
(cond
;; When you type text inside square brackets
(and (not (contains? #{"ArrowDown" "ArrowLeft" "ArrowRight" "ArrowUp" "Escape"} k))
(wrapped-by? input page-ref/left-brackets page-ref/right-brackets))
(let [orig-pos (cursor/get-caret-pos input)
value (gobj/get input "value")
square-pos (string/last-index-of (subs value 0 (:pos orig-pos)) page-ref/left-brackets)
pos (+ square-pos 2)
_ (state/set-editor-last-pos! pos)
pos (assoc orig-pos :pos pos)
command-step (if (= \# (util/nth-safe value (dec square-pos)))
:editor/search-page-hashtag
:editor/search-page)]
(commands/handle-step [command-step])
(state/set-editor-action-data! {:pos pos}))

;; Handle non-ascii square brackets
(and (input-page-ref? k current-pos blank-selected? last-key-code)
(not (wrapped-by? input page-ref/left-brackets page-ref/right-brackets)))
(do
(commands/handle-step [:editor/input page-ref/left-and-right-brackets {:backward-truncate-number 2
:backward-pos 2}])
(commands/handle-step [:editor/search-page])
(state/set-editor-action-data! {:pos (cursor/get-caret-pos input)}))

;; Handle non-ascii parentheses
(and blank-selected?
(contains? keycode/left-paren-keys k)
(= (:key last-key-code) k)
(> current-pos 0)
(not (wrapped-by? input block-ref/left-parens block-ref/right-parens)))
(do
(commands/handle-step [:editor/input block-ref/left-and-right-parens {:backward-truncate-number 2
:backward-pos 2}])
(commands/handle-step [:editor/search-page])
(state/set-editor-action-data! {:pos (cursor/get-caret-pos input)}))

;; Handle non-ascii parentheses
(and blank-selected?
(contains? keycode/left-paren-keys k)
(= (:key last-key-code) k)
(> current-pos 0)
(not (wrapped-by? input block-ref/left-parens block-ref/right-parens)))
(do
(commands/handle-step [:editor/input block-ref/left-and-right-parens {:backward-truncate-number 2
:backward-pos 2}])
(commands/handle-step [:editor/search-block :reference])
(state/set-editor-action-data! {:pos (cursor/get-caret-pos input)}))

;; Handle non-ascii angle brackets
(and (= "〈" c)
(= "《" (util/nth-safe (gobj/get input "value") (dec (dec current-pos))))
(> current-pos 0))
(do
(commands/handle-step [:editor/input commands/angle-bracket {:last-pattern "《〈"
:backward-pos 0}])
(state/set-editor-action-data! {:pos (cursor/get-caret-pos input)})
(state/set-editor-show-block-commands!))

:else
nil))))
(commands/handle-step [:editor/search-block :reference])
(state/set-editor-action-data! {:pos (cursor/get-caret-pos input)}))

;; Handle non-ascii angle brackets
(and (= "〈" c)
(= "《" (util/nth-safe (gobj/get input "value") (dec (dec current-pos))))
(> current-pos 0))
(do
(commands/handle-step [:editor/input commands/angle-bracket {:last-pattern "《〈"
:backward-pos 0}])
(state/set-editor-action-data! {:pos (cursor/get-caret-pos input)})
(state/set-editor-show-block-commands!))

:else
nil)))))

(defn keyup-handler
[_state input input-id]
Expand Down