Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/renderer/assets/scss/variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
--sidebar-width: 180px;
--snippets-list-width: 250px;
--title-bar-height: 15px;
--title-bar-height-offset: -5px;
--menu-header: 80px;

--spacing-unit: 4px;
Expand Down
19 changes: 19 additions & 0 deletions src/renderer/components/editor/TheEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ const setValue = () => {
const pos = editor.session.selection.toJSON()
editor.setValue(props.modelValue)
editor.session.selection.fromJSON(pos)

if (snippetStore.searchQuery) {
findAll(snippetStore.searchQuery)
} else {
editor.moveCursorTo(0, 0)
editor.clearSelection()
}
}

const setLang = () => {
Expand All @@ -145,6 +152,11 @@ const setTheme = () => {
editor.session.setMode(`ace/theme/${props.theme}`)
}

const findAll = (q: string) => {
if (q === '') return
editor.findAll(q, { caseSensitive: false, preventScroll: true })
}

const getCursorPosition = () => {
const { row, column } = editor.getCursorPosition()
cursorPosition.row = row
Expand All @@ -164,6 +176,13 @@ watch(
() => setValue()
)

watch(
() => snippetStore.searchQuery,
v => {
if (v) findAll(v)
}
)

window.addEventListener('resize', () => {
forceRefresh.value = Math.random()
})
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/components/snippets/SnippetHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ emitter.on('focus:snippet-name', () => {
justify-content: space-between;
align-items: center;
height: v-bind(headerHeight);
position: relative;
top: var(--title-bar-height-offset);
}
.name {
font-size: 16px;
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/components/snippets/SnippetList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ const snippetStore = useSnippetStore()
grid-template-rows: 50px 1fr;
}
.header {
margin-top: 12px;
padding-top: var(--title-bar-height);
display: flex;
border-bottom: 1px solid var(--color-border);
}
.body {
overflow-y: scroll;
Expand Down
38 changes: 34 additions & 4 deletions src/renderer/components/snippets/SnippetListHeader.vue
Original file line number Diff line number Diff line change
@@ -1,24 +1,46 @@
<template>
<div class="action">
<UniconsSearch />
<input placeholder="Search...">
<input
v-model="query"
placeholder="Search..."
>
<AppActionButton
class="add"
v-if="!query"
class="item"
@click="onAddNewSnippet"
>
<UniconsPlus />
</AppActionButton>
<AppActionButton
v-else
class="item"
@click="onReset"
>
<UniconsTimes />
</AppActionButton>
</div>
</template>

<script setup lang="ts">
import { emitter } from '@/composable'
import { useFolderStore } from '@/store/folders'
import { useSnippetStore } from '@/store/snippets'
import { useDebounceFn } from '@vueuse/core'
import { computed } from 'vue'

const snippetStore = useSnippetStore()
const folderStore = useFolderStore()

const query = computed({
get: () => snippetStore.searchQuery,
set: useDebounceFn(v => {
snippetStore.searchQuery = v
snippetStore.setSnippetsByAlias('all')
snippetStore.search(v!)
}, 300)
})

const onAddNewSnippet = async () => {
if (folderStore.selectedAlias !== undefined) return
if (!folderStore.selectedId) return
Expand All @@ -29,23 +51,31 @@ const onAddNewSnippet = async () => {

emitter.emit('focus:snippet-name', true)
}

const onReset = () => {
snippetStore.searchQuery = undefined
snippetStore.setSnippetsByAlias('all')
}
</script>

<style lang="scss" scoped>
.action {
display: flex;
align-items: center;
padding: var(--spacing-sm);
padding: 0 var(--spacing-sm);
position: relative;
top: var(--title-bar-height-offset);
input {
outline: none;
border: none;
width: 100%;
padding: 0 var(--spacing-xs);
height: 24px;
}
:deep(svg) {
flex-shrink: 0;
}
.add {
.item {
position: relative;
right: -8px;
}
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/store/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const useAppStore = defineStore('app', {
sizes: {
titlebar: 15,
editor: {
titleHeight: 30,
titleHeight: 34,
fragmentsHeight: 25,
tagsHeight: 40,
footerHeight: 30
Expand Down
33 changes: 24 additions & 9 deletions src/renderer/store/snippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ import type {
} from '@shared/types/renderer/store/snippets'
import { useTagStore } from './tags'
import { useAppStore } from './app'
import { uniqBy } from 'lodash'

export const useSnippetStore = defineStore('snippets', {
state: () =>
({
all: [],
snippets: [],
selected: undefined,
selectedMultiple: [],
fragment: 0,
isContextState: false
} as State),
state: (): State => ({
all: [],
snippets: [],
selected: undefined,
selectedMultiple: [],
fragment: 0,
isContextState: false,
searchQuery: undefined
}),

getters: {
selectedId: state => state.selected?.id,
Expand Down Expand Up @@ -263,6 +264,20 @@ export const useSnippetStore = defineStore('snippets', {
async emptyTrash () {
const ids = this.all.filter(i => i.isDeleted).map(i => i.id)
await this.deleteSnippetsByIds(ids)
},
search (query: string) {
const byName = this.all.filter(i =>
i.name.toLowerCase().includes(query.toLowerCase())
)

const byContent = this.all.filter(i => {
return i.content.some(c =>
c.value.toLowerCase().includes(query.toLowerCase())
)
})

this.snippets = uniqBy([...byName, ...byContent], 'id')
this.selected = this.snippets[0]
}
}
})
1 change: 1 addition & 0 deletions src/shared/types/renderer/store/snippets.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export interface State {
selectedMultiple: Snippet[]
fragment: number
isContextState: boolean
searchQuery?: string
}