Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Commit

Permalink
Fix: Copy slection fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
CaptainDredge committed Aug 25, 2020
1 parent b7281e8 commit 9ce4928
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
16 changes: 4 additions & 12 deletions js/app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {
formatText,
preventNewDiv,
trimContent,
setFalse,
setTrue,
addPage,
removePage
} from './utils/helpers.mjs';
Expand All @@ -28,11 +30,6 @@ const pageEl = document.querySelector('.page-a');

const setTextareaStyle = (attrib, v) => (pageEl.style[attrib] = v);

// eslint-disable-next-line no-var
var ctrlDown = false;
const ctrlKey = 17;
const cmdKey = 91;

/**
* Add event listeners here, they will be automatically mapped with addEventListener later
*/
Expand Down Expand Up @@ -134,16 +131,11 @@ const EVENT_MAP = {
const DELEGATED_EVENT_MAP = [
{
on: 'keydown',
action: (e) => {
if (e.keyCode == ctrlKey || e.keyCode == cmdKey) ctrlDown = true;
}
action: setTrue
},
{
on: 'keyup',
action: (e) => {
// eslint-disable-next-line no-unused-vars
if (e.keyCode == ctrlKey || e.keyCode == cmdKey) ctrlDown = false;
}
action: setFalse
},
{
on: 'paste',
Expand Down
20 changes: 18 additions & 2 deletions js/utils/helpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ const fixedPage = document.querySelector(
'.display-flex.left-margin-and-content'
);
const fixedHeight = fixedPage.clientHeight;

const vKey = 86;
const cKey = 67;
const ctrlKey = 17;
const cmdKey = 91;
let ctrlDown = false;

const isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);

function addFontFromFile(fileObj) {
Expand Down Expand Up @@ -126,9 +131,18 @@ function adjustContent(remainingContent = '') {
}
}

function setFalse(event) {
if (event.keyCode == ctrlKey || event.keyCode == cmdKey) ctrlDown = false;
}

function setTrue(event) {
if (event.keyCode == ctrlKey || event.keyCode == cmdKey) ctrlDown = true;
}

function trimContent(event) {
if (ctrlDown && (event.keyCode == vKey || event.keyCode == cKey)) return;
if (String.fromCharCode(event.keyCode).match(/(\w|\s|\n|\r|\t)/g))
if (ctrlDown && (event.keyCode == vKey || event.keyCode == cKey)) {
console.log("I'm here");
} else if (String.fromCharCode(event.keyCode).match(/(\w|\s|\n|\r|\t)/g))
adjustContent.call(this);
}

Expand Down Expand Up @@ -158,6 +172,8 @@ export {
formatText,
preventNewDiv,
trimContent,
setFalse,
setTrue,
addPage,
removePage
};

0 comments on commit 9ce4928

Please sign in to comment.