@Test public void testMoveSelection() throws Exception { setTextAndGet(""); EditorState viewState = editor.moveSelection(0); Assert.assertEquals(0, viewState.selection); viewState = editor.moveSelection(2); Assert.assertEquals(0, viewState.selection); viewState = editor.moveSelection(100); Assert.assertEquals(0, viewState.selection); viewState = editor.moveSelection(-3); Assert.assertEquals(0, viewState.selection); viewState = editor.moveSelection(-100); Assert.assertEquals(0, viewState.selection); setTextAndGet("0123456789"); viewState = editor.moveSelection(0); Assert.assertEquals(10, viewState.selection); viewState = editor.moveSelection(1); Assert.assertEquals(10, viewState.selection); viewState = editor.moveSelection(-2); Assert.assertEquals(8, viewState.selection); viewState = editor.moveSelection(1); Assert.assertEquals(9, viewState.selection); viewState = editor.moveSelection(-9); Assert.assertEquals(0, viewState.selection); viewState = editor.moveSelection(-10); Assert.assertEquals(0, viewState.selection); viewState = editor.moveSelection(2); Assert.assertEquals(2, viewState.selection); viewState = editor.moveSelection(2); Assert.assertEquals(4, viewState.selection); viewState = editor.moveSelection(-6); Assert.assertEquals(0, viewState.selection); }
@Nonnull public EditorState moveSelection(int offset) { Check.isMainThread(); return setSelection(state.selection + offset); }
Editor { @Nonnull public EditorState moveSelection(int offset) { Check.isMainThread(); return setSelection(state.selection + offset); } }
Editor { @Nonnull public EditorState moveSelection(int offset) { Check.isMainThread(); return setSelection(state.selection + offset); } @Inject  Editor(@Nonnull Application application, @Nonnull SharedPreferences preferences, @Nonnull Engine engine); }
Editor { @Nonnull public EditorState moveSelection(int offset) { Check.isMainThread(); return setSelection(state.selection + offset); } @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 { @Nonnull public EditorState moveSelection(int offset) { Check.isMainThread(); return setSelection(state.selection + offset); } @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);  }