简体   繁体   English

Sublime Text 3-CSS自动完成功能,无需输入属性值

[英]Sublime Text 3 - CSS Autocomplete WITHOUT typing property value

So I know autocomplete works great when you start typing a value. 因此,我知道当您开始输入值时,自动填充功能非常有用。 For example, the second you type the "c" in text-align: c enter, the available autocomplete values pop up (such as center, left, right ). 例如,第二次在文本对齐方式中键入"c"c输入,弹出可用的自动完成值(例如center, left, right )。

However, when I used Dreamweaver, for properties with specific value options like text-align (center, right, left), display (block, inline-block), cursor (pointer, default), etc. , the autocomplete popup would show immediately after the property was typed, it did NOT wait until I started typing a value. 但是,当我使用Dreamweaver时,对于具有特定值选项的属性,例如text-align (center, right, left), display (block, inline-block), cursor (pointer, default), etc. ,自动完成弹出窗口会立即显示键入属性后,它不会等到我开始键入一个值。 Right after text-align: was typed out, it would show me the autocomplete popup giving me the options center, right, left . 在输入text-align:输入后,它将显示自动完成弹出窗口,为我提供选项center, right, left

The value autocomplete should fire right after my property autocomplete fires: 我的媒体资源自动填充功能触发后,应立即触发值自动填充功能:

  • So after I type te ... 所以我输入te之后
  • the autocomplete popup for "te" properties displays text-align, text-decoration, text-shadow etc.... “ te”属性的自动完成弹出窗口显示text-align, text-decoration, text-shadow等。
  • then I press Enter to select text-align ... 然后我按Enter键选择text-align ...
  • then immediately after pressing Enter an autocomplete popup should show for the text-align values: center, left, right . 然后在按Enter键后,应立即显示一个自动完成弹出窗口以显示text-align值: center, left, right

Any idea how this can be accomplished in Sublime Text 3? 知道如何在Sublime Text 3中实现吗?

You can get ST to show the autocompletion popup again straight after a completion has been inserted using a small plugin and some preferences: 使用小插件和一些首选项插入完成后,您可以让ST直接显示自动完成弹出窗口:

With a CSS file open in ST, open the Preferences menu and select Preferences - Syntax Specific. 在ST中打开CSS文件后,打开“首选项”菜单,然后选择“首选项-特定于语法”。 Add the following to the settings on the right hand side: 将以下内容添加到右侧的设置中:

"auto_complete_triggers":
[
    {
        "characters": ": ",
        "selector": "source.css meta.property-list.css meta.property-value.css"
    },
],

and save it. 并保存。 This will tell ST to show the autocomplete popup automatically in CSS files when typing a : or a space when the syntax expects a property value. 这将告诉ST在键入:时自动在CSS文件中显示自动完成弹出窗口,或者在语法需要属性值时输入空格。

Now, unfortunately, ST doesn't consider an autocompletion to have "typed" anything, so this trigger isn't fired automatically when selecting a property value like text-align from the autocomplete popup, which inserts text-align: . 现在,不幸的是,ST不认为自动完成功能会“键入”任何内容,因此,当从自动完成弹出窗口中选择text-align类的属性值(插入text-align: :)时,不会自动触发此触发器。 So, to get round that, this is where we need a small plugin. 因此,为了解决这个问题,这是我们需要一个小插件的地方。 From the Tools menu, choose Developer -> New Plugin... 从“工具”菜单中,选择“开发人员”->“新插件...”。

Select all text and replace with the following and save it, in the folder ST recommends ( Packages/User/ ) as something like show_autocomplete_after_completion.py : 选择所有文本并替换为以下内容,并将其保存在ST建议( Packages/User/ )文件夹中,如show_autocomplete_after_completion.py

import sublime
import sublime_plugin


class AutoCompleteListener(sublime_plugin.EventListener):
    def on_post_text_command(self, view, command_name, args):
        if command_name in ('commit_completion', 'insert_best_completion'):
            act = view.settings().get('auto_complete_triggers', [])
            scope = view.scope_name(view.sel()[0].begin())
            char = view.substr(view.sel()[0].begin() - 1)
            for trigger in act:
                if sublime.score_selector(scope, trigger['selector']) > 0:
                    if char in trigger['characters']:
                        view.run_command('auto_complete', { 'insert_best_completion': False })
                        break

This plugin basically detects when a completion has been inserted (although due to a limitation of the ST API, it can't detect when you click on an entry with the mouse - see https://github.com/SublimeTextIssues/Core/issues/1166 ), and if the text/character immediately before the caret matches one of the autocompletion triggers defined in the settings, then it will show the autocomplete popup again. 该插件基本上可以检测到何时插入了完成内容(尽管由于ST API的限制,但是它无法检测到何时使用鼠标单击条目-参见https://github.com/SublimeTextIssues/Core/issues / 1166 ),并且如果插入符号前的文字/字符与设置中定义的自动完成触发器之一匹配,则它将再次显示自动完成弹出窗口。

You can try out this package. 您可以尝试此软件包。 This package indexes your .less and .scss (or .sass) and caches your mixins, variables, class or id names and autocompletes both on html and css. 该软件包为您的.less和.scss(或.sass)建立索引,并缓存您的mixins,变量,类或ID名称,并在html和css上自动完成。 It autocompletes your less and sass mixins with mixin arguments. 它使用mixin参数自动完成您的less和sass mixins。 It also supports emmet completions and gets your css classes on popup window. 它还支持emmet补全,并在弹出窗口中获取CSS类。 - -

https://github.com/subhaze/CSS-Extended/ https://github.com/subhaze/CSS-Extended/

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

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