Skip to content

Commit a0f763f

Browse files
committed
Add bookmark hotkey.
1 parent 995ba6d commit a0f763f

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

lute/static/js/lute.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,12 @@ let get_textitems_spans = function(e) {
539539
return $(`span.textitem[data-${attr_name}="${attr_value}"]`).toArray();
540540
};
541541

542+
let handle_bookmark = function() {
543+
// Function defined in read/index.html ... yuck, need to reorganize this js code.
544+
// TODO javascript: reorganize, or make modules.
545+
add_bookmark();
546+
}
547+
542548
/** Copy the text of the textitemspans to the clipboard, and add a
543549
* color flash. */
544550
let handle_copy = function(e) {
@@ -787,6 +793,7 @@ function handle_keydown (e) {
787793
const kRIGHT = 39;
788794
const kUP = 38;
789795
const kDOWN = 40;
796+
const kB = 66; // B)ookmark
790797
const kC = 67; // C)opy
791798
const kT = 84; // T)ranslate
792799
const kM = 77; // The(M)e
@@ -821,6 +828,7 @@ function handle_keydown (e) {
821828
map[kRIGHT] = () => move_cursor(right_increment);
822829
map[kUP] = () => increment_status_for_selected_elements(e, +1);
823830
map[kDOWN] = () => increment_status_for_selected_elements(e, -1);
831+
map[kB] = () => handle_bookmark();
824832
map[kC] = () => handle_copy(e);
825833
map[kT] = () => show_sentence_translation(e);
826834
map[kM] = () => next_theme();

lute/templates/read/index.html

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -530,15 +530,12 @@ <h2>&#127881;</h2>
530530
}
531531

532532
function add_bookmark() {
533-
const text_id = document.querySelector('#text_id')?.value;
534533
const book_id = document.querySelector('#book_id')?.value;
535534
const page_num = document.querySelector('#page_num')?.value;
536-
let title = prompt(`Enter a bookmark title for page ${page_num}`);
535+
let title = prompt(`Enter bookmark title, or Cancel to quit`);
537536

538-
if (!book_id || !page_num || !title) {
539-
alert(`Missing bookmark data. No bookmark added.`);
540-
return
541-
}
537+
if (!title)
538+
return;
542539

543540
fetch(`/bookmarks/add`, {
544541
method: "POST",

0 commit comments

Comments
 (0)