Skip to content

Commit 8311c48

Browse files
Copilottsnobip
andcommitted
Fix error validation logic - properly validate both line and column bounds
Co-authored-by: tsnobip <[email protected]>
1 parent cc339b5 commit 8311c48

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/components/CodeMirror.res

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,22 @@ let createEditor = %raw(`
191191
return errorsArray.map(err => {
192192
try {
193193
const doc = view.state.doc;
194-
// Validate line numbers (1-based to 0-based conversion)
194+
// Error row/endRow are 1-based (same as CodeMirror 5)
195+
// Validate line numbers are within document bounds
195196
const fromLine = Math.max(1, Math.min(err.row, doc.lines));
196197
const toLine = Math.max(1, Math.min(err.endRow, doc.lines));
197198
199+
// Get line objects
200+
const startLine = doc.line(fromLine);
201+
const endLine = doc.line(toLine);
202+
203+
// Validate column positions are within line bounds
204+
const fromCol = Math.max(0, Math.min(err.column, startLine.length));
205+
const toCol = Math.max(0, Math.min(err.endColumn, endLine.length));
206+
198207
return {
199-
from: doc.line(fromLine).from + err.column,
200-
to: doc.line(toLine).from + err.endColumn,
208+
from: startLine.from + fromCol,
209+
to: endLine.from + toCol,
201210
severity: err.kind === 0 ? "error" : "warning",
202211
message: err.text
203212
};

0 commit comments

Comments
 (0)