Skip to content

Commit

Permalink
feat: InsertClass 不再格式化为短横线间隔,而是驼峰式。GoCss 依然支持查找短横线间隔的class。
Browse files Browse the repository at this point in the history
  • Loading branch information
gucovip committed Aug 13, 2021
1 parent d29de60 commit 90938fb
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 16 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ windows: `Alt + insert`, Mac: `control + Enter`
QQ:11563928

#### 更新日志
* 2.0.1 InsertClass 不再格式化为短横线间隔,而是驼峰式。GoCss 依然支持查找短横线间隔的class。
* 2.0.0 调整整体代码架构兼容最新版的 IDE
* 1.4.4 优化代码
* 1.4.3 优化了InsertClass的首次插入操作。
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

pluginGroup = vip.guco.stylusassist
pluginName = Stylus Assist
pluginVersion = 2.0.0
pluginVersion = 2.0.1

# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
# for insight into build numbers and IntelliJ Platform versions.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/InsertClassAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void actionPerformed(AnActionEvent anActionEvent) {
selectedText = selectionModel.getSelectedText();
}

String insertClass = "." + JumpAction.HumpToMiddleline(selectedText);
String insertClass = "." + Utils.formatClass(selectedText);
String preInsertString = "\n " + insertClass + "\n \n";
Document document = editor.getDocument();
int endTag = allContent.indexOf("</style>");
Expand Down
18 changes: 4 additions & 14 deletions src/main/java/JumpAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void actionPerformed(AnActionEvent anActionEvent) {
//匹配类型1
String matchStr = "\\s{1}[\\.#]" + selectedText + "[\\r\\n,]";
//匹配类型2
String matchStr2 = HumpToMiddleline(matchStr);
String matchStr2 = Utils.formatClassWithShortLine(matchStr);
//获取匹配结果
List<Integer> x = findIndex(matchStr, allContent);

Expand All @@ -72,7 +72,7 @@ public void actionPerformed(AnActionEvent anActionEvent) {

if (x.size() <= 0) {
//未匹配到类型2识别为新增样式,生成格式化好的css类名并插入剪切板
CopyToClip("." + HumpToMiddleline(selectedText));
CopyToClip("." + Utils.formatClassWithShortLine(selectedText));
return;
}

Expand All @@ -97,7 +97,7 @@ public void actionPerformed(AnActionEvent anActionEvent) {
//匹配类型1
String matchStr = "\\." + selectedText + "[\\r\\n,]";
//匹配类型2
String matchStr2 = HumpToMiddleline(matchStr);
String matchStr2 = Utils.formatClassWithShortLine(matchStr);
//获取目标匹配文本
String targetText = PsiDocumentManager.getInstance(anActionEvent.getProject())
.getDocument(targetPsiFile).getText();
Expand All @@ -106,7 +106,7 @@ public void actionPerformed(AnActionEvent anActionEvent) {
if (x.size() <= 0) x = findIndex(matchStr2, targetText);

if (x.size() <= 0) {
CopyToClip("." + HumpToMiddleline(selectedText));
CopyToClip("." + Utils.formatClassWithShortLine(selectedText));
return;
}
//匹配到结果,打开文件并跳转位置
Expand Down Expand Up @@ -146,16 +146,6 @@ public static List<Integer> findIndex(String matchStr, String allContent) {
public void update(final AnActionEvent anActionEvent) {
}

public static String HumpToMiddleline(String para) {
StringBuilder sb = new StringBuilder(para);
for (int i = para.length() - 1; i > 0; i--) {
if (Character.isUpperCase(para.charAt(i))) {
sb.insert(i, "-");
}
}
return sb.toString().toLowerCase();
}

public static void CopyToClip(String str) {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();//获取系统剪切板
StringSelection selection = new StringSelection(str);//构建String数据类型
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/Utils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
public class Utils {
public static String formatClassWithShortLine(String str) {
StringBuilder sb = new StringBuilder(str);
for (int i = str.length() - 1; i > 0; i--) {
if (Character.isUpperCase(str.charAt(i))) {
sb.insert(i, "-");
}
}
return sb.toString().toLowerCase();
}

public static String formatClass(String str) {
return str;
}
}
1 change: 1 addition & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

<change-notes><![CDATA[
<ul>
<li>2.0.1 InsertClass 不再格式化为短横线间隔,而是驼峰式。GoCss 依然支持查找短横线间隔的class。</li>
<li>2.0.0 对新版本IDE的兼容</li>
<li>1.4.3 优化了InsertClass的首次插入操作。</li>
<li>1.4.2 修改开源项目地址。</li>
Expand Down

0 comments on commit 90938fb

Please sign in to comment.