Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions telega-completions.el
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ If FUZZY-MATCH is non-nil, also allow fuzzy hyphen matching."
(defun telega-completions--emoji-candidates (prefix fuzzy-match)
"Return local emoji candidates matching PREFIX.
Use FUZZY-MATCH to control fuzzy hyphen matching."
(telega-emoji-init)
(cl-remove-if-not
(lambda (emoji-name)
(telega-completions--emoji-match-p prefix emoji-name fuzzy-match))
Expand Down Expand Up @@ -568,11 +567,11 @@ Handles repeated leading CHARs (e.g. @@). Returns nil if not applicable."
(= (match-beginning 0) telega-chatbuf--input-marker))
(cons (match-beginning 0) (point))))


;;; CAPF: local emoji (:<name>:)

(defun telega-capf-emoji ()
"CAPF for emoji completion using the local emoji list."
(telega-emoji-init)
(when-let* ((end (point))
(start (save-excursion
(and (re-search-backward
Expand All @@ -583,7 +582,6 @@ Handles repeated leading CHARs (e.g. @@). Returns nil if not applicable."
(match-beginning 1))))
(prefix (buffer-substring-no-properties start end))
((string-prefix-p ":" prefix)))
(telega-emoji-init)
Comment thread
liaowang11 marked this conversation as resolved.
(let ((candidates
(telega-completions--emoji-candidates
prefix telega-completions-emoji-fuzzy-match)))
Expand All @@ -604,6 +602,7 @@ Handles repeated leading CHARs (e.g. @@). Returns nil if not applicable."

(defun telega-capf-telegram-emoji ()
"CAPF for emoji completion using TDLib searchEmojis."
(telega-emoji-init)
(when-let* ((end (point))
(start (save-excursion
(and (re-search-backward
Expand Down
55 changes: 55 additions & 0 deletions test.el
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,61 @@ Have Stoploss 690 Satoshi." :entities []))))
(should (equal (external-completion--all-completions "you" table nil 3)
'("i-love-you")))))

(ert-deftest telega-capf-emoji-initializes-before-search ()
"Local emoji CAPF should init emoji data before scanning for a prefix."
(with-temp-buffer
(insert " :rocket")
(goto-char (point-max))
(let ((telega-emoji-alist nil)
(telega-emoji-candidates nil)
(telega-emoji-candidate-max-length 0)
(init-calls 0))
(cl-letf (((symbol-function 'telega-emoji-init)
(lambda ()
(setq init-calls (1+ init-calls)
telega-emoji-alist '((":rocket:" . "\xF0\x9F\x9A\x80"))
telega-emoji-candidates '(":rocket:")
telega-emoji-candidate-max-length
(length ":rocket:")))))
(let ((capf (telega-capf-emoji)))
(should (= init-calls 1))
(should capf)
(should (equal (buffer-substring-no-properties
(nth 0 capf)
(nth 1 capf))
":rocket"))
(should (equal (nth 2 capf)
'(":rocket:"))))))))

(ert-deftest telega-capf-telegram-emoji-initializes-before-search ()
"Telegram emoji CAPF should init emoji data before scanning for a prefix."
(with-temp-buffer
(insert " :rocket")
(goto-char (point-max))
(let ((telega-emoji-alist nil)
(telega-emoji-candidates nil)
(telega-emoji-candidate-max-length 0)
(init-calls 0))
(cl-letf (((symbol-function 'telega-emoji-init)
(lambda ()
(setq init-calls (1+ init-calls)
telega-emoji-alist '((":rocket:" . "\xF0\x9F\x9A\x80"))
telega-emoji-candidates '(":rocket:")
telega-emoji-candidate-max-length
(length ":rocket:"))))
((symbol-function 'telega-completions--ensure-external-completion)
(lambda () t))
((symbol-function 'external-completion-table)
(lambda (&rest _args) 'telegram-emoji-table)))
(let ((capf (telega-capf-telegram-emoji)))
(should (= init-calls 1))
(should capf)
(should (equal (buffer-substring-no-properties
(nth 0 capf)
(nth 1 capf))
":rocket"))
(should (eq (nth 2 capf) 'telegram-emoji-table)))))))

(ert-deftest telega-bot-chat-with-topics-is-forum ()
"Bot chats with topics enabled should reuse forum topic support."
(let* ((bot-id 90901)
Expand Down
Loading