user exceptions fixed
This commit is contained in:
parent
061a559778
commit
6e09225366
@ -144,7 +144,8 @@ public class AndroidCalculatorEditorView extends EditText implements SharedPrefe
|
|||||||
editorView.viewStateChange = true;
|
editorView.viewStateChange = true;
|
||||||
editorView.viewState = viewState;
|
editorView.viewState = viewState;
|
||||||
editorView.setText(text, BufferType.EDITABLE);
|
editorView.setText(text, BufferType.EDITABLE);
|
||||||
editorView.setSelection(viewState.getSelection());
|
final int selection = CalculatorEditorImpl.correctSelection(viewState.getSelection(), editorView.getText());
|
||||||
|
editorView.setSelection(selection);
|
||||||
} finally {
|
} finally {
|
||||||
editorView.viewStateChange = false;
|
editorView.viewStateChange = false;
|
||||||
}
|
}
|
||||||
|
@ -269,11 +269,11 @@ public class CalculatorEditorImpl implements CalculatorEditor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int correctSelection(int selection, @NotNull String text) {
|
public static int correctSelection(int selection, @NotNull CharSequence text) {
|
||||||
return correctSelection(selection, text.length());
|
return correctSelection(selection, text.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
private int correctSelection(int selection, int textLength) {
|
public static int correctSelection(int selection, int textLength) {
|
||||||
int result = Math.max(selection, 0);
|
int result = Math.max(selection, 0);
|
||||||
result = Math.min(result, textLength);
|
result = Math.min(result, textLength);
|
||||||
return result;
|
return result;
|
||||||
|
@ -114,33 +114,35 @@ public class CalculatorHistoryImpl implements CalculatorHistory {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public List<CalculatorHistoryState> getStates(boolean includeIntermediateStates) {
|
public List<CalculatorHistoryState> getStates(boolean includeIntermediateStates) {
|
||||||
if (includeIntermediateStates) {
|
synchronized (history) {
|
||||||
return getStates();
|
if (includeIntermediateStates) {
|
||||||
} else {
|
return getStates();
|
||||||
final List<CalculatorHistoryState> states = getStates();
|
} else {
|
||||||
|
final List<CalculatorHistoryState> states = getStates();
|
||||||
|
|
||||||
final List<CalculatorHistoryState> result = new LinkedList<CalculatorHistoryState>();
|
final List<CalculatorHistoryState> result = new LinkedList<CalculatorHistoryState>();
|
||||||
|
|
||||||
CalculatorHistoryState laterState = null;
|
CalculatorHistoryState laterState = null;
|
||||||
for (CalculatorHistoryState state : CollectionsUtils.reversed(states)) {
|
for (CalculatorHistoryState state : CollectionsUtils.reversed(states)) {
|
||||||
if ( laterState != null ) {
|
if ( laterState != null ) {
|
||||||
final String laterEditorText = laterState.getEditorState().getText();
|
final String laterEditorText = laterState.getEditorState().getText();
|
||||||
final String editorText = state.getEditorState().getText();
|
final String editorText = state.getEditorState().getText();
|
||||||
if ( laterEditorText != null && editorText != null && isIntermediate(laterEditorText, editorText)) {
|
if ( laterEditorText != null && editorText != null && isIntermediate(laterEditorText, editorText)) {
|
||||||
// intermediate result => skip from add
|
// intermediate result => skip from add
|
||||||
} else {
|
} else {
|
||||||
result.add(0, state);
|
result.add(0, state);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
result.add(0, state);
|
result.add(0, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
laterState = state;
|
laterState = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isIntermediate(@NotNull String laterEditorText,
|
private boolean isIntermediate(@NotNull String laterEditorText,
|
||||||
@NotNull String editorText) {
|
@NotNull String editorText) {
|
||||||
|
Loading…
Reference in New Issue
Block a user