[英]How to automatically indent the JavaScript code in Aptana Studio?
Previously I used Eclipse for PHP and Java development, and I liked the command Ctrl + i
to automatically indent the code.之前我用 Eclipse 进行 PHP 和 Java 开发,我喜欢命令Ctrl + i
自动缩进代码。
Now am I using Aptana Studio that is based on Eclipse, for JavaScript development.现在我正在使用基于 Eclipse 的 Aptana Studio 进行 JavaScript 开发。 I would like to automatically indent my JavaScript code, but Ctrl + i
deletes all my code.我想自动缩进我的 JavaScript 代码,但是Ctrl + i
删除了我的所有代码。 Is there any other command that automatically indent JavaScript code in Aptana Studio?在 Aptana Studio 中是否有任何其他命令可以自动缩进 JavaScript 代码?
The Studio does not have this feature yet. Studio 尚无此功能。 You can add a feature request here: https://aptana.lighthouseapp.com/projects/35272-studio/tickets/new您可以在此处添加功能请求: https://aptana.lighthouseapp.com/projects/35272-studio/tickets/new
Ctrl+Shift+F will format your entire file, as Tim suggested.正如 Tim 建议的那样,Ctrl+Shift+F 将格式化您的整个文件。 You can control some of the formatter settings through the preferences at 'Window -> Preferences -> Aptana Studio -> Formatter'您可以通过“Window -> Preferences -> Aptana Studio -> Formatter”中的首选项控制一些格式化程序设置
Maybe you mean format feature CTRL+SHIFT+F
?也许您的意思是格式功能CTRL+SHIFT+F
?
I've just updated to Aptana Studio 3.0.9 and it now seems to be able to format specific (selected) lines of JavaScript, HTML and CSS, in some circumstances.我刚刚更新到 Aptana Studio 3.0.9,它现在似乎能够在某些情况下格式化 JavaScript、HTML 和 CSS 的特定(选定)行。 The default key binding for me was something odd so I changed the key binding to CTRL+I
in Preferences > General > Keys
.我的默认键绑定有点奇怪,所以我在Preferences > General > Keys
键绑定更改为CTRL+I
。
If no code is selected then Source > Format
seems to always reliably format the entire file.如果未选择任何代码,则Source > Format
似乎总是可靠地格式化整个文件。 The behaviour of Source > Format
on selections differs depending on the type of code you're editing: Source > Format
对选择的行为因您正在编辑的代码类型而异:
JavaScript JavaScript
Source > Format
appears to work as you'd expect: if you select a few lines of code then Source > Format
will correctly indent just the selected lines of code.编辑 a.js 文件: Source > Format
似乎可以正常工作:如果您 select 几行代码,那么Source > Format
将正确缩进所选的代码行。HTML HTML
Source > Format
will do the right thing.如果您 select 一大块 HTML,并且如果该选择的顶行已经正确缩进,并且如果选择不包含任何未关闭的元素,那么Source > Format
将做正确的事情。Source > Format
seems to act unpredictably with HTML.否则Source > Format
似乎对 HTML 的行为不可预测。CSS CSS
selector { declaration block; }
) (in which case Aptana formats just that rule).如果我 select 整个规则(即包括所有selector { declaration block; }
)(在这种情况下,Aptana 仅格式化该规则),则工作正常。<style>
block then source > format
will format all the css within that <style>
block.如果在<style>
块中选择了 CSS 的一部分,则source > format
将格式化该<style>
块中的所有css。 There seems to be no way to format just a few lines of css within html.似乎没有办法在 html 中仅格式化几行 css。Unless anyone points out that this post contains fatal flaws within the next few days, I'll post a feature request at https://jira.appcelerator.org to ask for consistency in formatting behaviour across code types (a quick look at the existing feature and bug requests suggests that code formatting has received a considerable amount of attention recently).除非有人在接下来的几天内指出这篇文章包含致命缺陷,否则我将在https://jira.appcelerator.org上发布功能请求,以要求跨代码类型的格式化行为保持一致(快速查看现有功能和错误请求表明代码格式化最近受到了相当多的关注)。
update 19/3/2012 I've posted this bug on the JIRA: https://jira.appcelerator.org/browse/APSTUD-4516更新 19/3/2012我在 JIRA 上发布了这个错误: https://jira.appcelerator.org/browse/APSTUD-4516
I was having the same issue and stumbled across this site: jsbeautifier You might wanna check it out.我遇到了同样的问题,偶然发现了这个网站: jsbeautifier你可能想看看。 Worked fine for me;)对我来说工作得很好;)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.