Skip to content

Commit 4fa2b46

Browse files
committed
Fix calculating indentation when user insert new lines on the end of the text
1 parent a2dc7a1 commit 4fa2b46

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

codeview/src/main/java/com/amrdeveloper/codeview/CodeView.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -790,17 +790,17 @@ public void draw(@NonNull Canvas canvas, CharSequence text,
790790
public CharSequence filter(CharSequence source, int start, int end,
791791
Spanned dest, int dStart, int dEnd) {
792792
if (modified && enableAutoIndentation && start < source.length()) {
793-
boolean isInsertedAtEnd = dest.length() == dEnd;
794793
if (source.charAt(start) == '\n') {
795-
char nextChar = dest.charAt(dEnd);
796-
if (isInsertedAtEnd) {
797-
return applyIndentation(source, currentIndentation);
798-
}
794+
// Apply the current indentation if it inserted at the end
795+
if (dest.length() == dEnd) return applyIndentation(source, currentIndentation);
799796

797+
// reCalculate the current indentation
800798
int indentation = calculateSourceIndentation(dest.subSequence(0, dStart));
801-
if (indentationEnds.contains(nextChar)) {
802-
indentation -= tabLength;
803-
}
799+
800+
// Decrement the indentation if the next char is on indentationEnds set
801+
if (indentationEnds.contains(dest.charAt(dEnd))) indentation -= tabLength;
802+
803+
// Apply the new indentation to the source code
804804
return applyIndentation(source, indentation);
805805
}
806806
}

0 commit comments

Comments
 (0)