From 0ace8e6e3f596565ce20a867d6b3a5c1ee4d733f Mon Sep 17 00:00:00 2001 From: Anton Leherbauer Date: Wed, 18 Apr 2007 13:50:07 +0000 Subject: [PATCH] Fix exception on auto-indent at end of file --- .../cdt/internal/ui/text/CAutoIndentStrategy.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CAutoIndentStrategy.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CAutoIndentStrategy.java index 5a945797e9f..ade36165f43 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CAutoIndentStrategy.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/CAutoIndentStrategy.java @@ -254,19 +254,19 @@ public class CAutoIndentStrategy extends DefaultIndentLineAutoEditStrategy { } } catch (BadLocationException exc) { } + int docLength = d.getLength(); + if (c.offset == -1 || docLength == 0) + return; + int p = (c.offset == docLength ? c.offset - 1 : c.offset); + CIndenter indenter = new CIndenter(d, scanner, fProject); - StringBuffer indent = indenter.computeIndentation(c.offset); + StringBuffer indent = indenter.computeIndentation(p); if (indent == null) indent = new StringBuffer(); if (addIndent > 0 && indent.length() == 0) { indent= indenter.createReusingIndent(indent, addIndent); } - int docLength = d.getLength(); - if (c.offset == -1 || docLength == 0) - return; - try { - int p = (c.offset == docLength ? c.offset - 1 : c.offset); int line = d.getLineOfOffset(p); StringBuffer buf = new StringBuffer(c.text + indent);