我过go 常常在NetBeans 8(JavaFX 8)上编写CSS JavaFX,但在带有JavaFX17的ApacheNetBeans 17上不再提供自动补全"-fx"CSS前缀.我在Linux上使用的是带有JavaFX 17和Java JDK 17 Coretto的Visual Studio Code 1.77,但它似乎也没有.有什么方法可以启用JavaFX CSS自动完成功能吗?

vscode css

推荐答案

你可以用VS Code's CSS Custom Data facility英镑买到一些基本的东西.这个设施相当有限.它目前似乎没有办法限制每个自定义属性的允许值(cssLanguageTypes.ts提到restrictionsvalues个字段,但由于我不知道的原因,这些字段不在CustomData JSON模式中),它似乎也没有办法限制属性与哪些 Select 器相关(但话又说回来,我认为VS代码的内置CSS无论如何都没有这样的功能).

在您的工作区中创建一个类似于"JavaFX-css-vscode-stomdata.json"的文件,并在其中放入以下内容:

{
  "$schema": "https://github.com/microsoft/vscode-css-languageservice/raw/main/docs/customData.schema.json",
  "version": 1.1,
  "properties": [

  ]
}

然后打开您正在使用的JavaFX版本(Ex.https://openjfx.io/javadoc/20/javafx.graphics/javafx/scene/doc-files/cssref.html),并在浏览器的DevTool中运行以下JavaScript代码:

console.log([...document.querySelectorAll("tr:has(th.propertyname)")]
  .filter(tr => tr.children[0].textContent.startsWith("-fx-"))
  .map(tr => {
    const clean = c => c.textContent.trim().replaceAll("\"","\\\"").replaceAll(/\n +/g," ");
    const descParts = [...tr.children].slice(1).map(clean);
    const headers = [...tr.parentElement.parentElement.querySelector("thead > tr").children].slice(1).map(clean);
    const description = headers.map((header,index) => `${header}: ${descParts[index]}`).join("\\n\\n");
    return `{\n  "name": "${tr.children[0].textContent}",\n  "description": "${description}"\n}`;
  })
  .join(",\n")
);

复制该代码的输出并将其粘贴到定制数据JSON文件中的properties数组中.

然后,在你的workspace's .vscode/settings.json file分中,写下以下内容:

"css.customData": [
   "./javafx-css-vscode-customdata.json"
]

以下是上述脚本的部分输出示例:

{
  "name": "-fx-opacity",
  "description": "**Values**: <number>\n\n**Default**: 1\n\n**Range**: [0.0 ... 1.0]\n\n**Comments**: Opacity can be thought of conceptually as a postprocessing operation. Conceptually, after the node (including its descendants) is rendered into an RGBA offscreen image, the opacity setting specifies how to blend the offscreen rendering into the current composite rendering."
},

您可能需要重新启动VS代码以使您的新更改生效.

我将包含一个示例定制数据JSON文件,但它太大了,无法满足Stack Exchange的POST大小限制.

请注意,如果您只想让属性不出现"无法识别的属性"警告,则可以使用css.lint.validProperties设置.

Css相关问答推荐

视频覆盖不适用于reactjs样式的组件

Vue3日期 Select 器:禁用向左和向右箭头

创建始终为剪辑元素的300%高度并左对齐的圆形剪辑路径

使用最小高度和边框使阴影DOM中的元素达到自定义元素高度的100%,如果溢出,还可以zoom 父元素

Firefox中的解决方法:has(不使用JavaScript)

如何在横向和纵向布局上使用 CSS 网格中的纵横比来保持纵横比

如何使用 Ant Design 为不同的屏幕尺寸制作自定义组件样式

为什么 width: 100% 在 Flex 父级中缩小这个 div ?

如何简化CSS?

在 React Native 中创建背景

全部:初始与使用 CSS 重置

如何更改下拉列表的宽度?

在固定高度的输入字段中垂直对齐文本而不显示:表格或填充?

Bootstrap:在列之间添加边距/填充空间

如何更改 Angular Material 上 mat-icon 的大小?

让 div 占据 100% 身体高度,减go 固定高度的页眉和页脚

如何从标题中删除粗体?

如何对齐标签和文本区域?

如何在 React 应用程序中使用 CSS 模块应用全局样式?

更改 html 列表中项目符号的 colored颜色 ?