Skip to content

Commit 7b6d8a9

Browse files
authored
Merge pull request #682 from jMonkeyEngine/copilot/fix-679
Fix shader template files creating empty files instead of proper template content
2 parents 5d19db7 + 79a9233 commit 7b6d8a9

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

jme3-glsl-highlighter/src/com/jme3/gde/glsl/highlighter/editor/GlslIndentTask.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,13 @@ public void reindent() throws BadLocationException {
5555
context.setCaretOffset(1);
5656
final Document doc = context.document();
5757
int indentModifier = 0;
58+
59+
int startOffset = context.startOffset();
60+
int startOffsetBounded = Math.max(startOffset - 1, 0);
5861

5962
//Check if previous line ends with a {
60-
int previousLineLength = context.startOffset() - 1 - context.lineStartOffset(context.startOffset() - 1);
61-
String previousLine = doc.getText(context.lineStartOffset(context.startOffset() - 1), previousLineLength);
63+
int previousLineLength = Math.max(startOffsetBounded - context.lineStartOffset(startOffsetBounded), 0);
64+
String previousLine = doc.getText(context.lineStartOffset(startOffsetBounded), previousLineLength);
6265

6366
//Hook other reasons for changes in indentation into this for loop
6467
for (int i = previousLineLength - 1; i >= 0; i--) {
@@ -69,8 +72,8 @@ public void reindent() throws BadLocationException {
6972
break;
7073
}
7174
}
72-
int previousLineIndent = context.lineIndent(context.lineStartOffset(context.startOffset() - 1));
73-
context.modifyIndent(context.startOffset(), previousLineIndent + indentModifier);
75+
int previousLineIndent = context.lineIndent(context.lineStartOffset(startOffsetBounded));
76+
context.modifyIndent(startOffset, previousLineIndent + indentModifier);
7477
}
7578

7679
@Override

0 commit comments

Comments
 (0)