feat: 格式刷支持双击连续使用

This commit is contained in:
pipipi-pikachu 2023-10-15 16:38:06 +08:00
parent 4030bd4fe1
commit d901fffd87
7 changed files with 19 additions and 8 deletions

View File

@ -6,12 +6,13 @@ export default () => {
const mainStore = useMainStore() const mainStore = useMainStore()
const { shapeFormatPainter, handleElement } = storeToRefs(mainStore) const { shapeFormatPainter, handleElement } = storeToRefs(mainStore)
const toggleShapeFormatPainter = () => { const toggleShapeFormatPainter = (keep = false) => {
const _handleElement = handleElement.value as PPTShapeElement const _handleElement = handleElement.value as PPTShapeElement
if (shapeFormatPainter.value) mainStore.setShapeFormatPainter(null) if (shapeFormatPainter.value) mainStore.setShapeFormatPainter(null)
else { else {
mainStore.setShapeFormatPainter({ mainStore.setShapeFormatPainter({
keep,
fill: _handleElement.fill, fill: _handleElement.fill,
gradient: _handleElement.gradient, gradient: _handleElement.gradient,
outline: _handleElement.outline, outline: _handleElement.outline,

View File

@ -5,10 +5,11 @@ export default () => {
const mainStore = useMainStore() const mainStore = useMainStore()
const { richTextAttrs, textFormatPainter } = storeToRefs(mainStore) const { richTextAttrs, textFormatPainter } = storeToRefs(mainStore)
const toggleTextFormatPainter = () => { const toggleTextFormatPainter = (keep = false) => {
if (textFormatPainter.value) mainStore.setTextFormatPainter(null) if (textFormatPainter.value) mainStore.setTextFormatPainter(null)
else { else {
mainStore.setTextFormatPainter({ mainStore.setTextFormatPainter({
keep,
bold: richTextAttrs.value.bold, bold: richTextAttrs.value.bold,
em: richTextAttrs.value.em, em: richTextAttrs.value.em,
underline: richTextAttrs.value.underline, underline: richTextAttrs.value.underline,

View File

@ -102,6 +102,7 @@ export type CreatingElement = CreatingTextElement | CreatingShapeElement | Creat
export type TextFormatPainterKeys = 'bold' | 'em' | 'underline' | 'strikethrough' | 'color' | 'backcolor' | 'fontsize' | 'fontname' | 'align' export type TextFormatPainterKeys = 'bold' | 'em' | 'underline' | 'strikethrough' | 'color' | 'backcolor' | 'fontsize' | 'fontname' | 'align'
export interface TextFormatPainter { export interface TextFormatPainter {
keep: boolean
bold?: boolean bold?: boolean
em?: boolean em?: boolean
underline?: boolean underline?: boolean
@ -114,6 +115,7 @@ export interface TextFormatPainter {
} }
export interface ShapeFormatPainter { export interface ShapeFormatPainter {
keep: boolean
fill?: string fill?: string
gradient?: ShapeGradient gradient?: ShapeGradient
outline?: PPTElementOutline outline?: PPTElementOutline

View File

@ -198,8 +198,9 @@
<CheckboxButton <CheckboxButton
style="flex: 1;" style="flex: 1;"
:checked="!!textFormatPainter" :checked="!!textFormatPainter"
v-tooltip="'格式刷'" v-tooltip="'格式刷(双击连续使用)'"
@click="toggleTextFormatPainter()" @click="toggleTextFormatPainter()"
@dblclick="toggleTextFormatPainter(true)"
><IconFormatBrush /></CheckboxButton> ><IconFormatBrush /></CheckboxButton>
</ButtonGroup> </ButtonGroup>
@ -239,9 +240,11 @@
<div class="row"> <div class="row">
<CheckboxButton <CheckboxButton
v-tooltip="'双击连续使用'"
style="flex: 1;" style="flex: 1;"
:checked="!!shapeFormatPainter" :checked="!!shapeFormatPainter"
@click="toggleShapeFormatPainter()" @click="toggleShapeFormatPainter()"
@dblclick="toggleShapeFormatPainter(true)"
><IconFormatBrush /> 形状格式刷</CheckboxButton> ><IconFormatBrush /> 形状格式刷</CheckboxButton>
</div> </div>
</div> </div>

View File

@ -143,8 +143,9 @@
<CheckboxButton <CheckboxButton
style="flex: 1;" style="flex: 1;"
:checked="!!textFormatPainter" :checked="!!textFormatPainter"
v-tooltip="'格式刷'" v-tooltip="'格式刷(双击连续使用)'"
@click="toggleTextFormatPainter()" @click="toggleTextFormatPainter()"
@dblclick="toggleTextFormatPainter(true)"
><IconFormatBrush /></CheckboxButton> ><IconFormatBrush /></CheckboxButton>
<Popover placement="bottom-end" trigger="click" v-model:value="linkPopoverVisible" style="width: 33.33%;"> <Popover placement="bottom-end" trigger="click" v-model:value="linkPopoverVisible" style="width: 33.33%;">
<template #content> <template #content>

View File

@ -231,16 +231,17 @@ const execCommand = ({ target, action }: RichTextCommand) => {
// //
const handleMouseup = () => { const handleMouseup = () => {
if (!textFormatPainter.value) return if (!textFormatPainter.value) return
const { keep, ...newProps } = textFormatPainter.value
const actions: RichTextAction[] = [{ command: 'clear' }] const actions: RichTextAction[] = [{ command: 'clear' }]
for (const key of Object.keys(textFormatPainter.value) as TextFormatPainterKeys[]) { for (const key of Object.keys(newProps) as TextFormatPainterKeys[]) {
const command = key const command = key
const value = textFormatPainter.value[key] const value = textFormatPainter.value[key]
if (value === true) actions.push({ command }) if (value === true) actions.push({ command })
else if (value) actions.push({ command, value }) else if (value) actions.push({ command, value })
} }
execCommand({ action: actions }) execCommand({ action: actions })
mainStore.setTextFormatPainter(null) if (!keep) mainStore.setTextFormatPainter(null)
} }
// Prosemirror // Prosemirror

View File

@ -116,13 +116,15 @@ const handleSelectElement = (e: MouseEvent | TouchEvent, canMove = true) => {
const execFormatPainter = () => { const execFormatPainter = () => {
if (!shapeFormatPainter.value) return if (!shapeFormatPainter.value) return
const { keep, ...newProps } = shapeFormatPainter.value
slidesStore.updateElement({ slidesStore.updateElement({
id: props.elementInfo.id, id: props.elementInfo.id,
props: shapeFormatPainter.value, props: newProps,
}) })
addHistorySnapshot() addHistorySnapshot()
mainStore.setShapeFormatPainter(null) if (!keep) mainStore.setShapeFormatPainter(null)
} }
const outline = computed(() => props.elementInfo.outline) const outline = computed(() => props.elementInfo.outline)