File tree 4 files changed +41
-8
lines changed
4 files changed +41
-8
lines changed Original file line number Diff line number Diff line change 1
- import { findParentByClassName , getPositionByPlacement } from '../dom' ;
1
+ import {
2
+ findParentByClassName ,
3
+ getPositionByPlacement ,
4
+ getElementClientCenter ,
5
+ } from '../dom' ;
2
6
3
7
describe ( 'Test functions in dom.ts' , ( ) => {
4
8
test ( 'The getPositionByPlacement function' , ( ) => {
@@ -47,4 +51,23 @@ describe('Test functions in dom.ts', () => {
47
51
findParentByClassName ( 1 , 'test' ) ;
48
52
} ) . toThrowError ( ) ;
49
53
} ) ;
54
+
55
+ test ( 'The getElementClientCenter function' , ( ) => {
56
+ const elem = document . createElement ( 'div' ) ;
57
+ const domRect = {
58
+ x : 10 ,
59
+ y : 10 ,
60
+ width : 10 ,
61
+ height : 10 ,
62
+ top : 10 ,
63
+ right : 10 ,
64
+ bottom : 10 ,
65
+ left : 10 ,
66
+ } as DOMRect ;
67
+ elem . getBoundingClientRect = jest . fn ( ( ) => domRect ) ;
68
+
69
+ const center = getElementClientCenter ( elem ) ;
70
+ expect ( center . x ) . toEqual ( 15 ) ;
71
+ expect ( center . y ) . toEqual ( 15 ) ;
72
+ } ) ;
50
73
} ) ;
Original file line number Diff line number Diff line change 1
- import { normalizeFlattedObject , colorLightOrDark } from '../utils' ;
1
+ import {
2
+ normalizeFlattedObject ,
3
+ colorLightOrDark ,
4
+ cloneInstance ,
5
+ } from '../utils' ;
2
6
3
7
describe ( 'Test Utils' , ( ) => {
4
8
test ( 'The normalizeFlattedObject function' , ( ) => {
@@ -40,4 +44,10 @@ describe('Test Utils', () => {
40
44
expect ( colorLightOrDark ( '#000' ) ) . toBe ( 'dark' ) ;
41
45
expect ( colorLightOrDark ( 'rgb(255,255,255)' ) ) . toBe ( 'light' ) ;
42
46
} ) ;
47
+
48
+ test ( 'The cloneInstance function' , ( ) => {
49
+ const obj1 = { name : 'test' } ;
50
+ const obj2 = cloneInstance ( obj1 ) ;
51
+ expect ( obj1 . name ) . toEqual ( obj2 . name ) ;
52
+ } ) ;
43
53
} ) ;
Original file line number Diff line number Diff line change @@ -48,6 +48,10 @@ export class MoleculeProvider extends Component<IMoleculeProps> {
48
48
}
49
49
50
50
componentDidMount ( ) {
51
+ // The monacoService needs to be initialized each time the MoleculeProvider is loaded to
52
+ // ensure that Keybinding events can be bound to the latest dom.
53
+ this . monacoService . initWorkspace ( this . layoutService . container ! ) ;
54
+
51
55
if ( ! this . extensionService . isLoaded ( ) ) {
52
56
this . initialize ( ) ;
53
57
}
@@ -59,9 +63,6 @@ export class MoleculeProvider extends Component<IMoleculeProps> {
59
63
const [ languages , restExts ] =
60
64
this . extensionService . splitLanguagesExts ( extensions ) ;
61
65
62
- // First to init the monacoService
63
- this . monacoService . initWorkspace ( this . layoutService . container ! ) ;
64
-
65
66
// Molecule should load the language extensions first to
66
67
// ensure that the custom language extensions is registered in localeService
67
68
this . initLocaleExts ( languages ) ;
Original file line number Diff line number Diff line change @@ -88,9 +88,8 @@ export class LayoutService
88
88
}
89
89
90
90
public get container ( ) {
91
- if ( ! this . _container ) {
92
- this . _container = document . getElementById ( ID_APP ) || document . body ;
93
- }
91
+ // Make sure to get the latest dom element.
92
+ this . _container = document . getElementById ( ID_APP ) || document . body ;
94
93
return this . _container ;
95
94
}
96
95
You can’t perform that action at this time.
0 commit comments