[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-patch] Fixed Bugzilla PR 25176 tabination to be real tabs and not just r eplacing tab with text.
|
2002-12-12 Judy N Green
*src/org/eclipse/cdt/internal/ui/editor/CEditor.java
Fixed Bugzilla bug PR 25176
The C editor doesn't properly handle the space conversion of tabs
properly.
If I put the following in and tab spaces are set to 8 spaces:
1234567890123456789
<tab> a
abc<tab> a
Where it should probably line up with the first entry.
***
cvs diff -N -u "CEditor.java"
Index: CEditor.java
===================================================================
RCS file:
/home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEdito
r.java,v
retrieving revision 1.13
diff -u -r1.13 CEditor.java
--- CEditor.java 25 Nov 2002 14:22:42 -0000 1.13
+++ CEditor.java 13 Dec 2002 04:07:41 -0000
@@ -10,6 +10,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.StringTokenizer;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
@@ -962,8 +963,10 @@
static class TabConverter implements ITextConverter {
private String fTabString= "";
+ private int tabRatio = 0;
public void setNumberOfSpacesPerTab(int ratio) {
+ tabRatio = ratio;
StringBuffer buffer= new StringBuffer();
for (int i= 0; i < ratio; i++)
buffer.append(' ');
@@ -972,22 +975,39 @@
public void customizeDocumentCommand(IDocument document,
DocumentCommand command) {
String text= command.text;
- if (text != null) {
- int index= text.indexOf('\t');
- if (index > -1) {
- int length= text.length();
- StringBuffer buffer= new
StringBuffer();
- buffer.append(text.substring(0,
index));
- for (int i= index; i < length; i++)
{
- char c= text.charAt(i);
- if (c == '\t')
-
buffer.append(fTabString);
- else
- buffer.append(c);
- }
- command.text= buffer.toString();
+ StringBuffer buffer= new StringBuffer();
+ final String TAB = "\t";
+ // create tokens including the tabs
+ StringTokenizer tokens = new StringTokenizer(text,
TAB, true);
+
+ int charCount = 0;
+ try{
+ // get offset of insertion less start of
line
+ // buffer to determine how many characters
+ // are already on this line and adjust tabs
accordingly
+ charCount = command.offset -
(document.getLineInformationOfOffset(command.offset).getOffset());
+ } catch (Exception ex){
+
+ }
+
+ String nextToken = null;
+ int spaces = 0;
+ while (tokens.hasMoreTokens()){
+ nextToken = tokens.nextToken();
+ if (TAB.equals(nextToken)){
+ spaces = tabRatio - (charCount %
tabRatio);
+
+ for (int i= 0; i < spaces; i++){
+ buffer.append(' ');
+ }
+
+ charCount += spaces;
+ } else {
+ buffer.append(nextToken);
+ charCount += nextToken.length();
}
}
+ command.text= buffer.toString();
}
};
¨¨¨°ºo§oº°¨¨¨¨°ºo§oº°¨¨¨¨°ºo§oº°¨¨¨¨°ºo§oº°¨¨¨
Judy N. Green Software Engineer
Eclipse CDT Team www.eclipse.org/cdt
QNX Software Systems Ltd. www.qnx.com
¨¨¨°ºo§oº°¨¨¨¨°ºo§oº°¨¨¨¨°ºo§oº°¨¨¨¨°ºo§oº°¨¨¨