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
40025c02
Commit
40025c02
authored
Mar 20, 2023
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
search settings
parent
f56d412e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
92 additions
and
44 deletions
+92
-44
CodeEditorSearch.tsx
ui/shared/monaco/CodeEditorSearch.tsx
+58
-7
CodeEditorTab.tsx
ui/shared/monaco/CodeEditorTab.tsx
+12
-15
CoderEditorCollapseButton.tsx
ui/shared/monaco/CoderEditorCollapseButton.tsx
+22
-22
No files found.
ui/shared/monaco/CodeEditorSearch.tsx
View file @
40025c02
import
{
Accordion
,
Box
,
Input
,
useColorModeValue
}
from
'
@chakra-ui/react
'
;
import
type
{
ChakraProps
}
from
'
@chakra-ui/react
'
;
import
{
Accordion
,
Box
,
Input
,
InputGroup
,
InputRightElement
,
useColorModeValue
,
useBoolean
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
import
type
{
File
,
Monaco
,
SearchResult
}
from
'
./types
'
;
...
...
@@ -20,6 +21,9 @@ const CodeEditorSearch = ({ monaco, data, onFileSelect, isInputStuck }: Props) =
const
[
searchTerm
,
changeSearchTerm
]
=
React
.
useState
(
''
);
const
[
searchResults
,
setSearchResults
]
=
React
.
useState
<
Array
<
SearchResult
>>
([]);
const
[
expandedSections
,
setExpandedSections
]
=
React
.
useState
<
Array
<
number
>>
([]);
const
[
isMatchCase
,
setMatchCase
]
=
useBoolean
();
const
[
isMatchWholeWord
,
setMatchWholeWord
]
=
useBoolean
();
const
[
isMatchRegex
,
setMatchRegex
]
=
useBoolean
();
const
debouncedSearchTerm
=
useDebounce
(
searchTerm
,
300
);
...
...
@@ -34,7 +38,7 @@ const CodeEditorSearch = ({ monaco, data, onFileSelect, isInputStuck }: Props) =
const
result
:
Array
<
SearchResult
>
=
monaco
.
editor
.
getModels
()
.
map
((
model
)
=>
{
const
matches
=
model
.
findMatches
(
debouncedSearchTerm
,
false
,
false
,
false
,
null
,
false
);
const
matches
=
model
.
findMatches
(
debouncedSearchTerm
,
false
,
isMatchRegex
,
isMatchCase
,
isMatchWholeWord
?
'
true
'
:
null
,
false
);
return
{
file_path
:
model
.
uri
.
path
,
matches
:
matches
.
map
(({
range
})
=>
({
...
range
,
lineContent
:
model
.
getLineContent
(
range
.
startLineNumber
)
})),
...
...
@@ -43,7 +47,7 @@ const CodeEditorSearch = ({ monaco, data, onFileSelect, isInputStuck }: Props) =
.
filter
(({
matches
})
=>
matches
.
length
>
0
);
setSearchResults
(
result
.
length
>
0
?
result
:
[]);
},
[
debouncedSearchTerm
,
monaco
]);
},
[
debouncedSearchTerm
,
isMatchCase
,
isMatchRegex
,
isMatchWholeWord
,
monaco
]);
React
.
useEffect
(()
=>
{
setExpandedSections
(
searchResults
.
map
((
item
,
index
)
=>
index
));
...
...
@@ -75,7 +79,16 @@ const CodeEditorSearch = ({ monaco, data, onFileSelect, isInputStuck }: Props) =
const
inputColor
=
useColorModeValue
(
'
rgb(97, 97, 97)
'
,
'
rgb(204, 204, 204)
'
);
const
inputBgColor
=
useColorModeValue
(
'
white
'
,
'
rgb(60, 60, 60)
'
);
const
inputFocusBorderColor
=
useColorModeValue
(
'
#0090f1
'
,
'
#007fd4
'
);
const
buttonActiveBgColor
=
useColorModeValue
(
'
rgba(0, 144, 241, 0.2)
'
,
'
rgba(0, 127, 212, 0.4)
'
);
const
colors
=
useColors
();
const
buttonProps
:
ChakraProps
=
{
boxSize
:
'
20px
'
,
p
:
'
1px
'
,
cursor
:
'
pointer
'
,
borderRadius
:
'
3px
'
,
borderWidth
:
'
1px
'
,
borderColor
:
'
transparent
'
,
};
return
(
<
Box
>
...
...
@@ -85,7 +98,16 @@ const CodeEditorSearch = ({ monaco, data, onFileSelect, isInputStuck }: Props) =
isDisabled=
{
searchResults
.
length
===
0
}
isCollapsed=
{
expandedSections
.
length
===
0
}
/>
<
Box
px=
{
2
}
position=
"sticky"
top=
"35px"
left=
"0"
zIndex=
"2"
bgColor=
{
colors
.
panels
.
bgColor
}
pb=
"8px"
boxShadow=
{
isInputStuck
?
'
md
'
:
'
none
'
}
>
<
InputGroup
px=
"8px"
position=
"sticky"
top=
"35px"
left=
"0"
zIndex=
"2"
bgColor=
{
colors
.
panels
.
bgColor
}
pb=
"8px"
boxShadow=
{
isInputStuck
?
'
md
'
:
'
none
'
}
>
<
Input
size=
"xs"
onChange=
{
handleSearchTermChange
}
...
...
@@ -96,7 +118,7 @@ const CodeEditorSearch = ({ monaco, data, onFileSelect, isInputStuck }: Props) =
bgColor=
{
inputBgColor
}
borderRadius=
"none"
fontSize=
"13px"
lineHeight=
"
19
px"
lineHeight=
"
20
px"
borderWidth=
"1px"
borderColor=
{
inputBgColor
}
py=
"2px"
...
...
@@ -106,14 +128,43 @@ const CodeEditorSearch = ({ monaco, data, onFileSelect, isInputStuck }: Props) =
borderColor
:
inputFocusBorderColor
,
}
}
/>
</
Box
>
<
InputRightElement
w=
"auto"
h=
"auto"
right=
"12px"
top=
"3px"
columnGap=
"2px"
>
<
Box
{
...
buttonProps
}
className=
"codicon codicon-case-sensitive"
onClick=
{
setMatchCase
.
toggle
}
bgColor=
{
isMatchCase
?
buttonActiveBgColor
:
'
transparent
'
}
_hover=
{
{
bgColor
:
isMatchCase
?
buttonActiveBgColor
:
colors
.
buttons
.
bgColorHover
}
}
title=
"Match Case"
aria
-
label=
"Match Case"
/>
<
Box
{
...
buttonProps
}
className=
"codicon codicon-whole-word"
bgColor=
{
isMatchWholeWord
?
buttonActiveBgColor
:
'
transparent
'
}
onClick=
{
setMatchWholeWord
.
toggle
}
_hover=
{
{
bgColor
:
isMatchWholeWord
?
buttonActiveBgColor
:
colors
.
buttons
.
bgColorHover
}
}
title=
"Match Whole Word"
aria
-
label=
"Match Whole Word"
/>
<
Box
{
...
buttonProps
}
className=
"codicon codicon-regex"
bgColor=
{
isMatchRegex
?
buttonActiveBgColor
:
'
transparent
'
}
onClick=
{
setMatchRegex
.
toggle
}
_hover=
{
{
bgColor
:
isMatchRegex
?
buttonActiveBgColor
:
colors
.
buttons
.
bgColorHover
}
}
title=
"Use Regular Expression"
aria
-
label=
"Use Regular Expression"
/>
</
InputRightElement
>
</
InputGroup
>
<
Accordion
key=
{
debouncedSearchTerm
}
allowMultiple
index=
{
expandedSections
}
onChange=
{
handleAccordionStateChange
}
reduceMotion
mt=
{
3
}
mt=
"4px"
>
{
searchResults
.
map
((
item
)
=>
<
CodeEditorSearchSection
key=
{
item
.
file_path
}
data=
{
item
}
onItemClick=
{
handleResultItemClick
}
/>)
}
</
Accordion
>
...
...
ui/shared/monaco/CodeEditorTab.tsx
View file @
40025c02
import
{
Flex
,
Icon
Button
,
Icon
,
chakra
,
useColorModeValue
}
from
'
@chakra-ui/react
'
;
import
{
Flex
,
Icon
,
chakra
,
useColorModeValue
,
Box
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
import
iconCross
from
'
icons/cross.svg
'
;
import
iconFile
from
'
./icons/file.svg
'
;
import
iconSolidity
from
'
./icons/solidity.svg
'
;
import
getFilePathParts
from
'
./utils/getFilePathParts
'
;
...
...
@@ -40,7 +38,7 @@ const CodeEditorTab = ({ isActive, path, onClick, onClose, isCloseDisabled, tabs
return
(
<
Flex
pl=
"10px"
pr=
{
isActive
?
'
4px
'
:
'
28px
'
}
pr=
"4px"
fontSize=
"13px"
lineHeight=
"34px"
bgColor=
{
isActive
?
bgColor
:
bgColorInactive
}
...
...
@@ -54,9 +52,8 @@ const CodeEditorTab = ({ isActive, path, onClick, onClose, isCloseDisabled, tabs
cursor=
"pointer"
onClick=
{
handleClick
}
_hover=
{
{
pr
:
'
4px
'
,
svg
:
{
display
:
'
block
'
,
'
.codicon-close
'
:
{
visibility
:
'
visible
'
,
},
}
}
userSelect=
"none"
...
...
@@ -64,19 +61,19 @@ const CodeEditorTab = ({ isActive, path, onClick, onClose, isCloseDisabled, tabs
<
Icon
as=
{
icon
}
boxSize=
"16px"
mr=
"4px"
/>
<
span
>
{
fileName
}
</
span
>
{
folderName
&&
<
chakra
.
span
fontSize=
"xs"
color=
"text_secondary"
ml=
{
1
}
>
{
folderName
[
0
]
===
'
.
'
?
''
:
'
...
'
}{
folderName
}
</
chakra
.
span
>
}
<
IconButton
as=
{
iconCross
}
boxSize=
{
5
}
<
Box
className=
"codicon codicon-close"
boxSize=
"20px"
ml=
"4px"
p=
"2px"
variant=
"unstyled
"
aria
-
label=
"
c
lose"
title=
"Close
"
aria
-
label=
"
C
lose"
onClick=
{
handleClose
}
isDisabled=
{
isCloseDisabled
}
display=
{
isActive
?
'
block
'
:
'
none
'
}
borderRadius=
"sm"
opacity=
{
isCloseDisabled
?
0.3
:
1
}
visibility=
{
isActive
?
'
visible
'
:
'
hidden
'
}
color=
{
colors
.
buttons
.
color
}
_hover=
{
{
bgColor
:
colors
.
buttons
.
bgColorHover
}
}
_hover=
{
{
bgColor
:
isCloseDisabled
?
'
transparent
'
:
colors
.
buttons
.
bgColorHover
}
}
/>
</
Flex
>
);
...
...
ui/shared/monaco/CoderEditorCollapseButton.tsx
View file @
40025c02
import
{
Tooltip
,
Box
}
from
'
@chakra-ui/react
'
;
import
{
Box
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
import
useColors
from
'
./utils/useColors
'
;
...
...
@@ -13,7 +13,6 @@ interface Props {
const
CoderEditorCollapseButton
=
({
onClick
,
label
,
isDisabled
,
isCollapsed
}:
Props
)
=>
{
const
colors
=
useColors
();
return
(
<
Tooltip
label=
{
label
}
isDisabled=
{
isDisabled
}
>
<
Box
position=
"absolute"
right=
"12px"
...
...
@@ -32,8 +31,9 @@ const CoderEditorCollapseButton = ({ onClick, label, isDisabled, isCollapsed }:
}
}
onClick=
{
onClick
}
cursor=
"pointer"
title=
{
label
}
aria
-
label=
{
label
}
/>
</
Tooltip
>
);
};
...
...
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