Skip to content

Commit

Permalink
shortcut E: edit note
Browse files Browse the repository at this point in the history
  • Loading branch information
SanjaySargam committed Aug 4, 2024
1 parent ce1b778 commit c8d6434
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
21 changes: 18 additions & 3 deletions AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,9 @@ open class CardBrowser :
Timber.i("Ctrl+E: Add Note")
launchCatchingTask { addNoteFromCardBrowser() }
return true
} else {
Timber.i("E: Edit note")
openNoteEditorForCurrentlySelectedNote()
}
}
KeyEvent.KEYCODE_D -> {
Expand Down Expand Up @@ -718,14 +721,26 @@ open class CardBrowser :
viewModel.endMultiSelectMode()
}

/**
* In case of selection, the first card that was selected, otherwise the first card of the list.
*/
private suspend fun getCardIdForNoteEditor(): CardId {
// Just select the first one if there's a multiselect occurring.
return if (viewModel.isInMultiSelectMode) {
viewModel.querySelectedCardIdAtPosition(0)
} else {
viewModel.getRowAtPosition(0).id
}
}

private fun openNoteEditorForCurrentlySelectedNote() = launchCatchingTask {
try {
// Just select the first one. It doesn't particularly matter if there's a multiselect occurring.
openNoteEditorForCard(viewModel.querySelectedCardIdAtPosition(0))
val cardId = getCardIdForNoteEditor()
openNoteEditorForCard(cardId)
} catch (e: Exception) {
Timber.w(e, "Error Opening Note Editor")
showSnackbar(
R.string.multimedia_editor_something_wrong,
R.string.no_note_to_edit,
Snackbar.LENGTH_LONG
)
}
Expand Down
1 change: 1 addition & 0 deletions AnkiDroid/src/main/res/values/07-cardbrowser.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<string name="card_browser_list_my_searches_new_name">Name for the current search</string>
<string name="card_browser_list_my_searches_new_search_error_empty_name">You can’t save a search without a name</string>
<string name="card_browser_list_my_searches_new_search_error_dup">Name exists</string>
<string name="no_note_to_edit">No note to edit</string>
<string name="card_browser_list_my_searches_remove_content">Delete “%1$s”?</string>
<string name="card_browser_change_display_order">Change display order</string>
<string name="card_browser_change_display_order_title">Choose display order</string>
Expand Down

0 comments on commit c8d6434

Please sign in to comment.