Skip to content

Commit

Permalink
feat: add dblclick to edit folder and fragment name (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
antonreshetov authored Mar 9, 2020
1 parent 22744a8 commit fbcd82d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 14 deletions.
25 changes: 20 additions & 5 deletions src/renderer/components/sidebar/SidebarListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
}"
v-on="$listeners"
@click="onClick"
@dblclick="onDblClick"
@contextmenu="onContext"
>
<div @click="$emit('click:toggle')">
Expand All @@ -21,6 +22,7 @@
</div>
<AppIcon :name="icon" />
<input
v-if="editable"
ref="input"
v-model="folderName"
class="sidebar-list-item__input"
Expand All @@ -31,6 +33,10 @@
:disabled="!editable"
@keydown.enter="onClickOutside"
>
<span
v-else
class="folder-name"
> {{ folderName }}</span>
<slot />
</div>
</template>
Expand Down Expand Up @@ -128,6 +134,10 @@ export default {
},
isEditable () {
return this.editableId === this.id
},
isSystem () {
const libraryItems = ['inBox', 'favorites', 'allSnippets', 'trash']
return libraryItems.includes(this.id)
}
},
Expand All @@ -145,16 +155,16 @@ export default {
this.$store.commit('tags/SET_SELECTED_ID', this.id)
}
},
onDblClick () {
if (!this.isSystem) this.setEditable()
},
onContext () {
if (!this.tag) {
const libraryItems = ['inBox', 'favorites', 'allSnippets', 'trash']
const isLibrary = libraryItems.includes(this.id)
if (this.id === 'trash') {
this.trashContext()
return this.trashContext()
}
if (isLibrary) return
if (this.isSystem) return
this.folderContext()
} else {
Expand Down Expand Up @@ -291,6 +301,11 @@ export default {
color: var(--color-contrast-higher);
}
}
.folder-name {
display: flex;
height: 20px;
align-items: center;
}
svg {
width: 16px;
height: 16px;
Expand Down
28 changes: 19 additions & 9 deletions src/renderer/components/snippets/SnippetTabsItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
active: isActive
}"
v-on="$listeners"
@dblclick="onDblClick"
@contextmenu="onTabContext"
>
<input
v-if="editable"
ref="input"
v-model="computedLabel"
:class="{
Expand All @@ -18,6 +20,10 @@
:disabled="!editable"
@keydown.enter="onClickOutside"
>
<span
v-else
class="fragment-name"
>{{ computedLabel }}</span>
</div>
</template>

Expand Down Expand Up @@ -61,17 +67,21 @@ export default {
},
methods: {
setEditable () {
this.editable = true
this.$nextTick(() => {
this.$refs.input.focus()
this.$refs.input.select()
})
},
onDblClick () {
this.setEditable()
},
onTabContext () {
menu.popup([
{
label: `Rename "${this.label}"`,
click: () => {
this.editable = true
this.$nextTick(() => {
this.$refs.input.focus()
this.$refs.input.select()
})
}
click: () => this.setEditable()
},
{
type: 'separator'
Expand Down Expand Up @@ -107,10 +117,11 @@ export default {
align-items: center;
justify-content: center;
height: 100%;
width: 100%;
padding: 0 var(--spacing-xs);
color: var(--color-contrast-medium);
font-size: var(--text-sm);
-webkit-user-select: none;
user-select: none;
input {
width: 100%;
color: var(--color-contrast-medium);
Expand All @@ -120,7 +131,6 @@ export default {
outline: none;
&[disabled] {
color: var(--color-contrast-medium);
-webkit-user-select: none;
}
&.is-editable {
border: 1px solid var(--color-primary);
Expand Down

0 comments on commit fbcd82d

Please sign in to comment.