Skip to content

Commit

Permalink
fix(cutLine): check navigator api
Browse files Browse the repository at this point in the history
  • Loading branch information
petersolopov committed Jun 13, 2020
1 parent a1a4d00 commit ccb4b2a
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/plugins/cutLine.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ const cutLine = (predicate) => (acc, event) => {
const newValue =
value.substring(0, selectionStart) + value.substring(selectionEnd);

navigator.clipboard
.writeText(value.substring(selectionStart, selectionEnd))
.catch(() => {}); // prevent any clipboard error. useful for iframe
if (navigator && navigator.clipboard) {
navigator.clipboard
.writeText(value.substring(selectionStart, selectionEnd))
.catch(() => {}); // prevent any clipboard error. useful for iframe
}

return {
value: newValue,
Expand Down Expand Up @@ -41,9 +43,12 @@ const cutLine = (predicate) => (acc, event) => {
.filter((line) => line != null)
.join("\n");

navigator.clipboard
.writeText(value.split("\n")[currentLineNumber])
.catch(() => {}); // prevent any clipboard error. useful for iframe
if (navigator && navigator.clipboard) {
navigator.clipboard
.writeText(value.split("\n")[currentLineNumber])
.catch(() => {
}); // prevent any clipboard error. useful for iframe
}

return {
value: newValue,
Expand Down

0 comments on commit ccb4b2a

Please sign in to comment.