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 incorrectLanguageWarning: "It looks like your post is in {detected}, but you selected
{current}.\nWould you like to set the language to {detected} instead?" {current}.\nWould you like to set the language to {detected} instead?"
noteEditHistory: "Post edit history" noteEditHistory: "Post edit history"
slashQuote: "Slash quote"

View file

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

View file

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

View file

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

View file

@ -1,5 +1,6 @@
<template> <template>
<button <button
ref="el"
v-if="canRenote && defaultStore.state.seperateRenoteQuote" v-if="canRenote && defaultStore.state.seperateRenoteQuote"
v-tooltip.noDelay.bottom="i18n.ts.quote" v-tooltip.noDelay.bottom="i18n.ts.quote"
class="eddddedb _button" class="eddddedb _button"
@ -10,8 +11,8 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { computed } from "vue"; import { computed, ref } from "vue";
import type { entities } from "firefish-js"; import { acct, type entities } from "firefish-js";
import { pleaseLogin } from "@/scripts/please-login"; import { pleaseLogin } from "@/scripts/please-login";
import * as os from "@/os"; import * as os from "@/os";
import { me } from "@/me"; import { me } from "@/me";
@ -23,6 +24,8 @@ const props = defineProps<{
note: entities.Note; note: entities.Note;
}>(); }>();
const el = ref<HTMLButtonElement>();
const canRenote = computed( const canRenote = computed(
() => () =>
["public", "home"].includes(props.note.visibility) || ["public", "home"].includes(props.note.visibility) ||
@ -31,10 +34,57 @@ const canRenote = computed(
function quote(): void { function quote(): void {
pleaseLogin(); 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({ os.post({
renote: props.note, 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> </script>
<style lang="scss" scoped> <style lang="scss" scoped>