mirror of
https://github.com/supabase/supabase.git
synced 2026-09-22 13:37:53 +08:00
8d59e69da4
## Context As per PR title - this behaviour currently exists in the SQL Editor so just bringing it over to the Explorer, applies to both QueryTab and QueryCell since they use the same QueryEditor component "Run" button also updates to "Run selected" for clarity when a specific portion of the code editor is selected <img width="1387" height="958" alt="image" src="https://github.com/user-attachments/assets/7e652951-3c07-4f8d-851b-bb9219d0c1f2" /> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Run only the selected SQL when text is highlighted in the query editor. * Run the full query when no text is selected. * Updated the run button label and tooltip to reflect the action. * **Bug Fixes** * Improved query execution for empty or collapsed selections. * Corrected selection state when reopening the query editor. * **Tests** * Added coverage for selected-text, full-query, and editor reopening scenarios. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
44 lines
1.5 KiB
TypeScript
44 lines
1.5 KiB
TypeScript
import type { editor } from 'monaco-editor'
|
|
|
|
/**
|
|
* Base Monaco editor options shared across Studio's editors so font size, indentation and
|
|
* chrome stay consistent everywhere a Monaco editor is rendered. CodeEditor layers per-instance
|
|
* options (read-only, line numbers) on top; GraphiQL (which runs its own Monaco instance) layers
|
|
* its own padding/glyphMargin on top via `editor.updateOptions`.
|
|
*
|
|
* Keep this as the single source of truth — don't redeclare these values at call sites.
|
|
*/
|
|
export const BASE_MONACO_EDITOR_OPTIONS: editor.IStandaloneEditorConstructionOptions = {
|
|
tabSize: 2,
|
|
fontSize: 13,
|
|
minimap: { enabled: false },
|
|
wordWrap: 'on',
|
|
fixedOverflowWidgets: false,
|
|
contextmenu: true,
|
|
scrollBeyondLastLine: false,
|
|
}
|
|
|
|
export const alignEditor = (editor: editor.IStandaloneCodeEditor) => {
|
|
// Add margin above first line
|
|
editor.changeViewZones((accessor) => {
|
|
accessor.addZone({
|
|
afterLineNumber: 0,
|
|
heightInPx: 4,
|
|
domNode: document.createElement('div'),
|
|
})
|
|
})
|
|
}
|
|
|
|
/**
|
|
* The text a "run" gesture should act on: the current selection if there is one
|
|
* (a collapsed cursor has an empty range, so `getValueInRange` returns `''` and
|
|
* this falls through), otherwise the full editor value.
|
|
*/
|
|
export const getEditorValueOrSelection = (
|
|
editor: editor.IStandaloneCodeEditor
|
|
): string | undefined => {
|
|
const selection = editor.getSelection()
|
|
const selectedValue = selection ? editor.getModel()?.getValueInRange(selection) : undefined
|
|
return selectedValue || editor.getValue()
|
|
}
|