@@ -13,7 +13,7 @@ import type { GitDiff } from "@/features/version-control/git/types/git";
1313import { useSessionStore } from "@/stores/session-store" ;
1414import { createSelectors } from "@/utils/zustand-selectors" ;
1515
16- interface Buffer {
16+ export interface Buffer {
1717 id : string ;
1818 path : string ;
1919 name : string ;
@@ -24,11 +24,14 @@ interface Buffer {
2424 isImage : boolean ;
2525 isSQLite : boolean ;
2626 isDiff : boolean ;
27+ isMarkdownPreview : boolean ;
2728 isExternalEditor : boolean ;
2829 isActive : boolean ;
2930 language ?: string ; // File language for syntax highlighting and formatting
3031 // For diff buffers, store the parsed diff data (single or multi-file)
3132 diffData ?: GitDiff | MultiFileDiff ;
33+ // For markdown preview buffers, store the source file path
34+ sourceFilePath ?: string ;
3235 // For external editor buffers, store the terminal connection ID
3336 terminalConnectionId ?: string ;
3437 // Cached syntax highlighting tokens
@@ -71,6 +74,8 @@ interface BufferActions {
7174 isDiff ?: boolean ,
7275 isVirtual ?: boolean ,
7376 diffData ?: GitDiff | MultiFileDiff ,
77+ isMarkdownPreview ?: boolean ,
78+ sourceFilePath ?: string ,
7479 ) => string ;
7580 openExternalEditorBuffer : ( path : string , name : string , terminalConnectionId : string ) => string ;
7681 closeBuffer : ( bufferId : string ) => void ;
@@ -126,7 +131,15 @@ const saveSessionToStore = (buffers: Buffer[], activeBufferId: string | null) =>
126131
127132 // Only save real files, not virtual/diff/image/sqlite/external editor buffers
128133 const persistableBuffers = buffers
129- . filter ( ( b ) => ! b . isVirtual && ! b . isDiff && ! b . isImage && ! b . isSQLite && ! b . isExternalEditor )
134+ . filter (
135+ ( b ) =>
136+ ! b . isVirtual &&
137+ ! b . isDiff &&
138+ ! b . isImage &&
139+ ! b . isSQLite &&
140+ ! b . isMarkdownPreview &&
141+ ! b . isExternalEditor ,
142+ )
130143 . map ( ( b ) => ( {
131144 path : b . path ,
132145 name : b . name ,
@@ -141,6 +154,7 @@ const saveSessionToStore = (buffers: Buffer[], activeBufferId: string | null) =>
141154 ! activeBuffer . isDiff &&
142155 ! activeBuffer . isImage &&
143156 ! activeBuffer . isSQLite &&
157+ ! activeBuffer . isMarkdownPreview &&
144158 ! activeBuffer . isExternalEditor
145159 ? activeBuffer . path
146160 : null ;
@@ -167,6 +181,8 @@ export const useBufferStore = createSelectors(
167181 isDiff = false ,
168182 isVirtual = false ,
169183 diffData ?: GitDiff | MultiFileDiff ,
184+ isMarkdownPreview = false ,
185+ sourceFilePath ?: string ,
170186 ) => {
171187 const { buffers, maxOpenTabs } = get ( ) ;
172188
@@ -202,10 +218,12 @@ export const useBufferStore = createSelectors(
202218 isImage,
203219 isSQLite,
204220 isDiff,
221+ isMarkdownPreview,
205222 isExternalEditor : false ,
206223 isActive : true ,
207224 language : detectLanguageFromFileName ( name ) ,
208225 diffData,
226+ sourceFilePath,
209227 tokens : [ ] ,
210228 } ;
211229
@@ -214,8 +232,8 @@ export const useBufferStore = createSelectors(
214232 state . activeBufferId = newBuffer . id ;
215233 } ) ;
216234
217- // Track in recent files (only for real files, not virtual/diff buffers)
218- if ( ! isVirtual && ! isDiff && ! isImage && ! isSQLite ) {
235+ // Track in recent files (only for real files, not virtual/diff/markdown preview buffers)
236+ if ( ! isVirtual && ! isDiff && ! isImage && ! isSQLite && ! isMarkdownPreview ) {
219237 useRecentFilesStore . getState ( ) . addOrUpdateRecentFile ( path , name ) ;
220238
221239 // Check if extension is available and start LSP or prompt installation
@@ -333,6 +351,7 @@ export const useBufferStore = createSelectors(
333351 isImage : false ,
334352 isSQLite : false ,
335353 isDiff : false ,
354+ isMarkdownPreview : false ,
336355 isExternalEditor : true ,
337356 isActive : true ,
338357 language : detectLanguageFromFileName ( name ) ,
@@ -392,6 +411,7 @@ export const useBufferStore = createSelectors(
392411 ! closedBuffer . isDiff &&
393412 ! closedBuffer . isImage &&
394413 ! closedBuffer . isSQLite &&
414+ ! closedBuffer . isMarkdownPreview &&
395415 ! closedBuffer . isExternalEditor
396416 ) {
397417 // Stop LSP for this file in background (don't block buffer closing)
@@ -690,7 +710,13 @@ export const useBufferStore = createSelectors(
690710
691711 reloadBufferFromDisk : async ( bufferId : string ) : Promise < void > => {
692712 const buffer = get ( ) . buffers . find ( ( b ) => b . id === bufferId ) ;
693- if ( ! buffer || buffer . isVirtual || buffer . isImage || buffer . isSQLite ) {
713+ if (
714+ ! buffer ||
715+ buffer . isVirtual ||
716+ buffer . isImage ||
717+ buffer . isSQLite ||
718+ buffer . isMarkdownPreview
719+ ) {
694720 return ;
695721 }
696722
0 commit comments