Skip to content

Commit

Permalink
Initial attempt at moving into VisualMode when the mouse selects text.
Browse files Browse the repository at this point in the history
Change-Id: Ia405a836ca42f7abf7f835cdcf16d599c89e9efb
  • Loading branch information
keforbes committed Jul 25, 2011
1 parent afb434c commit fda5e59
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,13 @@ public void onChangeEnabled(boolean enabled) {
changeModeSafely(enabled ? NormalMode.NAME : InsertMode.NAME,
InsertMode.DONT_MOVE_CURSOR);
}

public void beginMouseSelection() {
if(currentMode == null ||
(! VisualMode.NAME.equals(currentMode.getName()) && ! LinewiseVisualMode.NAME.equals(currentMode.getName()))) {
changeModeSafely(VisualMode.NAME);
}
}

public void rememberLastActiveSelection() {
registerManager.setLastActiveSelection(PositionlessSelection.getInstance(this));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public interface EditorAdaptor {
void changeModeSafely(String name, ModeSwitchHint... args);
String getCurrentModeName();
void onChangeEnabled(boolean enabled);
void beginMouseSelection();
EditorMode getMode(String name);
public boolean handleKey(KeyStroke key);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.text.TextSelection;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IStartup;
import org.eclipse.ui.IWindowListener;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchListener;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.plugin.AbstractUIPlugin;
Expand Down Expand Up @@ -101,22 +105,34 @@ private void restoreVimEmulationInActiveEditors() {
private void addEditorListeners() {
for (IWorkbenchWindow window: plugin.getWorkbench().getWorkbenchWindows()) {
addInterceptingListener(window);
addSelectionListener(window);
}
plugin.getWorkbench().addWindowListener(new IWindowListener() {

public void windowOpened(IWorkbenchWindow window) {
addInterceptingListener(window);
addSelectionListener(window);
}

public void windowDeactivated(IWorkbenchWindow window) { }
public void windowClosed(IWorkbenchWindow window) { }
public void windowActivated(IWorkbenchWindow window) { }
public void windowDeactivated(IWorkbenchWindow window) { }
});
}

private static void addInterceptingListener(IWorkbenchWindow window) {
window.getPartService().addPartListener(InputInterceptorManager.INSTANCE);
}

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()) {
beginMouseSelection();
}
}
};
window.getSelectionService().addSelectionListener(selectionListener);
}

private void addShutdownListener() {
getWorkbench().addWorkbenchListener(new IWorkbenchListener() {
Expand Down Expand Up @@ -164,6 +180,14 @@ private static void log(int status, String msg, Throwable exception) {
}

}

private static void beginMouseSelection() {
for (InputInterceptor interceptor: InputInterceptorManager.INSTANCE.getInterceptors()) {
EditorAdaptor adaptor = interceptor.getEditorAdaptor();
if (adaptor != null)
adaptor.beginMouseSelection();
}
}

public void info(String msg) {
log(IStatus.INFO, msg, null);
Expand Down

0 comments on commit fda5e59

Please sign in to comment.