Skip to content

Commit

Permalink
bugfix and enable alt+hotkey also in text area
Browse files Browse the repository at this point in the history
  • Loading branch information
Echsecutor committed Nov 2, 2024
1 parent 53baf87 commit 2a12dca
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions editor/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ const hot_keys = {
description: "Add new Section",
action: handle_add_node,
},
m: {
description: "Add Media",
action: add_or_remove_media,
},
};

var active_element = null;
Expand Down Expand Up @@ -368,7 +372,7 @@ function load_graph() {
});
}

function add__or_remove_media() {
function add_or_remove_media() {
if (active_element?.media?.type) {
active_element.media = {};
text_editor_load(active_element);
Expand Down Expand Up @@ -431,6 +435,7 @@ function get_parent_section_of_active_element() {
var sibbling_index = null;

for (const section_id of Object.keys(story.sections)) {
const section = story.sections[section_id];
if (!section?.next) {
continue;
}
Expand All @@ -456,6 +461,7 @@ function handle_global_key_down(event) {
for (const key of Object.keys(hot_keys)) {
if (event.key === key) {
hot_keys[key].action();
event.stopPropagation();
}
}

Expand All @@ -469,6 +475,7 @@ function handle_global_key_down(event) {
}

if (event.key === "ArrowDown") {
event.stopPropagation();
if (!active_section?.next || active_section.next.length < 1) {
return;
}
Expand All @@ -488,11 +495,13 @@ function handle_global_key_down(event) {
}

if (event.key === "ArrowUp") {
event.stopPropagation();
text_editor_load(parent_section);
return;
}

if (event.key === "ArrowLeft") {
event.stopPropagation();
if (sibbling_index > 0) {
text_editor_load(
story.sections[parent_section.next[sibbling_index - 1].next]
Expand All @@ -501,6 +510,7 @@ function handle_global_key_down(event) {
}
}
if (event.key === "ArrowRight") {
event.stopPropagation();
if (sibbling_index < parent_section.next.length - 1) {
text_editor_load(
story.sections[parent_section.next[sibbling_index + 1].next]
Expand All @@ -520,10 +530,12 @@ add_edge_button.addEventListener("click", handle_add_edge);
download_button.addEventListener("click", download_graph);
load_button.addEventListener("click", load_graph);
clear_all_button.addEventListener("click", clear_all);
add_media_button.addEventListener("click", add__or_remove_media);
add_media_button.addEventListener("click", add_or_remove_media);

text_area.addEventListener("keydown", (event) => {
event.stopPropagation();
if (!event.ctrlKey && !event.altKey) {
event.stopPropagation();
}
});

document.addEventListener("keydown", handle_global_key_down);
Expand Down

0 comments on commit 2a12dca

Please sign in to comment.