如何在 Aptana Studio 中自动缩进 JavaScript 代码?

发布于 2024-11-09 13:36:00 字数 230 浏览 0 评论 0原文

之前我使用 Eclipse 进行 PHP 和 Java 开发,我喜欢使用 Ctrl + i 命令来自动缩进代码。

现在我使用基于Eclipse的Aptana Studio进行JavaScript开发。我想自动缩进我的 JavaScript 代码,但是 Ctrl + i 删除了我的所有代码。 Aptana Studio 中是否有其他命令可以自动缩进 JavaScript 代码?

Previously I used Eclipse for PHP and Java development, and I liked the command Ctrl + i to automatically indent the code.

Now am I using Aptana Studio that is based on Eclipse, for JavaScript development. I would like to automatically indent my JavaScript code, but Ctrl + i deletes all my code. Is there any other command that automatically indent JavaScript code in Aptana Studio?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

岛歌少女 2024-11-16 13:36:00

Studio目前还没有这个功能。您可以在此处添加功能请求:https://aptana.lighthouseapp.com/projects /35272-studio/tickets/new

Ctrl+Shift+F 将格式化整个文件,正如蒂姆建议的那样。
您可以通过“窗口 -> ”中的首选项来控制某些格式化程序设置。首选项->阿普塔纳工作室 ->格式化程序'

The Studio does not have this feature yet. You can add a feature request here: https://aptana.lighthouseapp.com/projects/35272-studio/tickets/new

Ctrl+Shift+F will format your entire file, as Tim suggested.
You can control some of the formatter settings through the preferences at 'Window -> Preferences -> Aptana Studio -> Formatter'

浮生面具三千个 2024-11-16 13:36:00

也许您指的是格式功能CTRL+SHIFT+F

Maybe you mean format feature CTRL+SHIFT+F?

计㈡愣 2024-11-16 13:36:00

我刚刚更新到 Aptana Studio 3.0.9,现在它似乎能够在某些情况下格式化特定(选定)的 JavaScript、HTML 和 CSS 行。对我来说,默认的键绑定有些奇怪,所以我在 Preferences > 中将键绑定更改为 CTRL+I。一般>键

如果没有选择代码,则 Source > Format 似乎总是可靠地格式化整个文件。 Source > 的行为选择上的格式因您正在编辑的代码类型而异:

JavaScript

  • 编辑 .js 文件来源>> Format 似乎按您的预期工作:如果您选择几行代码,则 Source > Format 将正确缩进选定的代码行。
  • 在 HTML 中编辑 JavaScript:在 HTML 文件中设置 JavaScript 格式大多数情况下都可以正常工作,但有时会失败;我还没能发现规则。

HTML

  • 如果您选择 HTML 块,并且该选择的顶行已正确缩进,并且如果该选择不包含任何未封闭的元素,则 Source > Format 会做正确的事情。
  • 否则来源> HTML 格式似乎无法预测。

CSS

  • 编辑 .css 文件
    • 如果我选择整个规则(即包括所有 selector {declaration block; }),则效果很好(在这种情况下,Aptana 仅格式化该规则)。
    • 但如果我的选择不包含整个规则,则会出现错误。
  • 在 HTML 中编辑 css
    • 如果在

除非有人在接下来的几天内指出这篇文章包含致命缺陷,否则我将在 https://jira 上发布功能请求.appcelerator.org 要求跨代码类型的格式化行为保持一致(快速查看现有功能和错误请求表明代码格式化最近受到了相当多的关注)。

更新 19/3/2012 我已在 JIRA 上发布了此错误: https://jira.appcelerator.org/browse/APSTUD-4516

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. The default key binding for me was something odd so I changed the key binding to CTRL+I in Preferences > General > Keys.

If no code is selected then Source > Format seems to always reliably format the entire file. The behaviour of Source > Format on selections differs depending on the type of code you're editing:

JavaScript

  • Editing a .js file: 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.
  • Editing JavaScript within HTML: Formatting JavaScript within an HTML file appears to work most of the time but sometimes fails; I have not been able to discover the rules.

HTML

  • If you select a chunk of HTML, AND IF the top line of that selection is correctly indented ALREADY, AND IF the selection does not include any unclosed elements then Source > Format will do the right thing.
  • Otherwise Source > Format seems to act unpredictably with HTML.

CSS

  • Editing a .css file:
    • works fine if I select an entire rule (i.e. including all of selector { declaration block; }) (in which case Aptana formats just that rule).
    • But if my selection does not include the entire rule then I get an error.
  • Editing css within HTML:
    • If part of the CSS is selected within a <style> block then source > format will format all the css within that <style> block. There seems to be no way to format just a few lines of css within html.

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).

update 19/3/2012 I've posted this bug on the JIRA: https://jira.appcelerator.org/browse/APSTUD-4516

月依秋水 2024-11-16 13:36:00

我遇到了同样的问题并偶然发现了这个网站:
jsbeautifier
你可能想检查一下。对我来说效果很好;)

I was having the same issue and stumbled across this site:
jsbeautifier
You might wanna check it out. Worked fine for me ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文