mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-20 14:45:57 +02:00
fix to setSelection()
This commit is contained in:
parent
c064b57468
commit
e3eddeb9d1
1 changed files with 47 additions and 36 deletions
|
@ -107,8 +107,8 @@ public class CEditor extends TextEditor implements ISelectionChangedListener {
|
||||||
|
|
||||||
protected ISelectionChangedListener fStatusLineClearer;
|
protected ISelectionChangedListener fStatusLineClearer;
|
||||||
|
|
||||||
/** The property change listener */
|
/** The property change listener */
|
||||||
private PropertyChangeListener fPropertyChangeListener = new PropertyChangeListener();
|
private PropertyChangeListener fPropertyChangeListener = new PropertyChangeListener();
|
||||||
|
|
||||||
protected final static char[] BRACKETS = { '{', '}', '(', ')', '[', ']' };
|
protected final static char[] BRACKETS = { '{', '}', '(', ')', '[', ']' };
|
||||||
|
|
||||||
|
@ -131,20 +131,20 @@ public class CEditor extends TextEditor implements ISelectionChangedListener {
|
||||||
/** Preference key for linked position color */
|
/** Preference key for linked position color */
|
||||||
public final static String LINKED_POSITION_COLOR = "linkedPositionColor"; //$NON-NLS-1$
|
public final static String LINKED_POSITION_COLOR = "linkedPositionColor"; //$NON-NLS-1$
|
||||||
|
|
||||||
/** Preference key for compiler task tags */
|
/** Preference key for compiler task tags */
|
||||||
private final static String TRANSLATION_TASK_TAGS= CCorePlugin.TRANSLATION_TASK_TAGS;
|
private final static String TRANSLATION_TASK_TAGS= CCorePlugin.TRANSLATION_TASK_TAGS;
|
||||||
|
|
||||||
private class PropertyChangeListener implements org.eclipse.core.runtime.Preferences.IPropertyChangeListener, org.eclipse.jface.util.IPropertyChangeListener {
|
private class PropertyChangeListener implements org.eclipse.core.runtime.Preferences.IPropertyChangeListener, org.eclipse.jface.util.IPropertyChangeListener {
|
||||||
/*
|
/*
|
||||||
* @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
|
* @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
|
||||||
*/
|
*/
|
||||||
public void propertyChange(org.eclipse.jface.util.PropertyChangeEvent event) {
|
public void propertyChange(org.eclipse.jface.util.PropertyChangeEvent event) {
|
||||||
handlePreferencePropertyChanged(event);
|
handlePreferencePropertyChanged(event);
|
||||||
}
|
}
|
||||||
public void propertyChange(org.eclipse.core.runtime.Preferences.PropertyChangeEvent event) {
|
public void propertyChange(org.eclipse.core.runtime.Preferences.PropertyChangeEvent event) {
|
||||||
handlePreferencePropertyChanged(new org.eclipse.jface.util.PropertyChangeEvent(event.getSource(), event.getProperty(), event.getOldValue(), event.getNewValue()));
|
handlePreferencePropertyChanged(new org.eclipse.jface.util.PropertyChangeEvent(event.getSource(), event.getProperty(), event.getOldValue(), event.getNewValue()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor.
|
* Default constructor.
|
||||||
|
@ -349,11 +349,22 @@ public class CEditor extends TextEditor implements ISelectionChangedListener {
|
||||||
|
|
||||||
// 0 length and start and non-zero start line says we know
|
// 0 length and start and non-zero start line says we know
|
||||||
// the line for some reason, but not the offset.
|
// the line for some reason, but not the offset.
|
||||||
if (length == 0 && start == 0 && element.getStartLine() != 0) {
|
if (length == 0 && start == 0 && element.getStartLine() > 0) {
|
||||||
alternateRegion = getDocumentProvider().getDocument(getEditorInput()).getLineInformation(element.getStartLine());
|
// We have the information in term of lines, we can work it out.
|
||||||
if (alternateRegion != null) {
|
// Binary elements return the first executable statement so we have to substract -1
|
||||||
start = alternateRegion.getOffset();
|
start = getDocumentProvider().getDocument(getEditorInput()).getLineOffset(element.getStartLine() - 1);
|
||||||
length = alternateRegion.getLength();
|
if (element.getEndLine() > 0) {
|
||||||
|
length = getDocumentProvider().getDocument(getEditorInput()).getLineOffset(element.getEndLine()) - start;
|
||||||
|
} else {
|
||||||
|
length = start;
|
||||||
|
}
|
||||||
|
// create an alternate region for the keyword highlight.
|
||||||
|
alternateRegion = getDocumentProvider().getDocument(getEditorInput()).getLineInformation(element.getStartLine() - 1);
|
||||||
|
if (start == length || length < 0) {
|
||||||
|
if (alternateRegion != null) {
|
||||||
|
start = alternateRegion.getOffset();
|
||||||
|
length = alternateRegion.getLength();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setHighlightRange(start, length, moveCursor);
|
setHighlightRange(start, length, moveCursor);
|
||||||
|
@ -396,12 +407,12 @@ public class CEditor extends TextEditor implements ISelectionChangedListener {
|
||||||
fBracketMatcher.dispose();
|
fBracketMatcher.dispose();
|
||||||
fBracketMatcher = null;
|
fBracketMatcher = null;
|
||||||
}
|
}
|
||||||
if (fPropertyChangeListener != null) {
|
if (fPropertyChangeListener != null) {
|
||||||
Preferences preferences = CCorePlugin.getDefault().getPluginPreferences();
|
Preferences preferences = CCorePlugin.getDefault().getPluginPreferences();
|
||||||
preferences.removePropertyChangeListener(fPropertyChangeListener);
|
preferences.removePropertyChangeListener(fPropertyChangeListener);
|
||||||
IPreferenceStore preferenceStore = getPreferenceStore();
|
IPreferenceStore preferenceStore = getPreferenceStore();
|
||||||
preferenceStore.removePropertyChangeListener(fPropertyChangeListener);
|
preferenceStore.removePropertyChangeListener(fPropertyChangeListener);
|
||||||
}
|
}
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -876,18 +887,18 @@ public class CEditor extends TextEditor implements ISelectionChangedListener {
|
||||||
return textTools.affectsBehavior(event) || asmTools.affectsBehavior(event);
|
return textTools.affectsBehavior(event) || asmTools.affectsBehavior(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles a property change event describing a change
|
* Handles a property change event describing a change
|
||||||
* of the C core's preferences and updates the preference
|
* of the C core's preferences and updates the preference
|
||||||
* related editor properties.
|
* related editor properties.
|
||||||
*
|
*
|
||||||
* @param event the property change event
|
* @param event the property change event
|
||||||
*/
|
*/
|
||||||
protected void handlePreferencePropertyChanged(org.eclipse.jface.util.PropertyChangeEvent event) {
|
protected void handlePreferencePropertyChanged(org.eclipse.jface.util.PropertyChangeEvent event) {
|
||||||
if (TRANSLATION_TASK_TAGS.equals(event.getProperty())) {
|
if (TRANSLATION_TASK_TAGS.equals(event.getProperty())) {
|
||||||
ISourceViewer sourceViewer= getSourceViewer();
|
ISourceViewer sourceViewer= getSourceViewer();
|
||||||
if (sourceViewer != null && affectsTextPresentation(event))
|
if (sourceViewer != null && affectsTextPresentation(event))
|
||||||
sourceViewer.invalidateTextPresentation();
|
sourceViewer.invalidateTextPresentation();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue