1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 01:36:01 +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
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
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

View file

@ -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();
}
};