Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use only current line in tab-completing commands #2279

Merged
merged 3 commits into from
Sep 3, 2024
Merged
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
10 changes: 6 additions & 4 deletions play.pokemonshowdown.com/js/client-chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,11 @@
var m2 = /^([\s\S!/]*?)([A-Za-z0-9][^, \n]* [^, ]*)$/.exec(prefix);
if (!m1 && !m2) return true;
var cmds = this.tabComplete.commands;
var currentLine = prefix.substr(prefix.lastIndexOf('\n') + 1);
var shouldSearchCommands = !cmds || (cmds.length ? !!cmds.length && !cmds.filter(function (x) {
return x.startsWith(prefix);
return x.startsWith(currentLine);
}).length : prefix != this.tabComplete.prefix);
var isCommandSearch = (text.startsWith('/') && !text.startsWith('//')) || text.startsWith('!');
var isCommandSearch = (currentLine.startsWith('/') && !currentLine.startsWith('//')) || currentLine.startsWith('!');
var resultsExist = this.tabComplete.lastSearch === text && this.tabComplete.commands;
if (isCommandSearch && shouldSearchCommands && !resultsExist) {
if (this.tabComplete.searchPending) return true; // wait
Expand All @@ -378,7 +379,7 @@
self.handleTabComplete($textbox, reverse);
}
});
this.send('/crq cmdsearch ' + text);
this.send('/crq cmdsearch ' + currentLine);
return true;
} else if (!isCommandSearch) {
delete this.tabComplete.isCommand;
Expand Down Expand Up @@ -447,7 +448,8 @@
if (!substituteUser) return true;
var name = typeof substituteUser === 'object' ? substituteUser.name : substituteUser;
name = Dex.getShortName(name);
var fullPrefix = this.tabComplete.prefix.substr(0, candidate[1]) + name;
var prefixIndex = candidate[1].toString().charAt(0) === '/' ? prefix.lastIndexOf('\n') + 1 : candidate[1];
var fullPrefix = this.tabComplete.prefix.substr(0, prefixIndex) + name;
$textbox.val(fullPrefix + text.substr(idx));
var pos = fullPrefix.length;
$textbox[0].setSelectionRange(pos, pos);
Expand Down
Loading