Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find/Replace overlay: disable search scope when leaving #1919 #1920

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
Expand Down Expand Up @@ -226,10 +228,17 @@ public void controlResized(ControlEvent e) {
}
};

private FocusListener overlayFocusListener = FocusListener.focusLostAdapter(e -> {
findReplaceLogic.activate(SearchOptions.GLOBAL);
searchInSelectionButton.setSelection(false);
});
private ShellAdapter overlayDeactivationListener = new ShellAdapter() {
@Override
public void shellActivated(ShellEvent e) {
// Do nothing
}

@Override
public void shellDeactivated(ShellEvent e) {
removeSearchScope();
}
};

private PaintListener widgetMovementListener = __ -> positionToPart();

Expand Down Expand Up @@ -317,7 +326,7 @@ public int open() {
}
overlayOpen = true;
applyOverlayColors(backgroundToUse, true);
initFindStringFromSelection();
updateFromTargetSelection();

getShell().layout();
positionToPart();
Expand Down Expand Up @@ -361,7 +370,7 @@ private void applyOverlayColors(Color color, boolean tryToColorReplaceBar) {
}

private void unbindListeners() {
getShell().removeFocusListener(overlayFocusListener);
getShell().removeShellListener(overlayDeactivationListener);
if (targetPart != null && targetPart instanceof StatusTextEditor textEditor) {
Control targetWidget = textEditor.getSourceViewer().getTextWidget();
if (targetWidget != null) {
Expand All @@ -373,7 +382,7 @@ private void unbindListeners() {
}

private void bindListeners() {
getShell().addFocusListener(overlayFocusListener);
getShell().addShellListener(overlayDeactivationListener);
if (targetPart instanceof StatusTextEditor textEditor) {
Control targetWidget = textEditor.getSourceViewer().getTextWidget();

Expand Down Expand Up @@ -815,7 +824,7 @@ private void performSearch(boolean forward) {
findReplaceLogic.activate(SearchOptions.INCREMENTAL);
}

private void initFindStringFromSelection() {
private void updateFromTargetSelection() {
String initText = findReplaceLogic.getTarget().getSelectionText();
if (initText.isEmpty()) {
return;
Expand Down Expand Up @@ -863,4 +872,9 @@ private static boolean okayToUse(Widget widget) {
public void setPositionToTop(boolean shouldPositionOverlayOnTop) {
positionAtTop = shouldPositionOverlayOnTop;
}

private void removeSearchScope() {
findReplaceLogic.activate(SearchOptions.GLOBAL);
searchInSelectionButton.setSelection(false);
}
}
Loading