@Test public void testErase() throws Exception { setTextAndGet(""); editor.erase(); Assert.assertEquals("", editor.getState().getTextString()); setTextAndGet("test"); editor.erase(); Assert.assertEquals("tes", editor.getState().getTextString()); editor.erase(); Assert.assertEquals("te", editor.getState().getTextString()); editor.erase(); Assert.assertEquals("t", editor.getState().getTextString()); editor.erase(); Assert.assertEquals("", editor.getState().getTextString()); editor.erase(); Assert.assertEquals("", editor.getState().getTextString()); setTextAndGet("1234"); editor.moveCursorLeft(); editor.erase(); Assert.assertEquals("124", editor.getState().getTextString()); editor.erase(); Assert.assertEquals("14", editor.getState().getTextString()); editor.erase(); Assert.assertEquals("4", editor.getState().getTextString()); setTextAndGet("1"); editor.moveCursorLeft(); editor.erase(); Assert.assertEquals("1", editor.getState().getTextString()); }
public boolean erase() { Check.isMainThread(); final int selection = state.selection; final String text = state.getTextString(); if (selection <= 0 || text.length() <= 0 || selection > text.length()) { return false; } int removeStart = selection - 1; if (MathType.getType(text, selection - 1, false, engine).type == MathType.grouping_separator) { removeStart -= 1; } final String newText = text.substring(0, removeStart) + text.substring(selection, text.length()); onTextChanged(EditorState.create(newText, removeStart)); return !newText.isEmpty(); }
Editor { public boolean erase() { Check.isMainThread(); final int selection = state.selection; final String text = state.getTextString(); if (selection <= 0 || text.length() <= 0 || selection > text.length()) { return false; } int removeStart = selection - 1; if (MathType.getType(text, selection - 1, false, engine).type == MathType.grouping_separator) { removeStart -= 1; } final String newText = text.substring(0, removeStart) + text.substring(selection, text.length()); onTextChanged(EditorState.create(newText, removeStart)); return !newText.isEmpty(); } }
Editor { public boolean erase() { Check.isMainThread(); final int selection = state.selection; final String text = state.getTextString(); if (selection <= 0 || text.length() <= 0 || selection > text.length()) { return false; } int removeStart = selection - 1; if (MathType.getType(text, selection - 1, false, engine).type == MathType.grouping_separator) { removeStart -= 1; } final String newText = text.substring(0, removeStart) + text.substring(selection, text.length()); onTextChanged(EditorState.create(newText, removeStart)); return !newText.isEmpty(); } @Inject  Editor(@Nonnull Application application, @Nonnull SharedPreferences preferences, @Nonnull Engine engine); }
Editor { public boolean erase() { Check.isMainThread(); final int selection = state.selection; final String text = state.getTextString(); if (selection <= 0 || text.length() <= 0 || selection > text.length()) { return false; } int removeStart = selection - 1; if (MathType.getType(text, selection - 1, false, engine).type == MathType.grouping_separator) { removeStart -= 1; } final String newText = text.substring(0, removeStart) + text.substring(selection, text.length()); onTextChanged(EditorState.create(newText, removeStart)); return !newText.isEmpty(); } @Inject  Editor(@Nonnull Application application, @Nonnull SharedPreferences preferences, @Nonnull Engine engine); void init(); static int clamp(int selection, @Nonnull CharSequence text); static int clamp(int selection, int max); void setView(@Nonnull EditorView view); void clearView(@Nonnull EditorView view); @Nonnull EditorState getState(); void setState(@Nonnull EditorState state); @Nonnull EditorState setCursorOnStart(); @Nonnull EditorState setCursorOnEnd(); @Nonnull EditorState moveCursorLeft(); @Nonnull EditorState moveCursorRight(); boolean erase(); void clear(); void setText(@Nonnull String text); void setText(@Nonnull String text, int selection); void insert(@Nonnull String text); void insert(@Nonnull String text, int selectionOffset); @Nonnull EditorState moveSelection(int offset); @Nonnull EditorState setSelection(int selection); @Subscribe void onEngineChanged(@Nonnull Engine.ChangedEvent e); @Subscribe void onMemoryValueReady(@Nonnull Memory.ValueReadyEvent e); void onHistoryLoaded(@Nonnull RecentHistory history); }
Editor { public boolean erase() { Check.isMainThread(); final int selection = state.selection; final String text = state.getTextString(); if (selection <= 0 || text.length() <= 0 || selection > text.length()) { return false; } int removeStart = selection - 1; if (MathType.getType(text, selection - 1, false, engine).type == MathType.grouping_separator) { removeStart -= 1; } final String newText = text.substring(0, removeStart) + text.substring(selection, text.length()); onTextChanged(EditorState.create(newText, removeStart)); return !newText.isEmpty(); } @Inject  Editor(@Nonnull Application application, @Nonnull SharedPreferences preferences, @Nonnull Engine engine); void init(); static int clamp(int selection, @Nonnull CharSequence text); static int clamp(int selection, int max); void setView(@Nonnull EditorView view); void clearView(@Nonnull EditorView view); @Nonnull EditorState getState(); void setState(@Nonnull EditorState state); @Nonnull EditorState setCursorOnStart(); @Nonnull EditorState setCursorOnEnd(); @Nonnull EditorState moveCursorLeft(); @Nonnull EditorState moveCursorRight(); boolean erase(); void clear(); void setText(@Nonnull String text); void setText(@Nonnull String text, int selection); void insert(@Nonnull String text); void insert(@Nonnull String text, int selectionOffset); @Nonnull EditorState moveSelection(int offset); @Nonnull EditorState setSelection(int selection); @Subscribe void onEngineChanged(@Nonnull Engine.ChangedEvent e); @Subscribe void onMemoryValueReady(@Nonnull Memory.ValueReadyEvent e); void onHistoryLoaded(@Nonnull RecentHistory history);  }