From 9a06697a43410b386cdae4837d3786c360559d1d Mon Sep 17 00:00:00 2001 From: ice1000 Date: Sat, 13 Apr 2019 23:13:28 -0400 Subject: [PATCH] [ fix #16 ] Improve tester logic --- src/rs/pest/action/inline.kt | 5 ++--- src/rs/pest/action/ui/ui-impl.kt | 7 +++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/rs/pest/action/inline.kt b/src/rs/pest/action/inline.kt index 91e3ae0..edb313a 100644 --- a/src/rs/pest/action/inline.kt +++ b/src/rs/pest/action/inline.kt @@ -87,9 +87,8 @@ class PestInlineProcessor( .toTypedArray() override fun performRefactoring(usages: Array) { - val grammarBody = rule.grammarBody - val expression = grammarBody?.expression ?: return - val newText = when (expression) { + val grammarBody = rule.grammarBody ?: return + val newText = when (val expression = grammarBody.expression ?: return) { is PestString -> expression.text is PestCharacter -> expression.text is PestIdentifier -> expression.text diff --git a/src/rs/pest/action/ui/ui-impl.kt b/src/rs/pest/action/ui/ui-impl.kt index 2c6dcae..dc5e76a 100644 --- a/src/rs/pest/action/ui/ui-impl.kt +++ b/src/rs/pest/action/ui/ui-impl.kt @@ -26,10 +26,13 @@ class PestIntroduceRulePopupImpl( button.addActionListener { val runnable = act@{ val document = myEditor.document - val grammarBody = elementToRename.grammarBody!! - val offset = newRuleStartOffset + grammarBody.startOffset + val grammarBody = elementToRename.grammarBody ?: return@act + val local = elementToRename.startOffset == 0 + var offset = if (local) newRuleStartOffset + grammarBody.startOffset + else grammarBody.startOffset - 1 if (document.immutableCharSequence[offset] in "@!_$") document.deleteString(offset, offset + 1) + else offset += 1 when (button) { normal -> Unit atomic -> document.insertString(offset, "@")