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

		int pos = ev.getOffset(); // last letter of input
		String content = null;
		try {
			content = textField.getText(0, pos + 1);
		} catch (BadLocationException e) {
			e.printStackTrace();
		}

		// Find where the word starts
		if (lookingFor == false) {
			for (w = pos; w >= 0; w--) {
				if (!Character.isLetter(content.charAt(w))) {
					lookingFor = true;
					break;
				}
			}
		}

		if (pos - w < 1)
			return;

		String prefix = content.substring(w + 1);
		int n = Collections.binarySearch(words, prefix);
		if (n < 0 && -n <= words.size()) {
			String match = words.get(-n - 1);
			if (match.startsWith(prefix)) {
				// A completion is found
				String completion = match.substring(pos - w);
				// Submitting a new function to do the completion
				SwingUtilities.invokeLater(new CompletionTask(completion,
						pos + 1));
			}
		} else {
			// Nothing found
			mode = Mode.INSERT;
		}
	}