Skip to content

Commit 880ada0

Browse files
committed
sync comment
1 parent c5e0408 commit 880ada0

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

web_src/js/features/comp/TextExpander.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export function initTextExpander(expander: TextExpanderElement) {
5151

5252
const textarea = expander.querySelector<HTMLTextAreaElement>('textarea');
5353

54+
// help to fix the text-expander "multiword+promise" bug: do not show the popup when there is no "#" before current line
5455
const shouldShowIssueSuggestions = () => {
5556
const posVal = textarea.value.substring(0, textarea.selectionStart);
5657
const lineStart = posVal.lastIndexOf('\n');
@@ -59,13 +60,17 @@ export function initTextExpander(expander: TextExpanderElement) {
5960
};
6061

6162
const debouncedIssueSuggestions = debounce(async (key: string, text: string): Promise<TextExpanderProvideResult> => {
62-
// Upstream bug: when using "multiword", TextExpander will get wrong "key" position.
63-
// To reproduce, use the "await sleep" below,
64-
// then use content "close #20\nclose #20\close #20", keep changing the last line `#20` part from the end (including removing the `#`)
63+
// https://github.com/github/text-expander-element/issues/71
64+
// Upstream bug: when using "multiword+promise", TextExpander will get wrong "key" position.
65+
// To reproduce, comment out the "shouldShowIssueSuggestions" check, use the "await sleep" below,
66+
// then use content "close #20\nclose #20\nclose #20" (3 lines), keep changing the last line `#20` part from the end (including removing the `#`)
6567
// There will be a JS error: Uncaught (in promise) IndexSizeError: Failed to execute 'setStart' on 'Range': The offset 28 is larger than the node's length (27).
68+
69+
// check the input before the request, to avoid emitting empty query to backend (still related to the upstream bug)
6670
if (!shouldShowIssueSuggestions()) return {matched: false};
6771
// await sleep(Math.random() * 1000); // help to reproduce the text-expander bug
6872
const ret = await fetchIssueSuggestions(key, text);
73+
// check the input again to avoid text-expander using incorrect position (upstream bug)
6974
if (!shouldShowIssueSuggestions()) return {matched: false};
7075
return ret;
7176
}, 300); // to match onInputDebounce delay

0 commit comments

Comments
 (0)