@@ -2,18 +2,26 @@ import Source from "gi://GtkSource";
2
2
import Gio from "gi://Gio" ;
3
3
import GLib from "gi://GLib" ;
4
4
5
- export default function Document ( { session, code_view, lang } ) {
6
- const { buffer } = code_view ;
7
- let handler_id = null ;
5
+ export default class Document {
6
+ handler_id = null ;
8
7
9
- const file = session . file . get_child ( lang . default_file ) ;
10
- const source_file = new Source . File ( {
11
- location : file ,
12
- } ) ;
8
+ constructor ( { session, code_view, lang } ) {
9
+ this . code_view = code_view ;
10
+ this . buffer = code_view . buffer ;
11
+ this . session = session ;
12
+ this . source_view = code_view . source_view ;
13
+
14
+ const file = session . file . get_child ( lang . default_file ) ;
15
+ this . file = file ;
16
+ this . source_file = new Source . File ( {
17
+ location : file ,
18
+ } ) ;
13
19
14
- start ( ) ;
20
+ this . start ( ) ;
21
+ }
15
22
16
- function save ( ) {
23
+ save ( ) {
24
+ const { source_file, buffer, session } = this ;
17
25
saveSourceBuffer ( { source_file, buffer } )
18
26
. catch ( console . error )
19
27
. finally ( ( ) => {
@@ -25,26 +33,27 @@ export default function Document({ session, code_view, lang }) {
25
33
} ) ;
26
34
}
27
35
28
- function start ( ) {
29
- stop ( ) ;
30
- handler_id = buffer . connect ( "modified-changed" , ( ) => {
31
- if ( ! buffer . get_modified ( ) ) return ;
32
- save ( ) ;
36
+ start ( ) {
37
+ this . stop ( ) ;
38
+ this . handler_id = this . buffer . connect ( "modified-changed" , ( ) => {
39
+ if ( ! this . buffer . get_modified ( ) ) return ;
40
+ this . save ( ) ;
33
41
} ) ;
34
42
}
35
43
36
- function stop ( ) {
37
- if ( handler_id !== null ) {
38
- buffer . disconnect ( handler_id ) ;
39
- handler_id = null ;
44
+ stop ( ) {
45
+ if ( this . handler_id !== null ) {
46
+ this . buffer . disconnect ( this . handler_id ) ;
47
+ this . handler_id = null ;
40
48
}
41
49
}
42
50
43
- function load ( ) {
44
- return loadSourceBuffer ( { source_file, buffer, lang } ) ;
51
+ load ( ) {
52
+ const { source_file, buffer } = this ;
53
+ return loadSourceBuffer ( { source_file, buffer } ) ;
45
54
}
46
55
47
- return { start , stop , save , code_view , file , load } ;
56
+ format ( ) { }
48
57
}
49
58
50
59
async function saveSourceBuffer ( { source_file, buffer } ) {
0 commit comments