mirror of
https://github.com/lone-cloud/gerbil
synced 2026-06-03 19:54:44 -07:00
create 5 new lines on new tab, clear final tab content on close
This commit is contained in:
parent
42b817949c
commit
159fb1a423
3 changed files with 22 additions and 4 deletions
|
|
@ -5,3 +5,5 @@ export const DEFAULT_NOTEPAD_POSITION = {
|
|||
|
||||
export const NOTEPAD_MIN_WIDTH = 300;
|
||||
export const NOTEPAD_MIN_HEIGHT = 200;
|
||||
|
||||
export const DEFAULT_TAB_CONTENT = '\n\n\n\n\n';
|
||||
|
|
|
|||
|
|
@ -3,7 +3,10 @@ import { join } from 'path';
|
|||
import { safeExecute, tryExecute } from '@/utils/node/logging';
|
||||
import { getInstallDir } from './config';
|
||||
import type { SavedNotepadState, SavedNotepadTab } from '@/types/electron';
|
||||
import { DEFAULT_NOTEPAD_POSITION } from '@/constants/notepad';
|
||||
import {
|
||||
DEFAULT_NOTEPAD_POSITION,
|
||||
DEFAULT_TAB_CONTENT,
|
||||
} from '@/constants/notepad';
|
||||
|
||||
const NOTEPAD_DIR = join(getInstallDir(), 'notepad');
|
||||
const NOTEPAD_STATE_FILE = join(NOTEPAD_DIR, 'state.json');
|
||||
|
|
@ -104,10 +107,10 @@ export async function createNewTab(title?: string) {
|
|||
const newTab = {
|
||||
id: `tab-${Date.now()}-${Math.random().toString(36).substring(2, 11)}`,
|
||||
title: title || `Note ${tabCounter++}`,
|
||||
content: '',
|
||||
content: DEFAULT_TAB_CONTENT,
|
||||
};
|
||||
|
||||
await saveTabContent(newTab.id, '');
|
||||
await saveTabContent(newTab.id, newTab.content);
|
||||
|
||||
return newTab;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
import { create } from 'zustand';
|
||||
import { subscribeWithSelector } from 'zustand/middleware';
|
||||
import type { NotepadTab, NotepadState } from '@/types/electron';
|
||||
import { DEFAULT_NOTEPAD_POSITION } from '@/constants/notepad';
|
||||
import {
|
||||
DEFAULT_NOTEPAD_POSITION,
|
||||
DEFAULT_TAB_CONTENT,
|
||||
} from '@/constants/notepad';
|
||||
|
||||
interface NotepadStore extends NotepadState {
|
||||
isLoaded: boolean;
|
||||
|
|
@ -51,6 +54,16 @@ export const useNotepadStore = create<NotepadStore>()(
|
|||
const state = get();
|
||||
|
||||
if (state.tabs.length <= 1) {
|
||||
const tab = state.tabs.find((t) => t.id === tabId);
|
||||
if (tab) {
|
||||
set((state) => ({
|
||||
tabs: state.tabs.map((t) =>
|
||||
t.id === tabId ? { ...t, content: DEFAULT_TAB_CONTENT } : t
|
||||
),
|
||||
}));
|
||||
window.electronAPI.notepad.saveTabContent(tabId, DEFAULT_TAB_CONTENT);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue