Skip to content

Calculate highlighting of brackets #566

@stevedefazio

Description

@stevedefazio

I'm trying to calculate highlighting for brackets. And while I think the algorithm is right, I am not sure I'm using the right method to set the style. What I'm trying to do is say "Set the style for the characters from point A to point B", but codeArea.setStyle doesn't seem to be doing anything.

codeArea.caretPositionProperty()
    .addListener((observable, oldValue, newValue) -> {
        if (codeArea.getText(newValue - 1, newValue).equals("[")) {
            int match = computeHighlightingBrackets(configCode.getText(), newValue - 1);
            System.out.println(match);
            codeArea.setStyle(match-1, match, 
                Arrays.asList("-fx-font-family: consolas","-fx-font-size: 30pt;"));
        }
    });

int computeHighlightingBrackets(String text, int start){
	int openPos = start;
		int closePos = openPos;
		int counter = 1;
		while (counter > 0) {
			char c = text.charAt(++closePos);
			if (c == '[') {
				counter++;
			} else if (c == ']') {
				counter--;
			}
		}
	return closePos;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions