From db9858a832e07091d7d68f0229a77361b08eba7d Mon Sep 17 00:00:00 2001 From: "Judy N. Green" Date: Fri, 13 Dec 2002 04:13:47 +0000 Subject: [PATCH] Fixed Bugzilla PR 25176 tabination to be real tabs and not just replacing tab with text. --- core/org.eclipse.cdt.ui/ChangeLog | 14 +++++- .../cdt/internal/ui/editor/CEditor.java | 48 +++++++++++++------ 2 files changed, 47 insertions(+), 15 deletions(-) diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog index be0d5c39972..0d50e0c6755 100644 --- a/core/org.eclipse.cdt.ui/ChangeLog +++ b/core/org.eclipse.cdt.ui/ChangeLog @@ -1,5 +1,17 @@ 2002-12-12 Judy N Green - src/org/eclipse/cdt/internal/ui/editor/CMarkerAnnotation.java + *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 + a + abc a + + Where it should probably line up with the first entry. + +2002-12-12 Judy N Green + *src/org/eclipse/cdt/internal/ui/editor/CMarkerAnnotation.java Added a method that will attempt to highlight the correct instance of a variable. It will skip instances of the string if they are encased in String quotes and return the first instance that is not encased in quotes diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java index 986f0658aa6..5c2ed5875a4 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java @@ -10,6 +10,7 @@ import java.util.ArrayList; 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 @@ public class CEditor extends TextEditor implements ISelectionChangedListener { 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 class CEditor extends TextEditor implements ISelectionChangedListener { 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(); } };