Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import static org.fxmisc.wellbehaved.event.template.InputMapTemplate.*;
import static org.reactfx.EventStreams.*;

import java.util.Arrays;
import java.util.function.Predicate;

import javafx.event.Event;
Expand Down Expand Up @@ -90,7 +89,9 @@ class GenericStyledAreaBehavior {
consume(keyPressed(SHORTCUT_Z), (b, e) -> b.view.undo()),
consume(
anyOf(keyPressed(SHORTCUT_Y), keyPressed(SHORTCUT_SHIFT_Z)),
(b, e) -> b.view.redo())
(b, e) -> b.view.redo()),
// insert/overwrite
consume(keyPressed(INSERT), GenericStyledAreaBehavior::toggelOverwriteMode)
);
InputMapTemplate<GenericStyledAreaBehavior, KeyEvent> edits = when(b -> b.view.isEditable(), editsBase);

Expand Down Expand Up @@ -299,6 +300,11 @@ private enum DragState {

private final GenericStyledArea<?, ?, ?> view;

/**
* Indicates weather the area is in overwrite or insert mode.
*/
private boolean overwriteMode = false;

/**
* Indicates whether an existing selection is being dragged by the user.
*/
Expand Down Expand Up @@ -353,7 +359,19 @@ private void keyTyped(KeyEvent event) {
return;
}

view.replaceSelection(text);
IndexRange range = view.getSelection();
int start = range.getStart();
int end = range.getEnd();

if (overwriteMode && start == end) {
end = Math.min(end+1, view.getLength());
}

view.replaceText(start, end, text);
}

private void toggelOverwriteMode(KeyEvent ignore) {
overwriteMode = !overwriteMode;
}

private void deleteBackward(KeyEvent ignore) {
Expand Down