1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 09:46:02 +02:00

Fixed Bugzilla PR 25176 tabination to be real tabs and not just replacing tab with text.

This commit is contained in:
Judy N. Green 2002-12-13 04:13:47 +00:00
parent e643fbae33
commit db9858a832
2 changed files with 47 additions and 15 deletions

View file

@ -1,5 +1,17 @@
2002-12-12 Judy N Green 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
<tab> a
abc<tab> 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 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 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 String quotes and return the first instance that is not encased in quotes

View file

@ -10,6 +10,7 @@ import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.StringTokenizer;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
@ -962,8 +963,10 @@ public class CEditor extends TextEditor implements ISelectionChangedListener {
static class TabConverter implements ITextConverter { static class TabConverter implements ITextConverter {
private String fTabString= ""; private String fTabString= "";
private int tabRatio = 0;
public void setNumberOfSpacesPerTab(int ratio) { public void setNumberOfSpacesPerTab(int ratio) {
tabRatio = ratio;
StringBuffer buffer= new StringBuffer(); StringBuffer buffer= new StringBuffer();
for (int i= 0; i < ratio; i++) for (int i= 0; i < ratio; i++)
buffer.append(' '); buffer.append(' ');
@ -972,22 +975,39 @@ public class CEditor extends TextEditor implements ISelectionChangedListener {
public void customizeDocumentCommand(IDocument document, DocumentCommand command) { public void customizeDocumentCommand(IDocument document, DocumentCommand command) {
String text= command.text; String text= command.text;
if (text != null) { StringBuffer buffer= new StringBuffer();
int index= text.indexOf('\t'); final String TAB = "\t";
if (index > -1) { // create tokens including the tabs
int length= text.length(); StringTokenizer tokens = new StringTokenizer(text, TAB, true);
StringBuffer buffer= new StringBuffer();
buffer.append(text.substring(0, index)); int charCount = 0;
for (int i= index; i < length; i++) { try{
char c= text.charAt(i); // get offset of insertion less start of line
if (c == '\t') // buffer to determine how many characters
buffer.append(fTabString); // are already on this line and adjust tabs accordingly
else charCount = command.offset - (document.getLineInformationOfOffset(command.offset).getOffset());
buffer.append(c); } catch (Exception ex){
}
command.text= buffer.toString(); }
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();
} }
}; };