Is there a shortcut for inserting PHP's object operator upon code completion in PhpStorm?

前端 未结 3 1204
-上瘾入骨i
-上瘾入骨i 2020-12-14 03:29

Let\'s say I want to type the following in PhpStorm:

$longObjectName->propertyName = \'some value\';

Seems innocent enough, no? If I sta

相关标签:
3条回答
  • 2020-12-14 03:58

    Well, I solved this problem by recording a Macro and then binding it with a keyboard shortcut:

    1. Go to Edit | Macros | Start Macro Recording
    2. Type '->'
    3. Stop Macro Recording using the button in the lower right corner, then name it whatever you want.
    4. Assign Shortcut to it:
      • Go to File | Settings | Keymap | Macros |
      • Right click and choose 'Add Keyboard Shortcut'

    I chose Ctrl+. as the shortcut and now I am more than happy. :)

    0 讨论(0)
  • 2020-12-14 04:00

    You can use autohotkey (http://www.autohotkey.com/) to create new keystrokes and replace PHP Object Operator for period or anything else.

    For example, with a script like this:

    ^.::
    Send ->
    return
    

    Will replace (ctrl + .) with (->), in anywhere in Windows.

    Or

    #IfWinActive ahk_class SunAwtFrame
    .::
    Send ->
    return
    

    Will replace . (period) with (->) only in PhpStorm Window (Or others with ahk_class SunAwtFrame). Use Window Spy to see the ahk_class class of any Windows Window.

    You can use CTRL + . as . (period)

    #IfWinActive ahk_class SunAwtFrame
    ^.::
    Send .
    return
    
    0 讨论(0)
  • 2020-12-14 04:06

    1) As far as I remember this kind of completion was asked to be removed for PHP code (too unusual) .. but I cannot find such ticket right now (already spend over 20 mins on this) .. so I could be wrong (it was quite some time ago .. so possibly I'm confused with another code-completion improvement which was hard-configured to behave differently for PHP code only).

    Kind of related to "why it was disabled/what problems where there in the past":

    • http://youtrack.jetbrains.com/issue/WI-7013
    • http://youtrack.jetbrains.com/issue/IDEA-88179
    • http://youtrack.jetbrains.com/issue/IDEA-59718

    In any case: there is an open ticket to actually having it working: http://youtrack.jetbrains.com/issue/WI-21481 (only 1 vote so far).

    2) There is no "complete with ->" action available. Related ticket: http://youtrack.jetbrains.com/issue/WI-17658 (star/vote/comment to get notified on progress)

    0 讨论(0)
提交回复
热议问题