Skip to content

Commit

Permalink
#315 - insertion handler for JSX doesn't detect close tag
Browse files Browse the repository at this point in the history
  • Loading branch information
giraud committed Apr 6, 2021
1 parent 6d58ac4 commit 2f38a6b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ Please note that **rescript development is paused** until issues in rescript too
are solved.

## Unreleased


- :bug: [#315](https://github.com/reasonml-editor/reasonml-idea-plugin/issues/315) ![r] insertion handler for JSX doesn't detect close tag
- :nail_care: order jsx attributes, mandatory first

# 0.98.3 - 2021/04/06
Expand Down
23 changes: 19 additions & 4 deletions src/com/reason/ide/insight/provider/JsxNameCompletionProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public static void addCompletions(@NotNull PsiElement element, @NotNull Completi

Collection<PsiModule> modules = PsiFinder.getInstance(project).findComponents(scope);
LOG.debug(" -> Modules found", modules);

for (PsiModule module : modules) {
String moduleName = module.getModuleName();
if (moduleName != null) {
Expand All @@ -59,10 +60,24 @@ private static void insertTagNameHandler(@NotNull Project project, @NotNull Inse
context.setAddCompletionChar(false);
}

Editor editor = context.getEditor();
EditorModificationUtil.insertStringAtCaret(editor, " ></" + tagName + ">");
editor.getCaretModel().moveToOffset(editor.getCaretModel().getOffset() - 4 - tagName.length());
boolean closeTag = false;
CharSequence chars = context.getDocument().getCharsSequence();

int tagPrefixOffset = context.getStartOffset() - 2;
if (tagPrefixOffset >= 0) {
CharSequence tagPrefix = chars.subSequence(tagPrefixOffset, context.getStartOffset());
closeTag = "</".contentEquals(tagPrefix);
}

AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, null);
Editor editor = context.getEditor();
if (closeTag) {
if (chars.charAt(context.getTailOffset()) != '>') {
EditorModificationUtil.insertStringAtCaret(editor, ">");
}
} else {
EditorModificationUtil.insertStringAtCaret(editor, " ></" + tagName + ">");
editor.getCaretModel().moveToOffset(editor.getCaretModel().getOffset() - 4 - tagName.length());
AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, null);
}
}
}

0 comments on commit 2f38a6b

Please sign in to comment.