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
e5b6085b
Commit
e5b6085b
authored
Mar 21, 2023
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
temporary solution for match highlighting in editor
parent
9d7c3849
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
5 deletions
+24
-5
CodeEditor.tsx
ui/shared/monaco/CodeEditor.tsx
+6
-1
CodeEditorSearch.tsx
ui/shared/monaco/CodeEditorSearch.tsx
+18
-4
No files found.
ui/shared/monaco/CodeEditor.tsx
View file @
e5b6085b
...
@@ -14,6 +14,7 @@ import CodeEditorLoading from './CodeEditorLoading';
...
@@ -14,6 +14,7 @@ import CodeEditorLoading from './CodeEditorLoading';
import
CodeEditorSideBar
,
{
CONTAINER_WIDTH
as
SIDE_BAR_WIDTH
}
from
'
./CodeEditorSideBar
'
;
import
CodeEditorSideBar
,
{
CONTAINER_WIDTH
as
SIDE_BAR_WIDTH
}
from
'
./CodeEditorSideBar
'
;
import
CodeEditorTabs
from
'
./CodeEditorTabs
'
;
import
CodeEditorTabs
from
'
./CodeEditorTabs
'
;
import
*
as
themes
from
'
./utils/themes
'
;
import
*
as
themes
from
'
./utils/themes
'
;
import
useThemeColors
from
'
./utils/useThemeColors
'
;
const
EDITOR_OPTIONS
:
EditorProps
[
'
options
'
]
=
{
const
EDITOR_OPTIONS
:
EditorProps
[
'
options
'
]
=
{
readOnly
:
true
,
readOnly
:
true
,
...
@@ -41,6 +42,7 @@ const CodeEditor = ({ data }: Props) => {
...
@@ -41,6 +42,7 @@ const CodeEditor = ({ data }: Props) => {
const
{
colorMode
}
=
useColorMode
();
const
{
colorMode
}
=
useColorMode
();
const
isMobile
=
useIsMobile
();
const
isMobile
=
useIsMobile
();
const
themeColors
=
useThemeColors
();
const
editorWidth
=
containerRect
?
containerRect
.
width
-
(
isMobile
?
0
:
SIDE_BAR_WIDTH
)
:
0
;
const
editorWidth
=
containerRect
?
containerRect
.
width
-
(
isMobile
?
0
:
SIDE_BAR_WIDTH
)
:
0
;
...
@@ -109,7 +111,10 @@ const CodeEditor = ({ data }: Props) => {
...
@@ -109,7 +111,10 @@ const CodeEditor = ({ data }: Props) => {
width
:
`
${
editorWidth
}
px`
,
width
:
`
${
editorWidth
}
px`
,
height
:
'
100%
'
,
height
:
'
100%
'
,
},
},
}),
[
editorWidth
]);
'
.highlight
'
:
{
backgroundColor
:
themeColors
[
'
custom.findMatchHighlightBackground
'
],
},
}),
[
editorWidth
,
themeColors
]);
if
(
data
.
length
===
1
)
{
if
(
data
.
length
===
1
)
{
return
(
return
(
...
...
ui/shared/monaco/CodeEditorSearch.tsx
View file @
e5b6085b
import
type
{
ChakraProps
}
from
'
@chakra-ui/react
'
;
import
type
{
ChakraProps
}
from
'
@chakra-ui/react
'
;
import
{
Accordion
,
Box
,
Input
,
InputGroup
,
InputRightElement
,
useBoolean
}
from
'
@chakra-ui/react
'
;
import
{
Accordion
,
Box
,
Input
,
InputGroup
,
InputRightElement
,
useBoolean
}
from
'
@chakra-ui/react
'
;
import
type
*
as
monaco
from
'
monaco-editor/esm/vs/editor/editor.api
'
;
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
type
{
File
,
Monaco
,
SearchResult
}
from
'
./types
'
;
import
type
{
File
,
Monaco
,
SearchResult
}
from
'
./types
'
;
...
@@ -26,6 +27,7 @@ const CodeEditorSearch = ({ monaco, data, onFileSelect, isInputStuck, isActive,
...
@@ -26,6 +27,7 @@ const CodeEditorSearch = ({ monaco, data, onFileSelect, isInputStuck, isActive,
const
[
isMatchCase
,
setMatchCase
]
=
useBoolean
();
const
[
isMatchCase
,
setMatchCase
]
=
useBoolean
();
const
[
isMatchWholeWord
,
setMatchWholeWord
]
=
useBoolean
();
const
[
isMatchWholeWord
,
setMatchWholeWord
]
=
useBoolean
();
const
[
isMatchRegex
,
setMatchRegex
]
=
useBoolean
();
const
[
isMatchRegex
,
setMatchRegex
]
=
useBoolean
();
const
decorations
=
React
.
useRef
<
Record
<
string
,
Array
<
string
>>>
({});
const
themeColors
=
useThemeColors
();
const
themeColors
=
useThemeColors
();
...
@@ -40,12 +42,24 @@ const CodeEditorSearch = ({ monaco, data, onFileSelect, isInputStuck, isActive,
...
@@ -40,12 +42,24 @@ const CodeEditorSearch = ({ monaco, data, onFileSelect, isInputStuck, isActive,
setSearchResults
([]);
setSearchResults
([]);
}
}
const
result
:
Array
<
SearchResult
>
=
monaco
.
editor
.
getModels
()
const
models
=
monaco
.
editor
.
getModels
();
.
map
((
model
)
=>
{
const
matches
=
models
.
map
((
model
)
=>
model
.
findMatches
(
debouncedSearchTerm
,
false
,
isMatchRegex
,
isMatchCase
,
isMatchWholeWord
?
'
true
'
:
null
,
false
));
const
matches
=
model
.
findMatches
(
debouncedSearchTerm
,
false
,
isMatchRegex
,
isMatchCase
,
isMatchWholeWord
?
'
true
'
:
null
,
false
);
models
.
forEach
((
model
,
index
)
=>
{
const
filePath
=
model
.
uri
.
path
;
const
prevDecorations
=
decorations
.
current
[
filePath
]
||
[];
const
newDecorations
:
Array
<
monaco
.
editor
.
IModelDeltaDecoration
>
=
matches
[
index
].
map
(({
range
})
=>
({
range
,
options
:
{
className
:
'
highlight
'
}
}));
const
newDecorationsIds
=
model
.
deltaDecorations
(
prevDecorations
,
newDecorations
);
decorations
.
current
[
filePath
]
=
newDecorationsIds
;
});
const
result
:
Array
<
SearchResult
>
=
matches
.
map
((
match
,
index
)
=>
{
const
model
=
models
[
index
];
return
{
return
{
file_path
:
model
.
uri
.
path
,
file_path
:
model
.
uri
.
path
,
matches
:
match
es
.
map
(({
range
})
=>
({
...
range
,
lineContent
:
model
.
getLineContent
(
range
.
startLineNumber
)
})),
matches
:
match
.
map
(({
range
})
=>
({
...
range
,
lineContent
:
model
.
getLineContent
(
range
.
startLineNumber
)
})),
};
};
})
})
.
filter
(({
matches
})
=>
matches
.
length
>
0
);
.
filter
(({
matches
})
=>
matches
.
length
>
0
);
...
...
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