Skip to content
Open
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
109 changes: 61 additions & 48 deletions src/inline-tab-completion/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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 ) {
Expand All @@ -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 ) {
Expand All @@ -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();
2 changes: 1 addition & 1 deletion src/inline-tab-completion/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Loading