You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ace编辑器自动补全功能图标重复显示问题求助

Fixing Duplicate Icons in Ace Editor Custom Completions

I’ve run into this exact issue before with Ace’s autocompletion styling! The root cause lies in how Ace applies the className you set on completion items to its internal DOM structure.

When you assign className: "iconable" to a completion entry, Ace adds this class to both the top-level .ace_completion-item element and its child .ace_completion-label element. Your original CSS uses .ace_iconable:after, which targets any element with that class—so you end up with two pseudo-elements (one on the item container, one on the text label) rendering the same icon.

Here’s how to resolve it:

Adjust your CSS selector to target only the specific element where you want the icon to appear. The most reliable approach is to attach the icon to the completion label, which is where the text of the option lives:

.ace_completion-item.iconable .ace_completion-label:after {
    font-family: "Font Awesome 5 Free";
    content: "\f1b2";
    display: inline-block;
    padding-right: 10px;
    padding-left: 10px;
    vertical-align: middle;
    font-weight: 900;
}

If you prefer the icon to be tied to the entire item container instead, you can explicitly disable the pseudo-element on the child label:

.ace_completion-item.iconable:after {
    font-family: "Font Awesome 5 Free";
    content: "\f1b2";
    display: inline-block;
    padding-right: 10px;
    padding-left: 10px;
    vertical-align: middle;
    font-weight: 900;
}

/* Prevent the label from duplicating the icon */
.ace_completion-item.iconable .ace_completion-label:after {
    content: none;
}

Quick way to confirm the issue:

Right-click on a duplicate icon in your browser’s dev tools and inspect the DOM—you’ll see both the parent .ace_completion-item.iconable and child .ace_completion-label.iconable elements, which explains why your original CSS was generating two icons.

You can also double-check your getCompletions function to ensure you’re not accidentally pushing duplicate completion entries (though your code looks clean on that front!).

内容的提问来源于stack exchange,提问作者Daniel Lawton

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 04:02:38