microsoft / PowerToys

Windows system utilities to maximize productivity
MIT License
111.23k stars 6.54k forks source link

[PowerToys Run] Registry Plugin: Allow interchangeable use of / instead of \ #33155

Closed jhmaster2000 closed 1 month ago

jhmaster2000 commented 5 months ago

Description of the new feature / enhancement

: hkcu/AppEvents should work the same as : hkcu\AppEvents

Scenario when this would be used?

Other plugins such as Folders support slash interchangeability, C:/Windows and C:\Windows both work the same perfectly in PowerToys Run, one would expect to also be able to use the nicer forward slash on Registry paths but it currently breaks the Registry plugin.

Supporting information

I understand under the hood regedit doesn't support /, I expect the plugin can simply replace all / with \ on the fly between the user input and processing under the hood.

htcfreek commented 5 months ago

The question here is: Can I create a registry key or value with a name that contains /? Then we need a logic to deside if its part of the name or split to elements.

GhostVaibhav commented 5 months ago

Yes, you can create a registry and a value with a name containing /

GhostVaibhav commented 5 months ago

I investigated this and found out something. Here are my findings -

  1. The folders in Windows don't allow any slashes, therefore, we can use either / or \ to navigate.
  2. This thing doesn't hold valid in the case of Registry. In the Registry, we can't use \, but we can use /. Therefore, the default behavior.
  3. If we were to implement this feature, we would have ambiguities in resolving the name and the path (as suggested by @htcfreek). For eg -

    • HKEY_CLASSES_ROOT/Something/Data has two meanings -
      • Either Something/Data is a value, or
      • Data is a value, inside of Something, a key

I don't know the proper solution, but I have a suggestion. We could use " to identify the values. So, for referring to the above, we can use the following notation -

In hindsight, this solution is functional, but not pretty to look at. Different approaches are always welcome 😄

GhostVaibhav commented 5 months ago

@htcfreek what do you think about the above approach?

htcfreek commented 5 months ago

That I understand correctly:

So we would have a problem to decide if the slash is part of the key path or value name as you said? But don't we still use the ! or \\ for separating path and value name?

GhostVaibhav commented 5 months ago

@htcfreek A little correction.

Does that change anything though?

On a side note, when do we use ! in this?

htcfreek commented 5 months ago

@htcfreek A little correction.

  • The key path allows / in it's name.
  • The value can contain both / and \

Does that change anything though?

Nor for the value name. But for the key path. How do we decide if the typed / is part of a key name or not? 🤔

On a side note, when do we use ! in this?

My mistake. The rule is key path\\value name. (https://github.com/microsoft/PowerToys/blob/main/src%2Fmodules%2Flauncher%2FPlugins%2FMicrosoft.PowerToys.Run.Plugin.Registry%2FHelper%2FQueryHelper.cs#L44)

GhostVaibhav commented 5 months ago

For the key path problem, we could use " to denote a key name. If we are not using those, that becomes part of the path. How does that sound to you?

  • HKEY_CLASSES_ROOT/Something/Data - this is where Data is another key, inside of Something, a key
  • HKEY_CLASSES_ROOT/"Something/Data" - this is where Something/Data is a key
htcfreek commented 5 months ago

For the key path problem, we could use " to denote a key name. If we are not using those, that becomes part of the path. How does that sound to you?

  • HKEY_CLASSES_ROOT/Something/Data - this is where Data is another key, inside of Something, a key
  • HKEY_CLASSES_ROOT/"Something/Data" - this is where Something/Data is a key

Sounds good to me, even when it prevents simple copy and paste of such paths into pt run. @davidegiacometti what do you think?

By the way: If you have the code to detect the escaping/enclosing, I am interested in for an other issue.

GhostVaibhav commented 5 months ago

@htcfreek You know what! You are lucky for me. I was searching for the regex expression for a very long time. And the moment you pinged me, I got it. Have a look at it and let me know if we need any corrections.

https://regex101.com/r/3wwEUg/2

htcfreek commented 5 months ago

@htcfreek You know what! You are lucky for me. I was searching for the regex expression for a very long time. And the moment you pinged me, I got it. Take a look at it below and let me know if we need any corrections.

https://regex101.com/r/3wwEUg/1

Seems to be perfect. ♥️

GhostVaibhav commented 5 months ago

Hi @htcfreek, I have opened a draft PR trying to fix the issue. However, when I enter the first ", the context menu doesn't display any suggestions, but if I complete the same, it defaults to its normal behavior. GIF attached -

search

Another issue that I'm having is when I select anything from the context menu, the whole path changes from / to \. GIF attached -

search2

htcfreek commented 5 months ago

@GhostVaibhav I think the automatic change is okay as long as this doesn't kill the key nane containing a /. (And btw this happens as the result uses \ and selecting it updates the query field.)

What I had as idea is:

The registry contains:

Can we then suggest the two options as results:

htcfreek commented 5 months ago

@GhostVaibhav Regarding the query text update: https://github.com/microsoft/PowerToys/blob/main/src%2Fmodules%2Flauncher%2FPlugins%2FMicrosoft.PowerToys.Run.Plugin.Registry%2FHelper%2FResultHelper.cs#L49