Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GSoC'24] CardBrowser: Shortcut E #16814

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 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,10 +721,31 @@ 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 {
david-allison marked this conversation as resolved.
Show resolved Hide resolved
// 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 {
// Check whether the deck is empty
if (viewModel.rowCount == 0) {
showSnackbar(
R.string.no_note_to_edit,
Snackbar.LENGTH_LONG
)
return@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(
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