Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Remove timed validation in editor: https://bugzilla.redhat.com/show_b…
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Dec 23, 2013
1 parent c71e19d commit 640669e
Showing 1 changed file with 11 additions and 23 deletions.
34 changes: 11 additions & 23 deletions zanata-war/src/main/java/org/zanata/webtrans/client/ui/Editor.java
Expand Up @@ -63,18 +63,12 @@ public class Editor extends Composite implements ToggleEditor {
// Timer period, in ms
private final int TYPING_TIMER_INTERVAL = 200;

// Validation will be forced after this many periods
private final int TYPING_TIMER_INTERVALS_UNTIL_VALIDATION = 5;

// Has a key been pressed since the timer was started or the last firing
private boolean keyPressedSinceTimer;

// Has a timer been started
private boolean timerStarted;

// The number of timer cycles since the last keydown
private int typingCycles;

// NB: In some cases, the idle detection may take almost 2 cycles
// 1. Key pressed at time = 0
// 2. Key pressed at time = 1ms (keyPressedSinceTimer = true)
Expand All @@ -85,12 +79,7 @@ public class Editor extends Composite implements ToggleEditor {
@Override
public void run() {
if (keyPressedSinceTimer) {
// still typing, validate periodically
keyPressedSinceTimer = false;
typingCycles++;
if (typingCycles % TYPING_TIMER_INTERVALS_UNTIL_VALIDATION == 0) {
fireValidationEvent();
}
} else {
// finished, validate immediately
this.cancel();
Expand All @@ -101,7 +90,7 @@ public void run() {
};

public Editor(String displayString, final int index,
final TargetContentsDisplay.Listener listener, final TransUnitId id) {
final TargetContentsDisplay.Listener listener, final TransUnitId id) {
this.listener = listener;
this.index = index;
this.id = id;
Expand Down Expand Up @@ -134,9 +123,9 @@ public void execute() {
@Override
public void setEnableSpellCheck(Boolean enabled) {
targetWrapper.getElement().setAttribute("contenteditable",
enabled.toString());
enabled.toString());
targetWrapper.getElement().setAttribute("spellcheck",
enabled.toString());
enabled.toString());
}

private void fireValidationEvent() {
Expand All @@ -157,7 +146,6 @@ public void onValueChange(ValueChangeEvent<String> event) {
// set false so that next keypress is detectable
keyPressedSinceTimer = false;
timerStarted = true;
typingCycles = 0;
typingTimer.scheduleRepeating(TYPING_TIMER_INTERVAL);
}
listener.setEditingState(id, UNSAVED);
Expand Down Expand Up @@ -232,22 +220,22 @@ public void setFocus() {
@Override
public void insertTextInCursorPosition(String suggestion) {
String preCursor =
textArea.getText().substring(0, textArea.getCursorPos());
textArea.getText().substring(0, textArea.getCursorPos());
String postCursor =
textArea.getText().substring(textArea.getCursorPos(),
textArea.getText().length());
textArea.getText().substring(textArea.getCursorPos(),
textArea.getText().length());

setTextAndValidate(preCursor + suggestion + postCursor);
textArea.setCursorPos(textArea.getText().indexOf(suggestion)
+ suggestion.length());
+ suggestion.length());
}

@Override
public String toString() {
return Objects.toStringHelper(this).add("id", id)
// .add("label", label.getText())
// .add("textArea", textArea.getText())
.add("isFocused", isFocused()).toString();
// .add("label", label.getText())
// .add("textArea", textArea.getText())
.add("isFocused", isFocused()).toString();
}

@Override
Expand All @@ -267,7 +255,7 @@ public void showCopySourceButton(boolean displayButtons) {

@Override
public void updateValidationMessages(
Map<ValidationAction, List<String>> messages) {
Map<ValidationAction, List<String>> messages) {
if (messages.isEmpty()) {
targetWrapper.removeStyleName(style.hasValidationError());
} else {
Expand Down

0 comments on commit 640669e

Please sign in to comment.