diff --git a/README.md b/README.md index 3881bf5..12b3eac 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,8 @@ windows: `Alt + insert`, Mac: `control + Enter` #### 最近更新 -* 2018.11.2 - * 1.4.3 优化了InsertClass的首次插入操作。 +* 2020.07.20 + * 1.4.4 优化代码 #### 功能介绍 ##### 简体中文 @@ -65,6 +65,7 @@ QQ:11563928 * 1.4.1 修复没有style标签异常的情况,优化了实现缩小了插件大小。 * 1.4.2 修改开源项目地址。 * 1.4.3 优化了InsertClass的首次插入操作。 +* 1.4.4 优化代码 #### 给我买杯咖啡 Buy me a coffee ![image](https://user-images.githubusercontent.com/13230237/35954042-88d45846-0cc2-11e8-98a3-29adb4f0be9a.png) diff --git a/src/main/java/InsertAction.java b/src/main/java/InsertAction.java index f362e87..496a921 100644 --- a/src/main/java/InsertAction.java +++ b/src/main/java/InsertAction.java @@ -29,9 +29,7 @@ public void actionPerformed(AnActionEvent anActionEvent) { String text = null;//从数据中获取文本值 try { text = (String) content.getTransferData(DataFlavor.stringFlavor); - } catch (UnsupportedFlavorException e) { - e.printStackTrace(); - } catch (IOException e) { + } catch (UnsupportedFlavorException | IOException e) { e.printStackTrace(); } //获取位置 @@ -42,15 +40,15 @@ public void actionPerformed(AnActionEvent anActionEvent) { //获取空格数 CaretModel caretModel = editor.getCaretModel(); caretModel.moveToOffset(start); - String space = ""; + StringBuilder space = new StringBuilder(); for (int i = 0; i < caretModel.getLogicalPosition().column; i++) { - space += " "; + space.append(" "); } if (text == null) { return; } //格式化代码 - final String resultText = formatCode(text, space); + final String resultText = formatCode(text, space.toString()); //插入内容 WriteCommandAction.runWriteCommandAction(editor.getProject(), () -> document.replaceString(start, end, resultText)); diff --git a/src/main/java/InsertClassAction.java b/src/main/java/InsertClassAction.java index 25ad3cf..6291207 100644 --- a/src/main/java/InsertClassAction.java +++ b/src/main/java/InsertClassAction.java @@ -57,13 +57,16 @@ public void actionPerformed(AnActionEvent anActionEvent) { int newEndTag = endTag; String insertString = preInsertString; WriteCommandAction.runWriteCommandAction(editor.getProject(), () -> document.insertString(newEndTag, insertString)); + assert currentPsiFile.getParent() != null; PsiFile targetPsiFile = currentPsiFile.getParent().findFile(currentFileName + ".vue"); + assert targetPsiFile != null; OpenFileDescriptor openFileDescriptor = new OpenFileDescriptor( anActionEvent.getProject(), targetPsiFile.getVirtualFile(), document.getLineNumber(endTag - 1)); Editor targetEdit = FileEditorManager.getInstance(anActionEvent.getProject()) .openTextEditor(openFileDescriptor, true); + assert targetEdit != null; ScrollingModel scrollingModel = targetEdit.getScrollingModel(); scrollingModel.scrollTo(targetEdit.offsetToLogicalPosition(endTag + insertString.length() - 1), ScrollType.MAKE_VISIBLE); CaretModel caretModel = targetEdit.getCaretModel(); diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index d800594..529ddf8 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -42,11 +42,11 @@
  • ......
  • -
  • 1.3.0 GoCss加入一直期待支持的 Navigate Back & Forward 快捷键来回切换。
  • 1.4.0 新增InsertClass功能,该功能处于公共测试阶段,如有问题,欢迎在github上提出。
  • 1.4.1 修复没有style标签异常的情况,优化了实现缩小了插件大小。
  • 1.4.2 修改开源项目地址。
  • 1.4.3 优化了InsertClass的首次插入操作。
  • +
  • 1.4.4 优化代码
  • ]]>