From c082a258c78348a04682c59b6dc8c3be6a26f0be Mon Sep 17 00:00:00 2001 From: BrokenEagle Date: Sat, 1 Feb 2020 00:07:30 +0000 Subject: [PATCH] Add note key resize function - Same as using the key nudge, however it's used with the shift key --- app/javascript/src/javascripts/notes.js | 39 +++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/app/javascript/src/javascripts/notes.js b/app/javascript/src/javascripts/notes.js index f3c8f763a..1afc1a60c 100644 --- a/app/javascript/src/javascripts/notes.js +++ b/app/javascript/src/javascripts/notes.js @@ -168,6 +168,44 @@ let Note = { event.preventDefault(); }, + key_resize: function (event) { + if (!Note.move_id) { + return; + } + const $note_box = Note.Box.find(Note.move_id); + if ($note_box.length === 0) { + return; + } + let current_height = $note_box.height(); + let current_width = $note_box.width(); + switch (event.originalEvent.key) { + case "ArrowUp": + current_height--; + break; + case "ArrowDown": + current_height++; + break; + case "ArrowLeft": + current_width--; + break; + case "ArrowRight": + current_width++; + break; + default: + // do nothing + } + const position = Note.Box.get_min_max_position($note_box, null, null, current_height, current_width); + $note_box.css({ + top: position.top, + left: position.left, + height: current_height, + width: current_width, + }); + Note.Box.resize_inner_border($note_box); + $note_box.find(".note-box-inner-border").addClass("unsaved"); + event.preventDefault(); + }, + get_min_max_position: function($note_box, current_top = null, current_left = null, current_height = null, current_width = null) { const computed_style = window.getComputedStyle($note_box[0]); current_top = (current_top === null ? parseFloat(computed_style.top) : current_top); @@ -864,6 +902,7 @@ let Note = { this.initialize_highlight(); $(document).on("hashchange.danbooru.note", this.initialize_highlight); Utility.keydown("up down left right", "nudge_note", Note.Box.key_nudge); + Utility.keydown("shift+up shift+down shift+left shift+right", "resize_note", Note.Box.key_resize); }, initialize_shortcuts: function() {