Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
84fc5da9
Commit
84fc5da9
authored
Apr 07, 2023
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
named imports highlight
parent
2d8cd224
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
15 deletions
+34
-15
CodeEditor.tsx
ui/shared/monaco/CodeEditor.tsx
+13
-7
addFileImportDecorations.ts
ui/shared/monaco/utils/addFileImportDecorations.ts
+21
-8
No files found.
ui/shared/monaco/CodeEditor.tsx
View file @
84fc5da9
...
@@ -136,7 +136,15 @@ const CodeEditor = ({ data }: Props) => {
...
@@ -136,7 +136,15 @@ const CodeEditor = ({ data }: Props) => {
const
target
=
event
.
target
as
HTMLSpanElement
;
const
target
=
event
.
target
as
HTMLSpanElement
;
const
isImportLink
=
target
.
classList
.
contains
(
'
import-link
'
);
const
isImportLink
=
target
.
classList
.
contains
(
'
import-link
'
);
if
(
isImportLink
)
{
if
(
isImportLink
)
{
const
path
=
target
.
innerText
;
const
path
=
[
target
.
previousElementSibling
as
HTMLSpanElement
,
target
,
target
.
nextElementSibling
as
HTMLSpanElement
,
]
.
filter
((
element
)
=>
element
?.
classList
.
contains
(
'
import-link
'
))
.
map
((
element
:
HTMLSpanElement
)
=>
element
.
innerText
)
.
join
(
''
);
const
fullPath
=
getFullPathOfImportedFile
(
data
[
index
].
file_path
,
path
);
const
fullPath
=
getFullPathOfImportedFile
(
data
[
index
].
file_path
,
path
);
const
fileIndex
=
data
.
findIndex
((
file
)
=>
file
.
file_path
===
fullPath
);
const
fileIndex
=
data
.
findIndex
((
file
)
=>
file
.
file_path
===
fullPath
);
if
(
fileIndex
>
-
1
)
{
if
(
fileIndex
>
-
1
)
{
...
@@ -165,13 +173,11 @@ const CodeEditor = ({ data }: Props) => {
...
@@ -165,13 +173,11 @@ const CodeEditor = ({ data }: Props) => {
'
.highlight
'
:
{
'
.highlight
'
:
{
backgroundColor
:
themeColors
[
'
custom.findMatchHighlightBackground
'
],
backgroundColor
:
themeColors
[
'
custom.findMatchHighlightBackground
'
],
},
},
'
&&.meta-pressed .import-link
'
:
{
'
&&.meta-pressed .import-link:hover, &&.meta-pressed .import-link:hover + .import-link
'
:
{
_hover
:
{
color
:
themeColors
[
'
custom.fileLink.hoverForeground
'
],
color
:
themeColors
[
'
custom.fileLink.hoverForeground
'
],
textDecoration
:
'
underline
'
,
textDecoration
:
'
underline
'
,
cursor
:
'
pointer
'
,
cursor
:
'
pointer
'
,
},
},
},
}),
[
editorWidth
,
themeColors
]);
}),
[
editorWidth
,
themeColors
]);
if
(
data
.
length
===
1
)
{
if
(
data
.
length
===
1
)
{
...
...
ui/shared/monaco/utils/addFileImportDecorations.ts
View file @
84fc5da9
import
type
*
as
monaco
from
'
monaco-editor/esm/vs/editor/editor.api
'
;
import
type
*
as
monaco
from
'
monaco-editor/esm/vs/editor/editor.api
'
;
export
default
function
addFileImportDecorations
(
model
:
monaco
.
editor
.
ITextModel
)
{
export
default
function
addFileImportDecorations
(
model
:
monaco
.
editor
.
ITextModel
)
{
const
matches
=
model
.
findMatches
(
'
^import (
\'
|")((
\\
/|
\\
.)(
\\
w|
\\
.|
\\
/|-)+)(
\'
|")
'
,
false
,
true
,
false
,
null
,
true
);
const
options
:
monaco
.
editor
.
IModelDecorationOptions
=
{
const
decorations
:
Array
<
monaco
.
editor
.
IModelDeltaDecoration
>
=
matches
.
map
(({
range
})
=>
({
inlineClassName
:
'
import-link
'
,
hoverMessage
:
{
value
:
'
Cmd/Win + click to open file
'
,
},
};
const
regularImportMatches
=
model
.
findMatches
(
'
^import (
\'
|")((
\\
/|
\\
.).+)(
\'
|")
'
,
false
,
true
,
false
,
null
,
true
);
const
regularImportDecorations
:
Array
<
monaco
.
editor
.
IModelDeltaDecoration
>
=
regularImportMatches
.
map
(({
range
})
=>
({
range
:
{
range
:
{
...
range
,
...
range
,
startColumn
:
range
.
startColumn
+
8
,
startColumn
:
range
.
startColumn
+
8
,
endColumn
:
range
.
endColumn
-
1
,
endColumn
:
range
.
endColumn
-
1
,
},
},
options
:
{
options
,
inlineClassName
:
'
import-link
'
,
}));
hoverMessage
:
{
value
:
'
Cmd/Win + click to open file
'
,
const
namedImportMatches
=
model
.
findMatches
(
'
(^import
\\
{.+
\\
} from )(
\'
|")((
\\
/|
\\
.).+)(
\'
|")
'
,
false
,
true
,
false
,
null
,
true
);
},
const
namedImportDecorations
:
Array
<
monaco
.
editor
.
IModelDeltaDecoration
>
=
namedImportMatches
.
map
(({
range
,
matches
})
=>
({
range
:
{
...
range
,
startColumn
:
range
.
startColumn
+
(
Array
.
isArray
(
matches
)
?
matches
?.[
1
]?.
length
+
1
:
0
),
endColumn
:
range
.
endColumn
-
1
,
},
},
options
,
}));
}));
model
.
deltaDecorations
([],
decorations
);
model
.
deltaDecorations
([],
regularImportDecorations
.
concat
(
namedImportDecorations
));
}
}
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