Thread Tools Display Modes
03/17/18, 03:40 PM   #1
Phuein
 
Phuein's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 132
[SOLVED] Remove /slash command from autocomplete?

I added a /slash command to my addon, and then added a menu toggle to turn it on/off. When off, it's an invalid command. But the autocomplete menu still shows it! I don't want to request a UI restart. How can I remove it from autocomplete?

Code:
SLASH_COMMANDS["/myspecialcommand"] = nil
tl;dr Removes the command, but not the autocomplete.

I searched for a while but couldn't find an answer. References:
https://wiki.esoui.com/API#libraries.5Cutility
(Scroll down a bit for autocomplete section)
http://esoapi.uesp.net/100018/src/li...plete.lua.html
(Saw the Add function, but not a Remove function. Tried it, didn't work.)

Last edited by Phuein : 03/20/18 at 09:33 AM.
  Reply With Quote
03/17/18, 09:02 PM   #2
Dolgubon
 
Dolgubon's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2016
Posts: 408
Take a look at the esoui source code on github, and check out SlashCommandAutoComplete:GetAutoCompletionResults. You night just need to overmore or less paste it in your code and change just a bit, or maybe just post hook it.
  Reply With Quote
03/18/18, 06:35 AM   #3
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,567
No need to overwrite anything. It should be enough to call SLASH_COMMAND_AUTO_COMPLETE:InvalidateSlashCommandCache()
  Reply With Quote
03/18/18, 08:36 AM   #4
Phuein
 
Phuein's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 132
Originally Posted by sirinsidiator View Post
No need to overwrite anything. It should be enough to call SLASH_COMMAND_AUTO_COMPLETE:InvalidateSlashCommandCache()
Wouldn't that lose ALL the other autocompletes as well? I assume I can't just take the specific autocomplete item from:
Code:
self.possibleMatches
  Reply With Quote
03/18/18, 09:00 AM   #5
Shadowfen
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 83
Just judging from the function name, it would force the autocomplete cache to refresh itself from the current values of the SLASHCOMMAND table - which you have removed your entry from. Testing is, of course, required.
  Reply With Quote
03/18/18, 09:58 AM   #6
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,567
Removing it manually from the table when there is a nice function that will invalidate the cache for you is a bad idea. You don't know how the internal implementation will change in the future, so it might just break your addon when you do it like that. And as Shadowfen said, it will just force the slash command table from getting scanned again which is exactly what you want when you remove a command.
  Reply With Quote
03/19/18, 03:52 PM   #7
Phuein
 
Phuein's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 132
I agree with you guys. And after testing it now, I'm very surprised to see it's not working. Tried and tried, that function doesn't actually do what it should - the command when removed (verified) is still in autocomplete - made sure to save addon and restart UI and all, even restarted game (unrelated.)

I'm stumped. Any ideas? It'd suck to ask users to restart UI for this small thing. Bad implementation from dev's, eh.
  Reply With Quote
03/19/18, 04:09 PM   #8
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,567
I just tried the following two commands with and without any addons enabled and it works fine for me:
Code:
/script SLASH_COMMANDS["/sleep"] = nil
/script SLASH_COMMAND_AUTO_COMPLETE:InvalidateSlashCommandCache()
After running them, the sleep command won't show up in the results for the autocomplete, where it did before.
  Reply With Quote
03/20/18, 09:26 AM   #9
Phuein
 
Phuein's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 132
Originally Posted by sirinsidiator View Post
I just tried the following two commands with and without any addons enabled and it works fine for me:
Code:
/script SLASH_COMMANDS["/sleep"] = nil
/script SLASH_COMMAND_AUTO_COMPLETE:InvalidateSlashCommandCache()
After running them, the sleep command won't show up in the results for the autocomplete, where it did before.
SMH Of course!
Code:
/script SlashCommandAutoComplete:InvalidateSlashCommandCache()
I took the naming convention from original script, instead of globals lol. I'll try again.
  Reply With Quote
03/20/18, 09:33 AM   #10
Phuein
 
Phuein's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 132
Ok, definitely works, no issues. Cheers guys!
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Remove /slash command from autocomplete?

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off