Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve card title editing #6327

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 39 additions & 8 deletions src/components/cards/CardItem.vue
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inlineEditingBlocked computed doesn't seem to be used anymore.

Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
</div>
<CardCover v-if="showCardCover" :card-id="card.id" />
<div class="card-upper">
<h4 v-if="inlineEditingBlocked" dir="auto">
{{ card.title }}
<h4 v-if="!editingTitle" dir="auto">
<span v-auto-link class="dragDisabled">{{ card.title }}</span>
</h4>
<h4 v-else
dir="auto"
class="editable"
class="editable dragDisabled"
:aria-label="t('deck', 'Edit card title')">
<span ref="titleContentEditable"
tabindex="0"
Expand All @@ -38,7 +38,10 @@
</h4>

<DueDate v-if="compactMode" :card="card" />
<CardMenu v-if="showMenuAtTitle" :card="card" class="right card-menu" />
<CardMenu v-if="showMenuAtTitle"
:card="card"
class="right card-menu"
@edit-title="triggerEditTitle" />
</div>

<div v-if="hasLabels" class="card-labels">
Expand All @@ -51,7 +54,10 @@
<span @click.stop="applyLabelFilter(label)">{{ label.title }}</span>
</li>
</transition-group>
<CardMenu v-if="showMenuAtLabels" :card="card" class="right" />
<CardMenu v-if="showMenuAtLabels"
:card="card"
class="right"
@edit-title="triggerEditTitle" />
</div>

<div v-if="hasBadges"
Expand Down Expand Up @@ -83,6 +89,14 @@ export default {
components: { CardBadges, AttachmentDragAndDrop, CardMenu, CardCover, DueDate },
directives: {
ClickOutside,
'auto-link': {
inserted(el) {
el.innerHTML = el.innerHTML.replace(
/(\s|\n|^)((https?:\/\/)([-A-Z0-9+_.]+(?::[0-9]+)?(?:\/[-A-Z0-9+&@#%?=~_|!:,.;()]*)*))(\s|\n|$)/gi,
'$1<a href="$2" target="_blank">$2</a>$5',
)
},
},
},
mixins: [Color, labelStyle],
props: {
Expand All @@ -106,6 +120,7 @@ export default {
data() {
return {
highlight: false,
editingTitle: false,
}
},
computed: {
Expand Down Expand Up @@ -189,15 +204,22 @@ 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) {
openCard(event) {
if (event.target.tagName.toLowerCase() === 'a') {
return
}
if (this.dragging || this.hasSelection()) {
return
}
const boardId = this.card && this.card.boardId ? this.card.boardId : (this.$route?.params.id ?? this.currentBoard.id)
Expand All @@ -209,7 +231,11 @@ export default {

this.$root.$emit('open-card', this.card.id)
},
triggerEditTitle() {
this.editingTitle = true
},
onTitleBlur(e) {
this.editingTitle = false
// TODO Handle empty title
if (e.target.innerText !== this.card.title) {
this.$store.dispatch('updateCardTitle', {
Expand Down Expand Up @@ -336,6 +362,11 @@ export default {
word-wrap: break-word;
padding-left: 4px;
align-self: center;

:deep(a) {
text-decoration: underline;
}

&.editable {
span {
cursor: text;
Expand Down
3 changes: 2 additions & 1 deletion src/components/cards/CardMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<template>
<div v-if="card" class="card-menu" @click.stop.prevent>
<NcActions>
<CardMenuEntries :card="card" />
<CardMenuEntries :card="card" @edit-title="(id) => $emit('edit-title', id)" />
</NcActions>
</div>
</template>
Expand All @@ -23,5 +23,6 @@ export default {
default: null,
},
},
emits: ['edit-title'],
}
</script>
13 changes: 12 additions & 1 deletion src/components/cards/CardMenuEntries.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
<CardBulletedIcon slot="icon" :size="20" decorative />
{{ t('deck', 'Card details') }}
</NcActionButton>
<NcActionButton v-if="canEdit" :close-after-click="true" @click="editTitle">
<template #icon>
<PencilIcon :size="20" decorative />
</template>
{{ t('deck', 'Edit title') }}
</NcActionButton>
<NcActionButton v-if="canEdit && !isCurrentUserAssigned"
icon="icon-user"
:close-after-click="true"
Expand Down Expand Up @@ -59,6 +65,7 @@ import { NcActionButton } from '@nextcloud/vue'
import { mapGetters, mapState } from 'vuex'
import ArchiveIcon from 'vue-material-design-icons/Archive.vue'
import CardBulletedIcon from 'vue-material-design-icons/CardBulleted.vue'
import PencilIcon from 'vue-material-design-icons/Pencil.vue'
import { generateUrl } from '@nextcloud/router'
import { getCurrentUser } from '@nextcloud/auth'
import { showUndo } from '@nextcloud/dialogs'
Expand All @@ -68,7 +75,7 @@ import { emit } from '@nextcloud/event-bus'

export default {
name: 'CardMenuEntries',
components: { NcActionButton, ArchiveIcon, CardBulletedIcon },
components: { NcActionButton, ArchiveIcon, CardBulletedIcon, PencilIcon },
props: {
card: {
type: Object,
Expand All @@ -79,6 +86,7 @@ export default {
default: false,
},
},
emits: ['edit-title'],
data() {
return {
modalShow: false,
Expand Down Expand Up @@ -136,6 +144,9 @@ export default {

this.$root.$emit('open-card', this.card.id)
},
editTitle() {
this.$emit('edit-title', this.card.id)
},
deleteCard() {
this.$store.dispatch('deleteCard', this.card)
const undoCard = { ...this.card, deletedAt: 0 }
Expand Down
Loading