|
|
|
@ -30,6 +30,7 @@ import android.os.Build;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.os.Parcel;
|
|
|
|
|
import android.os.Parcelable;
|
|
|
|
|
import android.text.Editable;
|
|
|
|
|
import android.text.Html;
|
|
|
|
|
import android.text.SpannableStringBuilder;
|
|
|
|
|
import android.text.Spanned;
|
|
|
|
@ -43,6 +44,7 @@ import android.view.MenuItem;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.view.inputmethod.EditorInfo;
|
|
|
|
|
import android.view.inputmethod.InputConnection;
|
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
|
|
import androidx.core.view.inputmethod.EditorInfoCompat;
|
|
|
|
|
import androidx.core.view.inputmethod.InputConnectionCompat;
|
|
|
|
@ -95,6 +97,7 @@ public class EditTextCompose extends FixedEditText {
|
|
|
|
|
menu.add(Menu.CATEGORY_ALTERNATIVE, R.string.title_undo, 1, getTitle(R.string.title_undo));
|
|
|
|
|
if (can(android.R.id.redo))
|
|
|
|
|
menu.add(Menu.CATEGORY_ALTERNATIVE, R.string.title_redo, 2, getTitle(R.string.title_redo));
|
|
|
|
|
menu.add(Menu.CATEGORY_ALTERNATIVE, R.string.title_insert_line, 3, R.string.title_insert_line);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -117,6 +120,8 @@ public class EditTextCompose extends FixedEditText {
|
|
|
|
|
return EditTextCompose.super.onTextContextMenuItem(android.R.id.undo);
|
|
|
|
|
else if (id == R.string.title_redo)
|
|
|
|
|
return EditTextCompose.super.onTextContextMenuItem(android.R.id.redo);
|
|
|
|
|
else if (id == R.string.title_insert_line)
|
|
|
|
|
return insertLine();
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
@ -125,6 +130,40 @@ public class EditTextCompose extends FixedEditText {
|
|
|
|
|
public void onDestroyActionMode(ActionMode mode) {
|
|
|
|
|
// Do nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean insertLine() {
|
|
|
|
|
try {
|
|
|
|
|
int start = getSelectionStart();
|
|
|
|
|
if (start < 0)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
Editable edit = getText();
|
|
|
|
|
if (edit == null)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (start == 0 || edit.charAt(start - 1) != '\n')
|
|
|
|
|
edit.insert(start++, "\n");
|
|
|
|
|
if (start == edit.length() || edit.charAt(start) != '\n')
|
|
|
|
|
edit.insert(start, "\n");
|
|
|
|
|
|
|
|
|
|
edit.insert(start, "\uFFFC"); // Object replacement character
|
|
|
|
|
|
|
|
|
|
int colorSeparator = Helper.resolveColor(getContext(), R.attr.colorSeparator);
|
|
|
|
|
float stroke = context.getResources().getDisplayMetrics().density;
|
|
|
|
|
edit.setSpan(
|
|
|
|
|
new LineSpan(colorSeparator, stroke, 0f),
|
|
|
|
|
start, start + 1,
|
|
|
|
|
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
|
|
|
|
|
|
setSelection(start + 2);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
|
Log.e(ex);
|
|
|
|
|
ToastEx.makeText(context, Log.formatThrowable(ex), Toast.LENGTH_LONG).show();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|