package com.redhat.ceylon.eclipse.code.refactor;

import static java.lang.Character.isUpperCase;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.widgets.Text;

final class SubwordIterator implements KeyListener {
	private final Text text;

	SubwordIterator(Text text) {
		this.text = text;
	}

	@Override
	public void keyReleased(KeyEvent e) {}

	@Override
	public void keyPressed(KeyEvent e) {
		if (e.keyCode==SWT.ARROW_RIGHT && 
				e.stateMask==SWT.MOD3) { //TODO: CTRL on windows?
			int len = text.getText().length();
			for (int i = text.getCaretPosition()+1; i<len; i++) {
				if (isUpperCase(text.getText().charAt(i))) {
					text.setSelection(i);
					e.doit = false;
					break;
				}
			}
		}
		if (e.keyCode==SWT.ARROW_LEFT && 
				e.stateMask==SWT.MOD3) { //TODO: CTRL on windows?
			for (int i = text.getCaretPosition()-1; i>=0; i--) {
				if (isUpperCase(text.getText().charAt(i))) {
					text.setSelection(i);
					e.doit = false;
					break;
				}
			}
		}
	}
}
@@ -318,16 +318,224 @@
 xt text;
+%0A%09private static final int MOD; %0A%09static %7B%0A%09%09String platform = SWT.getPlatform();%0A%09%09if (%22carbon%22.equals (platform) %7C%7C %0A%09%09%09%22cocoa%22.equals (platform)) %7B%0A%09%09%09MOD = SWT.MOD3;%0A%09%09%7D%0A%09%09else %7B%0A%09%09%09MOD = SWT.MOD1;%0A%09%09%7D%0A%09%7D
 %0A%0A%09Subwo
@@ -733,32 +733,27 @@
 .stateMask==
-SWT.
 MOD
-3
 ) %7B //TODO: 
@@ -1041,24 +1041,19 @@
 teMask==
-SWT.
 MOD
-3
 ) %7B //TO

correct modifier for windows fixes #462