Skip to content

Commit cf6af2b

Browse files
committed
fix
1 parent 33439b7 commit cf6af2b

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

web_src/js/features/comp/TextExpander.js

+13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
import {matchEmoji, matchMention} from '../../utils/match.js';
22
import {emojiString} from '../emoji.js';
33

4+
function userFriendlyScrollBehavior(el) {
5+
// the TextExpander uses ComboboxNav, which uses scrollIntoView to scroll to the selected item.
6+
// but their default behavior uses undefined (aka "start"), which annoys the end users a lot.
7+
// if upstream could fix it, our code could be removed then. https://github.com/github/text-expander-element/issues/50
8+
const oldScrollIntoView = el.scrollIntoView;
9+
el.scrollIntoView = function (opts) {
10+
opts = opts || {block: 'nearest', inline: 'nearest'};
11+
oldScrollIntoView.call(this, opts);
12+
};
13+
}
14+
415
export function initTextExpander(expander) {
516
expander?.addEventListener('text-expander-change', ({detail: {key, provide, text}}) => {
617
if (key === ':') {
@@ -15,6 +26,7 @@ export function initTextExpander(expander) {
1526
li.setAttribute('role', 'option');
1627
li.setAttribute('data-value', emoji);
1728
li.textContent = `${emoji} ${name}`;
29+
userFriendlyScrollBehavior(li);
1830
ul.append(li);
1931
}
2032

@@ -45,6 +57,7 @@ export function initTextExpander(expander) {
4557
li.append(fullnameSpan);
4658
}
4759

60+
userFriendlyScrollBehavior(li);
4861
ul.append(li);
4962
}
5063

0 commit comments

Comments
 (0)