package org.fxmisc.wellbehaved.input;

import java.util.function.BiConsumer;

import javafx.scene.input.InputEvent;

@FunctionalInterface
public interface InputHandlerTemplate<T extends InputReceiver> {
    BiConsumer<? super T, ? super InputEvent> getHandler();

    default AffinedEventHandler bind(T target) {
        BiConsumer<? super T, ? super InputEvent> handler = getHandler();
        return new AffinedEventHandler() {

            @Override
            public void handle(InputEvent event) {
                handler.accept(target, event);
            }

            @Override
            public InputReceiver getTarget() {
                return target;
            }
        };
    }

    default <U extends T> InputHandlerTemplate<U> orElse(InputHandlerTemplate<U> that) {
        return () -> {
            BiConsumer<? super T, ? super InputEvent> thisHandler = this.getHandler();
            BiConsumer<? super U, ? super InputEvent> thatHandler = that.getHandler();
            return (u, e) -> {
                thisHandler.accept(u, e);
                if(!e.isConsumed()) {
                    thatHandler.accept(u, e);
                }
            };
        };
    }
}

@@ -871,16 +871,37 @@
 ndler = 
+InputHandlerTemplate.
 this.get
@@ -1204,11 +1204,475 @@
 %7D;%0A    %7D
+%0A%0A    default %3CU extends T%3E InputHandlerTemplate%3CU%3E ifConsumed(BiConsumer%3C? super U, ? super InputEvent%3E postConsumption) %7B%0A        return () -%3E %7B%0A            BiConsumer%3C? super T, ? super InputEvent%3E thisHandler = InputHandlerTemplate.this.getHandler();%0A            return (u, e) -%3E %7B%0A                thisHandler.accept(u, e);%0A                if(e.isConsumed()) %7B%0A                    postConsumption.accept(u, e);%0A                %7D%0A            %7D;%0A        %7D;%0A    %7D
 %0A%7D%0A

Add InputHandlerTemplate.ifConsumed() combinator.