This repository was archived by the owner on Dec 15, 2022. It is now read-only.
File tree 2 files changed +25
-2
lines changed
2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,10 @@ class SimpleFile {
19
19
return this . path
20
20
}
21
21
22
+ setPath ( path ) {
23
+ this . path = path
24
+ }
25
+
22
26
createReadStream ( ) {
23
27
return fs . createReadStream ( this . path )
24
28
}
@@ -149,9 +153,10 @@ describe('TextBuffer IO', () => {
149
153
150
154
describe ( '.save' , ( ) => {
151
155
let filePath
156
+ let tempDir
152
157
153
158
beforeEach ( ( ) => {
154
- const tempDir = temp . mkdirSync ( )
159
+ tempDir = temp . mkdirSync ( )
155
160
filePath = path . join ( tempDir , 'temp.txt' )
156
161
fs . writeFileSync ( filePath , '' )
157
162
buffer = new TextBuffer ( )
@@ -257,6 +262,17 @@ describe('TextBuffer IO', () => {
257
262
done ( )
258
263
} )
259
264
} )
265
+
266
+ it ( 'passes setPath to the custom File object' , ( done ) => {
267
+ const newPath = path . join ( tempDir , 'temp2.txt' )
268
+ buffer . setPath ( newPath )
269
+ buffer . setText ( 'test' )
270
+ buffer . save ( ) . then ( ( ) => {
271
+ expect ( fs . readFileSync ( newPath , 'utf8' ) ) . toEqual ( buffer . getText ( ) )
272
+ expect ( file . createWriteStream ) . toHaveBeenCalled ( )
273
+ done ( )
274
+ } )
275
+ } )
260
276
} )
261
277
} )
262
278
Original file line number Diff line number Diff line change @@ -585,6 +585,10 @@ class TextBuffer
585
585
# * `filePath` A {String} representing the new file path
586
586
setPath : (filePath ) ->
587
587
return if filePath is @ getPath ()
588
+ if @file ? and filePath
589
+ @file .setPath filePath
590
+ @ updateFilePath ()
591
+ return
588
592
@ setFile (new File (filePath) if filePath)
589
593
590
594
# Experimental: Set a custom {File} object as the buffer's backing store.
@@ -607,8 +611,11 @@ class TextBuffer
607
611
setFile : (file ) ->
608
612
return if file ? .getPath () is @ getPath ()
609
613
@file = file
614
+ @file ? .setEncoding ? (@ getEncoding ())
615
+ @ updateFilePath ()
616
+
617
+ updateFilePath : ->
610
618
if @file ?
611
- @file .setEncoding ? (@ getEncoding ())
612
619
@ subscribeToFile ()
613
620
@emitter .emit ' did-change-path' , @ getPath ()
614
621
You can’t perform that action at this time.
0 commit comments