From c5c8a6ef71fba5e00df3065e06e725346f99349b Mon Sep 17 00:00:00 2001 From: Julius Knorr Date: Wed, 18 Sep 2024 21:25:16 +0200 Subject: [PATCH] fix: Fix title selection and editing Signed-off-by: Julius Knorr --- src/components/cards/CardItem.vue | 52 ++++++++++++++++++------ src/components/cards/CardMenu.vue | 11 ++++- src/components/cards/CardMenuEntries.vue | 13 +++++- 3 files changed, 61 insertions(+), 15 deletions(-) diff --git a/src/components/cards/CardItem.vue b/src/components/cards/CardItem.vue index 2eee570dc..67f1ad1d1 100644 --- a/src/components/cards/CardItem.vue +++ b/src/components/cards/CardItem.vue @@ -19,12 +19,12 @@
-

- {{ displayTitle }} +

+ {{ displayTitle }}

- +

@@ -51,7 +54,10 @@ {{ label.title }} - +
- +
@@ -78,6 +87,12 @@ import CardCover from './CardCover.vue' import DueDate from './badges/DueDate.vue' import { getCurrentUser } from '@nextcloud/auth' +const TITLE_EDITING_STATE = { + OFF: 0, + PENDING: 1, + ON: 2, +} + export default { name: 'CardItem', components: { CardBadges, AttachmentDragAndDrop, CardMenu, CardCover, DueDate }, @@ -106,6 +121,7 @@ export default { data() { return { highlight: false, + editingTitle: TITLE_EDITING_STATE.OFF, } }, computed: { @@ -132,9 +148,6 @@ export default { const board = this.$store.getters.boards.find((item) => item.id === this.card.boardId) return board ? !board.archived && board.permissions.PERMISSION_EDIT : false }, - inlineEditingBlocked() { - return this.card.referenceData || this.isArchived || this.showArchived || !this.canEdit || this.standalone - }, card() { return this.item ? this.item : this.$store.getters.cardById(this.id) }, @@ -193,15 +206,19 @@ export default { }, }, methods: { + hasSelection() { + const selection = window.getSelection() + return selection.toString() !== '' + }, focus(card) { - if (this.shortcutLock) { + if (this.shortcutLock || this.hasSelection()) { return } card = this.$refs[`card${card}`] card.focus() }, openCard() { - if (this.dragging) { + if (this.dragging || this.hasSelection()) { return } const boardId = this.card && this.card.boardId ? this.card.boardId : (this.$route?.params.id ?? this.currentBoard.id) @@ -213,8 +230,19 @@ export default { this.$root.$emit('open-card', this.card.id) }, + triggerEditTitle() { + this.editingTitle = TITLE_EDITING_STATE.PENDING + this.$store.dispatch('toggleShortcutLock', true) + setTimeout(() => { + this.$refs.titleContentEditable.focus() + this.editingTitle = TITLE_EDITING_STATE.ON + }, 0) + }, onTitleBlur(e) { - // TODO Handle empty title + if (this.editingTitle !== TITLE_EDITING_STATE.ON || e.target.innerText === '') { + return + } + this.editingTitle = TITLE_EDITING_STATE.OFF if (e.target.innerText !== this.card.title) { this.$store.dispatch('updateCardTitle', { ...this.card, diff --git a/src/components/cards/CardMenu.vue b/src/components/cards/CardMenu.vue index b9746c6d6..75f4aa6e2 100644 --- a/src/components/cards/CardMenu.vue +++ b/src/components/cards/CardMenu.vue @@ -5,13 +5,16 @@ @@ -29,11 +32,15 @@ export default { default: null, }, }, + emits: ['edit-title'], methods: { openLink() { window.open(this.card?.referenceData?.openGraphObject?.link) return false }, + editTitle(id) { + this.$emit('edit-title', id) + }, }, } diff --git a/src/components/cards/CardMenuEntries.vue b/src/components/cards/CardMenuEntries.vue index 4c6874605..373cadeae 100644 --- a/src/components/cards/CardMenuEntries.vue +++ b/src/components/cards/CardMenuEntries.vue @@ -9,6 +9,12 @@ {{ t('deck', 'Card details') }} + + + {{ t('deck', 'Edit title') }} +