diff --git a/src/inline-tab-completion/index.jsx b/src/inline-tab-completion/index.jsx index 791bca2e..251c64db 100644 --- a/src/inline-tab-completion/index.jsx +++ b/src/inline-tab-completion/index.jsx @@ -492,10 +492,6 @@ class InlineTab extends Addon { if ( event.ctrlKey || event.altKey ) // || ! inst.chatInputRef ) return; - const el = this.getElement(inst); - if ( ! el ) - return; - const code = event.charCode || event.keyCode, current = inst.ffzGetValue(); @@ -543,50 +539,7 @@ class InlineTab extends Addon { ); } - if ( suggestions.length > 0 ) { - pos += event.shiftKey ? -1 : 1; - if ( pos >= suggestions.length ) - pos = 0; - else if ( pos < 0 ) - pos = suggestions.length - 1; - - inst.ffztc_position = pos; - - const suggestion = suggestions[pos]; - if ( suggestion ) { - const parts = inst.ffztc_parts, - empty = parts[2].trim() === ''; - - // If the completion includes a specific - // selection, we select that. Otherwise - // we just put the caret after our - // tab-completion. - let caret = parts[0].length; - let end; - - if ( suggestion.sel ) { - caret += suggestion.sel[0]; - end = caret + suggestion.sel[1]; - } else { - caret += suggestion.text.length + (empty ? 1 : 0); - end = caret; - } - - inst.autocompleteInputRef.setValue(parts[0] + suggestion.text + (empty && ! suggestion.sel ? ' ' : parts[2])); - inst.ffzSetSelection(caret, end); - - if ( this.tt ) { - el._ffz_inst = inst; - const tip = el[this.tt._accessor]; - if ( tip ) { - setChildren(tip.element, this.renderTooltip(inst, tip)); - tip.update(); - } else - this.tt._enter(el); - } - } - } - + this.moveSelection(inst, event.shiftKey); return; } else if ( code === KEYS.Escape && inst.ffztc_position !== -1 ) { @@ -600,6 +553,13 @@ class InlineTab extends Addon { event.stopPropagation(); event.stopImmediatePropagation(); return; + } else if ( code === KEYS.ArrowUp || code === KEYS.ArrowDown ) { + event.preventDefault(); + event.stopPropagation(); + event.stopImmediatePropagation(); + + this.moveSelection(inst, code === KEYS.ArrowUp); + return; } if ( code !== KEYS.Shift ) { @@ -608,6 +568,59 @@ class InlineTab extends Addon { this.clearAutocomplete(inst); } } + + moveSelection(inst, downDirection) { + const el = this.getElement(inst); + if ( ! el ) + return; + + let pos = inst.ffztc_position, + suggestions = inst.ffztc_suggestions; + + if ( suggestions && suggestions.length > 0 ) { + pos += downDirection ? -1 : 1; + if ( pos >= suggestions.length ) + pos = 0; + else if ( pos < 0 ) + pos = suggestions.length - 1; + + inst.ffztc_position = pos; + + const suggestion = suggestions[pos]; + if ( suggestion ) { + const parts = inst.ffztc_parts, + empty = parts[2].trim() === ''; + + // If the completion includes a specific + // selection, we select that. Otherwise + // we just put the caret after our + // tab-completion. + let caret = parts[0].length; + let end; + + if ( suggestion.sel ) { + caret += suggestion.sel[0]; + end = caret + suggestion.sel[1]; + } else { + caret += suggestion.text.length + (empty ? 1 : 0); + end = caret; + } + + inst.autocompleteInputRef.setValue(parts[0] + suggestion.text + (empty && ! suggestion.sel ? ' ' : parts[2])); + inst.ffzSetSelection(caret, end); + + if ( this.tt ) { + el._ffz_inst = inst; + const tip = el[this.tt._accessor]; + if ( tip ) { + setChildren(tip.element, this.renderTooltip(inst, tip)); + tip.update(); + } else + this.tt._enter(el); + } + } + } + } } InlineTab.register(); diff --git a/src/inline-tab-completion/manifest.json b/src/inline-tab-completion/manifest.json index f1e0ee5e..fc8ea119 100644 --- a/src/inline-tab-completion/manifest.json +++ b/src/inline-tab-completion/manifest.json @@ -8,5 +8,5 @@ "description": "Adds support for inline tab-completion to chat. Meaning, tab-completion without a popup.\n\nCertain settings from [Chat > Input >> Tab Completion](~chat.input.tab_completion) may not function while this add-on is enabled. This add-on is designed to mimic the tab-completion behavior of BetterTTV.", "settings": "add_ons.inline_tab", "created": "2021-06-07T19:38:46.958Z", - "updated": "2024-03-19T21:38:12.374Z" + "updated": "2026-06-22T03:30:01.604Z" } \ No newline at end of file