1
+ import * as React from 'react' ;
1
2
import { EditorEvent , IEditorTab } from 'mo/model/workbench/editor' ;
2
3
import { Controller } from 'mo/react/controller' ;
3
- import { editorService } from 'mo/services' ;
4
+ import { editorService , statusBarService } from 'mo/services' ;
4
5
import { singleton } from 'tsyringe' ;
6
+ import * as monaco from 'monaco-editor' ;
7
+ import { editorLineColumnItem } from './statusBar' ;
8
+
5
9
export interface IEditorController {
6
10
groupSplitPos ?: string [ ] ;
7
11
onCloseAll ?: ( group : number ) => void ;
@@ -14,10 +18,11 @@ export interface IEditorController {
14
18
onTabContextMenu ?: ( e : React . MouseEvent , tab : IEditorTab ) => void ;
15
19
}
16
20
21
+ type IStandaloneCodeEditor = monaco . editor . IStandaloneCodeEditor ;
22
+
17
23
@singleton ( )
18
24
export class EditorController extends Controller implements IEditorController {
19
- private editorInstance ;
20
- // Group Pos locate here temporary, we can move it to state or localStorage if you need
25
+ // Group Pos locate here temporary, we can move it to state or localStorage in future.
21
26
public groupSplitPos : string [ ] = [ ] ;
22
27
23
28
constructor ( ) {
@@ -51,7 +56,7 @@ export class EditorController extends Controller implements IEditorController {
51
56
} ;
52
57
53
58
public onUpdateEditorIns = (
54
- editorInstance : IStandaloneCodeEditor ,
59
+ editorInstance : monaco . editor . IStandaloneCodeEditor ,
55
60
groupId : number
56
61
) => {
57
62
if ( editorInstance ) {
@@ -79,7 +84,6 @@ export class EditorController extends Controller implements IEditorController {
79
84
editorInstance : IStandaloneCodeEditor ,
80
85
groupId : number
81
86
) {
82
- this . editorInstance = editorInstance ;
83
87
if ( editorInstance ) {
84
88
editorInstance . onDidChangeModelContent ( ( event : any ) => {
85
89
const newValue = editorInstance . getValue ( ) ;
@@ -97,19 +101,47 @@ export class EditorController extends Controller implements IEditorController {
97
101
} ,
98
102
groupId
99
103
) ;
104
+ this . updateStatusBar ( editorInstance ) ;
100
105
}
101
106
} ) ;
102
107
103
108
editorInstance . onDidFocusEditorText ( ( ) => {
104
109
const group = editorService . getGroupById ( groupId ) ;
105
110
if ( group ?. tab ! . id ) {
106
111
editorService . setActive ( groupId , group . tab . id ) ;
112
+ this . updateEditorLineColumnInfo ( editorInstance ) ;
107
113
}
108
114
} ) ;
115
+
116
+ editorInstance . onDidChangeCursorSelection ( ( ) => {
117
+ this . updateEditorLineColumnInfo ( editorInstance ) ;
118
+ } ) ;
109
119
}
110
120
}
111
121
112
- getEditorInstance ( ) {
113
- return this . editorInstance ;
122
+ private updateStatusBar ( editorInstance : IStandaloneCodeEditor ) {
123
+ if ( editorInstance ) {
124
+ const model :
125
+ | monaco . editor . ITextModel
126
+ | null
127
+ | undefined = editorInstance ?. getModel ( ) ;
128
+ const decorations = model ?. getAllDecorations ( ) ;
129
+ console . log ( 'decorations:' , decorations ) ;
130
+ }
131
+ }
132
+
133
+ public updateEditorLineColumnInfo ( editorInstance : IStandaloneCodeEditor ) {
134
+ if ( editorInstance ) {
135
+ const position = editorInstance . getPosition ( ) ;
136
+ statusBarService . updateItem (
137
+ Object . assign ( editorLineColumnItem , {
138
+ render : ( ) => (
139
+ < span >
140
+ Ln { position ?. lineNumber } , Col { position ?. column }
141
+ </ span >
142
+ ) ,
143
+ } )
144
+ ) ;
145
+ }
114
146
}
115
147
}
0 commit comments