@@ -8,7 +8,7 @@ export class BudgetCodeWriter {
88 private values : TableStoreValues ;
99 private isWriting = false ;
1010
11- constructor ( ) {
11+ constructor ( protected readonly app : App ) {
1212 this . values = {
1313 categories : new Map ( ) ,
1414 rows : new Map ( ) ,
@@ -109,16 +109,15 @@ export class BudgetCodeWriter {
109109 }
110110
111111 private async updateFileContent (
112- app : App ,
113112 sectionInfo : MarkdownSectionInformation ,
114113 formattedCode : string
115114 ) : Promise < void > {
116- const activeFile = app . workspace . getActiveFile ( ) ;
115+ const activeFile = this . app . workspace . getActiveFile ( ) ;
117116 if ( ! activeFile ) {
118117 throw new Error ( 'Active file not found' ) ;
119118 }
120119
121- const editor = await app . vault . read ( activeFile ) ;
120+ const editor = await this . app . vault . read ( activeFile ) ;
122121 const lines = editor . split ( '\n' ) ;
123122 const currentSection = lines . slice ( sectionInfo . lineStart , sectionInfo . lineEnd + 1 ) ;
124123
@@ -133,7 +132,7 @@ export class BudgetCodeWriter {
133132 // Make sure we're only using exactly one closing code block
134133 const newContent = [ codeBlockStart , formattedCode . trim ( ) , '```' ] . join ( '\n' ) ;
135134
136- const view = app . workspace . getActiveViewOfType ( MarkdownView ) ;
135+ const view = this . app . workspace . getActiveViewOfType ( MarkdownView ) ;
137136 if ( ! view ) {
138137 throw new Error ( 'Active markdown view not found' ) ;
139138 }
@@ -147,8 +146,7 @@ export class BudgetCodeWriter {
147146
148147 public async write (
149148 values : TableStoreValues ,
150- sectionInfo : MarkdownSectionInformation ,
151- app : App
149+ sectionInfo : MarkdownSectionInformation
152150 ) : Promise < void > {
153151 if ( this . isWriting ) {
154152 logWarning ( 'Writing is already in progress, skipping' ) ;
@@ -164,7 +162,7 @@ export class BudgetCodeWriter {
164162 try {
165163 this . values = values ;
166164 const formattedCode = this . formatCode ( newCode ) ;
167- await this . updateFileContent ( app , sectionInfo , formattedCode ) ;
165+ await this . updateFileContent ( sectionInfo , formattedCode ) ;
168166 } catch ( error ) {
169167 logError ( 'Error writing to file' , error ) ;
170168 } finally {
0 commit comments