1
0
Fork 0
mirror of https://github.com/codex-team/codex.docs.git synced 2025-08-08 06:55:26 +02:00

fix: fix shortcuts to support Mac

* fix shortcuts to support Mac
* add comment to explain properties
This commit is contained in:
Yeokyung Yoon 2022-08-05 00:45:51 +09:00
parent b0b42d958c
commit ca04604b42

View file

@ -6,7 +6,6 @@ import { Storage } from '../utils/storage';
const LOCAL_STORAGE_KEY = 'docs_sidebar_state'; const LOCAL_STORAGE_KEY = 'docs_sidebar_state';
const SIDEBAR_VISIBILITY_KEY = 'docs_sidebar_visibility'; const SIDEBAR_VISIBILITY_KEY = 'docs_sidebar_visibility';
/** /**
* Section list item height in px * Section list item height in px
*/ */
@ -60,10 +59,14 @@ export default class Sidebar {
this.sectionsState = storedState ? JSON.parse(storedState) : {}; this.sectionsState = storedState ? JSON.parse(storedState) : {};
// Initialize localStorage that contains sidebar visibility
this.sidebarVisibilityStorage = new Storage(SIDEBAR_VISIBILITY_KEY); this.sidebarVisibilityStorage = new Storage(SIDEBAR_VISIBILITY_KEY);
// Get current sidebar visibility from storage
const storedVisibility = this.sidebarVisibilityStorage.get(); const storedVisibility = this.sidebarVisibilityStorage.get();
// Sidebar visibility
this.isVisible = storedVisibility !== 'false'; this.isVisible = storedVisibility !== 'false';
// Keys to store currently pressed keys
this.keys = {}; this.keys = {};
} }
@ -204,7 +207,6 @@ export default class Sidebar {
// add event listener to execute keyboard shortcut // add event listener to execute keyboard shortcut
document.body.addEventListener('keydown', (e) => this.executeSlide(e), false); document.body.addEventListener('keydown', (e) => this.executeSlide(e), false);
document.body.addEventListener('keyup', (e) => this.executeSlide(e), false);
} }
/** /**
@ -212,12 +214,10 @@ export default class Sidebar {
* @returns {void} * @returns {void}
*/ */
executeSlide(event) { executeSlide(event) {
this.keys[event.key.toLowerCase()] = event.type === 'keydown';
/** /**
* Execute slide when ctrl + . is pressed * Execute slide when ctrl + . is pressed
*/ */
if (this.keys['control'] && this.keys['.']) { if ((event.ctrlKey || event.metaKey) && event.code === 'Period') {
this.handleSliderClick(); this.handleSliderClick();
} }
} }