void () { if (isDisposed()) return; myEditorDocumentListener = new DocumentListener() { @Override public void beforeDocumentChange(@NotNull DocumentEvent e) { if (CommandProcessor.getInstance().getCurrentCommand() != null && !isUndoOrRedoInProgress()) { myDocumentChanged = true; } } }; myLookupListener = new LookupListener() { @Override public void itemSelected(@NotNull LookupEvent event) { if (isCaretOutsideCurrentSegment(null)) { if (isCaretInsideOrBeforeNextVariable()) { nextTab(); } else { gotoEnd(true); } } } }; LookupManager.getInstance(myProject).addPropertyChangeListener(evt -> { if (LookupManager.PROP_ACTIVE_LOOKUP.equals(evt.getPropertyName())) { Lookup lookup = (Lookup)evt.getNewValue(); if (lookup != null) { lookup.addLookupListener(myLookupListener); } } }, this); if (getEditor() != null) { installCaretListener(getEditor()); } getDocument().addDocumentListener(myEditorDocumentListener, this); myProject.getMessageBus().connect(this).subscribe(CommandListener.TOPIC, new CommandListener() { boolean started; @Override public void commandStarted(@NotNull CommandEvent event) { if (!isUndoOrRedoInProgress()) { myDocumentChangesTerminateTemplate = isCaretOutsideCurrentSegment(event.getCommandName()); started = true; } } @Override public void beforeCommandFinished(@NotNull CommandEvent event) { if (started && !isDisposed() && !isUndoOrRedoInProgress()) { LookupUtil.performGuardedChange(getEditor(), () -> afterChangedUpdate()); } } }); }