0

我知道如何将 glyphMarginClassName、linesDecorationsClassName 和 inlineClassName 添加到 Monaco Editor 的选项中。但是有没有办法在边距中添加字母字符?像这样:

Monaco Editor 的屏幕截图,显示通过使用 Chrome 调试器编辑 HTML 创建的边距文本

4

1 回答 1

1

你可以这样做,是的。但是,不是动态文本,而是将 ::before 或 ::after 元素附加到该边距节点。

首先在线条装饰中设置自定义 CSS 类名称:

            let ids = this.backend.deltaDecorations(sourceIDs, [{
                range: new Range(this.startLine, 1, this.startLine, model.getLineLength(this.startLine)),
                options: {
                    stickiness: Monaco.TrackedRangeStickiness.GrowsOnlyWhenTypingBefore,
                    isWholeLine: false,
                    linesDecorationsClassName: `editorPromptFirst.${this.language}`,
                },
            }]);

在您的 CSS 中添加如下文本:

.codeEditor .editorPromptFirst.sql::before,
.codeEditor .editorPromptFirst.mysql::before {
    content: "sql>";
    display: block;
    margin-left: 4px;
    font-size: 0.9rem;
    color: #db8f00;
}

这导致此显示:

在此处输入图像描述

于 2021-05-20T07:10:53.650 回答