Skip to content

Commit

Permalink
Only move to visual mode on selection change if the mouse initiated
Browse files Browse the repository at this point in the history
the selection change.

Change-Id: Ifb020e3c1434955d1eb7cf7fc7c416769cdd3a00
  • Loading branch information
keforbes committed Aug 9, 2011
1 parent fda5e59 commit 9983b36
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.text.TextSelection;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.ISelectionListener;
Expand Down Expand Up @@ -41,6 +44,8 @@ public class VrapperPlugin extends AbstractUIPlugin implements IStartup, Log {
private static final String KEY_VRAPPER_ENABLED = "vrapperEnabled";

private static final String COMMAND_TOGGLE_VRAPPER = "net.sourceforge.vrapper.eclipse.commands.toggle";

private boolean mouseDown = false;

/**
* The constructor
Expand Down Expand Up @@ -125,12 +130,24 @@ private static void addInterceptingListener(IWorkbenchWindow window) {
private static void addSelectionListener(IWorkbenchWindow window) {
ISelectionListener selectionListener = new ISelectionListener() {
public void selectionChanged(IWorkbenchPart sourcepart, ISelection selection) {
//TODO: is there any way to know if the mouse initiated this selection?
if (selection instanceof TextSelection && ! ((TextSelection) selection).isEmpty()) {
//TODO: is there a better way to know if the mouse initiated this selection?
if (plugin.mouseDown && selection instanceof TextSelection && ! selection.isEmpty()) {
beginMouseSelection();
}
}
};
Listener downListener = new Listener() {
public void handleEvent(Event event) {
plugin.mouseDown = true;
}
};
Listener upListener = new Listener() {
public void handleEvent(Event event) {
plugin.mouseDown = false;
}
};
window.getWorkbench().getDisplay().addFilter(SWT.MouseDown, downListener);
window.getWorkbench().getDisplay().addFilter(SWT.MouseUp, upListener);
window.getSelectionService().addSelectionListener(selectionListener);
}

Expand Down

0 comments on commit 9983b36

Please sign in to comment.