mirror of
https://github.com/ankidroid/Anki-Android.git
synced 2024-09-20 03:52:15 +02:00
Add insert cloze option to the paperclip menu (#4606)
Add cloze deletion option to the paperclip menu
This commit is contained in:
parent
fd59757caa
commit
86c60faf7c
@ -1177,6 +1177,13 @@ public class NoteEditor extends AnkiActivity {
|
||||
mNote.setField(index, field);
|
||||
startMultimediaFieldEditor(index, mNote, field);
|
||||
return true;
|
||||
case R.id.menu_multimedia_cloze:
|
||||
FieldEditText fieldEditText = mEditFields.get(index);
|
||||
String text = fieldEditText.getText().toString();
|
||||
int selectionStart = fieldEditText.getSelectionStart();
|
||||
int selectionEnd = fieldEditText.getSelectionEnd();
|
||||
fieldEditText.setText(insertClozeAround(text, selectionStart, selectionEnd));
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@ -1188,6 +1195,12 @@ public class NoteEditor extends AnkiActivity {
|
||||
});
|
||||
}
|
||||
|
||||
private String insertClozeAround(String text, int selectionStart, int selectionEnd) {
|
||||
int selectionMin = Math.min(selectionStart, selectionEnd);
|
||||
int selectionMax = Math.max(selectionStart, selectionEnd);
|
||||
return text.substring(0, selectionMin) + "{{c1::" + text.substring(selectionMin, selectionMax) + "}}" + text.substring(selectionMax);
|
||||
}
|
||||
|
||||
|
||||
private void setRemapButtonListener(ImageButton remapButton, final int newFieldIndex) {
|
||||
remapButton.setOnClickListener(new View.OnClickListener() {
|
||||
|
@ -12,6 +12,9 @@
|
||||
<item
|
||||
android:id="@+id/menu_multimedia_text"
|
||||
android:title="@string/multimedia_editor_popup_text"/>
|
||||
<item
|
||||
android:id="@+id/menu_multimedia_cloze"
|
||||
android:title="@string/multimedia_editor_popup_cloze"/>
|
||||
</group>
|
||||
|
||||
</menu>
|
||||
|
@ -17,6 +17,7 @@
|
||||
<string name="multimedia_editor_popup_image">Add image</string>
|
||||
<string name="multimedia_editor_popup_audio">Record audio</string>
|
||||
<string name="multimedia_editor_popup_text">Advanced editor</string>
|
||||
<string name="multimedia_editor_popup_cloze">Cloze deletion</string>
|
||||
|
||||
<!-- Translation activity (Glosbe) -->
|
||||
<string name="multimedia_editor_trans_poweredglosbe">Powered by glosbe.com</string>
|
||||
|
Loading…
Reference in New Issue
Block a user