File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 4040 )
4141 return ;
4242 is_processing = true ;
43- await add_new_note (focused_subtree , focused_directory , root_path );
43+ opened_filenode = await add_new_note (
44+ focused_subtree ,
45+ focused_directory ,
46+ root_path
47+ );
4448 is_processing = false ;
49+
50+ const input: HTMLInputElement | null = document .getElementById (
51+ ' note_file_name_input'
52+ ) as HTMLInputElement | null ;
53+ if (! input ) return ;
54+ setTimeout (() => {
55+ input .focus ();
56+ input .select ();
57+ }, 50 );
4558 }}
4659 ><div class =" i-tabler:edit size-5" ></div >
4760 </button >
Original file line number Diff line number Diff line change 55 import Prosemark from ' ./prosemark.svelte' ;
66 import { toast } from ' svelte-sonner' ;
77 import { current_platform_type } from ' @/lib/file_tree' ;
8+ import { type EditorView } from ' @codemirror/view' ;
9+
810 let {
911 filenode = $bindable (),
1012 root_path,
1517 let text_content: string | undefined = $state ();
1618 let current_file_name: string | undefined = $state ();
1719 let is_file_named_changed: boolean = $state (false );
20+ let editor_view: EditorView | undefined = $state ();
1821
1922 $effect (() => {
2023 if (! filenode ) return ;
3942 <div class =" max-w-170 w-full font-sans" >
4043 <input
4144 type =" text"
45+ id =" note_file_name_input"
4246 oninput ={(e ) => {
4347 current_file_name = current_file_name ?.replace (
4448 / [^ A-Za-z0-9 _. \-( )] / g ,
6064 if (e instanceof Error ) toast .error (e .message );
6165 }
6266 }}
67+ onkeydown ={async (e ) => {
68+ if (e .key === ' Enter' ) {
69+ e .preventDefault ();
70+ if (editor_view ) editor_view .focus ();
71+ }
72+ }}
6373 bind:value ={current_file_name }
6474 class =" w-full outline-none b-0 focus:ring-0 mb-16 mt-10 font-semibold text-5xl"
6575 />
6676
6777 <Prosemark
6878 {text_content }
79+ bind:editor _view
6980 write _to_file={(content ) => {
7081 if (! filenode ) return ;
7182 writeTextFile (filenode ?.path , content );
Original file line number Diff line number Diff line change 1717 let {
1818 text_content,
1919 write_to_file,
20+ editor_view = $bindable (),
2021 }: {
2122 text_content: string | undefined ;
23+ editor_view: EditorView | undefined ;
2224 write_to_file: (markdown_content_state : string ) => void ;
2325 } = $props ();
2426 let element: HTMLDivElement | undefined = $state ();
25- let editor: EditorView | undefined = $state ();
2627 let is_contents_changed = $state (false );
2728 $effect (() => {
2829 let newEditor: EditorView | undefined ;
5152 ],
5253 });
5354 }
54- editor = newEditor ;
55+ editor_view = newEditor ;
5556
5657 return () => {
5758 newEditor ?.destroy ();
6263<div
6364 bind:this ={element }
6465 onfocusout ={() => {
65- if (! editor || ! is_contents_changed ) return ;
66- write_to_file (editor .state .doc .toString ());
66+ if (! editor_view || ! is_contents_changed ) return ;
67+ write_to_file (editor_view .state .doc .toString ());
6768 is_contents_changed = false ;
6869 }}
6970 class =" pb-50vh"
Original file line number Diff line number Diff line change @@ -64,6 +64,9 @@ export async function add_new_note(
6464 is_directory : false ,
6565 children : [ ] ,
6666 } ) ;
67+ const node = subtree . find ( ( n ) => n . path === new_file_path ) ;
68+ if ( ! node ) throw new Error ( 'Failed to find the newly created note node.' ) ;
69+ return node ;
6770}
6871export async function add_new_folder (
6972 subtree : FileNode [ ] ,
You can’t perform that action at this time.
0 commit comments