mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Stabilize synchronization between editor and outline view
This commit is contained in:
parent
f3878f3175
commit
8bc761d4c6
2 changed files with 10 additions and 40 deletions
|
@ -515,9 +515,9 @@ public class CModelBuilder2 implements IContributedModelBuilder {
|
|||
for (int i= 0; i < declarators.length; i++) {
|
||||
final IASTDeclarator declarator= declarators[i];
|
||||
final CElement element= createSimpleDeclaration(parent, declSpecifier, declarator, isTemplate);
|
||||
// if (!isTemplate && element instanceof SourceManipulation) {
|
||||
// setBodyPosition((SourceManipulation)element, declaration);
|
||||
// }
|
||||
if (!isTemplate && element instanceof SourceManipulation && i > 0) {
|
||||
setBodyPosition((SourceManipulation)element, declarator);
|
||||
}
|
||||
elements[i]= element;
|
||||
}
|
||||
} else {
|
||||
|
@ -874,7 +874,7 @@ public class CModelBuilder2 implements IContributedModelBuilder {
|
|||
// set positions
|
||||
setIdentifierPosition(element, astVariableName);
|
||||
if (!isTemplate) {
|
||||
setBodyPosition(element, declarator);
|
||||
setBodyPosition(element, specifier.getParent());
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
|
|
@ -52,9 +52,6 @@ import org.eclipse.ui.views.navigator.LocalSelectionTransfer;
|
|||
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.IParent;
|
||||
import org.eclipse.cdt.core.model.ISourceRange;
|
||||
import org.eclipse.cdt.core.model.ISourceReference;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.refactoring.actions.CRefactoringActionGroup;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
|
@ -244,7 +241,7 @@ public class CContentOutlinePage extends Page implements IContentOutlinePage, IS
|
|||
|
||||
|
||||
/**
|
||||
* Sets the selected element to the one at the current line in the editor.
|
||||
* Sets the selected element to the one at the current cursor position in the editor.
|
||||
*/
|
||||
public void synchronizeSelectionWithEditor() {
|
||||
if(fInput == null || fEditor == null || fTreeViewer == null)
|
||||
|
@ -258,43 +255,16 @@ public class CContentOutlinePage extends Page implements IContentOutlinePage, IS
|
|||
|
||||
ICElement editorElement;
|
||||
try {
|
||||
editorElement = getElementAtOffset(fInput, offset);
|
||||
editorElement = fInput.getElementAtOffset(offset);
|
||||
} catch (CModelException e) {
|
||||
return;
|
||||
}
|
||||
|
||||
IStructuredSelection selection = (editorElement == null)
|
||||
? StructuredSelection.EMPTY
|
||||
: new StructuredSelection(editorElement);
|
||||
|
||||
if (editorElement != null) {
|
||||
IStructuredSelection selection = new StructuredSelection(editorElement);
|
||||
fTreeViewer.setSelection(selection, true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the smallest element at the given offset.
|
||||
*/
|
||||
private static ICElement getElementAtOffset(ICElement element, int offset) throws CModelException {
|
||||
ISourceRange range = ((ISourceReference)element).getSourceRange();
|
||||
int start = range.getStartPos();
|
||||
int end = start + range.getLength();
|
||||
|
||||
ICElement closest = null;
|
||||
|
||||
if((offset >= start && offset <= end) || element instanceof ITranslationUnit) {
|
||||
closest = element;
|
||||
if(element instanceof IParent) {
|
||||
ICElement[] children = ((IParent)element).getChildren();
|
||||
for(int i = 0; i < children.length; i++) {
|
||||
ICElement found = getElementAtOffset(children[i], offset);
|
||||
if(found != null)
|
||||
closest = found;
|
||||
}
|
||||
}
|
||||
}
|
||||
return closest;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* called to create the context menu of the outline
|
||||
|
|
Loading…
Add table
Reference in a new issue