How to know what the default FAYT filter is via scripting

Although I have a hunch about how this is going to end, I'll ask anyway:

Does anyone know if there's a way to find out what the default FAYT filter is?

I ask because there seems to be a bug in the way the entered text in the FAYT bar is handled when asking for suggestions.

If the filter is set as default, the suggestions work fine. But if the assigned quick key is entered, the filter activates, the entered character is not taked into account in ScriptFAYTCommandData.cmdline (which is correct), but Tab.UpdateFAYTSuggestions understands as if a character has already been entered (the quick key), and therefore returns no suggestions.

I've come up with a workaround to that, but for it to work, I need to know if the filter is set as default or not.

Thanks!

Is there a simple script that demonstrates the bug? I'd rather fix that than add a way to work around it.

I don't have one at hand, sorry. But I think that you can reproduce the issue with your own script.

Make sure that:

  1. Set the script as default filter.
  2. Call the script via its quick key.
  3. Try to get some suggestions. You shouldn't be able to see any (unless there's one that starts with the quick key character).

@Leo I made a simple test script.

// FAYT_test

function OnInit(initData) {
	initData.name = "FAYT_test";
	initData.version = "1.0";
	initData.desc = "FAYT test to reproduce UpdateSuggestions issue";
	initData.default_enable = true;
	initData.min_version = "13.0";

}

// Called to add commands to Opus
function OnAddCommands(addCmdData) {
	var cmd = addCmdData.AddCommand();
	cmd.name = "fayt_test";
	cmd.method = "Onfayt_test";
	cmd.label = "fayt_test";
	cmd.hide = true; 
	var fayt = cmd.fayt;
	fayt.enable = true;
	fayt.key = '%';
	fayt.backcolor = '#ffad5b';
	fayt.textcolor = '#000000';
	fayt.label = "fayt_test";
	fayt.realtime = true;
}

// Implement the fayt_test command
function Onfayt_test(scriptFAYTData) {
	DOpus.Output('fayt : "' + scriptFAYTData.fayt + '"');
	if (scriptFAYTData.fayt != "fayt_test") return;
	DOpus.Output('cmdline : "' + scriptFAYTData.cmdline + '"');
	if (scriptFAYTData.suggest)
		scriptFAYTData.tab.UpdateFAYTSuggestions(DOpus.Create.Vector('abc', 'bcd', 'cde', 'def', 'efg', 'ghi', 'hij', 'ijk', 'jkl', 'klm', 'lmn'));
	return;
}

FAYT_test.opusscriptinstall (877 Bytes)

By default, you can call it with %.
Using it as non default mode, you can type a for example, and get a suggestion.
In order to reproduce the issue, please:

  1. Set the script as the default filter.
  2. Call the script via its quick key. (e.g. %a).
  3. Try to get some suggestions. You shouldn't be able to see any.

Seems that when using tab.UpdateFAYTSuggestions, DO is using the complete text introduced in the FAYT bar, % included, to ask for suggestions. Since scriptFAYTData.cmdline ignores the first character if it is the configured quick key (even if the script is the default filter), make DO acts the same when asking for suggestions would be ideal.

Thanks for taking the time to check this!

If a FAYT mode is set as the default it doesn't have a quick key (that's the point of it being the default).

Either:

  • Assign a quick key, which you have to press to trigger the mode, OR
  • Set as default, in which case all keys that don't trigger a different mode will go through to the default

Either way the script seems to get told the right thing.

With quick key:

Without quick key:

Hi Jon. Yes, I've noticed that.
However, there are at least 2 reasons to type the quick key even when it's the default filter:

  1. If you want to type a character that's assigned as a quick key for another script.
  2. If your script has additional functionality when the quick key is entered twice.

The FAYT scripts understands that the quick key has been entered, even when it's the default filter, and doesn't pass it in scriptFAYTData.cmdline. But there seems to be a discrepancy with what tab.UpdateFAYTSuggestions receives to display suggestions.

Anyway, I completely understand that you're short on time, and this was more of a question than a complaint or something related. Besides, I ended up finding a workaround (if the term applies) for this issue, by appending the quick key when asking for suggestions. It's not nice, but it works.

If a FAYT mode is set as the default it literally doesn't have a quick key.

I have recorded some videos that hopefully can illustrate my point.
Since in v13.3.1 you can now get suggestions without having to type anything, this is more evident.
In both videos you can see the value that the script gets via scriptFAYTData.cmdline.

Video 1 : Filter is not set as default

Everything working right.
You can see how it automatically removes the quick key (%) from cmdline value, if it is the first character.

Video 2 : Filter is set as default

Everything working as expected if I don't type at first %.
But if I do, you can see how it still automatically removes the quick key (%) from cmdline, if it is the first character. (At the beginning cmdline = "") But tab.UpdateSuggestions does not interpret it in the same way (it does take into account the first %) so there are no suggestions.

Thanks for the extra information, I understand the issue now. Fixed in the next beta.

1 Like

I've noticed this since v13.3.2:
Now, if it is the default filter, it literally has no quickkey (scriptFAYTData.quickkey = ""), so there is no easy way to know which key it was. As I mentioned before, some reasons why you might need to use the quickkey, even if it is the default filter, are:

  • Accessing the suggestions when nothing has been typed yet.
  • Entering a character that is used as a quickkey by another script.
  • The script itself has a special syntax based on that key.

I wonder if this new behavior is intended or a bug.

The ideal change would be for scriptFAYTData.cmdline to stay as it was (remove the quick key if it was the first character, even if the filter is the default), and for tab.UpdateFAYTSuggestions to adapt (if the first character is the quick key, ignore it, whether it is the default filter or not).

It's intended. If the FAYT mode is the default, it has no quick key.

There's no key for the user to see or configure in Preferences when a mode is the default, since the point of a default mode is it doesn't require a key to activate it.

It wouldn't make sense to make the previously configured quick-key do something special in the script, as the user can't see it (and might have changed it from the script's initial default).

You could give the script a separate, configurable "escape key" or similar (via the script's config dialog).