<commit_before>package org.fxmisc.richtext.mouse;

import com.nitorcreations.junit.runners.NestedRunner;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.geometry.Bounds;
import javafx.stage.Stage;
import org.fxmisc.richtext.InlineCssTextAreaAppTest;
import org.junit.Test;
import org.junit.runner.RunWith;

import static javafx.scene.input.KeyCode.*;
import static javafx.scene.input.MouseButton.*;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertFalse;
import static junit.framework.TestCase.assertTrue;

@RunWith(NestedRunner.class)
public class ClickAndDragTests {

    public class When_Area_Is_Disabled extends InlineCssTextAreaAppTest {

        @Override
        public void start(Stage stage) throws Exception {
            super.start(stage);
            area.setDisable(true);
            area.replaceText("When Area Is Disabled Test: Some text goes here");
            area.moveTo(0);
        }

        @Test
        public void shift_clicking_area_does_nothing() {
            moveTo(firstLineOfArea())
                    .moveBy(20, 0)
                    .press(SHIFT)
                    .press(PRIMARY);

            assertFalse(area.isFocused());
        }

        @Test
        public void single_clicking_area_does_nothing() {
            leftClickOnFirstLine();

            assertFalse(area.isFocused());
        }

        @Test
        public void double_clicking_area_does_nothing() {
            doubleClickOnFirstLine();

            assertFalse(area.isFocused());
        }

        @Test
        public void triple_clicking_area_does_nothing() {
            tripleClickOnFirstLine();

            assertFalse(area.isFocused());
        }

        @Test
        public void dragging_the_mouse_does_not_select_text() {
            moveTo(firstLineOfArea())
                    .press(PRIMARY)
                    .moveBy(20, 0);

            assertTrue(area.getSelectedText().isEmpty());
        }

        @Test
        public void releasing_the_mouse_after_drag_does_nothing() {
            assertEquals(0, area.getCaretPosition());

            SimpleIntegerProperty i = new SimpleIntegerProperty(0);
            area.setOnNewSelectionDragFinished(e -> i.set(1));

            moveTo(firstLineOfArea())
                    .press(PRIMARY)
                    .dropBy(20, 0);

            assertEquals(0, area.getCaretPosition());
            assertEquals(0, i.get());
        }

    }

    public class When_Area_Is_Enabled {

        public class And_Text_Is_Not_Selected extends InlineCssTextAreaAppTest {

            private String firstWord = "Some";
            private String firstParagraph = firstWord + " text goes here";

            @Override
            public void start(Stage stage) throws Exception {
                super.start(stage);
                area.replaceText(firstParagraph);
                area.moveTo(0);
            }

            @Test
            public void single_clicking_area_moves_caret_to_that_position() {
                assertEquals(0, area.getCaretPosition());

                Bounds bounds = area.getCharacterBoundsOnScreen(
                        firstWord.length(), firstWord.length() + 1).get();

                moveTo(bounds).clickOn(PRIMARY);

                assertEquals(firstWord.length(), area.getCaretPosition());
            }

            @Test
            public void double_clicking_text_in_area_selects_closest_word() {
                doubleClickOnFirstLine();

                assertEquals(firstWord, area.getSelectedText());
            }

            @Test
            public void triple_clicking_line_in_area_selects_paragraph() {
                tripleClickOnFirstLine();

                assertEquals(firstParagraph, area.getSelectedText());
            }

            @Test
            public void pressing_mouse_over_text_and_dragging_mouse_selects_text() {
                moveTo(firstLineOfArea())
                        .press(PRIMARY)
                        .moveBy(20, 0);

                assertFalse(area.getSelectedText().isEmpty());
            }

            @Test
            public void pressing_mouse_over_text_and_dragging_and_releasing_mouse_triggers_new_selection_finished() {
                SimpleIntegerProperty i = new SimpleIntegerProperty(0);
                area.setOnNewSelectionDragFinished(e -> i.set(1));
                moveTo(firstLineOfArea())
                        .press(PRIMARY)
                        .moveBy(20, 0)
                        .release(PRIMARY);

                assertFalse(area.getSelectedText().isEmpty());
                assertEquals(1, i.get());
            }

        }

        public class And_Text_Is_Selected extends InlineCssTextAreaAppTest {

            private String firstWord = "Some";
            private String firstParagraph = firstWord + " text goes here";
            private String extraText = "This is extra text";

            @Test
            public void single_clicking_within_selected_text_moves_caret_to_that_position() {
                // setup
                interact(() -> {
                    area.replaceText(firstParagraph);
                    area.selectAll();
                });
<commit_msg>Skip test on Mac builds (passes on Linux & Windows)<commit_after>package org.fxmisc.richtext.mouse;

import com.nitorcreations.junit.runners.NestedRunner;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.geometry.Bounds;
import javafx.stage.Stage;
import org.fxmisc.richtext.InlineCssTextAreaAppTest;
import org.junit.Test;
import org.junit.runner.RunWith;

import static javafx.scene.input.KeyCode.*;
import static javafx.scene.input.MouseButton.*;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertFalse;
import static junit.framework.TestCase.assertTrue;

@RunWith(NestedRunner.class)
public class ClickAndDragTests {

    public class When_Area_Is_Disabled extends InlineCssTextAreaAppTest {

        @Override
        public void start(Stage stage) throws Exception {
            super.start(stage);
            area.setDisable(true);
            area.replaceText("When Area Is Disabled Test: Some text goes here");
            area.moveTo(0);
        }

        @Test
        public void shift_clicking_area_does_nothing() {
            moveTo(firstLineOfArea())
                    .moveBy(20, 0)
                    .press(SHIFT)
                    .press(PRIMARY);

            assertFalse(area.isFocused());
        }

        @Test
        public void single_clicking_area_does_nothing() {
            leftClickOnFirstLine();

            assertFalse(area.isFocused());
        }

        @Test
        public void double_clicking_area_does_nothing() {
            doubleClickOnFirstLine();

            assertFalse(area.isFocused());
        }

        @Test
        public void triple_clicking_area_does_nothing() {
            tripleClickOnFirstLine();

            assertFalse(area.isFocused());
        }

        @Test
        public void dragging_the_mouse_does_not_select_text() {
            moveTo(firstLineOfArea())
                    .press(PRIMARY)
                    .moveBy(20, 0);

            assertTrue(area.getSelectedText().isEmpty());
        }

        @Test
        public void releasing_the_mouse_after_drag_does_nothing() {
            assertEquals(0, area.getCaretPosition());

            SimpleIntegerProperty i = new SimpleIntegerProperty(0);
            area.setOnNewSelectionDragFinished(e -> i.set(1));

            moveTo(firstLineOfArea())
                    .press(PRIMARY)
                    .dropBy(20, 0);

            assertEquals(0, area.getCaretPosition());
            assertEquals(0, i.get());
        }

    }

    public class When_Area_Is_Enabled {

        public class And_Text_Is_Not_Selected extends InlineCssTextAreaAppTest {

            private String firstWord = "Some";
            private String firstParagraph = firstWord + " text goes here";

            @Override
            public void start(Stage stage) throws Exception {
                super.start(stage);
                area.replaceText(firstParagraph);
                area.moveTo(0);
            }

            @Test
            public void single_clicking_area_moves_caret_to_that_position() {
                assertEquals(0, area.getCaretPosition());

                Bounds bounds = area.getCharacterBoundsOnScreen(
                        firstWord.length(), firstWord.length() + 1).get();

                moveTo(bounds).clickOn(PRIMARY);

                assertEquals(firstWord.length(), area.getCaretPosition());
            }

            @Test
            public void double_clicking_text_in_area_selects_closest_word() {
                doubleClickOnFirstLine();

                assertEquals(firstWord, area.getSelectedText());
            }

            @Test
            public void triple_clicking_line_in_area_selects_paragraph() {
                tripleClickOnFirstLine();

                assertEquals(firstParagraph, area.getSelectedText());
            }

            @Test
            public void pressing_mouse_over_text_and_dragging_mouse_selects_text() {
                moveTo(firstLineOfArea())
                        .press(PRIMARY)
                        .moveBy(20, 0);

                assertFalse(area.getSelectedText().isEmpty());
            }

            @Test
            public void pressing_mouse_over_text_and_dragging_and_releasing_mouse_triggers_new_selection_finished() {
                // Doesn't work on Mac builds; works on Linux & Windows
                skip_if_on_mac();

                SimpleIntegerProperty i = new SimpleIntegerProperty(0);
                area.setOnNewSelectionDragFinished(e -> i.set(1));
                moveTo(firstLineOfArea())
                        .press(PRIMARY)
                        .moveBy(20, 0)
                        .release(PRIMARY);

                assertFalse(area.getSelectedText().isEmpty());
                assertEquals(1, i.get());
            }

        }

        public class And_Text_Is_Selected extends InlineCssTextAreaAppTest {

            private String firstWord = "Some";
            private String firstParagraph = firstWord + " text goes here";
            private String extraText = "This is extra text";

            @Test
            public void single_clicking_within_selected_text_moves_caret_to_that_position() {
                // setup
                interact(() -> {
                    area.replaceText(firstParagraph);
                    area.selectAll();
                });

{'fraction_non_alphanumeric': 0.08510837946889369, 'fraction_numerical': 0.005067092052172281, 'mean_word_length': 1.8782068593032677, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3637545', 'n_tokens_mistral': 2859, 'n_tokens_neox': 2668, 'n_words': 482}