开发者

Eclipse: "Simple" Template Problem with ${word_selection}

开发者 https://www.devze.com 2023-02-10 22:23 出处:网络
i got a (hopefully) simple prob开发者_JAVA技巧lem with a Code Template on Eclipse. I try to use a Code Template to surround a word with somehing. The Replacement is nearly successful, but i have a pro

i got a (hopefully) simple prob开发者_JAVA技巧lem with a Code Template on Eclipse. I try to use a Code Template to surround a word with somehing. The Replacement is nearly successful, but i have a problem with handling the selected word.

My task is to select "save " on this example

<button type="submit">save</button>

and want to have

<button type="submit"><?= $this->_('save') ?></button>

The problem is, that i got this after replacement

<button type="submit">save<?= $this->_('save') ?></button>

Is there a possibility to remove the selected word after using a code template? I am thankful for every help i get. Smile

I forgot, the template looks like this:

<?= $$this->_('${word_selection}') ?>${cursor}


Maybe this question is somewhat old, but I came across the same idea in Java for adding String constants by simply typing the desired name and then replace it with a template, like this for example:

type VALUE and get it replaced with private static final String VALUE = "VALUE";

I use eclipse 3.6 and got it working with the following template:

private static final String ${word_selection} = "${word_selection}";

Then I do the following steps:

  1. type VALUE

  2. select it by double-clicking and hit CTRL+SPACE

  3. enter first few chars for the template name in the opened proposal pop-up and select the template (see image below)

    Eclipse: "Simple" Template Problem with ${word_selection}

  4. hit ENTER

And the result is this:

Eclipse: "Simple" Template Problem with ${word_selection}

Maybe this is helpful.


Using templates and the ${line_selection} or ${word_selection} variables, Eclipse (Helios, 3.6.1 here) always seems to insert the rendered template after the text you initially selected.

I've experienced this myself (in the HTML editor) while trying to implement a similar 'Surround with Tag' template, and gave up and reverted to using Ctrl+1 (after selecting text), and using 'Surround with new element...'. Unfortunately this workaround doesn't help you much w/ PHP.

Possible bug report?


I also faced the same problem in jsp page. I resolved this issue by using 4 or more characters to select the template in eclipse. And I got the correct result.

0

精彩评论

暂无评论...
验证码 换一张
取 消