/*
 * Copyright (c) 2017 Karl Tauber <karl at jformdesigner dot com>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *  o Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 *  o Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package org.markdownwriterfx.editor;

import javafx.scene.control.IndexRange;
import org.fxmisc.richtext.StyleClassedTextArea;

/**
 * Markdown text area.
 *
 * @author Karl Tauber
 */
class MarkdownTextArea
	extends StyleClassedTextArea
{
	public MarkdownTextArea() {
		super(false);
	}

	@Override
	public void cut() {
		selectLineIfEmpty();
		super.cut();
	}

	@Override
	public void copy() {
		IndexRange oldSelection = selectLineIfEmpty();
		super.copy();
		if (oldSelection != null)
			selectRange(oldSelection.getStart(), oldSelection.getEnd());
	}


	private IndexRange selectLineIfEmpty() {
		IndexRange oldSelection = null;
		if (getSelectedText().isEmpty()) {
			oldSelection = getSelection();
			selectLine();
			nextChar(SelectionPolicy.ADJUST);
		}
		return oldSelection;
	}
}

@@ -1452,241 +1452,913 @@
 java
-fx.scene.control.IndexRange;%0Aimport org.fxmisc.richtext.StyleClassedTextArea;%0A%0A/**%0A * Markdown text area.%0A *%0A * @author Karl Tauber%0A */%0Aclass MarkdownTextArea%0A%09extends StyleClassedTextArea%0A%7B%0A%09public MarkdownTextArea() %7B%0A%09%09super(false
+.util.Collection;%0Aimport java.util.Collections;%0Aimport javafx.scene.control.IndexRange;%0Aimport org.fxmisc.richtext.GenericStyledArea;%0Aimport org.fxmisc.richtext.StyledTextArea;%0Aimport org.fxmisc.richtext.model.StyledText;%0A%0A/**%0A * Markdown text area.%0A *%0A * @author Karl Tauber%0A */%0Aclass MarkdownTextArea%0A%09extends GenericStyledArea%3CCollection%3CString%3E, StyledText%3CCollection%3CString%3E%3E, Collection%3CString%3E%3E%0A%7B%0A%09public MarkdownTextArea() %7B%0A%09%09super(%0A%09%09%09/* initialParagraphStyle */ Collections.%3CString%3EemptyList(),%0A%09%09%09/* applyParagraphStyle */ (paragraph, styleClasses) -%3E paragraph.getStyleClass().addAll(styleClasses),%0A%09%09%09/* initialTextStyle */ Collections.%3CString%3EemptyList(),%0A%09%09%09/* textOps */ StyledText.textOps(),%0A%09%09%09/* preserveStyle */ false,%0A%09%09%09/* nodeFactory */ seg -%3E StyledTextArea.createStyledTextNode(seg, StyledText.textOps(),%0A%09%09%09%09(text, styleClasses) -%3E text.getStyleClass().addAll(styleClasses))%0A%09%09%09
 );%0A%09

use GenericStyledArea instead of StyleClassedTextArea