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
f3329841
Commit
f3329841
authored
Mar 16, 2023
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simple tabs
parent
0f94a75f
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
140 additions
and
3 deletions
+140
-3
CodeEditor.tsx
ui/shared/monaco/CodeEditor.tsx
+31
-2
CodeEditorSearchSection.tsx
ui/shared/monaco/CodeEditorSearchSection.tsx
+2
-1
CodeEditorTab.tsx
ui/shared/monaco/CodeEditorTab.tsx
+67
-0
CodeEditorTabs.tsx
ui/shared/monaco/CodeEditorTabs.tsx
+35
-0
getFileName.ts
ui/shared/monaco/utils/getFileName.ts
+5
-0
No files found.
ui/shared/monaco/CodeEditor.tsx
View file @
f3329841
...
...
@@ -6,6 +6,7 @@ import React from 'react';
import
type
{
File
,
Monaco
}
from
'
./types
'
;
import
CodeEditorSideBar
from
'
./CodeEditorSideBar
'
;
import
CodeEditorTabs
from
'
./CodeEditorTabs
'
;
import
*
as
themes
from
'
./utils/themes
'
;
const
EDITOR_OPTIONS
=
{
...
...
@@ -20,6 +21,7 @@ interface Props {
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
editorRef
=
React
.
useRef
<
monaco
.
editor
.
IStandaloneCodeEditor
>
();
const
{
colorMode
}
=
useColorMode
();
...
...
@@ -45,16 +47,43 @@ const CodeEditor = ({ data }: Props) => {
const
handleSelectFile
=
React
.
useCallback
((
index
:
number
,
lineNumber
?:
number
)
=>
{
setIndex
(
index
);
setTabs
((
prev
)
=>
prev
.
some
((
item
)
=>
item
===
data
[
index
].
file_path
)
?
prev
:
([
...
prev
,
data
[
index
].
file_path
]));
if
(
lineNumber
!==
undefined
&&
!
Object
.
is
(
lineNumber
,
NaN
))
{
window
.
setTimeout
(()
=>
{
editorRef
.
current
?.
revealLineInCenter
(
lineNumber
);
},
0
);
}
},
[]);
},
[
data
]);
const
handleTabSelect
=
React
.
useCallback
((
path
:
string
)
=>
{
const
index
=
data
.
findIndex
((
item
)
=>
item
.
file_path
===
path
);
if
(
index
>
-
1
)
{
setIndex
(
index
);
}
},
[
data
]);
const
handleTabClose
=
React
.
useCallback
((
path
:
string
)
=>
{
setTabs
((
prev
)
=>
{
if
(
prev
.
length
>
1
)
{
const
tabIndex
=
prev
.
findIndex
((
item
)
=>
item
===
path
);
const
isActive
=
data
[
index
].
file_path
===
path
;
if
(
isActive
)
{
const
nextActiveIndex
=
data
.
findIndex
((
item
)
=>
item
.
file_path
===
prev
[
Math
.
max
(
0
,
tabIndex
-
1
)]);
setIndex
(
nextActiveIndex
);
}
return
prev
.
filter
((
item
)
=>
item
!==
path
);
}
return
prev
;
});
},
[
data
,
index
]);
return
(
<
Flex
overflow=
"hidden"
borderRadius=
"md"
height=
"5
0
0px"
>
<
Flex
overflow=
"hidden"
borderRadius=
"md"
height=
"5
4
0px"
>
<
Box
flexGrow=
{
1
}
>
<
CodeEditorTabs
tabs=
{
tabs
}
activeTab=
{
data
[
index
].
file_path
}
onTabSelect=
{
handleTabSelect
}
onTabClose=
{
handleTabClose
}
/>
<
MonacoEditor
language=
"sol"
path=
{
data
[
index
].
file_path
}
...
...
ui/shared/monaco/CodeEditorSearchSection.tsx
View file @
f3329841
...
...
@@ -4,6 +4,7 @@ import React from 'react';
import
type
{
SearchResult
}
from
'
./types
'
;
import
CodeEditorSearchResultItem
from
'
./CodeEditorSearchResultItem
'
;
import
getFileName
from
'
./utils/getFileName
'
;
interface
Props
{
data
:
SearchResult
;
...
...
@@ -11,7 +12,7 @@ interface Props {
}
const
CodeEditorSearchSection
=
({
data
,
onItemClick
}:
Props
)
=>
{
const
fileName
=
data
.
file_path
.
split
(
'
/
'
).
at
(
-
1
);
const
fileName
=
getFileName
(
data
.
file_path
);
const
handleFileLineClick
=
React
.
useCallback
((
event
:
React
.
MouseEvent
)
=>
{
const
lineNumber
=
Number
((
event
.
currentTarget
as
HTMLDivElement
).
getAttribute
(
'
data-line-number
'
));
...
...
ui/shared/monaco/CodeEditorTab.tsx
0 → 100644
View file @
f3329841
import
{
Flex
,
IconButton
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
import
iconCross
from
'
icons/cross.svg
'
;
import
getFileName
from
'
./utils/getFileName
'
;
interface
Props
{
isActive
?:
boolean
;
path
:
string
;
onClick
:
(
path
:
string
)
=>
void
;
onClose
:
(
path
:
string
)
=>
void
;
isCloseDisabled
:
boolean
;
}
const
CodeEditorTab
=
({
isActive
,
path
,
onClick
,
onClose
,
isCloseDisabled
}:
Props
)
=>
{
const
name
=
getFileName
(
path
);
const
handleClick
=
React
.
useCallback
(()
=>
{
onClick
(
path
);
},
[
onClick
,
path
]);
const
handleClose
=
React
.
useCallback
((
event
:
React
.
MouseEvent
)
=>
{
event
.
stopPropagation
();
!
isCloseDisabled
&&
onClose
(
path
);
},
[
isCloseDisabled
,
onClose
,
path
]);
return
(
<
Flex
py=
{
1
}
pl=
{
3
}
pr=
{
isActive
?
0
:
5
}
fontSize=
"sm"
lineHeight=
{
6
}
borderRightWidth=
"1px"
borderRightColor=
"divider"
borderBottomWidth=
"1px"
borderBottomColor=
{
isActive
?
'
deeppink
'
:
'
divider
'
}
color=
{
isActive
?
'
black
'
:
'
gray.600
'
}
alignItems=
"center"
fontWeight=
{
500
}
mb=
"-1px"
cursor=
"pointer"
onClick=
{
handleClick
}
_hover=
{
{
pr
:
'
0
'
,
svg
:
{
display
:
'
block
'
,
},
}
}
>
<
span
>
{
name
}
</
span
>
<
IconButton
as=
{
iconCross
}
boxSize=
{
5
}
p=
"2px"
variant=
"unstyled"
aria
-
label=
"close"
onClick=
{
handleClose
}
isDisabled=
{
isCloseDisabled
}
display=
{
isActive
?
'
block
'
:
'
none
'
}
/>
</
Flex
>
);
};
export
default
React
.
memo
(
CodeEditorTab
);
ui/shared/monaco/CodeEditorTabs.tsx
0 → 100644
View file @
f3329841
import
{
Flex
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
import
CodeEditorTab
from
'
./CodeEditorTab
'
;
interface
Props
{
tabs
:
Array
<
string
>
;
activeTab
:
string
;
onTabSelect
:
(
tab
:
string
)
=>
void
;
onTabClose
:
(
tab
:
string
)
=>
void
;
}
const
CodeEditorTabs
=
({
tabs
,
activeTab
,
onTabSelect
,
onTabClose
}:
Props
)
=>
{
return
(
<
Flex
bgColor=
"lightblue"
borderBottomWidth=
"1px"
borderColor=
"divider"
flexWrap=
"wrap"
>
{
tabs
.
map
((
tab
)
=>
(
<
CodeEditorTab
key=
{
tab
}
path=
{
tab
}
isActive=
{
activeTab
===
tab
}
onClick=
{
onTabSelect
}
onClose=
{
onTabClose
}
isCloseDisabled=
{
tabs
.
length
===
1
}
/>
))
}
</
Flex
>
);
};
export
default
React
.
memo
(
CodeEditorTabs
);
ui/shared/monaco/utils/getFileName.ts
0 → 100644
View file @
f3329841
export
default
function
getFileName
(
path
:
string
)
{
const
chunks
=
path
.
split
(
'
/
'
);
return
chunks
[
chunks
.
length
-
1
];
}
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