diff --git a/CHANGELOG.md b/CHANGELOG.md index da021e8..221dbef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ## [Unreleased] +## [1.6.0] - 2025-12-10 + +- fix css icon lose +- fix completion with two dot + ## [1.5.4] - 2025-12-10 - 升级版本号到 1.5.4 并准备发布 @@ -160,7 +165,8 @@ - support a little complex parents selector - support css selector has pseudo -[Unreleased]: https://github.com/Q-Peppa/react-css-modules-all/compare/v1.5.4...HEAD +[Unreleased]: https://github.com/Q-Peppa/react-css-modules-all/compare/v1.6.0...HEAD +[1.6.0]: https://github.com/Q-Peppa/react-css-modules-all/compare/v1.5.4...v1.6.0 [1.5.4]: https://github.com/Q-Peppa/react-css-modules-all/compare/v1.5.3...v1.5.4 [1.5.3]: https://github.com/Q-Peppa/react-css-modules-all/compare/v1.5.2...v1.5.3 [1.5.2]: https://github.com/Q-Peppa/react-css-modules-all/compare/v1.5.1...v1.5.2 diff --git a/gradle.properties b/gradle.properties index cbe0dce..8cb2baf 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,8 +4,8 @@ pluginGroup = com.peppa.css pluginName = CSS Modules pluginRepositoryUrl = https://github.com/Q-Peppa/react-css-modules-all # SemVer format -> https://semver.org -pluginVersion = 1.5.4 -version = 1.5.4 +pluginVersion = 1.6.0 +version = 1.6.0 # Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html pluginSinceBuild=242 # pluginUntilBuild = 242.* # for Supported all version > 231 diff --git a/src/main/kotlin/com/peppa/css/annotator/SimpleCssSelectorFix.kt b/src/main/kotlin/com/peppa/css/annotator/SimpleCssSelectorFix.kt index 288e107..4351ee5 100644 --- a/src/main/kotlin/com/peppa/css/annotator/SimpleCssSelectorFix.kt +++ b/src/main/kotlin/com/peppa/css/annotator/SimpleCssSelectorFix.kt @@ -28,24 +28,20 @@ class SimpleCssSelectorFix(private val key: String, private val stylesheetFile: if (editor == null || file == null) return val rulesetText = "\n.$key {\n\t\t\n}" - val ruleset = CssElementFactory.getInstance(project).createRuleset( - rulesetText, - stylesheetFile.language - ) + val ruleset = CssElementFactory.getInstance(project).createRuleset(rulesetText, stylesheetFile.language) stylesheetFile.navigate(true) stylesheetFile.add(ruleset) - val newEditor = FileEditorManager.getInstance(project).selectedEditor ?: return; - if (newEditor is TextEditor) { - newEditor.editor.caretModel.moveToLogicalPosition( - LogicalPosition(newEditor.editor.document.lineCount - 2, 0) - ) - newEditor.editor.scrollingModel.scrollTo( - newEditor.editor.caretModel.logicalPosition, - ScrollType.MAKE_VISIBLE - ) - DeclarativeInlayHintsPassFactory.scheduleRecompute(editor, project) - DeclarativeInlayHintsPassFactory.scheduleRecompute(newEditor.editor, project) + + FileEditorManager.getInstance(project).selectedEditor?.let { newEditor -> + if (newEditor is TextEditor) { + newEditor.editor.apply { + caretModel.moveToLogicalPosition(LogicalPosition(document.lineCount - 2, 0)) + scrollingModel.scrollTo(caretModel.logicalPosition, ScrollType.MAKE_VISIBLE) + } + DeclarativeInlayHintsPassFactory.scheduleRecompute(editor, project) + DeclarativeInlayHintsPassFactory.scheduleRecompute(newEditor.editor, project) + } } } } \ No newline at end of file diff --git a/src/main/kotlin/com/peppa/css/completion/CssModulesClassNameCompletionContributor.kt b/src/main/kotlin/com/peppa/css/completion/CssModulesClassNameCompletionContributor.kt index 94f4d36..15be4df 100644 --- a/src/main/kotlin/com/peppa/css/completion/CssModulesClassNameCompletionContributor.kt +++ b/src/main/kotlin/com/peppa/css/completion/CssModulesClassNameCompletionContributor.kt @@ -73,8 +73,8 @@ class CssModulesClassNameCompletionContributor : CompletionContributor() { private fun convertToBracketSyntax(context: InsertionContext, lookupString: String) { val document = context.editor.document val dotOffset = context.startOffset - 1 - document.replaceString(dotOffset, context.tailOffset, "['$lookupString']") - context.editor.caretModel.moveToOffset(dotOffset + lookupString.length + 4) + document.replaceString(dotOffset, context.tailOffset, "[$lookupString]") + context.editor.caretModel.moveToOffset(context.tailOffset) } } diff --git a/src/main/kotlin/com/peppa/css/completion/QCssModulesUtil.kt b/src/main/kotlin/com/peppa/css/completion/QCssModulesUtil.kt index 1f44207..d77faa1 100644 --- a/src/main/kotlin/com/peppa/css/completion/QCssModulesUtil.kt +++ b/src/main/kotlin/com/peppa/css/completion/QCssModulesUtil.kt @@ -178,7 +178,7 @@ fun buildLookupElementHelper( private fun toGetStylesheetFile(ref: PsiReference?): StylesheetFile? { // 增强解析逻辑:支持直接 resolve 到 StylesheetFile、PsiFile,或 ES6ImportedBinding, - // 并尝试沿引用链继续解析,提升命中率和鲁棒性。 + // 并尝试沿引用链继续解析,提升命中率��鲁棒性。 val resolved = ref?.resolve() ?: return null return when (resolved) { is StylesheetFile -> resolved @@ -191,26 +191,17 @@ private fun toGetStylesheetFile(ref: PsiReference?): StylesheetFile? { } } -fun resolveStylesheetFromReference(element: PsiElement?): StylesheetFile? { - if (element == null) return null - - // 字符串字面量的情况:查找最近的引用表达式(支持多种父级结构) - if (element is JSLiteralExpression) { - // 优先查找索引访问 foo["bar"] 的首子表达式 - val indexed = PsiTreeUtil.getParentOfType(element, JSIndexedPropertyAccessExpression::class.java) - val candidateRef = (indexed?.firstChild as? JSReferenceExpression) - // 否则向上查找通用的 JSReferenceExpression(例如 foo.bar 或 更复杂结构) - ?: PsiTreeUtil.getParentOfType(element, JSReferenceExpression::class.java) - - return toGetStylesheetFile(candidateRef?.reference) - } - - // 直接是引用表达式:优先用自身的 reference,再退回到 firstChild 的 reference(兼容旧逻辑) - if (element is JSReferenceExpression) { - return toGetStylesheetFile(element.reference ?: element.firstChild?.reference) +fun resolveStylesheetFromReference(element: PsiElement?): StylesheetFile? = element?.let { + when (it) { + is JSLiteralExpression -> { + val indexed = PsiTreeUtil.getParentOfType(it, JSIndexedPropertyAccessExpression::class.java) + val candidateRef = (indexed?.firstChild as? JSReferenceExpression) + ?: PsiTreeUtil.getParentOfType(it, JSReferenceExpression::class.java) + toGetStylesheetFile(candidateRef?.reference) + } + is JSReferenceExpression -> toGetStylesheetFile(it.reference ?: it.firstChild?.reference) + else -> null } - - return null } /**