Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ui/src/components/codemirror-editor/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ defineOptions({ name: 'CodemirrorEditor' })
function getRangeFromLineAndColumn(state: any, line: number, column: number, end_column?: number) {
const l = state.doc.line(line)
const form = l.from + column
return { form: form > l.to ? l.to : form, to: end_column ? l.from + end_column : l.to }
const to_end_column = l.from + end_column
return {
form: form > l.to ? l.to : form,
to: end_column && to_end_column < l.to ? to_end_column : l.to
}
}

const regexpLinter = linter(async (view) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code snippet has some minor optimizations and corrections that can be suggested:

  1. Variable Naming Consistency: The variable to_end_column is unnecessarily defined before use, which could be removed.

  2. Condition Simplification: The condition in the return statement of getRangeFromLineAndColumn can be simplified using logical AND (&&) instead of multiple comparison checks.

Here's an optimized version of the function:

function getRangeFromLineAndColumn(state: any, line: number, column: number, end_column?: number): { form: number, to: number } {
  const l = state.doc.line(line);
  const form = l.from + column;
  
  let rangeTo =
    end_column !== undefined && end_column < l.to ?
      l.from + end_column :
      l.to;

  return {
    form: form > l.to ? l.to : form,
    to: rangeTo
  };
}

These changes reduce redundancy and improve readability while maintaining correct functionality.

Expand Down