Skip to content

Commit

Permalink
Workaround for #477 and #604
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-niedermann committed Dec 16, 2019
1 parent 5d937ad commit 90b7cc0
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
break;
case R.id.link:
boolean textToFormatIsLink = TextUtils.indexOf(editText.getText().subSequence(start, end), "http") == 0;
if(textToFormatIsLink) {
if (textToFormatIsLink) {
ssb.insert(end, ")");
ssb.insert(start, "[](");
} else {
Expand All @@ -92,12 +92,25 @@ public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
end++;
ssb.setSpan(new StyleSpan(Typeface.NORMAL), start, end, 1);
editText.setText(ssb);
if(textToFormatIsLink) {
if (textToFormatIsLink) {
editText.setSelection(start + 1);
} else {
editText.setSelection(end + 2); // after <end>](
}
return true;
case android.R.id.cut: {
// https://github.com/stefan-niedermann/nextcloud-notes/issues/604
// https://github.com/stefan-niedermann/nextcloud-notes/issues/477
try {
editText.onTextContextMenuItem(item.getItemId());
return true;
} catch (Exception e) {
e.printStackTrace();
editText.setSelection(0, 0);
editText.clearFocus();
return true;
}
}
}
return false;
}
Expand Down

0 comments on commit 90b7cc0

Please sign in to comment.