From 08045f8bb9d158c93d91eff4e2b88a64a62f30b5 Mon Sep 17 00:00:00 2001 From: Alex Plate Date: Wed, 21 Nov 2018 19:46:21 +0300 Subject: [PATCH] Use String.take instead of substring. Rename `i` variable to `bracketCharacterPos` --- .../src/com/intellij/internal/retype/RetypeSession.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/internal/retype/RetypeSession.kt b/platform/lang-impl/src/com/intellij/internal/retype/RetypeSession.kt index 51a1a266a799..27a23639aacb 100644 --- a/platform/lang-impl/src/com/intellij/internal/retype/RetypeSession.kt +++ b/platform/lang-impl/src/com/intellij/internal/retype/RetypeSession.kt @@ -146,7 +146,7 @@ class RetypeSession( // There changes wasn't made by lookup, so we don't know how to handle them // Restore text as it should be at this point without any intelligence WriteCommandAction.runWriteCommandAction(project) { - document.replaceText(originalText.substring(0, pos) + originalText.substring(endPos), document.modificationStamp + 1) + document.replaceText(originalText.take(pos) + originalText.takeLast(endPos), document.modificationStamp + 1) } } } @@ -166,12 +166,12 @@ class RetypeSession( val nextChar = originalText[pos] if (document.textLength - pos > tailLength && nextChar in listOf('}', ')', ']')) { // Still have something extra characters in front. Probably closing bracket. - for (i in pos until document.textLength - tailLength) { - if (document.text[i] == nextChar) { + for (bracketCharacterPos in pos until document.textLength - tailLength) { + if (document.text[bracketCharacterPos] == nextChar) { // Found brackets character after caret. All characters between caret and matched symbol should be deleted // Because we don't expect them (in most cases this is just whitespaces) WriteCommandAction.runWriteCommandAction(project) { - document.deleteString(pos, i) + document.deleteString(pos, bracketCharacterPos) } break }