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
5a9adb66
Commit
5a9adb66
authored
Feb 07, 2022
by
Jacques
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix line selection in the refactored blob viewer
Fixes the line selection on the refactored blob viewer
parent
3d6de92f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
3 deletions
+31
-3
app/assets/javascripts/vue_shared/components/blob_viewers/simple_viewer.vue
...ipts/vue_shared/components/blob_viewers/simple_viewer.vue
+12
-2
spec/frontend/vue_shared/components/blob_viewers/simple_viewer_spec.js
.../vue_shared/components/blob_viewers/simple_viewer_spec.js
+19
-1
No files found.
app/assets/javascripts/vue_shared/components/blob_viewers/simple_viewer.vue
View file @
5a9adb66
<
script
>
import
{
GlIcon
,
GlSafeHtmlDirective
}
from
'
@gitlab/ui
'
;
import
glFeatureFlagsMixin
from
'
~/vue_shared/mixins/gl_feature_flags_mixin
'
;
import
LineHighlighter
from
'
~/blob/line_highlighter
'
;
import
{
HIGHLIGHT_CLASS_NAME
}
from
'
./constants
'
;
import
ViewerMixin
from
'
./mixins
'
;
...
...
@@ -20,13 +21,22 @@ export default {
};
},
computed
:
{
refactorBlobViewerEnabled
()
{
return
this
.
glFeatures
.
refactorBlobViewer
;
},
lineNumbers
()
{
return
this
.
content
.
split
(
'
\n
'
).
length
;
},
},
mounted
()
{
const
{
hash
}
=
window
.
location
;
if
(
hash
)
this
.
scrollToLine
(
hash
,
true
);
if
(
this
.
refactorBlobViewerEnabled
)
{
// This line will be removed once we start using highlight.js on the frontend (https://gitlab.com/groups/gitlab-org/-/epics/7146)
new
LineHighlighter
();
// eslint-disable-line no-new
}
else
{
const
{
hash
}
=
window
.
location
;
if
(
hash
)
this
.
scrollToLine
(
hash
,
true
);
}
},
methods
:
{
scrollToLine
(
hash
,
scroll
=
false
)
{
...
...
spec/frontend/vue_shared/components/blob_viewers/simple_viewer_spec.js
View file @
5a9adb66
...
...
@@ -2,16 +2,20 @@ import { shallowMount } from '@vue/test-utils';
import
{
nextTick
}
from
'
vue
'
;
import
{
HIGHLIGHT_CLASS_NAME
}
from
'
~/vue_shared/components/blob_viewers/constants
'
;
import
SimpleViewer
from
'
~/vue_shared/components/blob_viewers/simple_viewer.vue
'
;
import
LineHighlighter
from
'
~/blob/line_highlighter
'
;
jest
.
mock
(
'
~/blob/line_highlighter
'
);
describe
(
'
Blob Simple Viewer component
'
,
()
=>
{
let
wrapper
;
const
contentMock
=
`<span id="LC1">First</span>\n<span id="LC2">Second</span>\n<span id="LC3">Third</span>`
;
const
blobHash
=
'
foo-bar
'
;
function
createComponent
(
content
=
contentMock
,
isRawContent
=
false
)
{
function
createComponent
(
content
=
contentMock
,
isRawContent
=
false
,
glFeatures
=
{}
)
{
wrapper
=
shallowMount
(
SimpleViewer
,
{
provide
:
{
blobHash
,
glFeatures
,
},
propsData
:
{
content
,
...
...
@@ -26,6 +30,20 @@ describe('Blob Simple Viewer component', () => {
wrapper
.
destroy
();
});
describe
(
'
refactorBlobViewer feature flag
'
,
()
=>
{
it
(
'
loads the LineHighlighter if refactorBlobViewer is enabled
'
,
()
=>
{
createComponent
(
''
,
false
,
{
refactorBlobViewer
:
true
});
expect
(
LineHighlighter
).
toHaveBeenCalled
();
});
it
(
'
does not load the LineHighlighter if refactorBlobViewer is disabled
'
,
()
=>
{
createComponent
(
''
,
false
,
{
refactorBlobViewer
:
false
});
expect
(
LineHighlighter
).
not
.
toHaveBeenCalled
();
});
});
it
(
'
does not fail if content is empty
'
,
()
=>
{
const
spy
=
jest
.
spyOn
(
window
.
console
,
'
error
'
);
createComponent
(
''
);
...
...
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