enhance: allow longpress and contextmenu copy paste
This commit is contained in:
parent
518e05b842
commit
e755a4ec37
7 changed files with 144 additions and 18 deletions
|
@ -1,10 +1,9 @@
|
|||
<template>
|
||||
<div
|
||||
ref="contextMenu"
|
||||
class="absolute flex flex-col gap-1 border border-gray-400 bg-white rounded-md select-none text-left shadow-md z-50 p-1"
|
||||
class="absolute flex flex-col gap-1 border border-gray-400 bg-white rounded-md select-none text-left shadow-md z-[100] p-1"
|
||||
v-show="show"
|
||||
:style="contextMenuStyle"
|
||||
@contextmenu.prevent
|
||||
@click="closeContextMenu"
|
||||
>
|
||||
<component :is="component_ref" :data="data" />
|
||||
|
|
61
src/components/CopyPasteContextMenu.vue
Normal file
61
src/components/CopyPasteContextMenu.vue
Normal file
|
@ -0,0 +1,61 @@
|
|||
<template>
|
||||
<div class="flex flex-row gap-2 cursor-pointer hover:bg-gray-300 p-1 rounded-md" @click="copy">
|
||||
<DocumentDuplicateIcon class="w-5 h-5" />
|
||||
<p>kopieren</p>
|
||||
</div>
|
||||
<div
|
||||
v-if="data != 'nopaste'"
|
||||
class="flex flex-row gap-2 cursor-pointer hover:bg-gray-300 p-1 rounded-md"
|
||||
@click="paste"
|
||||
>
|
||||
<ClipboardDocumentIcon class="w-5 h-5" />
|
||||
<p>einfügen</p>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { defineComponent } from "vue";
|
||||
import { ClipboardDocumentIcon, DocumentDuplicateIcon } from "@heroicons/vue/24/outline";
|
||||
import { mapState } from "pinia";
|
||||
import { useContextMenuStore } from "@/stores/context-menu";
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export default defineComponent({
|
||||
props: ["data"],
|
||||
data() {
|
||||
return {
|
||||
selectedText: "",
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
...mapState(useContextMenuStore, ["clickedOnEl"]),
|
||||
},
|
||||
mounted() {
|
||||
this.selectedText =
|
||||
document.getSelection()?.toString() || this.clickedOnEl.value || this.clickedOnEl.innerText || "";
|
||||
|
||||
let selection = document.getSelection()?.toString();
|
||||
console.log(selection);
|
||||
if (selection == "") {
|
||||
console.log("jo");
|
||||
const range = document.createRange();
|
||||
range.selectNode(this.clickedOnEl);
|
||||
console.log(range);
|
||||
window.getSelection()?.removeAllRanges();
|
||||
window.getSelection()?.addRange(range);
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
copy() {
|
||||
navigator.clipboard.writeText(this.selectedText);
|
||||
},
|
||||
paste() {
|
||||
const el = this.clickedOnEl;
|
||||
navigator.clipboard.readText().then((e) => {
|
||||
el.value = e;
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
||||
</script>
|
|
@ -3,21 +3,15 @@
|
|||
ref="contextMenu"
|
||||
class="absolute inset-0 w-full h-full flex justify-center items-center bg-black/50 select-none z-50 p-2"
|
||||
v-show="show"
|
||||
@contextmenu.prevent
|
||||
>
|
||||
<!-- @click="closeModal" -->
|
||||
<component
|
||||
:is="component_ref"
|
||||
:data="data"
|
||||
@click.stop
|
||||
class="p-4 bg-white rounded-lg max-h-[95%] overflow-y-auto"
|
||||
/>
|
||||
<component :is="component_ref" :data="data" class="p-4 bg-white rounded-lg max-h-[95%] overflow-y-auto" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { mapState, mapActions } from "pinia";
|
||||
import { useModalStore } from "@/stores/modal";
|
||||
import { useContextMenuStore } from "@/stores/context-menu";
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
|
@ -27,6 +21,7 @@ export default {
|
|||
},
|
||||
methods: {
|
||||
...mapActions(useModalStore, ["closeModal"]),
|
||||
...mapActions(useContextMenuStore, ["closeContextMenu"]),
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue