use of org.eclipse.search.ui.text.Match in project eclipse.platform.text by eclipse.
the class EditorAnnotationManager method searchResultChanged.
@Override
public synchronized void searchResultChanged(SearchResultEvent e) {
ISearchResult searchResult = e.getSearchResult();
if (searchResult instanceof AbstractTextSearchResult) {
AbstractTextSearchResult result = (AbstractTextSearchResult) searchResult;
if (e instanceof MatchEvent) {
MatchEvent me = (MatchEvent) e;
Match[] matchesInEditor = getMatchesInEditor(me.getMatches(), result);
if (matchesInEditor != null) {
if (me.getKind() == MatchEvent.ADDED) {
addAnnotations(matchesInEditor);
} else {
removeAnnotations(matchesInEditor);
}
}
} else if (e instanceof RemoveAllEvent) {
removeAnnotations(result);
} else if (e instanceof FilterUpdateEvent) {
Match[] matchesInEditor = getMatchesInEditor(((FilterUpdateEvent) e).getUpdatedMatches(), result);
if (matchesInEditor != null) {
removeAnnotations(matchesInEditor);
addAnnotations(matchesInEditor);
}
}
}
}
use of org.eclipse.search.ui.text.Match in project eclipse.platform.text by eclipse.
the class EditorAnnotationManager method getMatchesInEditor.
private Match[] getMatchesInEditor(Match[] matches, AbstractTextSearchResult result) {
IEditorMatchAdapter adapter = result.getEditorMatchAdapter();
if (adapter == null) {
return null;
}
// optimize the array-length == 1 case (most common)
if (matches.length == 1) {
return adapter.isShownInEditor(matches[0], fEditor) ? matches : null;
}
// lazy initialization
ArrayList<Match> matchesInEditor = null;
for (Match curr : matches) {
if (adapter.isShownInEditor(curr, fEditor)) {
if (matchesInEditor == null) {
matchesInEditor = new ArrayList<>();
}
matchesInEditor.add(curr);
}
}
if (matchesInEditor != null) {
return matchesInEditor.toArray(new Match[matchesInEditor.size()]);
}
return null;
}
use of org.eclipse.search.ui.text.Match in project eclipse.platform.text by eclipse.
the class PositionTracker method searchResultChanged.
// tracking matches ---------------------------------------------------------------------
@Override
public void searchResultChanged(SearchResultEvent e) {
if (e instanceof MatchEvent) {
MatchEvent evt = (MatchEvent) e;
Match[] matches = evt.getMatches();
int kind = evt.getKind();
AbstractTextSearchResult result = (AbstractTextSearchResult) e.getSearchResult();
for (Match match : matches) {
ITextFileBuffer fb = getTrackedFileBuffer(result, match.getElement());
if (fb != null) {
updateMatch(match, fb, kind, result);
}
}
} else if (e instanceof RemoveAllEvent) {
RemoveAllEvent evt = (RemoveAllEvent) e;
ISearchResult result = evt.getSearchResult();
untrackAll((AbstractTextSearchResult) result);
}
}
use of org.eclipse.search.ui.text.Match in project eclipse.platform.text by eclipse.
the class PositionTrackerTest method checkInsertInsideMatch.
private void checkInsertInsideMatch(FileSearchResult result, IFile file) throws PartInitException, BadLocationException {
Match[] matches = result.getMatches(file);
try {
SearchTestPlugin.openTextEditor(SearchPlugin.getActivePage(), file);
ITextFileBuffer fb = FileBuffers.getTextFileBufferManager().getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
IDocument doc = fb.getDocument();
for (int i = 0; i < matches.length; i++) {
Position currentPosition = InternalSearchUI.getInstance().getPositionTracker().getCurrentPosition(matches[i]);
assertNotNull(currentPosition);
doc.replace(currentPosition.offset + 1, 0, "Test");
}
for (int i = 0; i < matches.length; i++) {
Position currentPosition = InternalSearchUI.getInstance().getPositionTracker().getCurrentPosition(matches[i]);
assertNotNull(currentPosition);
String text = doc.get(currentPosition.offset, currentPosition.length);
StringBuilder buf = new StringBuilder();
buf.append(text.charAt(0));
buf.append(text.substring(5));
assertEquals(buf.toString(), ((FileSearchQuery) result.getQuery()).getSearchString());
}
} finally {
SearchPlugin.getActivePage().closeAllEditors(false);
}
}
use of org.eclipse.search.ui.text.Match in project eclipse.platform.text by eclipse.
the class SearchResultPageTest method testRemoveTreeMatches.
@Test
// checkElementDisplay(..) misses cases where one line contains multiple matches
@Ignore
public void testRemoveTreeMatches() throws Exception {
NewSearchUI.runQueryInForeground(null, fQuery1);
ISearchResultViewPart view = NewSearchUI.getSearchResultView();
FileSearchPage page = (FileSearchPage) view.getActivePage();
page.setLayout(AbstractTextSearchViewPage.FLAG_LAYOUT_TREE);
AbstractTreeViewer viewer = (AbstractTreeViewer) page.getViewer();
AbstractTextSearchResult result = (AbstractTextSearchResult) fQuery1.getSearchResult();
// make sure all elements have items.
viewer.expandAll();
Object[] elements = result.getElements();
// page.setUpdateTracing(true);
for (int i = 0; i < elements.length; i++) {
Match[] matches = result.getMatches(elements[i]);
viewer.reveal(elements[i]);
for (int j = 0; j < matches.length; j++) {
checkElementDisplay(viewer, result, elements[i]);
result.removeMatch(matches[j]);
consumeEvents(page);
}
}
// page.setUpdateTracing(false);
}
Aggregations