Page MenuHomePhabricator

Select current value of the search box when pressing enter
Closed, ResolvedPublicBUG REPORT

Description

When pressing enter after typing something in the VisualEditor template search field, one of two things happens:

  1. If any search results have loaded, the first result is chosen. E.g. if you search for cit and there's a template called Citation then it'll be selected.
  2. If you're fast at typing and hit enter before the search results have loaded, the search text is used as the template name.

Note that this only applies to the use of TemplateData search widget in VE, as in TemplateWizard it is not allowed to select a non-existing template.

The desired behaviour has not yet been determined.

First reported at https://pl.wikipedia.org/w/index.php?title=Dyskusja_wikipedysty:Sannita_(WMF)&oldid=76907111

Event Timeline

@JSengupta-WMF I'm not quite sure what the correct behaviour here should be. I'm guessing there's a standard way this should work?

The VE behavior is an extension of how links to other pages work in general: you're always allowed to enter one, even if it definitely doesn't exist (yet).

I think it's the correct choice, because:

  1. It lets power users act quickly, particularly with the quick-and-easy templates that're optimized for only needing a few keystrokes anyway (the example of k on plwiki)
  2. It stops the system from breaking in situations where the user has temporarily poor internet connectivity (imagine someone editing on a laptop on a train) -- it's better to degrade into "we've let you insert something but we don't know about what it is" rather than just blocking the user entirely on a stalled dialog

For 2. I would rather go with an error message whenever there is an internet issue notifying user about the main issue i.e. your internet connection is poor/no internet connection. What would be a valid (and quite widely used) use case for us to allow user to enter something that we don't know about?

@JSengupta-WMF I'm fine with an error message letting them know if we can detect an actual outage (though I think this should be a core VE functionality rather than something any given component tries to implement on its own, to avoid spamming the user with such notifications), but I do think we should then keep on going with editing if we can, albeit in a degraded state. Particularly in cases where the issue isn't a complete internet outage, but rather notable lag -- forcing users with poor connections to suffer through an unskippable 5 second delay every time they try to enter a template whose name they know is going to discourage them from completing their edits, or at least drive them off to source mode where they won't receive any assistance at all. (Particularly in areas like SSA where we expect underpowered devices and spotty connections.)

Since we're just talking about not waiting for the search results to load, I think the quick-and-simple templates for power users are good examples. Things like ., tl, yesno, k (plwiki), etc. Those ones are easily written and enter pressed before the search results can load on my quite-good connection.

We could probably make it clearer in the case where someone's presenting with a template that does actually have templatedata, because at the moment it's possible to end up with the "This template has no documented parameters…" message when that's not accurate. But that's an existing issue and I don't think we need to solve it here.

I agree that we should be able to choose the current value of the template search field, without waiting for the search results to load.

In T390017 we removed the 'Add' button, and I feel like we're sort of going around in circles with this topic! Because if we can select the current search term by pressing enter, it seems like there should be a way to do that with the mouse too, and so the button should be added back in. And in T390017#10681044 Amin came up with a good idea for making it clear that a non-existing template would be used (although this is slightly different to the no-data-yet scenario).

Another way to do it would be to show a single search result immediately upon typing, and for it to resolve (to include description etc.) as soon as possible but also be selectable before that. It'd be the first result and so would be highlighted and hitting enter would thus select it.

Note that template data loads quite fast. You can test on enwiki, as previous behavior still works there (no favourites yet).

Test:

  1. Open a private browsing window.
  2. Go to: https://en.wikipedia.org/w/index.php?title=Richard_Rennison&veaction=edit
  3. Open developer tools (F12).
  4. Simulate network: Good 3G.
  5. Type {{ (to open the template dialog).
  6. Type tl + Enter.

Opening the template form is pretty much instant. Autocomplete is slower.

As an added bonus, now that we have favourites, two things could happen:

  1. My favourites could be instantly available in autocomplete—quicker selection.
  2. TemplateData of my favourites could be saved in some storage, lazy-loaded when starting to edit, and then cached for a week or so. This would make the template form appear even faster.

Change #1167227 had a related patch set uploaded (by Samtar; author: Samtar):

[mediawiki/extensions/TemplateData@master] ext.templateData.templateDiscovery: Handle early enter

https://gerrit.wikimedia.org/r/1167227

TheresNoTime subscribed.

(will just grab this for now while I work on it :D)

KSiebert changed the task status from Open to In Progress.Jul 16 2025, 9:40 AM

Change #1173603 had a related patch set uploaded (by Samwilson; author: Samwilson):

[mediawiki/extensions/TemplateWizard@master] Avoid templatedata (pageID and params) that may not exist

https://gerrit.wikimedia.org/r/1173603

Change #1173603 merged by jenkins-bot:

[mediawiki/extensions/TemplateWizard@master] Avoid templatedata (pageID and params) that may not exist

https://gerrit.wikimedia.org/r/1173603

Change #1167227 merged by jenkins-bot:

[mediawiki/extensions/TemplateData@master] ext.templateData.templateDiscovery: Handle early enter

https://gerrit.wikimedia.org/r/1167227

dom_walden subscribed.

Pressing enter before the template search has returned results will take you to Insert: <name> for a non-existent template.

nonexistent_template.png (489×924 px, 30 KB)