Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
ec351d2c
Commit
ec351d2c
authored
Jan 12, 2021
by
Denys Mishunov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing model's disposal
parent
9b5b4fe3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
26 deletions
+29
-26
app/assets/javascripts/editor/editor_lite.js
app/assets/javascripts/editor/editor_lite.js
+12
-8
spec/frontend/editor/editor_lite_spec.js
spec/frontend/editor/editor_lite_spec.js
+17
-18
No files found.
app/assets/javascripts/editor/editor_lite.js
View file @
ec351d2c
...
...
@@ -103,11 +103,11 @@ export default class EditorLite {
}
static
createEditorModel
({
blobPath
=
''
,
blobContent
=
''
,
originalBlobContent
=
null
,
blobGlobalId
=
uuids
()[
0
]
,
instance
=
null
,
blobPath
,
blobContent
,
originalBlobContent
,
blobGlobalId
,
instance
,
}
=
{})
{
if
(
!
instance
)
{
return
null
;
...
...
@@ -116,7 +116,7 @@ export default class EditorLite {
const
existingModel
=
monacoEditor
.
getModel
(
uriFilePath
);
const
model
=
existingModel
||
monacoEditor
.
createModel
(
blobContent
,
undefined
,
Uri
.
file
(
uriFilePath
));
if
(
originalBlobContent
===
null
)
{
if
(
!
originalBlobContent
)
{
instance
.
setModel
(
model
);
}
else
{
instance
.
setModel
({
...
...
@@ -124,6 +124,7 @@ export default class EditorLite {
modified
:
model
,
});
}
return
instance
.
getModel
();
}
/**
...
...
@@ -148,6 +149,7 @@ export default class EditorLite {
EditorLite
.
prepareInstance
(
el
);
let
instance
;
let
model
;
if
(
!
diff
)
{
instance
=
monacoEditor
.
create
(
el
,
{
...
...
@@ -155,7 +157,7 @@ export default class EditorLite {
...
instanceOptions
,
});
if
(
instanceOptions
.
model
!==
null
)
{
EditorLite
.
createEditorModel
({
blobGlobalId
,
blobPath
,
blobContent
,
instance
});
model
=
EditorLite
.
createEditorModel
({
blobGlobalId
,
blobPath
,
blobContent
,
instance
});
}
}
else
{
instance
=
monacoEditor
.
createDiffEditor
(
el
,
{
...
...
@@ -163,7 +165,7 @@ export default class EditorLite {
...
instanceOptions
,
});
if
(
instanceOptions
.
model
!==
null
)
{
EditorLite
.
createEditorModel
({
model
=
EditorLite
.
createEditorModel
({
blobGlobalId
,
originalBlobContent
,
blobPath
,
...
...
@@ -194,6 +196,8 @@ export default class EditorLite {
}
else
{
instanceModel
.
dispose
();
}
}
else
if
(
model
)
{
model
.
dispose
();
}
});
EditorLite
.
manageDefaultExtensions
(
instance
,
el
,
extensions
);
...
...
spec/frontend/editor/editor_lite_spec.js
View file @
ec351d2c
/* eslint-disable max-classes-per-file */
import
{
editor
as
monacoEditor
,
languages
as
monacoLanguages
,
Uri
}
from
'
monaco-editor
'
;
import
waitForPromises
from
'
helpers/wait_for_promises
'
;
import
Editor
from
'
~/editor/editor_lite
'
;
import
Editor
Lite
from
'
~/editor/editor_lite
'
;
import
{
EditorLiteExtension
}
from
'
~/editor/extensions/editor_lite_extension_base
'
;
import
{
DEFAULT_THEME
,
themes
}
from
'
~/ide/lib/themes
'
;
import
{
...
...
@@ -21,7 +21,7 @@ describe('Base editor', () => {
beforeEach
(()
=>
{
setFixtures
(
'
<div id="editor" data-editor-loading></div>
'
);
editorEl
=
document
.
getElementById
(
'
editor
'
);
editor
=
new
Editor
();
editor
=
new
Editor
Lite
();
});
afterEach
(()
=>
{
...
...
@@ -148,16 +148,14 @@ describe('Base editor', () => {
editorEl2
=
document
.
getElementById
(
'
editor2
'
);
inst1Args
=
{
el
:
editorEl1
,
blobGlobalId
,
};
inst2Args
=
{
el
:
editorEl2
,
blobContent
,
blobPath
,
blobGlobalId
,
};
editor
=
new
Editor
();
editor
=
new
Editor
Lite
();
instanceSpy
=
jest
.
spyOn
(
monacoEditor
,
'
create
'
);
});
...
...
@@ -188,7 +186,7 @@ describe('Base editor', () => {
});
it
(
'
shares global editor options among all instances
'
,
()
=>
{
editor
=
new
Editor
({
editor
=
new
Editor
Lite
({
readOnly
:
true
,
});
...
...
@@ -200,7 +198,7 @@ describe('Base editor', () => {
});
it
(
'
allows overriding editor options on the instance level
'
,
()
=>
{
editor
=
new
Editor
({
editor
=
new
Editor
Lite
({
readOnly
:
true
,
});
inst1
=
editor
.
createInstance
({
...
...
@@ -423,19 +421,20 @@ describe('Base editor', () => {
el
:
editorEl
,
blobPath
,
blobContent
,
blobGlobalId
,
extensions
,
});
};
beforeEach
(()
=>
{
editorExtensionSpy
=
jest
.
spyOn
(
Editor
,
'
pushToImportsArray
'
).
mockImplementation
((
arr
)
=>
{
arr
.
push
(
Promise
.
resolve
({
default
:
{},
}),
);
});
editorExtensionSpy
=
jest
.
spyOn
(
EditorLite
,
'
pushToImportsArray
'
)
.
mockImplementation
((
arr
)
=>
{
arr
.
push
(
Promise
.
resolve
({
default
:
{},
}),
);
});
});
it
.
each
([
undefined
,
[],
[
''
],
''
])(
...
...
@@ -547,7 +546,7 @@ describe('Base editor', () => {
it
(
'
sets default syntax highlighting theme
'
,
()
=>
{
const
expectedTheme
=
themes
.
find
((
t
)
=>
t
.
name
===
DEFAULT_THEME
);
editor
=
new
Editor
();
editor
=
new
Editor
Lite
();
expect
(
themeDefineSpy
).
toHaveBeenCalledWith
(
DEFAULT_THEME
,
expectedTheme
.
data
);
expect
(
themeSetSpy
).
toHaveBeenCalledWith
(
DEFAULT_THEME
);
...
...
@@ -559,7 +558,7 @@ describe('Base editor', () => {
expect
(
expectedTheme
.
name
).
not
.
toBe
(
DEFAULT_THEME
);
window
.
gon
.
user_color_scheme
=
expectedTheme
.
name
;
editor
=
new
Editor
();
editor
=
new
Editor
Lite
();
expect
(
themeDefineSpy
).
toHaveBeenCalledWith
(
expectedTheme
.
name
,
expectedTheme
.
data
);
expect
(
themeSetSpy
).
toHaveBeenCalledWith
(
expectedTheme
.
name
);
...
...
@@ -570,7 +569,7 @@ describe('Base editor', () => {
const
nonExistentTheme
=
{
name
};
window
.
gon
.
user_color_scheme
=
nonExistentTheme
.
name
;
editor
=
new
Editor
();
editor
=
new
Editor
Lite
();
expect
(
themeDefineSpy
).
not
.
toHaveBeenCalled
();
expect
(
themeSetSpy
).
toHaveBeenCalledWith
(
DEFAULT_THEME
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment