PowerToys icon indicating copy to clipboard operation
PowerToys copied to clipboard

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

Open jhmaster2000 opened this issue 1 year ago • 14 comments

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.

jhmaster2000 avatar May 30 '24 04:05 jhmaster2000

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.

htcfreek avatar Jun 01 '24 09:06 htcfreek

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

GhostVaibhav avatar Jun 01 '24 11:06 GhostVaibhav

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 -

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

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

GhostVaibhav avatar Jun 01 '24 14:06 GhostVaibhav

@htcfreek what do you think about the above approach?

GhostVaibhav avatar Jun 09 '24 11:06 GhostVaibhav

That I understand correctly:

  • The key path doesn't allow / and \ in it's name.
  • The value name can contain /, but not \.

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?

htcfreek avatar Jun 09 '24 11:06 htcfreek

@htcfreek A little correction.

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

Does that change anything though?

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

GhostVaibhav avatar Jun 09 '24 12:06 GhostVaibhav

@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)

htcfreek avatar Jun 09 '24 12:06 htcfreek

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

GhostVaibhav avatar Jun 09 '24 12:06 GhostVaibhav

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.

htcfreek avatar Jun 09 '24 13:06 htcfreek

@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

GhostVaibhav avatar Jun 09 '24 13:06 GhostVaibhav

@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. ♥️

htcfreek avatar Jun 09 '24 13:06 htcfreek

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

GhostVaibhav avatar Jun 09 '24 15:06 GhostVaibhav

@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:

  • Hklm\software\test\key\223\new
  • hklm\software\test/key\223\new And the user types hklm/software/test/.

Can we then suggest the two options as results:

  • Hklm\software\test\key
  • hklm\software\"test/key" So that the user can select it and then continue typing with / like Hklm\software\test/key\223/new.

htcfreek avatar Jun 09 '24 15:06 htcfreek

@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

htcfreek avatar Jun 09 '24 16:06 htcfreek