create 5 new lines on new tab, clear final tab content on close

This commit is contained in:
Egor 2025-09-23 13:50:28 -07:00
parent 42b817949c
commit 159fb1a423
3 changed files with 22 additions and 4 deletions

View file

@ -5,3 +5,5 @@ export const DEFAULT_NOTEPAD_POSITION = {
export const NOTEPAD_MIN_WIDTH = 300; export const NOTEPAD_MIN_WIDTH = 300;
export const NOTEPAD_MIN_HEIGHT = 200; export const NOTEPAD_MIN_HEIGHT = 200;
export const DEFAULT_TAB_CONTENT = '\n\n\n\n\n';

View file

@ -3,7 +3,10 @@ import { join } from 'path';
import { safeExecute, tryExecute } from '@/utils/node/logging'; import { safeExecute, tryExecute } from '@/utils/node/logging';
import { getInstallDir } from './config'; import { getInstallDir } from './config';
import type { SavedNotepadState, SavedNotepadTab } from '@/types/electron'; 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_DIR = join(getInstallDir(), 'notepad');
const NOTEPAD_STATE_FILE = join(NOTEPAD_DIR, 'state.json'); const NOTEPAD_STATE_FILE = join(NOTEPAD_DIR, 'state.json');
@ -104,10 +107,10 @@ export async function createNewTab(title?: string) {
const newTab = { const newTab = {
id: `tab-${Date.now()}-${Math.random().toString(36).substring(2, 11)}`, id: `tab-${Date.now()}-${Math.random().toString(36).substring(2, 11)}`,
title: title || `Note ${tabCounter++}`, title: title || `Note ${tabCounter++}`,
content: '', content: DEFAULT_TAB_CONTENT,
}; };
await saveTabContent(newTab.id, ''); await saveTabContent(newTab.id, newTab.content);
return newTab; return newTab;
} }

View file

@ -1,7 +1,10 @@
import { create } from 'zustand'; import { create } from 'zustand';
import { subscribeWithSelector } from 'zustand/middleware'; import { subscribeWithSelector } from 'zustand/middleware';
import type { NotepadTab, NotepadState } from '@/types/electron'; 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 { interface NotepadStore extends NotepadState {
isLoaded: boolean; isLoaded: boolean;
@ -51,6 +54,16 @@ export const useNotepadStore = create<NotepadStore>()(
const state = get(); const state = get();
if (state.tabs.length <= 1) { 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; return;
} }