Skip to content

Commit

Permalink
replace xor
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Wilke committed Nov 16, 2023
1 parent cfd409a commit 31820ef
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion frontend/src/components/CreatePaste/CreatePaste.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const CreatePaste: Component<CreatePasteProps> = ({onCreatePaste, initialPaste})
return;
}

if ((e.ctrlKey && e.code === 'Enter') ^ (e.metaKey && e.code === 'Enter')) {
if (e.code === 'Enter' && ((e.ctrlKey || e.metaKey) && e.ctrlKey !== e.metaKey)) { // XOR
creationForm.requestSubmit();
}
}
Expand Down
19 changes: 12 additions & 7 deletions frontend/src/components/ReadPaste/ReadPaste.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,26 @@ const ReadPaste: Component<ReadPasteProps> = ({paste, onClonePaste, onDeletePast
return;
}

if ((e.ctrlKey && e.code === 'KeyA') ^ (e.metaKey && e.code === 'KeyA')) {
if (e.code === 'KeyA' && ((e.ctrlKey || e.metaKey) && e.ctrlKey !== e.metaKey)) { // XOR
selectContent();
e.preventDefault();
}
}

function selectContent() {
if (window.getSelection && document.createRange) {
let range = document.createRange();
range.selectNodeContents(contentElement);
let range = document.createRange();
range.selectNodeContents(contentElement);

let selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
} else if (document.body.createTextRange) {
let selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
return;
}

// @ts-ignore
if (document.body.createTextRange) {
// @ts-ignore
let range = document.body.createTextRange();
range.moveToElementText(contentElement);
range.select();
Expand Down

0 comments on commit 31820ef

Please sign in to comment.