    private void hookupKeybindings() {
        input = new SimpleInputMethod();
        input.connect(new InputMethod.Commit() {
            public void onCommit(InputMethod source, String text) {
                insertText(text);
            }
        });
        view.connect(new Widget.KeyPressEvent() {
            public boolean onKeyPressEvent(Widget source, EventKey event) {
                final Keyval key;
                final ModifierType mod;
                if (input.filterKeypress(event)) {
                    return true;
                }
                key = event.getKeyval();
                if ((key == Keyval.Up) || (key == Keyval.Right)) {
                    if (insertOffset == 0) {
                        return false;
                    }
                }
                if ((key == Keyval.Down) || (key == Keyval.Left)) {
                    if (insertOffset == chain.length()) {
                        return false;
                    }
                }
                if ((key == Keyval.Home) || (key == Keyval.End) || (key == Keyval.PageUp)
                        || (key == Keyval.PageDown) || (key == Keyval.Compose)) {
                    return false;
                }
                if ((key == Keyval.F1) || (key == Keyval.F2) || (key == Keyval.F3) || (key == Keyval.F4)
                        || (key == Keyval.F5) || (key == Keyval.F6) || (key == Keyval.F7)
                        || (key == Keyval.F8) || (key == Keyval.F9) || (key == Keyval.F10)
                        || ((key == Keyval.F11) || (key == Keyval.F12))) {
                    return false;
                }
                if (key == Keyval.Escape) {
                    return true;
                }
                if (key == Keyval.Insert) {
                    popupInsertMenu();
                    return true;
                }
                if (key == Keyval.Return) {
                    insertMarkup = null;
                    return false;
                } else if (key == Keyval.Delete) {
                    deleteAt();
                    return true;
                } else if (key == Keyval.BackSpace) {
                    deleteBack();
                    return true;
                }
                if (key == Keyval.Menu) {
                    return false;
                }
                if ((key == Keyval.ShiftLeft) || (key == Keyval.ShiftRight) || (key == Keyval.AltLeft)
                        || (key == Keyval.AltRight) || (key == Keyval.ControlLeft)
                        || (key == Keyval.ControlRight) || (key == Keyval.SuperLeft)
                        || (key == Keyval.SuperRight)) {
                    return false;
                }
                if (key == Keyval.Tab) {
                    if (isCodeBlock()) {
                        return false;
                    } else {
                        return true;
                    }
                }
                mod = event.getState();
                if ((mod == ModifierType.NONE) || (mod == ModifierType.SHIFT_MASK)) {
                    return false;
                }
                if (mod == ModifierType.CONTROL_MASK) {
                    if (key == Keyval.a) {
                        return false;
                    } else if (key == Keyval.b) {
                        toggleMarkup(Common.BOLD);
                        return true;
                    } else if (key == Keyval.c) {
                        copyText();
                        return true;
                    } else if (key == Keyval.g) {
                        insertImage();
                        return true;
                    } else if (key == Keyval.i) {
                        toggleMarkup(Common.ITALICS);
                        return true;
                    } else if (key == Keyval.v) {
                        pasteText();
                        return true;
                    } else if (key == Keyval.x) {
                        cutText();
                        return true;
                    } else {
                        return false;
                    }
                } else if (mod.contains(ModifierType.CONTROL_MASK)
                        && mod.contains(ModifierType.SHIFT_MASK)) {
                    if (key == Keyval.Space) {
                        clearFormat();
                        return true;
                    } else if (key == Keyval.A) {
                        toggleMarkup(Common.APPLICATION);
                        return true;
                    } else if (key == Keyval.L) {
                        toggleMarkup(Common.LITERAL);
                        return true;
                    } else if (key == Keyval.F) {
                        toggleMarkup(Common.FILENAME);
                        return true;
                    } else if (key == Keyval.M) {
                        toggleMarkup(Common.FUNCTION);
                        return true;
                    } else if (key == Keyval.O) {
                        toggleMarkup(Common.COMMAND);
                        return true;
                    } else if (key == Keyval.T) {
                        toggleMarkup(Common.TYPE);
                        return true;
                    } else if (key == Keyval.U) {
                        return false;
                    } else {
                        return false;
                    }
                } else if (mod == ModifierType.LOCK_MASK) {
                    return false;
                }
                throw new IllegalStateException("\n" + "Unhandled " + key + " with " + mod);
            }
        });
        view.connect(new Widget.KeyReleaseEvent() {
            public boolean onKeyReleaseEvent(Widget source, EventKey event) {
                if (input.filterKeypress(event)) {
                    return true;
                }
                return false;
            }
        });
    }

    private void hookupKeybindings() {
        input = new SimpleInputMethod();
        input.connect(new InputMethod.Commit() {
            public void onCommit(InputMethod source, String text) {
                insertText(text);
            }
        });
        view.connect(new Widget.KeyPressEvent() {
            public boolean onKeyPressEvent(Widget source, EventKey event) {
                final Keyval key;
                final ModifierType mod;
                if (input.filterKeypress(event)) {
                    return true;
                }
                key = event.getKeyval();
                if ((key == Keyval.Up) || (key == Keyval.Right)) {
                    if (insertOffset == 0) {
                        return false;
                    }
                }
                if ((key == Keyval.Down) || (key == Keyval.Left)) {
                    if (insertOffset == chain.length()) {
                        return false;
                    }
                }
                if ((key == Keyval.Home) || (key == Keyval.End) || (key == Keyval.PageUp)
                        || (key == Keyval.PageDown) || (key == Keyval.Compose)) {
                    return false;
                }
                if ((key == Keyval.F1) || (key == Keyval.F2) || (key == Keyval.F3) || (key == Keyval.F4)
                        || (key == Keyval.F5) || (key == Keyval.F6) || (key == Keyval.F7)
                        || (key == Keyval.F8) || (key == Keyval.F9) || (key == Keyval.F10)
                        || ((key == Keyval.F11) || (key == Keyval.F12))) {
                    return false;
                }
                if (key == Keyval.Escape) {
                    return true;
                }
                if (key == Keyval.Insert) {
                    popupInsertMenu();
                    return true;
                }
                if (key == Keyval.Return) {
                    insertMarkup = null;
                    insertText("\n");
                    return true;
                } else if (key == Keyval.Delete) {
                    deleteAt();
                    return true;
                } else if (key == Keyval.BackSpace) {
                    deleteBack();
                    return true;
                }
                if (key == Keyval.Menu) {
                    return false;
                }
                if ((key == Keyval.ShiftLeft) || (key == Keyval.ShiftRight) || (key == Keyval.AltLeft)
                        || (key == Keyval.AltRight) || (key == Keyval.ControlLeft)
                        || (key == Keyval.ControlRight) || (key == Keyval.SuperLeft)
                        || (key == Keyval.SuperRight)) {
                    return false;
                }
                if (key == Keyval.Tab) {
                    if (isCodeBlock()) {
                        return false;
                    } else {
                        return true;
                    }
                }
                mod = event.getState();
                if ((mod == ModifierType.NONE) || (mod == ModifierType.SHIFT_MASK)) {
                    return false;
                }
                if (mod == ModifierType.CONTROL_MASK) {
                    if (key == Keyval.a) {
                        return false;
                    } else if (key == Keyval.b) {
                        toggleMarkup(Common.BOLD);
                        return true;
                    } else if (key == Keyval.c) {
                        copyText();
                        return true;
                    } else if (key == Keyval.g) {
                        insertImage();
                        return true;
                    } else if (key == Keyval.i) {
                        toggleMarkup(Common.ITALICS);
                        return true;
                    } else if (key == Keyval.v) {
                        pasteText();
                        return true;
                    } else if (key == Keyval.x) {
                        cutText();
                        return true;
                    } else {
                        return false;
                    }
                } else if (mod.contains(ModifierType.CONTROL_MASK)
                        && mod.contains(ModifierType.SHIFT_MASK)) {
                    if (key == Keyval.Space) {
                        clearFormat();
                        return true;
                    } else if (key == Keyval.A) {
                        toggleMarkup(Common.APPLICATION);
                        return true;
                    } else if (key == Keyval.L) {
                        toggleMarkup(Common.LITERAL);
                        return true;
                    } else if (key == Keyval.F) {
                        toggleMarkup(Common.FILENAME);
                        return true;
                    } else if (key == Keyval.M) {
                        toggleMarkup(Common.FUNCTION);
                        return true;
                    } else if (key == Keyval.O) {
                        toggleMarkup(Common.COMMAND);
                        return true;
                    } else if (key == Keyval.T) {
                        toggleMarkup(Common.TYPE);
                        return true;
                    } else if (key == Keyval.U) {
                        return false;
                    } else {
                        return false;
                    }
                } else if (mod == ModifierType.LOCK_MASK) {
                    return false;
                }
                throw new IllegalStateException("\n" + "Unhandled " + key + " with " + mod);
            }
        });
        view.connect(new Widget.KeyReleaseEvent() {
            public boolean onKeyReleaseEvent(Widget source, EventKey event) {
                if (input.filterKeypress(event)) {
                    return true;
                }
                return false;
            }
        });
    }
