简体   繁体   English

IntelliJ Live Templates错误与completeSmart()函数

[英]IntelliJ Live Templates bug with completeSmart() function

I am trying to create a Live-Template in Android Studio that will somewhat speed up creation of findViewById(...) 我正在尝试在Android Studio中创建一个实时模板,这将有助于加快findViewById(...)创建

Part of it is self-learning, and part is curious in creating such live-templates. 其中一部分是自学,部分是对创建这样的实时模板感到好奇。

I want to be able to type in the following... 我希望能够输入以下内容......

Button find + (enter) Button find +(输入)

...and that should create something like this... ......那应该创造这样的东西......

Button btnAdd = (Button) findViewById(R.id.btnAddition);


My current implementation has issues... 我目前的实施有问题......

在此输入图像描述在此输入图像描述

...and these issues stem from the use of completeSmart() . ......而这些问题源于使用completeSmart() Whenever you use completeSmart() , the template ignores everything after that call and ends editing. 无论何时使用completeSmart() ,模板都会忽略该调用后的所有内容并结束编辑。

For example, If I moved the CAST named-variable up one slot (above ID ) , then the cast would be automatically filled out and it would not let me easily edit ID anymore. 例如,如果我将CAST命名变量向上移动一个插槽( ID以上) ,则会自动填写演员表并且不再允许我轻松编辑ID Same as below picture, but without btnAddition . 与下图相同,但没有btnAddition Just ...findViewById(R.id.); 只是...findViewById(R.id.);

With my current setup, I have CAST on the very bottom so I can easily edit all of the named-variables; 使用我当前的设置,我在底部有CAST因此我可以轻松编辑所有命名变量; however, the use of completeSmart() does not let the template end (Place the cursor by the $END$ marker - Line 29 in the picture below) when I am complete. 但是,当我完成时,使用completeSmart()不会让模板结束(将光标放在$END$标记 - 下图中的第29行)。

Instead, it places the cursor right after the cast , like so... 相反,它将光标放在演员之后 ,就像这样...... 在此输入图像描述

...when it should be placed on the start of the next line. ......当它应该放在下一行的开头。 This template does put a new line in, but the cursor does not go there at the end. 这个模板确实添加了一个新行,但光标最后没有放在那里。 Why? 为什么?


So I want this... 所以我想要这个......

1 ) Since I already but in Button , I want to cast to be Button . 1)因为我已经在Button ,我想要成为Button I should not have to type in in twice! 我不应该两次输入!

you should use method typeOfVariable() 你应该使用方法typeOfVariable()

you can change like this: 你可以这样改变:

FOO

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM