Skip to content

Commit

Permalink
Select all multi-cursor queries on Ctrl+e
Browse files Browse the repository at this point in the history
  • Loading branch information
msanchezdev committed Feb 21, 2025
1 parent 08ee9dc commit 7175df5
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions src/editor/query.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { EditorSelection, StateEffect, StateField } from "@codemirror/state";
import {
EditorSelection,
SelectionRange,
StateEffect,
StateField,
} from "@codemirror/state";
import type { Command, EditorView } from "@codemirror/view";
import {
executeGraphql,
Expand Down Expand Up @@ -61,9 +66,9 @@ export const executeEditorQuery: Command = (view: EditorView) => {
if (!query) continue;

const [from, to] = query;
override += editor.state.sliceDoc(from, to) + ";\n";
override += `${editor.state.sliceDoc(from, to)};\n`;
} else {
override += editor.state.sliceDoc(range.from, range.to) + ";\n";
override += `${editor.state.sliceDoc(range.from, range.to)};\n`;
}
}
}
Expand All @@ -79,20 +84,27 @@ export const executeEditorQuery: Command = (view: EditorView) => {
* Select the query the cursor is currently in
*/
export const selectCursorQuery: Command = (view: EditorView) => {
const range = getQueryRange(view);
const ranges = [] as SelectionRange[];

if (range) {
const [from, to] = range;
const selection = EditorSelection.single(from, to);
for (const selection of view.state.selection.ranges) {
const range = getQueryRange(view, selection.head);
if (!range) {
continue;
}

view.dispatch({
selection,
});
const [from, to] = range;
ranges.push(EditorSelection.range(from, to));
}

if (!ranges.length) {
return true;
}

return false;
view.dispatch({
selection: EditorSelection.create(ranges),
});

return true;
};

/**
Expand Down

0 comments on commit 7175df5

Please sign in to comment.