Merge pull request 'Change note right click menu to link context menu' (#10186) from Freeplay/calckey:a into develop

Reviewed-on: https://codeberg.org/calckey/calckey/pulls/10186
This commit is contained in:
Kainoa Kanter 2023-05-24 06:29:06 +00:00
commit 4fae29e471
3 changed files with 101 additions and 11 deletions

View File

@ -239,6 +239,8 @@ import XStarButtonNoEmoji from "@/components/MkStarButtonNoEmoji.vue";
import XQuoteButton from "@/components/MkQuoteButton.vue";
import MkUrlPreview from "@/components/MkUrlPreview.vue";
import MkVisibility from "@/components/MkVisibility.vue";
import copyToClipboard from "@/scripts/copy-to-clipboard";
import { url } from "@/config";
import { pleaseLogin } from "@/scripts/please-login";
import { focusPrev, focusNext } from "@/scripts/focus";
import { getWordSoftMute } from "@/scripts/check-word-mute";
@ -254,6 +256,7 @@ import { useNoteCapture } from "@/scripts/use-note-capture";
import { notePage } from "@/filters/note";
import { deepClone } from "@/scripts/clone";
const router = useRouter();
const props = defineProps<{
@ -386,16 +389,43 @@ function onContextmenu(ev: MouseEvent): void {
react();
} else {
os.contextMenu(
getNoteMenu({
note: note,
translating,
translation,
menuButton,
isDeleted,
currentClipPage,
}),
[
{
type: "label",
text: notePage(appearNote),
},
{
icon: "ph-browser ph-bold ph-lg",
text: i18n.ts.openInWindow,
action: () => {
os.pageWindow(notePage(appearNote));
},
},
{
icon: "ph-arrows-out-simple ph-bold ph-lg",
text: i18n.ts.showInPage,
action: () => {
router.push(notePage(appearNote), "forcePage");
},
},
null,
{
icon: "ph-arrow-square-out ph-bold ph-lg",
text: i18n.ts.openInNewTab,
action: () => {
window.open(notePage(appearNote), "_blank");
},
},
{
icon: "ph-link-simple ph-bold ph-lg",
text: i18n.ts.copyLink,
action: () => {
copyToClipboard(`${url}${notePage(appearNote)}`);
},
},
],
ev
).then(focus);
);
}
}
@ -596,6 +626,7 @@ defineExpose({
margin-right: 14px;
margin-top: 0;
flex-grow: 0;
pointer-events: none;
}
> div > i {
@ -659,7 +690,7 @@ defineExpose({
}
> .article {
overflow: hidden;
overflow: clip;
padding: 4px 32px 10px;
cursor: pointer;

View File

@ -551,7 +551,7 @@ onUnmounted(() => {
}
// Hover
.reply :deep(.main),
:deep(.reply > .main),
.reply-to,
:deep(.more) {
position: relative;

View File

@ -11,6 +11,7 @@
singleStart: replies.length == 1,
firstColumn: depth == 1 && conversation,
}"
@contextmenu.stop="onContextmenu"
>
<div v-if="conversation && depth > 1" class="line"></div>
<div class="main" @click="noteClick">
@ -180,6 +181,8 @@ import XStarButton from "@/components/MkStarButton.vue";
import XStarButtonNoEmoji from "@/components/MkStarButtonNoEmoji.vue";
import XRenoteButton from "@/components/MkRenoteButton.vue";
import XQuoteButton from "@/components/MkQuoteButton.vue";
import copyToClipboard from "@/scripts/copy-to-clipboard";
import { url } from "@/config";
import { pleaseLogin } from "@/scripts/please-login";
import { getNoteMenu } from "@/scripts/get-note-menu";
import { getWordSoftMute } from "@/scripts/check-word-mute";
@ -318,6 +321,61 @@ function menu(viaKeyboard = false): void {
).then(focus);
}
function onContextmenu(ev: MouseEvent): void {
const isLink = (el: HTMLElement) => {
if (el.tagName === "A") return true;
if (el.parentElement) {
return isLink(el.parentElement);
}
};
if (isLink(ev.target)) return;
if (window.getSelection().toString() !== "") return;
if (defaultStore.state.useReactionPickerForContextMenu) {
ev.preventDefault();
react();
} else {
os.contextMenu(
[
{
type: "label",
text: notePage(appearNote),
},
{
icon: "ph-browser ph-bold ph-lg",
text: i18n.ts.openInWindow,
action: () => {
os.pageWindow(notePage(appearNote));
},
},
{
icon: "ph-arrows-out-simple ph-bold ph-lg",
text: i18n.ts.showInPage,
action: () => {
router.push(notePage(appearNote), "forcePage");
},
},
null,
{
icon: "ph-arrow-square-out ph-bold ph-lg",
text: i18n.ts.openInNewTab,
action: () => {
window.open(notePage(appearNote), "_blank");
},
},
{
icon: "ph-link-simple ph-bold ph-lg",
text: i18n.ts.copyLink,
action: () => {
copyToClipboard(`${url}${notePage(appearNote)}`);
},
},
],
ev
);
}
}
function focus() {
el.value.focus();
}
@ -562,6 +620,7 @@ function noteClick(e) {
display: flex;
flex-grow: 1;
margin-bottom: -10px;
pointer-events: none;
&::before {
content: "";
position: absolute;