Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 并准备发布
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 11 additions & 15 deletions src/main/kotlin/com/peppa/css/annotator/SimpleCssSelectorFix.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
31 changes: 11 additions & 20 deletions src/main/kotlin/com/peppa/css/completion/QCssModulesUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

/**
Expand Down
Loading