Skip to content

Commit

Permalink
Change terminology Note -> Buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
heyman committed Dec 6, 2024
1 parent 0ecec06 commit 62ee0e0
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 175 deletions.
62 changes: 31 additions & 31 deletions src/components/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@
import { mapState, mapActions } from 'pinia'
import { mapWritableState } from 'pinia'
import { useNotesStore } from "../stores/notes-store"
import { useHeynoteStore } from "../stores/heynote-store"
import { useErrorStore } from "../stores/error-store"
import StatusBar from './StatusBar.vue'
import Editor from './Editor.vue'
import LanguageSelector from './LanguageSelector.vue'
import NoteSelector from './NoteSelector.vue'
import BufferSelector from './BufferSelector.vue'
import Settings from './settings/Settings.vue'
import ErrorMessages from './ErrorMessages.vue'
import NewNote from './NewNote.vue'
import EditNote from './EditNote.vue'
import NewBuffer from './NewBuffer.vue'
import EditBuffer from './EditBuffer.vue'
export default {
components: {
Editor,
StatusBar,
LanguageSelector,
Settings,
NoteSelector,
BufferSelector,
ErrorMessages,
NewNote,
EditNote,
NewBuffer,
EditBuffer,
},
data() {
Expand Down Expand Up @@ -67,37 +67,37 @@
watch: {
// when a dialog is closed, we want to focus the editor
showLanguageSelector(value) { this.dialogWatcher(value) },
showNoteSelector(value) { this.dialogWatcher(value) },
showCreateNote(value) { this.dialogWatcher(value) },
showEditNote(value) { this.dialogWatcher(value) },
showBufferSelector(value) { this.dialogWatcher(value) },
showCreateBuffer(value) { this.dialogWatcher(value) },
showEditBuffer(value) { this.dialogWatcher(value) },
currentNotePath() {
currentBufferPath() {
this.focusEditor()
},
},
computed: {
...mapState(useNotesStore, [
"currentNotePath",
...mapState(useHeynoteStore, [
"currentBufferPath",
"showLanguageSelector",
"showNoteSelector",
"showCreateNote",
"showEditNote",
"showBufferSelector",
"showCreateBuffer",
"showEditBuffer",
]),
editorInert() {
return this.showCreateNote || this.showSettings || this.showEditNote
return this.showCreateBuffer || this.showSettings || this.showEditBuffer
},
},
methods: {
...mapActions(useNotesStore, [
...mapActions(useHeynoteStore, [
"openLanguageSelector",
"openNoteSelector",
"openCreateNote",
"openBufferSelector",
"openCreateBuffer",
"closeDialog",
"closeNoteSelector",
"openNote",
"closeBufferSelector",
"openBuffer",
]),
// Used as a watcher for the booleans that control the visibility of editor dialogs.
Expand Down Expand Up @@ -177,7 +177,7 @@
<StatusBar
:autoUpdate="settings.autoUpdate"
:allowBetaVersions="settings.allowBetaVersions"
@openNoteSelector="openNoteSelector"
@openBufferSelector="openBufferSelector"
@openLanguageSelector="openLanguageSelector"
@formatCurrentBlock="formatCurrentBlock"
@openSettings="showSettings = true"
Expand All @@ -190,10 +190,10 @@
@selectLanguage="onSelectLanguage"
@close="closeDialog"
/>
<NoteSelector
v-if="showNoteSelector"
@openNote="openNote"
@close="closeNoteSelector"
<BufferSelector
v-if="showBufferSelector"
@openBuffer="openBuffer"
@close="closeBufferSelector"
/>
<Settings
v-if="showSettings"
Expand All @@ -202,12 +202,12 @@
@closeSettings="closeSettings"
@setTheme="setTheme"
/>
<NewNote
v-if="showCreateNote"
<NewBuffer
v-if="showCreateBuffer"
@close="closeDialog"
/>
<EditNote
v-if="showEditNote"
<EditBuffer
v-if="showEditBuffer"
@close="closeDialog"
/>
<ErrorMessages />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { mapState, mapActions } from 'pinia'
import { toRaw } from 'vue';
import { SCRATCH_FILE_NAME } from "../common/constants"
import { useNotesStore } from "../stores/notes-store"
import { useHeynoteStore } from "../stores/heynote-store"
export default {
data() {
Expand All @@ -19,7 +19,7 @@
},
async mounted() {
await this.updateNotes()
await this.updateBuffers()
this.$refs.container.focus()
this.$refs.input.focus()
this.buildItems()
Expand All @@ -29,13 +29,13 @@
},
computed: {
...mapState(useNotesStore, [
"notes",
"recentNotePaths",
...mapState(useHeynoteStore, [
"buffers",
"recentBufferPaths",
]),
orderedItems() {
const sortKeys = Object.fromEntries(this.recentNotePaths.map((item, idx) => [item, idx]))
const sortKeys = Object.fromEntries(this.recentBufferPaths.map((item, idx) => [item, idx]))
const getSortScore = (item) => sortKeys[item.path] !== undefined ? sortKeys[item.path] : 1000
const compareFunc = (a, b) => {
const sortScore = getSortScore(a) - getSortScore(b)
Expand Down Expand Up @@ -90,16 +90,16 @@
},
methods: {
...mapActions(useNotesStore, [
"updateNotes",
"editNote",
"deleteNote",
"openCreateNote",
...mapActions(useHeynoteStore, [
"updateBuffers",
"editBufferMetadata",
"deleteBuffer",
"openCreateBuffer",
]),
buildItems() {
//console.log("buildItems", Object.entries(this.notes))
this.items = Object.entries(this.notes).map(([path, metadata]) => {
//console.log("buildItems", Object.entries(this.buffers))
this.items = Object.entries(this.buffers).map(([path, metadata]) => {
return {
"path": path,
"name": metadata?.name || path,
Expand Down Expand Up @@ -158,7 +158,7 @@
event.preventDefault()
if (this.actionButton === 1) {
//console.log("edit file:", path)
this.editNote(item.path)
this.editBufferMetadata(item.path)
} else if (this.actionButton === 2) {
this.deleteConfirmNote(item.path)
} else {
Expand All @@ -170,12 +170,12 @@
selectItem(item) {
if (item.createNew) {
if (this.filteredItems.length === 1) {
this.openCreateNote("new", this.filter)
this.openCreateBuffer("new", this.filter)
} else {
this.openCreateNote("new", "")
this.openCreateBuffer("new", "")
}
} else {
this.$emit("openNote", item.path)
this.$emit("openBuffer", item.path)
}
},
Expand Down Expand Up @@ -220,7 +220,7 @@
async deleteConfirmNote(path) {
if (this.deleteConfirm) {
//console.log("delete file:", path)
await this.deleteNote(path)
await this.deleteBuffer(path)
this.hideActionButtons()
this.buildItems()
this.selected = Math.min(this.selected, this.items.length - 1)
Expand Down Expand Up @@ -264,7 +264,7 @@
<button
v-if="actionButton > 0 && idx === selected"
:class="{'selected':actionButton === 1}"
@click.stop.prevent="editNote(item.path)"
@click.stop.prevent="editBufferMetadata(item.path)"
>Edit</button>
<button
v-if="actionButton > 0 && idx === selected"
Expand Down
28 changes: 14 additions & 14 deletions src/components/EditNote.vue → src/components/EditBuffer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { toRaw } from 'vue';
import { mapState, mapActions } from 'pinia'
import { useNotesStore } from "../stores/notes-store"
import { useHeynoteStore } from "../stores/heynote-store"
import FolderSelector from './folder-selector/FolderSelector.vue'
Expand All @@ -26,7 +26,7 @@
async mounted() {
this.$refs.nameInput.focus()
this.updateNotes()
this.updateBuffers()
console.log("EditNote mounted", this.currentNote)
this.name = this.currentNote.name
Expand Down Expand Up @@ -56,7 +56,7 @@
name: part,
children: [],
path: currentPath,
open: this.currentNotePath.startsWith(currentPath),
open: this.currentBufferPath.startsWith(currentPath),
}
currentLevel.children.push(node)
currentLevel = node
Expand All @@ -68,17 +68,17 @@
},
computed: {
...mapState(useNotesStore, [
"notes",
"currentNotePath",
...mapState(useHeynoteStore, [
"buffers",
"currentBufferPath",
]),
currentNote() {
return this.notes[this.currentNotePath]
return this.buffers[this.currentBufferPath]
},
currentNoteDirectory() {
return this.currentNotePath.split("/").slice(0, -1).join("/")
return this.currentBufferPath.split("/").slice(0, -1).join("/")
},
nameInputClass() {
Expand All @@ -90,9 +90,9 @@
},
methods: {
...mapActions(useNotesStore, [
"updateNotes",
"updateNoteMetadata",
...mapActions(useHeynoteStore, [
"updateBuffers",
"updateBufferMetadata",
]),
onKeydown(event) {
Expand Down Expand Up @@ -137,19 +137,19 @@
for (let i=0; i<1000; i++) {
let filename = slug + ".txt"
path = parentPathPrefix + filename
if (path === this.currentNotePath || !this.notes[path]) {
if (path === this.currentBufferPath || !this.buffers[path]) {
// file name is ok if it's the current note, or if it doesn't exist
break
}
slug = slugify(this.name + "-" + i)
}
if (path !== this.currentNotePath && this.notes[path]) {
if (path !== this.currentBufferPath && this.buffers[path]) {
console.error("Failed to edit note, path already exists", path)
this.errors.name = true
return
}
console.log("Update note", path)
this.updateNoteMetadata(this.currentNotePath, this.name, path)
this.updateBufferMetadata(this.currentBufferPath, this.name, path)
this.$emit("close")
//this.$emit("create", this.$refs.input.value)
},
Expand Down
18 changes: 9 additions & 9 deletions src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { toRaw } from 'vue';
import { mapState, mapWritableState, mapActions } from 'pinia'
import { useErrorStore } from "../stores/error-store"
import { useNotesStore } from "../stores/notes-store"
import { useHeynoteStore } from "../stores/heynote-store.js"
import { useEditorCacheStore } from "../stores/editor-cache"
const NUM_EDITOR_INSTANCES = 5
Expand Down Expand Up @@ -50,7 +50,7 @@
},
mounted() {
this.loadBuffer(this.currentNotePath)
this.loadBuffer(this.currentBufferPath)
// set up window close handler that will save the buffer and quit
window.heynote.onWindowClose(() => {
Expand Down Expand Up @@ -87,8 +87,8 @@
watch: {
loadNewEditor() {
//console.log("currentNotePath changed to", path)
this.loadBuffer(this.currentNotePath)
//console.log("currentBufferPath changed to", path)
this.loadBuffer(this.currentBufferPath)
},
theme(newTheme) {
Expand Down Expand Up @@ -150,17 +150,17 @@
},
computed: {
...mapState(useNotesStore, [
"currentNotePath",
...mapState(useHeynoteStore, [
"currentBufferPath",
"libraryId",
]),
...mapWritableState(useNotesStore, [
...mapWritableState(useHeynoteStore, [
"currentEditor",
"currentNoteName",
"currentBufferName",
]),
loadNewEditor() {
return `${this.currentNotePath}|${this.libraryId}`
return `${this.currentBufferPath}|${this.libraryId}`
},
},
Expand Down
Loading

0 comments on commit 62ee0e0

Please sign in to comment.