feat: add slash quote

This commit is contained in:
Lhcfl 2024-04-15 15:12:51 +08:00
parent 0f3126196f
commit a07483996e
5 changed files with 72 additions and 6 deletions

View file

@ -2229,3 +2229,4 @@ autocorrectNoteLanguage: "Show a warning if the post language does not match the
incorrectLanguageWarning: "It looks like your post is in {detected}, but you selected
{current}.\nWould you like to set the language to {detected} instead?"
noteEditHistory: "Post edit history"
slashQuote: "Slash quote"

View file

@ -2057,3 +2057,4 @@ autocorrectNoteLanguage: 当帖子语言不符合自动检测的结果的时候
incorrectLanguageWarning: "看上去您帖子使用的语言是{detected},但您选择的语言是{current}。\n要改为以{detected}发帖吗?"
noteEditHistory: "帖子编辑历史"
media: 媒体
slashQuote: "斜杠引用"

View file

@ -363,6 +363,11 @@ const props = withDefaults(
autofocus?: boolean;
showMfmCheatSheet?: boolean;
editId?: entities.Note["id"];
selectRange?: [
start: number,
end: number,
direction?: "forward" | "backward" | "none",
];
}>(),
{
initialVisibleUsers: () => [],
@ -683,10 +688,14 @@ function togglePoll() {
function focus() {
if (textareaEl.value) {
textareaEl.value.focus();
textareaEl.value.setSelectionRange(
textareaEl.value.value.length,
textareaEl.value.value.length,
);
if (props.selectRange) {
textareaEl.value.setSelectionRange(...props.selectRange);
} else {
textareaEl.value.setSelectionRange(
textareaEl.value.value.length,
textareaEl.value.value.length,
);
}
}
}

View file

@ -43,6 +43,11 @@ const props = defineProps<{
fixed?: boolean;
autofocus?: boolean;
editId?: entities.Note["id"];
selectRange?: [
start: number,
end: number,
direction?: "forward" | "backward" | "none",
];
}>();
const emit = defineEmits<{

View file

@ -1,5 +1,6 @@
<template>
<button
ref="el"
v-if="canRenote && defaultStore.state.seperateRenoteQuote"
v-tooltip.noDelay.bottom="i18n.ts.quote"
class="eddddedb _button"
@ -10,8 +11,8 @@
</template>
<script lang="ts" setup>
import { computed } from "vue";
import type { entities } from "firefish-js";
import { computed, ref } from "vue";
import { acct, type entities } from "firefish-js";
import { pleaseLogin } from "@/scripts/please-login";
import * as os from "@/os";
import { me } from "@/me";
@ -23,6 +24,8 @@ const props = defineProps<{
note: entities.Note;
}>();
const el = ref<HTMLButtonElement>();
const canRenote = computed(
() =>
["public", "home"].includes(props.note.visibility) ||
@ -31,10 +34,57 @@ const canRenote = computed(
function quote(): void {
pleaseLogin();
if (
props.note.renote != null &&
(props.note.text != null ||
props.note.fileIds.length === 0 ||
props.note.poll != null)
) {
menu();
} else {
normalQuote();
}
}
function normalQuote(): void {
os.post({
renote: props.note,
});
}
function slashQuote(): void {
os.post({
initialText: ` // @${acct.toString(props.note.user)}: ${props.note.text}`,
selectRange: [0, 0],
renote: props.note.renote,
channel: props.note.channel,
});
}
function menu(viaKeyboard = false): void {
os.popupMenu(
[
{
text: i18n.ts.quote,
icon: `${icon("ph-quotes")}`,
action: normalQuote,
},
{
text: i18n.ts.slashQuote,
icon: `${icon("ph-notches")}`,
action: slashQuote,
},
],
el.value,
{
viaKeyboard,
},
).then(focus);
}
function focus(): void {
el.value!.focus();
}
</script>
<style lang="scss" scoped>