Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide caret on focus loss #204

Closed
hwaite opened this issue Nov 2, 2015 · 11 comments
Closed

Hide caret on focus loss #204

hwaite opened this issue Nov 2, 2015 · 11 comments

Comments

@hwaite
Copy link

hwaite commented Nov 2, 2015

CodeArea's caret should be hidden when control lacks focus.

public class Test extends Application {
    public static void main(String[] args) {launch(args);}

    public void start(Stage pStage) {
        pStage.setTitle("Test");

        final Pane root = new VBox();

        root.getChildren().addAll(
            new CodeArea(), new TextArea(), new TextField()
        );

        pStage.setScene(new Scene(root, 300, 250));
        pStage.show();
    }
}
@TomasMikula
Copy link
Member

Hi, isn't it the case already? In your example, the CodeArea does have focus upon startup, so the caret is visible. If you request, e.g., the TextField to have focus, CodeArea's caret is not shown:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

import org.fxmisc.richtext.CodeArea;

public class CodeAreaCaretVisibilityTest extends Application {
    public static void main(String[] args) {launch(args);}

    @Override
    public void start(Stage pStage) {
        pStage.setTitle("Test");

        CodeArea ca = new CodeArea();
        TextArea ta = new TextArea();
        TextField tf = new TextField();
        final Pane root = new VBox(ca, ta, tf);

        pStage.setScene(new Scene(root, 300, 250));
        pStage.show();

        tf.requestFocus();
    }
}

@hwaite
Copy link
Author

hwaite commented Nov 3, 2015

Oops, you're right. I can't reproduce problem when running with official jars. Only see it with HEAD of richtextfx/reactfx/undofx/flowless/wellbehaved. Apologies; will close this bug.

@hwaite hwaite closed this as completed Nov 3, 2015
@TomasMikula
Copy link
Member

Hmm, that is weird, though. It shouldn't happen even when working with the latest sources.

@hwaite
Copy link
Author

hwaite commented Nov 3, 2015

Just refreshed all from GitHub and am no longer seeing problem. A couple snippets of reactfx/richtextfx code won't compile in Eclipse -- I probably patched locally and broke something in the process.

I have this problem all the time when I get too aggressive with lambdas, method references, ternary operators and/or generics. IDEs tend to get confused with type inference and I'll need to add some casts or convert to anonymous class or something. Although your code is technically valid, you might catalyze outside contribution by tweaking tiny number of problematic expressions:

StyledTextAreaView.java:

caretVisible = EventStreams.valuesOf(blinkCaret)
    .flatMap(blink -> blink
        ? booleanPulse(Duration.ofMillis(500))
        : valuesOf(Val.constant(false)))


caretVisible = EventStreams.valuesOf(blinkCaret)
    .flatMap(blink -> blink
        ? booleanPulse(Duration.ofMillis(500))
        : (EventStream<Boolean>) valuesOf(Val.constant(false)))

Lists.java

return lists.stream()
    .filter(l -> !l.isEmpty())
    .map(l -> {
        @SuppressWarnings("unchecked") // cast safe because l is unmodifiable
        List<E> lst = (List<E>) l;
        return lst instanceof ListConcatenation
            ? ((ListConcatenation<E>) lst).ft
            : FingerTree.mkTree(Collections.singletonList(lst), LIST_SIZE_MONOID);
    })
    .reduce(FingerTree::join)
    .<List<E>>map(ListConcatenation<E>::new)
    .orElse(Collections.emptyList());

return lists.stream()
    .filter(l -> !l.isEmpty())
    .map(l -> {
        @SuppressWarnings("unchecked") // cast safe because l is unmodifiable
        List<E> lst = (List<E>) l;
        return (FingerTree<List<E>, Integer>) (lst instanceof ListConcatenation
            ? ((ListConcatenation<E>) lst).ft
            : FingerTree.mkTree(Collections.singletonList(lst), LIST_SIZE_MONOID));
    })
    .reduce(FingerTree::join)
    .<List<E>>map(ListConcatenation<E>::new)
    .orElse(Collections.emptyList());

@TomasMikula
Copy link
Member

I'm using Eclipse and RichTextFX compiles fine in it. My Eclipse JDT version is

Eclipse Java Development Tools  3.10.1.v20150204-1700

@hwaite
Copy link
Author

hwaite commented Nov 3, 2015

Strange. I'm using

Eclipse Java Development Tools  3.11.0.v20150603-2000

mars fail

@TomasMikula
Copy link
Member

Strange. When I check for updates, it doesn't even offer me a newer version of JDT. Maybe because I have Eclipse 4.4 and yours is 4.5?

@hwaite
Copy link
Author

hwaite commented Nov 3, 2015

Well, I am using v4.5.0 (Build ID: 20150621-1200). I'm thoroughly ignorant of how Eclipse decides to update individual components. Probably not worth it to invest a bunch of time into this issue.

@TomasMikula
Copy link
Member

I'm trying out the new version of Eclipse, JDT version

      Eclipse Java Development Tools 3.11.1.v20150904-0015

and I do get the first error you report (not the second one, though). To help the type inference, it suffices to change the line

                        : valuesOf(Val.constant(false)))

to

                        : EventStreams.valuesOf(Val.constant(false)))

(yes, just adding EventStreams.)

OR

to change the line

                .flatMap(blink -> blink

to

                .<Boolean>flatMap(blink -> blink

Does either of those changes make your Eclipse compiler happy? I would prefer one of these instead of type casting proposed above.

@hwaite
Copy link
Author

hwaite commented Nov 12, 2015

I tested each of your proposed solutions and they both work.

@TomasMikula
Copy link
Member

Thanks, I will go with the first one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants