简体   繁体   English

Textmate切换崩溃/扩展CSS规则命令?

[英]Textmate toggle collapse/expand CSS rule command?

Does anyone know of a command (not a macro) for Textmate / E Text Editor / Redcar / etc . 有没有人知道Textmate / E Text Editor / Redcar / 命令 (不是宏)。 that will collapse a multi-line CSS rule down to one line OR , if the rule is already on one line, expand it out to multi-line? 这会将多行CSS规则折叠为一行或者 ,如果规则已经在一行上,则将其展开为多行? I already know about code folding and that's not what I require - I need to be able to toggle the rules between single and multi-line and have them be edited and saved like that. 我已经知道代码折叠了,这不是我需要的东西 - 我需要能够在单行和多行之间切换规则并让它们像这样被编辑和保存。

For example, if I have this: 例如,如果我有这个:

h1 {font-size:3em;line-height:1;margin-bottom:0.5em;}

I would like to be able to place my cursor anywhere within the rule, hit a keyboard shortcut and it would turn into this: 我希望能够将光标放在规则中的任何位置,点击键盘快捷键,它将变为:

h1 {
  font-size:3em;
  line-height:1;
  margin-bottom:0.5em;
}

On hitting the shortcut again, it would convert back into single-line. 在再次点击快捷方式时,它将转换回单行。

Does anything like this exist? 有这样的事吗? Does anyone have any code that does something similar I could repurpose (ideally Ruby)? 有没有人有任何类似的代码可以重新调整用途(理想情况下是Ruby)? Does anyone know if this is even possible in Textmate? 有谁知道在Textmate中这是否可行?

Update : it seems that CSS rule collapsing and expanding is implemented as a pair of macros in Textmate. 更新 :似乎CSS规则折叠和扩展在Textmate中实现为一对宏 However, this isn't toggling and it also doesn't work in E Text Editor (which doesn't support macros). 但是,这不是切换,它也不能在E文本编辑器(不支持宏)中工作。 Not sure whether it works in Redcar. 不确定它是否适用于Redcar。 Is it possible to implement something similar as a command that can do toggling? 是否可以实现类似于可以切换的命令?

I ended up creating my own command to do this. 我最终创建了自己的命令来执行此操作。 Grab it here . 抓住这里

There is a limitation in that for the command to work, the cursor has to be in whitespace within a rule declaration; 在命令工作方面存在一个限制,游标必须在规则声明中的空白区域内; ie, not in a property/value pair scope. 即,不在属性/值对范围内。 I've found placing the cursor just inside the opening brace to be a good place to trigger the command from. 我发现将光标放在开口支架内是一个触发命令的好地方。

If anyone knows how to select a parent scope that would be neat. 如果有人知道如何选择一个整洁的父作用域。

使用CSS捆绑包ctrl + opt + Q会将当前选定的规则折叠为1行。

附加到Mark Story的答案, ctrl + Q则相反,将单行CSS转换为格式良好的CSS。

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

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