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

a prototype of a way to get multiple buffers #41

Open
wants to merge 1 commit 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
1 change: 1 addition & 0 deletions electron/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const schema = {
"allowBetaVersions": {type: "boolean", default: false},
"enableGlobalHotkey": {type: "boolean", default: false},
"globalHotkey": {type: "string", default: "CmdOrCtrl+Shift+H"},
"bufferSuffix": {type: "string", default: "1"},
},
},

Expand Down
6 changes: 4 additions & 2 deletions electron/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,10 @@ ipcMain.handle('dark-mode:set', (event, mode) => {

ipcMain.handle('dark-mode:get', () => nativeTheme.themeSource)

const bufferPath = isDev ? join(app.getPath("userData"), "buffer-dev.txt") : join(app.getPath("userData"), "buffer.txt")
const bufferPathBase = isDev ? join(app.getPath("userData"), "buffer-dev") : join(app.getPath("userData"), "buffer")

ipcMain.handle('buffer-content:load', async () =>  {
ipcMain.handle('buffer-content:load', async () => {
let bufferPath=bufferPathBase+CONFIG.get("settings.bufferSuffix")
if (jetpack.exists(bufferPath) === "file") {
return await jetpack.read(bufferPath, 'utf8')
} else {
Expand All @@ -221,6 +222,7 @@ ipcMain.handle('buffer-content:load', async () =>  {
});

async function save(content) {
let bufferPath=bufferPathBase+CONFIG.get("settings.bufferSuffix")
return await jetpack.write(bufferPath, content, {
atomic: true,
mode: '600',
Expand Down
54 changes: 54 additions & 0 deletions src/editor/keymap.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {

import { formatBlockContent } from "./block/format-code.js"

import CONFIG from "../../electron/config.js"


export function keymapFromSpec(specs) {
return keymap.of(specs.map((spec) => {
Expand All @@ -34,6 +36,49 @@ export function keymapFromSpec(specs) {
}))
}

function setBuffer(b) {
console.log(b)
console.log('call save')
CONFIG.set("settings.bufferSuffix", b)
console.log('call load')
}

function setBuffer1(state, dispatch) {
setBuffer(1)
}

function setBuffer2(state, dispatch) {
setBuffer(2)
}

function setBuffer3(state, dispatch) {
setBuffer(3)
}

function setBuffer4(state, dispatch) {
setBuffer(4)
}

function setBuffer5(state, dispatch) {
setBuffer(5)
}

function setBuffer6(state, dispatch) {
setBuffer(6)
}

function setBuffer7(state, dispatch) {
setBuffer(7)
}

function setBuffer8(state, dispatch) {
setBuffer(8)
}

function setBuffer9(state, dispatch) {
setBuffer(9)
}

export function heynoteKeymap(editor) {
return keymapFromSpec([
["Tab", indentMore],
Expand All @@ -51,5 +96,14 @@ export function heynoteKeymap(editor) {
{key:"Mod-ArrowDown", run:gotoNextBlock, shift:selectNextBlock},
{key:"Ctrl-ArrowUp", run:gotoPreviousParagraph, shift:selectPreviousParagraph},
{key:"Ctrl-ArrowDown", run:gotoNextParagraph, shift:selectNextParagraph},
["Mod-1", setBuffer1],
["Mod-2", setBuffer2],
["Mod-3", setBuffer3],
["Mod-4", setBuffer4],
["Mod-5", setBuffer5],
["Mod-6", setBuffer6],
["Mod-7", setBuffer7],
["Mod-8", setBuffer8],
["Mod-9", setBuffer9],
])
}