Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
wxiaoguang committed Dec 23, 2023
1 parent 33439b7 commit cf6af2b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions web_src/js/features/comp/TextExpander.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import {matchEmoji, matchMention} from '../../utils/match.js';
import {emojiString} from '../emoji.js';

function userFriendlyScrollBehavior(el) {
// the TextExpander uses ComboboxNav, which uses scrollIntoView to scroll to the selected item.
// but their default behavior uses undefined (aka "start"), which annoys the end users a lot.
// if upstream could fix it, our code could be removed then. https://github.com/github/text-expander-element/issues/50
const oldScrollIntoView = el.scrollIntoView;
el.scrollIntoView = function (opts) {
opts = opts || {block: 'nearest', inline: 'nearest'};
oldScrollIntoView.call(this, opts);
};
}

export function initTextExpander(expander) {
expander?.addEventListener('text-expander-change', ({detail: {key, provide, text}}) => {
if (key === ':') {
Expand All @@ -15,6 +26,7 @@ export function initTextExpander(expander) {
li.setAttribute('role', 'option');
li.setAttribute('data-value', emoji);
li.textContent = `${emoji} ${name}`;
userFriendlyScrollBehavior(li);
ul.append(li);
}

Expand Down Expand Up @@ -45,6 +57,7 @@ export function initTextExpander(expander) {
li.append(fullnameSpan);
}

userFriendlyScrollBehavior(li);
ul.append(li);
}

Expand Down

0 comments on commit cf6af2b

Please sign in to comment.