@@ -27,8 +27,6 @@ interface VSCodeMessage {
2727function WebviewEditor ( ) {
2828 const [ isReady , setIsReady ] = useState ( false ) ;
2929 const isLoadingFromFile = useRef ( false ) ;
30- const saveTimeoutRef = useRef < NodeJS . Timeout | null > ( null ) ;
31- const commandTriggerRef = useRef < string | null > ( null ) ;
3230
3331 // Get store methods
3432 const getRoadmapData = useEditorStore ( state => state . getRoadmapData ) ;
@@ -90,6 +88,17 @@ function WebviewEditor() {
9088 return shiftCommands . includes ( command ) ;
9189 } ;
9290
91+ // Handle explicit save command
92+ const handleSave = ( ) => {
93+ if ( ! isLoadingFromFile . current ) {
94+ const data = getRoadmapData ( ) ;
95+ vscode . postMessage ( {
96+ type : 'save' ,
97+ content : data ,
98+ } ) ;
99+ }
100+ } ;
101+
93102 // Handle messages from extension
94103 useEffect ( ( ) => {
95104 const messageHandler = ( event : MessageEvent < VSCodeMessage > ) => {
@@ -98,7 +107,11 @@ function WebviewEditor() {
98107 case 'command' :
99108 // Handle command from VS Code
100109 if ( message . command ) {
101- handleVSCodeCommand ( message . command ) ;
110+ if ( message . command === 'save' ) {
111+ handleSave ( ) ;
112+ } else {
113+ handleVSCodeCommand ( message . command ) ;
114+ }
102115 }
103116 break ;
104117 case 'update' :
@@ -148,44 +161,8 @@ function WebviewEditor() {
148161
149162 return ( ) => {
150163 window . removeEventListener ( 'message' , messageHandler ) ;
151- if ( saveTimeoutRef . current ) {
152- clearTimeout ( saveTimeoutRef . current ) ;
153- }
154- } ;
155- } , [ loadRoadmapData ] ) ;
156-
157- // Auto-save changes to the document (debounced)
158- useEffect ( ( ) => {
159- if ( ! isReady ) return ;
160-
161- // Subscribe to store changes
162- const unsubscribe = useEditorStore . subscribe ( ( ) => {
163- // Don't save if we're loading from file
164- if ( isLoadingFromFile . current ) {
165- return ;
166- }
167-
168- // Debounce saves to avoid too many updates
169- if ( saveTimeoutRef . current ) {
170- clearTimeout ( saveTimeoutRef . current ) ;
171- }
172-
173- saveTimeoutRef . current = setTimeout ( ( ) => {
174- const data = getRoadmapData ( ) ;
175- vscode . postMessage ( {
176- type : 'save' ,
177- content : data ,
178- } ) ;
179- } , 500 ) ; // Wait 500ms after last change before saving
180- } ) ;
181-
182- return ( ) => {
183- unsubscribe ( ) ;
184- if ( saveTimeoutRef . current ) {
185- clearTimeout ( saveTimeoutRef . current ) ;
186- }
187164 } ;
188- } , [ isReady , getRoadmapData ] ) ;
165+ } , [ loadRoadmapData , getRoadmapData ] ) ;
189166
190167 if ( ! isReady ) {
191168 return < div style = { { padding : '20px' } } > Loading editor...</ div > ;
0 commit comments