Automate copy+paste across files, with placeholders / Dynamic macro?!

Hi!

I'm not sure where to begin.

I have a tedious task to perform across a huge number of files, let me describe the scenario:

1. I open a template file that contains mainly HTML and some template syntax (Fluid in this case, for TYPO3)

2. I need to find any hard-coded content output, like "Submit issue" and replace it with a language placeholder, in this case something like:

<f:translate key="submit_issue" />

3. Now the string that was formerly at the place of the new `<f:translate>` needs to be inserted into a XML language file, like `

<trans-unit id="submit_issue">
<source>Submit issue</source>
</trans-unit>

This would need to both contain the placeholder previously inserted, as well as the old text at that place.

 

So the problem is two-fold:

1. The action is performed across two files, the HTML source files (many many files) and a (known, singular) XML file

2. The action needs to get a unique placeholder, that usually needs to be entered manually and cannot be derived.

How I imagine it could work for me:

  • Select the static HTML string
  • Hit a button/key
  • A popup lets me enter the unique string like "submit_issue"
  • The selected portion gets cut, replaced by a fixed replacement text plus the entered unique string placeholder
  • Then the editor would automatically tab out to a specified file (the XML file), go to the end of the file and add a fixed replacement text, PLUS the unique string placeholder (as key) PLUS the clipboard content in its value.


Any ideas how I could get that interactive part solved? Or am I doomed to perform this manually? Could I at least get the "tabbing to the fixed file, inserting the cut text, create a auto-incremented value like string1, string2, string3.. as string placeholders in there, then tab back, and re-use that auto-incremented value back"-part of this to work with macros (that I've never used before)?

It seems macros don't support the dynamic part, and live templates don't support switching between files or executing recorded functionality... and when I use a macro to record opening another file by entering the filename it replaces "?" instead of "_" and "-" instead of "/", so it won't find a file when playbacked. Also the typing is suuuuuper slow and painful to watch...

Thanks for any suggestions. :-)

7 comments
Comment actions Permalink

Hi,
Unfortunately, there is no refactorings of this kind in PhpStorm (just in case, I double-checked that with the WebStorm team).

A short notice about the macro file name typing part though:

when I use a macro to record opening another file by entering the filename it replaces "?" instead of "_" and "-" instead of "/"

Do you mind me asking on how to reproduce it, what exact part does not accept the recorded part?

0
Comment actions Permalink

Hi Vasily,

sorry for taking me some time to get back to you, I wanted to record this properly.

I believe the issue is, I'm using a german keyboard, but it seems when playing back macros, they get executed with an english keymap. When I recorded a video, I notized also "y" got replaced with "z". Funnily, when recording the macro, all the proper keys are executed and shown in the lower right section. So maybe the keycodes do not get executed with the "real" keyboard, but a virtual one, which does not use the same keymap?

Here's the video showing this: https://www.dropbox.com/s/xajf51tsr7ofhk7/phpstorm-recording.mov?dl=0

0
Comment actions Permalink

Hello,

Thank you for sharing the screencast and sorry for the delayed response, I am a Windows user and needed some time to get macOS laptop to reproduce the issue.

Unfortunately, I was not able to reproduce this behaviour on my side by following the steps from your recording.
I tried adding the German AZERTY layout and used it to record the macro (Shift+7 is the slash key on that layout, right?) but in my case, macro replay had no issues with the layout at all -- everything was just like I recorded it.

What did I miss here?
Just in case, I have PhpStorm 2022.2.2 installed on my test machine, what version do you have? 

0
Comment actions Permalink

Hi Vasiliy,

thanks for getting back in touch to me. I can only say that:

* PhpStorm 2022.2.1 #PS-222.3739.61

* My keyboard is a Microsoft Surface Ergonomic (Bluetooth) with german keymap

* My layout is QWERTZ

* In MacOS system preferences the Input Source is configured as "DE German"

* The same issue occurs if I use the Macbook Pro native keyboard (which also has a QWERTZ layout, same input source as external keyboard)

* Shift+7 is the slash key on my QWERTZ layout too, yes.

0
Comment actions Permalink

Hi,

After some struggle, I have finally managed to reproduce the issue on my side.

Turns out that playback works fine with proper slashes when English layout is currently active even if macro was recorded with German AZERTY. I guess that was the reason why I was not able to reproduce the issue before -- most probably, I have automatically switched the layout back to English when I played the recorded macro. Also, I have managed to find a similar YouTrack report and added my findings there:
https://youtrack.jetbrains.com/issue/IDEA-100649/FindReplace-input-mixes-up-macro-key-codes

Thank you for reporting the issue and all your help on this matter so far!

On a side notice, there is an annoying thing that macro playback just silently does not want to play any keystrokes in search input boxes unless you add IDE in permissions list of the macOS Accessibility -- that was definitely unclear, so I spent an hour to understand it (got a new PhpStorm installation that was not added there).

0
Comment actions Permalink

Hi Vasiliy,

 

awesome, thanks for your efforts and keeping your eyes on it. Much appreciated. Also great you found a Youtrack report, I'm sorry I didn't see it.

Maybe this'll end up getting addressed, but for a ten year old bug it doesn't seem to be priority, and not many users affected like me :D

Best regards,
Garvin

1
Comment actions Permalink

Hi Garvin,

I hope that my comment will draw some extra attention to the ticket and bring it to life :)

Once again, thank you for your time. Have a nice day and a productive rest of the week!

0

Please sign in to leave a comment.