@Override
	public void insertUpdate(DocumentEvent ev) {
		if (ev.getLength() != 1) {
			return;
		}

		int pos = ev.getOffset();
		String content = null;
		try {
			content = getCommandField().getText(0, pos + 1);
		} catch (BadLocationException e) {
			System.out.println("Bad location.");
		}

		// Find where the word starts
		int w;
		for (w = pos; w >= 0; w--) {
			if (!Character.isLetter(content.charAt(w))) {
				break;
			}
		}
		if (pos - w < 2) {
			// Too few chars
			return;
		}

		String prefix = content.substring(w + 1).toUpperCase();
		int n = Collections.binarySearch(control.getAutoWords(), prefix);

		if (n < 0 && -n <= control.getAutoWords().size()) {
			String match = control.getAutoWords().get(-n - 1);
			if (match.toLowerCase().startsWith(prefix.toLowerCase())) {
				String completion = match.substring(pos - w).toLowerCase();
				SwingUtilities.invokeLater(new CompletionTask(completion,
						pos + 1));
			}
		} else {
			// Nothing found
			mode = Mode.INSERT;
		}

	}