mirror of
https://github.com/nextcloud/notes-android.git
synced 2024-11-22 21:06:09 +03:00
#1019 ↪️ Auto continuation should continue a list at the same indention level
Signed-off-by: Stefan Niedermann <info@niedermann.it>
This commit is contained in:
parent
7f5c2989ed
commit
14a3e6928c
2 changed files with 27 additions and 10 deletions
|
@ -91,11 +91,17 @@ public class AutoContinuationTextWatcher extends InterceptorTextWatcher {
|
|||
isInsert = false;
|
||||
sequenceStart = startOfLine;
|
||||
} else {
|
||||
// TODO use Java 11 String::repeat
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < line.indexOf(line.trim()); i++) {
|
||||
builder.append(" ");
|
||||
}
|
||||
for (EListType listType : EListType.values()) {
|
||||
final boolean isCheckboxList = lineStartsWithCheckbox(line, listType);
|
||||
final boolean isPlainList = !isCheckboxList && line.startsWith(listType.listSymbolWithTrailingSpace);
|
||||
if (isPlainList || isCheckboxList) {
|
||||
customText = isPlainList ? listType.listSymbolWithTrailingSpace : listType.checkboxUncheckedWithTrailingSpace;
|
||||
builder.append(isPlainList ? listType.listSymbolWithTrailingSpace : listType.checkboxUncheckedWithTrailingSpace);
|
||||
customText = builder;
|
||||
isInsert = true;
|
||||
sequenceStart = start + count;
|
||||
return;
|
||||
|
@ -104,7 +110,7 @@ public class AutoContinuationTextWatcher extends InterceptorTextWatcher {
|
|||
|
||||
final Optional<Integer> orderedListNumber = getOrderedListNumber(line);
|
||||
if (orderedListNumber.isPresent()) {
|
||||
customText = (orderedListNumber.get() + 1) + ". ";
|
||||
customText = builder.append(orderedListNumber.get() + 1).append(". ");
|
||||
isInsert = true;
|
||||
sequenceStart = start + count;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package it.niedermann.android.markdown.markwon.textwatcher;
|
||||
|
||||
import android.os.Looper;
|
||||
import android.view.KeyEvent;
|
||||
import android.widget.EditText;
|
||||
|
||||
|
@ -9,7 +8,6 @@ import androidx.test.core.app.ApplicationProvider;
|
|||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
@ -19,8 +17,6 @@ import org.robolectric.RobolectricTestRunner;
|
|||
import it.niedermann.android.markdown.markwon.MarkwonMarkdownEditor;
|
||||
import it.niedermann.android.markdown.model.EListType;
|
||||
|
||||
import static org.robolectric.Shadows.shadowOf;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class AutoContinuationTextWatcherTest extends TestCase {
|
||||
|
||||
|
@ -86,10 +82,25 @@ public class AutoContinuationTextWatcherTest extends TestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldContinueNestedLists() {
|
||||
this.editText.setText("- [ ] Parent\n - [x] Child");
|
||||
public void shouldContinueNestedListsAtTheSameIndention() {
|
||||
this.editText.setText("- [ ] Parent\n - [x] Child\n - [ ] Third");
|
||||
pressEnter(26);
|
||||
assertText("- [ ] Parent\n - [x] Child\n- [ ] ", 33);
|
||||
assertText("- [ ] Parent\n - [x] Child\n - [ ] \n - [ ] Third", 35);
|
||||
|
||||
this.editText.setText("- [ ] Parent\n - [x] Child\n - [ ] Third");
|
||||
pressEnter(42);
|
||||
assertText("- [ ] Parent\n - [x] Child\n - [ ] Third\n - [ ] ", 53);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRemoveAutoContinuedListItemWhenPressingEnterMultipleTimes() {
|
||||
this.editText.setText("- Foo");
|
||||
pressEnter(5);
|
||||
assertText("- Foo\n- ", 8);
|
||||
pressEnter(8);
|
||||
assertText("- Foo\n\n", 7);
|
||||
pressEnter(7);
|
||||
assertText("- Foo\n\n\n", 8);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in a new issue