Skip to content

Commit

Permalink
Set focus after returning to item form
Browse files Browse the repository at this point in the history
  • Loading branch information
isteinbrecher committed Feb 23, 2025
1 parent 7a9319f commit 80aa592
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion ui/js/main_item.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ $(function () {
window.addEventListener("focus", function () {
if (close_on_focus) {
csInterface.closeExtension()
} else {
set_form_focus(null)
}
})

Expand Down Expand Up @@ -258,10 +260,17 @@ function update_create_item(event) {
// Set the item text
$("#latex_text").val(latex_text_input)

// Set the text window as the active element of the form
set_form_focus(cursor_position_input)
}

function set_form_focus(cursor_position_input) {
// We have to show the form before we can set the focus
$("#dashForm").show()
$("#latex_text").focus()
$("#latex_text").prop("selectionEnd", cursor_position_input)
if (cursor_position_input != null) {
$("#latex_text").prop("selectionEnd", cursor_position_input)
}
}

function set_close_on_focus(event) {
Expand Down

0 comments on commit 80aa592

Please sign in to comment.