mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-12 10:45:37 +02:00
Fix for 180433: [Editor] Highlighting of preprocessor directives is bogus
This commit is contained in:
parent
edd4b98198
commit
a71f94b6dc
2 changed files with 23 additions and 1 deletions
|
@ -24,7 +24,10 @@ import org.eclipse.jface.text.IDocument;
|
||||||
import org.eclipse.jface.text.ITextSelection;
|
import org.eclipse.jface.text.ITextSelection;
|
||||||
import org.eclipse.jface.text.TextSelection;
|
import org.eclipse.jface.text.TextSelection;
|
||||||
import org.eclipse.jface.text.source.SourceViewer;
|
import org.eclipse.jface.text.source.SourceViewer;
|
||||||
|
import org.eclipse.swt.custom.StyleRange;
|
||||||
import org.eclipse.swt.custom.StyledText;
|
import org.eclipse.swt.custom.StyledText;
|
||||||
|
import org.eclipse.swt.graphics.Color;
|
||||||
|
import org.eclipse.swt.graphics.RGB;
|
||||||
import org.eclipse.swt.widgets.Event;
|
import org.eclipse.swt.widgets.Event;
|
||||||
import org.eclipse.ui.IEditorPart;
|
import org.eclipse.ui.IEditorPart;
|
||||||
import org.eclipse.ui.PartInitException;
|
import org.eclipse.ui.PartInitException;
|
||||||
|
@ -35,11 +38,14 @@ import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
||||||
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
import org.eclipse.cdt.ui.tests.BaseUITestCase;
|
import org.eclipse.cdt.ui.tests.BaseUITestCase;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.core.model.ExternalTranslationUnit;
|
import org.eclipse.cdt.internal.core.model.ExternalTranslationUnit;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||||
|
import org.eclipse.cdt.internal.ui.text.ICColorConstants;
|
||||||
|
import org.eclipse.cdt.internal.ui.text.util.CColorManager;
|
||||||
import org.eclipse.cdt.internal.ui.util.EditorUtility;
|
import org.eclipse.cdt.internal.ui.util.EditorUtility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -163,6 +169,23 @@ public class BasicCEditorTest extends BaseUITestCase {
|
||||||
tmpFile.delete();
|
tmpFile.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testSyntaxHighlighting_Bug180433() throws Exception {
|
||||||
|
CColorManager colorMgr= CUIPlugin.getDefault().getTextTools().getColorManager();
|
||||||
|
colorMgr.unbindColor(ICColorConstants.PP_DIRECTIVE);
|
||||||
|
colorMgr.bindColor(ICColorConstants.PP_DIRECTIVE, new RGB(7,7,7));
|
||||||
|
final Color ppDirectiveColor= colorMgr.getColor(ICColorConstants.PP_DIRECTIVE);
|
||||||
|
final String file= "/ceditor/src/main.cpp";
|
||||||
|
fCProject= EditorTestHelper.createCProject("ceditor", "resources/ceditor", false);
|
||||||
|
setUpEditor(file);
|
||||||
|
fSourceViewer= EditorTestHelper.getSourceViewer(fEditor);
|
||||||
|
assertTrue(EditorTestHelper.joinReconciler(fSourceViewer, 0, 10000, 100));
|
||||||
|
String content= fDocument.get();
|
||||||
|
String include= "#include";
|
||||||
|
int includeIdx= content.indexOf(include);
|
||||||
|
StyleRange style= fTextWidget.getStyleRangeAtOffset(includeIdx);
|
||||||
|
assertSame(style.foreground, ppDirectiveColor);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type characters into the styled text.
|
* Type characters into the styled text.
|
||||||
*
|
*
|
||||||
|
|
|
@ -75,7 +75,6 @@ public class CPreprocessorScanner extends AbstractCScanner {
|
||||||
|
|
||||||
token= getToken(ICColorConstants.PP_DIRECTIVE);
|
token= getToken(ICColorConstants.PP_DIRECTIVE);
|
||||||
PreprocessorRule preprocessorRule = new PreprocessorRule(new CWordDetector(), token);
|
PreprocessorRule preprocessorRule = new PreprocessorRule(new CWordDetector(), token);
|
||||||
token= getToken(ICColorConstants.C_TYPE);
|
|
||||||
String[] ppKeywords= fKeywords.getPreprocessorKeywords();
|
String[] ppKeywords= fKeywords.getPreprocessorKeywords();
|
||||||
for (int i = 0; i < ppKeywords.length; i++) {
|
for (int i = 0; i < ppKeywords.length; i++) {
|
||||||
preprocessorRule.addWord(ppKeywords[i], token);
|
preprocessorRule.addWord(ppKeywords[i], token);
|
||||||
|
|
Loading…
Add table
Reference in a new issue