Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fba2260a authored by desperateCoder's avatar desperateCoder Committed by Niedermann IT-Dienstleistungen
Browse files

#1040 fixed auto continuation (i guess)

parent 3cc45830
Loading
Loading
Loading
Loading
+19 −4
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ import androidx.annotation.NonNull;
import it.niedermann.android.markdown.markwon.MarkwonMarkdownEditor;
import it.niedermann.android.markdown.model.EListType;

import static it.niedermann.android.markdown.MarkdownUtil.getEndOfLine;
import static it.niedermann.android.markdown.MarkdownUtil.getListItemIfIsEmpty;
import static it.niedermann.android.markdown.MarkdownUtil.getOrderedListNumber;
import static it.niedermann.android.markdown.MarkdownUtil.getStartOfLine;
@@ -22,6 +23,7 @@ public class AutoContinuationTextWatcher extends InterceptorTextWatcher {
    private final MarkwonMarkdownEditor editText;

    private CharSequence customText = null;
    private CharSequence oldText = null;
    private boolean isInsert = true;
    private int sequenceStart = 0;

@@ -34,10 +36,14 @@ public class AutoContinuationTextWatcher extends InterceptorTextWatcher {
    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        MarkwonMarkdownEditor.log(AutoContinuationTextWatcher.class.getSimpleName() + " [onTextChanged] with " + s + "|" + start + "|" + before + "|" + count);
        if (count == 1 && s.charAt(start) == '\n') {
        if (count > 0) {
            CharSequence inserted = getInsertedString(s, start, before, count);
            if (inserted.length() == 1 && inserted.charAt(0)=='\n'){
                MarkwonMarkdownEditor.log(AutoContinuationTextWatcher.class.getSimpleName() + " [onTextChanged] count == 1 && s.charAt(start == \\n");
                handleNewlineInserted(s, start, count);
            }
        }
        oldText = s.toString();
        MarkwonMarkdownEditor.log(AutoContinuationTextWatcher.class.getSimpleName() + " [onTextChanged] passing to originalWatcher");
        originalWatcher.onTextChanged(s, start, before, count);
    }
@@ -61,6 +67,15 @@ public class AutoContinuationTextWatcher extends InterceptorTextWatcher {
        editText.setMarkdownStringModel(s);
    }

    private CharSequence getInsertedString(CharSequence newText, int start, int before, int count){
        if(newText != null && newText.length() > (oldText == null ? 0 : oldText.length())){
            // character added
            int position = start + before ;
            return newText.subSequence(position, position+count-before);
        }
        return "";
    }

    private void deleteCustomText(Editable s, CharSequence customText) {
        MarkwonMarkdownEditor.log(AutoContinuationTextWatcher.class.getSimpleName() + " [deleteCustomText] with customText = " + customText);
        s.replace(sequenceStart, sequenceStart + customText.length() + 1, "\n");
@@ -76,7 +91,7 @@ public class AutoContinuationTextWatcher extends InterceptorTextWatcher {
        MarkwonMarkdownEditor.log(AutoContinuationTextWatcher.class.getSimpleName() + " [handleNewlineInserted] with " + start + "|" + count);
        final CharSequence s = originalSequence.subSequence(0, originalSequence.length());
        final int startOfLine = getStartOfLine(s, start);
        final String line = s.subSequence(startOfLine, start).toString();
        final String line = s.subSequence(startOfLine, getEndOfLine(s, start)).toString();

        final String emptyListString = getListItemIfIsEmpty(line);
        MarkwonMarkdownEditor.log(AutoContinuationTextWatcher.class.getSimpleName() + " [handleNewlineInserted] emptyListString = " + emptyListString);