Skip to content

Commit

Permalink
Use only current line in tab-completing commands (smogon#2279)
Browse files Browse the repository at this point in the history
* Use only current line in tab-completing commands

https://www.smogon.com/forums/threads/bug-report.3749269/

At this point, it's a bit more than a bug fix.

* Update client-chat.js

Changed stuff that npm run test did not like.

* Restore subcommand behavior
  • Loading branch information
dot-Comfey authored Sep 3, 2024
1 parent c724dae commit 04ed96b
Showing 1 changed file with 6 additions and 4 deletions.
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

0 comments on commit 04ed96b

Please sign in to comment.