Skip to content

Commit df2ecd5

Browse files
author
lukaw3d
committed
Fix highlighted error logs offset
Highlights were off by a few lines as new lines got fetched.
1 parent 7dac9a7 commit df2ecd5

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

.changelog/346.feature.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Highlight errors in logs

src/components/CodeDisplay/index.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,16 @@ export const CodeDisplay: FC<CodeDisplayProps> = ({ data, className, readOnly =
6262
})
6363
}
6464

65-
const highlightErrorLogs = () => {
65+
const highlightErrorLogs = (value: string) => {
6666
const monacoInstance = monacoInstanceRef.current
67-
if (!monacoInstance || !editorRef.current || data === undefined) {
67+
if (!monacoInstance || !editorRef.current || value === undefined) {
6868
return
6969
}
7070
const model = editorRef.current.getModel()
7171
if (!model) return
7272

7373
const markers: monaco.editor.IMarkerData[] = []
74-
for (const [i, line] of data.split('\n').entries()) {
74+
for (const [i, line] of value.split('\n').entries()) {
7575
if (
7676
line.includes('"err"') ||
7777
line.toLowerCase().includes('error') ||
@@ -97,7 +97,7 @@ export const CodeDisplay: FC<CodeDisplayProps> = ({ data, className, readOnly =
9797
) => {
9898
editorRef.current = editor
9999
monacoInstanceRef.current = monacoInstance
100-
highlightErrorLogs()
100+
highlightErrorLogs(data)
101101
}
102102

103103
const handleEditorChange = (value: string | undefined) => {
@@ -131,7 +131,7 @@ export const CodeDisplay: FC<CodeDisplayProps> = ({ data, className, readOnly =
131131

132132
monacoInstance.editor.setModelMarkers(model, 'yaml-validator', markers)
133133

134-
highlightErrorLogs()
134+
highlightErrorLogs(value)
135135

136136
onChange?.(value)
137137
}

0 commit comments

Comments
 (0)