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
bdff7e4e
Commit
bdff7e4e
authored
Mar 22, 2023
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
meta key for go to file
parent
71df46a8
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
3 deletions
+25
-3
isMetaKey.tsx
lib/isMetaKey.tsx
+3
-0
CodeEditor.tsx
ui/shared/monaco/CodeEditor.tsx
+21
-2
addFileImportDecorations.ts
ui/shared/monaco/utils/addFileImportDecorations.ts
+1
-1
No files found.
lib/isMetaKey.tsx
0 → 100644
View file @
bdff7e4e
export
default
function
isMetaKey
(
event
:
React
.
KeyboardEvent
)
{
return
event
.
metaKey
||
event
.
getModifierState
(
'
Meta
'
)
||
event
.
getModifierState
(
'
OS
'
);
}
ui/shared/monaco/CodeEditor.tsx
View file @
bdff7e4e
...
...
@@ -9,6 +9,7 @@ import type { File, Monaco } from './types';
import
useClientRect
from
'
lib/hooks/useClientRect
'
;
import
useIsMobile
from
'
lib/hooks/useIsMobile
'
;
import
isMetaKey
from
'
lib/isMetaKey
'
;
import
CodeEditorBreadcrumbs
from
'
./CodeEditorBreadcrumbs
'
;
import
CodeEditorLoading
from
'
./CodeEditorLoading
'
;
...
...
@@ -40,6 +41,7 @@ const CodeEditor = ({ data }: Props) => {
const
[
instance
,
setInstance
]
=
React
.
useState
<
Monaco
|
undefined
>
();
const
[
index
,
setIndex
]
=
React
.
useState
(
0
);
const
[
tabs
,
setTabs
]
=
React
.
useState
([
data
[
index
].
file_path
]);
const
[
isMetaPressed
,
setIsMetaPressed
]
=
React
.
useState
(
false
);
const
editorRef
=
React
.
useRef
<
monaco
.
editor
.
IStandaloneCodeEditor
>
();
const
[
containerRect
,
containerNodeRef
]
=
useClientRect
<
HTMLDivElement
>
();
...
...
@@ -81,6 +83,7 @@ const CodeEditor = ({ data }: Props) => {
editorRef
.
current
?.
revealLineInCenter
(
lineNumber
);
},
0
);
}
editorRef
.
current
?.
focus
();
},
[
data
]);
const
handleTabSelect
=
React
.
useCallback
((
path
:
string
)
=>
{
...
...
@@ -109,6 +112,10 @@ const CodeEditor = ({ data }: Props) => {
},
[
data
,
index
]);
const
handleClick
=
React
.
useCallback
((
event
:
React
.
MouseEvent
)
=>
{
if
(
!
isMetaPressed
&&
!
isMobile
)
{
return
;
}
const
target
=
event
.
target
as
HTMLSpanElement
;
const
isImportLink
=
target
.
classList
.
contains
(
'
import-link
'
);
if
(
isImportLink
)
{
...
...
@@ -116,10 +123,19 @@ const CodeEditor = ({ data }: Props) => {
const
fullPath
=
getFullPathOfImportedFile
(
data
[
index
].
file_path
,
path
);
const
fileIndex
=
data
.
findIndex
((
file
)
=>
file
.
file_path
===
fullPath
);
if
(
fileIndex
>
-
1
)
{
event
.
stopPropagation
();
handleSelectFile
(
fileIndex
);
}
}
},
[
data
,
handleSelectFile
,
index
]);
},
[
data
,
handleSelectFile
,
index
,
isMetaPressed
,
isMobile
]);
const
handleKeyDown
=
React
.
useCallback
((
event
:
React
.
KeyboardEvent
)
=>
{
isMetaKey
(
event
)
&&
setIsMetaPressed
(
true
);
},
[]);
const
handleKeyUp
=
React
.
useCallback
(()
=>
{
setIsMetaPressed
(
false
);
},
[]);
const
containerSx
:
SystemStyleObject
=
React
.
useMemo
(()
=>
({
'
.editor-container
'
:
{
...
...
@@ -132,7 +148,7 @@ const CodeEditor = ({ data }: Props) => {
'
.highlight
'
:
{
backgroundColor
:
themeColors
[
'
custom.findMatchHighlightBackground
'
],
},
'
.import-link
'
:
{
'
&&.meta-pressed
.import-link
'
:
{
_hover
:
{
color
:
themeColors
[
'
custom.fileLink.hoverForeground
'
],
textDecoration
:
'
underline
'
,
...
...
@@ -158,6 +174,7 @@ const CodeEditor = ({ data }: Props) => {
return
(
<
Flex
className=
{
isMetaPressed
?
'
meta-pressed
'
:
undefined
}
overflow=
"hidden"
borderRadius=
"md"
width=
"100%"
...
...
@@ -166,6 +183,8 @@ const CodeEditor = ({ data }: Props) => {
ref=
{
containerNodeRef
}
sx=
{
containerSx
}
onClick=
{
handleClick
}
onKeyDown=
{
handleKeyDown
}
onKeyUp=
{
handleKeyUp
}
>
<
Box
flexGrow=
{
1
}
>
<
CodeEditorTabs
tabs=
{
tabs
}
activeTab=
{
data
[
index
].
file_path
}
onTabSelect=
{
handleTabSelect
}
onTabClose=
{
handleTabClose
}
/>
...
...
ui/shared/monaco/utils/addFileImportDecorations.ts
View file @
bdff7e4e
...
...
@@ -11,7 +11,7 @@ export default function addFileImportDecorations(model: monaco.editor.ITextModel
options
:
{
inlineClassName
:
'
import-link
'
,
hoverMessage
:
{
value
:
'
Click to open file
'
,
value
:
'
C
md/Win + c
lick to open file
'
,
},
},
}));
...
...
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