From beecc84d1427693fdf9cfe75d821692d1caeb0a9 Mon Sep 17 00:00:00 2001 From: sergeyteleshev Date: Mon, 23 Jun 2025 13:44:18 +0200 Subject: [PATCH] [CB] SQL editor - ctrl+z during autosave scrolls the script to the top #5645 (#3470) * dbeaver/pro#5645 removes scroll to top for sql editor * removes floating second scroll bar on ctrl+z * removes cursor jumping + removes scrolling to top * reverts layout scroll behavior * reverts layout scroll behavior 2 * removes unneeded cursorOffset * removes offset and unused code * reverts has insert property behavior * remembers previous cursor position from history * adds mobx action * reverts insert property logic * fixes cursor position during ctrl+z * Revert "fixes cursor position during ctrl+z" This reverts commit d1aac8e75098c9ae53fb1dd8800e4bd6396c3e05. * dbeaver/pro#5645 sets cursor in sync with code mirror onChange event * eslint fix --------- Co-authored-by: Evgenia <139753579+EvgeniaBzzz@users.noreply.github.com> --- .../src/IReactCodemirrorProps.ts | 4 +-- .../src/ReactCodemirror.tsx | 14 +++++---- .../src/hasInsertProperty.ts | 4 +-- .../src/ResourceSqlDataSource.ts | 6 ++-- .../useSQLCodeEditorPanel.ts | 13 ++++---- .../src/SqlDataSource/BaseSqlDataSource.ts | 30 ++++++++++++------- .../src/SqlDataSource/ISqlDataSource.ts | 5 ++-- .../LocalStorage/LocalStorageSqlDataSource.ts | 7 +++-- .../src/SqlDataSource/MemorySqlDataSource.ts | 7 +++-- .../ISqlDataSourceHistory.ts | 10 +++++-- .../ISqlDataSourceHistoryData.ts | 5 +++- .../SqlDataSourceHistory.ts | 20 ++++++++----- .../createSqlDataSourceHistoryInitialState.ts | 4 +-- .../src/SqlEditor/ISQLEditorData.ts | 8 ++--- .../src/SqlEditor/useSqlEditor.ts | 10 +++---- .../plugin-sql-editor/src/SqlEditorService.ts | 4 +-- 16 files changed, 91 insertions(+), 60 deletions(-) diff --git a/webapp/packages/plugin-codemirror6/src/IReactCodemirrorProps.ts b/webapp/packages/plugin-codemirror6/src/IReactCodemirrorProps.ts index 73dc02c305..bec9a880f9 100644 --- a/webapp/packages/plugin-codemirror6/src/IReactCodemirrorProps.ts +++ b/webapp/packages/plugin-codemirror6/src/IReactCodemirrorProps.ts @@ -1,6 +1,6 @@ /* * CloudBeaver - Cloud Database Manager - * Copyright (C) 2020-2024 DBeaver Corp and others + * Copyright (C) 2020-2025 DBeaver Corp and others * * Licensed under the Apache License, Version 2.0. * you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ export interface IReactCodeMirrorProps extends React.PropsWithChildren { readonly?: boolean; copyEventHandler?: (event: ClipboardEvent) => boolean; autoFocus?: boolean; - onChange?: (value: string, update: ViewUpdate) => void; + onChange?: (value: string, selection: SelectionRange, update: ViewUpdate) => void; onCursorChange?: (selection: SelectionRange, update: ViewUpdate) => void; onUpdate?: (update: ViewUpdate) => void; } diff --git a/webapp/packages/plugin-codemirror6/src/ReactCodemirror.tsx b/webapp/packages/plugin-codemirror6/src/ReactCodemirror.tsx index 9e5cf8ed3b..cd831342ba 100644 --- a/webapp/packages/plugin-codemirror6/src/ReactCodemirror.tsx +++ b/webapp/packages/plugin-codemirror6/src/ReactCodemirror.tsx @@ -13,13 +13,13 @@ import { forwardRef, useImperativeHandle, useLayoutEffect, useMemo, useRef, useS import { useObjectRef } from '@cloudbeaver/core-blocks'; -import { hasInsertProperty } from './hasInsertProperty.js'; import type { IEditorRef } from './IEditorRef.js'; import type { IReactCodeMirrorProps } from './IReactCodemirrorProps.js'; import { type IReactCodemirrorContext, ReactCodemirrorContext } from './ReactCodemirrorContext.js'; import { useCodemirrorExtensions } from './useCodemirrorExtensions.js'; import { validateCursorBoundaries } from './validateCursorBoundaries.js'; import { ReactCodemirrorSearchPanel } from './ReactCodemirrorSearchPanel.js'; +import { hasInsertProperty } from './hasInsertProperty.js'; const External = Annotation.define(); @@ -67,16 +67,16 @@ export const ReactCodemirror = observer( if (container) { const updateListener = EditorView.updateListener.of((update: ViewUpdate) => { const remote = update.transactions.some(tr => tr.annotation(External)); + const selection = update.state.selection.main; if (update.docChanged && !remote) { const doc = update.state.doc; const value = doc.toString(); - callbackRef.onChange?.(value, update); + callbackRef.onChange?.(value, selection, update); } if (update.selectionSet && !remote) { - const selection = update.state.selection.main; callbackRef.onCursorChange?.(selection, update); } @@ -221,8 +221,12 @@ export const ReactCodemirror = observer( }; } - if (transaction.changes || transaction.selection) { - view.dispatch(transaction); + if (transaction.changes) { + view.dispatch({ changes: transaction.changes }); + } + + if (transaction.selection) { + view.dispatch({ selection: transaction.selection }); } } }); diff --git a/webapp/packages/plugin-codemirror6/src/hasInsertProperty.ts b/webapp/packages/plugin-codemirror6/src/hasInsertProperty.ts index c6f6a45492..5988b45c91 100644 --- a/webapp/packages/plugin-codemirror6/src/hasInsertProperty.ts +++ b/webapp/packages/plugin-codemirror6/src/hasInsertProperty.ts @@ -1,6 +1,6 @@ /* * CloudBeaver - Cloud Database Manager - * Copyright (C) 2020-2024 DBeaver Corp and others + * Copyright (C) 2020-2025 DBeaver Corp and others * * Licensed under the Apache License, Version 2.0. * you may not use this file except in compliance with the License. @@ -9,4 +9,4 @@ import type { ChangeSpec, Text } from '@codemirror/state'; export function hasInsertProperty(spec: ChangeSpec | undefined): spec is { from: number; to?: number; insert?: string | Text } { return typeof spec === 'object' && spec !== null && 'insert' in spec; -} +} \ No newline at end of file diff --git a/webapp/packages/plugin-sql-editor-navigation-tab-script/src/ResourceSqlDataSource.ts b/webapp/packages/plugin-sql-editor-navigation-tab-script/src/ResourceSqlDataSource.ts index bcb820e486..25cc0138cd 100644 --- a/webapp/packages/plugin-sql-editor-navigation-tab-script/src/ResourceSqlDataSource.ts +++ b/webapp/packages/plugin-sql-editor-navigation-tab-script/src/ResourceSqlDataSource.ts @@ -21,7 +21,7 @@ import type { NetworkStateService } from '@cloudbeaver/core-root'; import { debounce, getPathName, isArraysEqual, isObjectsEqual, isValuesEqual } from '@cloudbeaver/core-utils'; import { isNotNullDefined } from '@dbeaver/js-helpers'; import { SCRIPTS_TYPE_ID } from '@cloudbeaver/plugin-resource-manager-scripts'; -import { BaseSqlDataSource, ESqlDataSourceFeatures, SqlEditorService } from '@cloudbeaver/plugin-sql-editor'; +import { BaseSqlDataSource, ESqlDataSourceFeatures, SqlEditorService, type ISqlEditorCursor } from '@cloudbeaver/plugin-sql-editor'; import type { IResourceSqlDataSourceState } from './IResourceSqlDataSourceState.js'; @@ -219,14 +219,14 @@ export class ResourceSqlDataSource extends BaseSqlDataSource { super.setProject(projectId); } - override setScript(script: string): void { + override setScript(script: string, source?: string, cursor?: ISqlEditorCursor): void { const previous = this.state.script; if (previous === script) { return; } this.state.script = script; - super.setScript(script); + super.setScript(script, source, cursor); if (this.isAutoSaveEnabled) { this.debouncedWrite(); diff --git a/webapp/packages/plugin-sql-editor-new/src/SQLEditor/SQLCodeEditorPanel/useSQLCodeEditorPanel.ts b/webapp/packages/plugin-sql-editor-new/src/SQLEditor/SQLCodeEditorPanel/useSQLCodeEditorPanel.ts index 719760b6cd..1c503cdda7 100644 --- a/webapp/packages/plugin-sql-editor-new/src/SQLEditor/SQLCodeEditorPanel/useSQLCodeEditorPanel.ts +++ b/webapp/packages/plugin-sql-editor-new/src/SQLEditor/SQLCodeEditorPanel/useSQLCodeEditorPanel.ts @@ -1,6 +1,6 @@ /* * CloudBeaver - Cloud Database Manager - * Copyright (C) 2020-2024 DBeaver Corp and others + * Copyright (C) 2020-2025 DBeaver Corp and others * * Licensed under the Apache License, Version 2.0. * you may not use this file except in compliance with the License. @@ -10,16 +10,18 @@ import { useCallback } from 'react'; import { useExecutor, useObservableRef } from '@cloudbeaver/core-blocks'; import { throttle } from '@cloudbeaver/core-utils'; -import type { ISQLEditorData } from '@cloudbeaver/plugin-sql-editor'; +import type { ISqlEditorCursor, ISQLEditorData } from '@cloudbeaver/plugin-sql-editor'; import type { IEditor } from '../SQLCodeEditor/useSQLCodeEditor.js'; interface State { highlightActiveQuery: () => void; - onQueryChange: (query: string) => void; + onQueryChange: (query: string, selection: ISqlEditorCursor) => void; onCursorChange: (anchor: number, head?: number) => void; } +export const ON_QUERY_CHANGE_SOURCE = 'QueryChange'; + export function useSQLCodeEditorPanel(data: ISQLEditorData, editor: IEditor) { const state: State = useObservableRef( () => ({ @@ -32,8 +34,9 @@ export function useSQLCodeEditorPanel(data: ISQLEditorData, editor: IEditor) { this.editor.highlightActiveQuery(segment.begin, segment.end); } }, - onQueryChange(query: string) { - this.data.setScript(query); + onQueryChange(query: string, selection: ISqlEditorCursor) { + this.data.setScript(query, ON_QUERY_CHANGE_SOURCE, selection); + this.onCursorChange(selection.anchor, selection.head); }, onCursorChange(anchor: number, head?: number) { this.data.setCursor(anchor, head); diff --git a/webapp/packages/plugin-sql-editor/src/SqlDataSource/BaseSqlDataSource.ts b/webapp/packages/plugin-sql-editor/src/SqlDataSource/BaseSqlDataSource.ts index 2683e627eb..6ce22f5815 100644 --- a/webapp/packages/plugin-sql-editor/src/SqlDataSource/BaseSqlDataSource.ts +++ b/webapp/packages/plugin-sql-editor/src/SqlDataSource/BaseSqlDataSource.ts @@ -1,6 +1,6 @@ /* * CloudBeaver - Cloud Database Manager - * Copyright (C) 2020-2024 DBeaver Corp and others + * Copyright (C) 2020-2025 DBeaver Corp and others * * Licensed under the Apache License, Version 2.0. * you may not use this file except in compliance with the License. @@ -104,14 +104,24 @@ export abstract class BaseSqlDataSource implements ISqlDataSource { this.onDatabaseModelUpdate.setInitialDataGetter(() => this.databaseModels); this.onSetScript.next(this.onUpdate); - this.onSetScript.addHandler(({ script, source }) => { - if (source === SOURCE_HISTORY) { - return; - } - this.history.add(script); - }); + this.onSetScript.addHandler( + action(({ script, source, cursor }) => { + if (source === SOURCE_HISTORY) { + return; + } + this.history.add(script, source, cursor); + }), + ); - this.history.onNavigate.addHandler(value => this.setScript(value, SOURCE_HISTORY)); + this.history.onNavigate.addHandler( + action(({ value, cursor }) => { + this.setScript(value, SOURCE_HISTORY); + + if (cursor) { + this.setCursor(cursor.anchor, cursor.head); + } + }), + ); makeObservable(this, { isSaved: computed, @@ -142,8 +152,8 @@ export abstract class BaseSqlDataSource implements ISqlDataSource { }); } - setScript(script: string, source?: string): void { - this.onSetScript.execute({ script, source }); + setScript(script: string, source?: string, cursor?: ISqlEditorCursor): void { + this.onSetScript.execute({ script, source, cursor }); } setIncomingScript(script: string): void { diff --git a/webapp/packages/plugin-sql-editor/src/SqlDataSource/ISqlDataSource.ts b/webapp/packages/plugin-sql-editor/src/SqlDataSource/ISqlDataSource.ts index 4c65385222..c2d07960af 100644 --- a/webapp/packages/plugin-sql-editor/src/SqlDataSource/ISqlDataSource.ts +++ b/webapp/packages/plugin-sql-editor/src/SqlDataSource/ISqlDataSource.ts @@ -1,6 +1,6 @@ /* * CloudBeaver - Cloud Database Manager - * Copyright (C) 2020-2024 DBeaver Corp and others + * Copyright (C) 2020-2025 DBeaver Corp and others * * Licensed under the Apache License, Version 2.0. * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ export interface ISqlDataSourceKey { export interface ISetScriptData { script: string; + cursor?: ISqlEditorCursor; source?: string; } @@ -70,7 +71,7 @@ export interface ISqlDataSource extends ILoadableState { setName(name: string | null): void; setProject(projectId: string | null): void; - setScript(script: string, source?: string): void; + setScript(script: string, source?: string, cursor?: ISqlEditorCursor): void; setCursor(anchor: number, head?: number): void; setEditing(state: boolean): void; setExecutionContext(executionContext?: IConnectionExecutionContextInfo): void; diff --git a/webapp/packages/plugin-sql-editor/src/SqlDataSource/LocalStorage/LocalStorageSqlDataSource.ts b/webapp/packages/plugin-sql-editor/src/SqlDataSource/LocalStorage/LocalStorageSqlDataSource.ts index ea86c489b6..872e1794bc 100644 --- a/webapp/packages/plugin-sql-editor/src/SqlDataSource/LocalStorage/LocalStorageSqlDataSource.ts +++ b/webapp/packages/plugin-sql-editor/src/SqlDataSource/LocalStorage/LocalStorageSqlDataSource.ts @@ -1,6 +1,6 @@ /* * CloudBeaver - Cloud Database Manager - * Copyright (C) 2020-2024 DBeaver Corp and others + * Copyright (C) 2020-2025 DBeaver Corp and others * * Licensed under the Apache License, Version 2.0. * you may not use this file except in compliance with the License. @@ -12,6 +12,7 @@ import type { IConnectionExecutionContextInfo } from '@cloudbeaver/core-connecti import { BaseSqlDataSource } from '../BaseSqlDataSource.js'; import { ESqlDataSourceFeatures } from '../ESqlDataSourceFeatures.js'; import type { ILocalStorageSqlDataSourceState } from './ILocalStorageSqlDataSourceState.js'; +import type { ISqlEditorCursor } from '../ISqlDataSource.js'; export class LocalStorageSqlDataSource extends BaseSqlDataSource { get baseScript(): string { @@ -75,9 +76,9 @@ export class LocalStorageSqlDataSource extends BaseSqlDataSource { return true; } - override setScript(script: string): void { + override setScript(script: string, source?: string, cursor?: ISqlEditorCursor): void { this.state.script = script; - super.setScript(script); + super.setScript(script, source, cursor); } override setExecutionContext(executionContext?: IConnectionExecutionContextInfo): void { diff --git a/webapp/packages/plugin-sql-editor/src/SqlDataSource/MemorySqlDataSource.ts b/webapp/packages/plugin-sql-editor/src/SqlDataSource/MemorySqlDataSource.ts index 7bb79ec64a..d29a9cd6b2 100644 --- a/webapp/packages/plugin-sql-editor/src/SqlDataSource/MemorySqlDataSource.ts +++ b/webapp/packages/plugin-sql-editor/src/SqlDataSource/MemorySqlDataSource.ts @@ -1,6 +1,6 @@ /* * CloudBeaver - Cloud Database Manager - * Copyright (C) 2020-2024 DBeaver Corp and others + * Copyright (C) 2020-2025 DBeaver Corp and others * * Licensed under the Apache License, Version 2.0. * you may not use this file except in compliance with the License. @@ -11,6 +11,7 @@ import type { IConnectionExecutionContextInfo } from '@cloudbeaver/core-connecti import { BaseSqlDataSource } from './BaseSqlDataSource.js'; import { ESqlDataSourceFeatures } from './ESqlDataSourceFeatures.js'; +import type { ISqlEditorCursor } from './ISqlDataSource.js'; export class MemorySqlDataSource extends BaseSqlDataSource { get baseScript(): string { @@ -69,9 +70,9 @@ export class MemorySqlDataSource extends BaseSqlDataSource { return false; } - override setScript(script: string): void { + override setScript(script: string, source?: string, cursor?: ISqlEditorCursor): void { this._script = script; - super.setScript(script); + super.setScript(script, source, cursor); } override setExecutionContext(executionContext?: IConnectionExecutionContextInfo): void { diff --git a/webapp/packages/plugin-sql-editor/src/SqlDataSource/SqlDataSourceHistory/ISqlDataSourceHistory.ts b/webapp/packages/plugin-sql-editor/src/SqlDataSource/SqlDataSourceHistory/ISqlDataSourceHistory.ts index f80e035bf3..5c29862a8f 100644 --- a/webapp/packages/plugin-sql-editor/src/SqlDataSource/SqlDataSourceHistory/ISqlDataSourceHistory.ts +++ b/webapp/packages/plugin-sql-editor/src/SqlDataSource/SqlDataSourceHistory/ISqlDataSourceHistory.ts @@ -1,6 +1,6 @@ /* * CloudBeaver - Cloud Database Manager - * Copyright (C) 2020-2024 DBeaver Corp and others + * Copyright (C) 2020-2025 DBeaver Corp and others * * Licensed under the Apache License, Version 2.0. * you may not use this file except in compliance with the License. @@ -8,11 +8,15 @@ import type { ISyncExecutor } from '@cloudbeaver/core-executor'; import type { ISqlDataSourceHistoryState } from './ISqlDataSourceHistoryState.js'; +import type { ISqlEditorCursor } from '../ISqlDataSource.js'; export interface ISqlDataSourceHistory { readonly state: ISqlDataSourceHistoryState; - readonly onNavigate: ISyncExecutor; - add(value: string, source?: string): void; + readonly onNavigate: ISyncExecutor<{ + value: string; + cursor?: ISqlEditorCursor; + }>; + add(value: string, source?: string, cursor?: ISqlEditorCursor): void; undo(): void; redo(): void; restore(data: ISqlDataSourceHistoryState): void; diff --git a/webapp/packages/plugin-sql-editor/src/SqlDataSource/SqlDataSourceHistory/ISqlDataSourceHistoryData.ts b/webapp/packages/plugin-sql-editor/src/SqlDataSource/SqlDataSourceHistory/ISqlDataSourceHistoryData.ts index 7171ab4db2..4ae0c12aa7 100644 --- a/webapp/packages/plugin-sql-editor/src/SqlDataSource/SqlDataSourceHistory/ISqlDataSourceHistoryData.ts +++ b/webapp/packages/plugin-sql-editor/src/SqlDataSource/SqlDataSourceHistory/ISqlDataSourceHistoryData.ts @@ -1,13 +1,16 @@ /* * CloudBeaver - Cloud Database Manager - * Copyright (C) 2020-2024 DBeaver Corp and others + * Copyright (C) 2020-2025 DBeaver Corp and others * * Licensed under the Apache License, Version 2.0. * you may not use this file except in compliance with the License. */ +import type { ISqlEditorCursor } from '../ISqlDataSource.js'; + export interface ISqlDataSourceHistoryData { value: string; + cursor?: ISqlEditorCursor; timestamp: number; source?: string; } diff --git a/webapp/packages/plugin-sql-editor/src/SqlDataSource/SqlDataSourceHistory/SqlDataSourceHistory.ts b/webapp/packages/plugin-sql-editor/src/SqlDataSource/SqlDataSourceHistory/SqlDataSourceHistory.ts index cc03554e5f..435b5a8b21 100644 --- a/webapp/packages/plugin-sql-editor/src/SqlDataSource/SqlDataSourceHistory/SqlDataSourceHistory.ts +++ b/webapp/packages/plugin-sql-editor/src/SqlDataSource/SqlDataSourceHistory/SqlDataSourceHistory.ts @@ -1,6 +1,6 @@ /* * CloudBeaver - Cloud Database Manager - * Copyright (C) 2020-2024 DBeaver Corp and others + * Copyright (C) 2020-2025 DBeaver Corp and others * * Licensed under the Apache License, Version 2.0. * you may not use this file except in compliance with the License. @@ -12,13 +12,17 @@ import { type ISyncExecutor, SyncExecutor } from '@cloudbeaver/core-executor'; import { createSqlDataSourceHistoryInitialState } from './createSqlDataSourceHistoryInitialState.js'; import type { ISqlDataSourceHistory } from './ISqlDataSourceHistory.js'; import type { ISqlDataSourceHistoryState } from './ISqlDataSourceHistoryState.js'; +import type { ISqlEditorCursor } from '../ISqlDataSource.js'; const HOT_HISTORY_SIZE = 30; const COMPRESSED_HISTORY_DELAY = 5000; export class SqlDataSourceHistory implements ISqlDataSourceHistory { state: ISqlDataSourceHistoryState; - readonly onNavigate: ISyncExecutor; + readonly onNavigate: ISyncExecutor<{ + value: string; + cursor?: ISqlEditorCursor; + }>; constructor() { this.state = createSqlDataSourceHistoryInitialState(); @@ -29,7 +33,7 @@ export class SqlDataSourceHistory implements ISqlDataSourceHistory { }); } - add(value: string, source?: string): void { + add(value: string, source?: string, cursor?: ISqlEditorCursor): void { // skip history if value is the same as current if (this.state.history[this.state.historyIndex]!.value === value) { return; @@ -40,7 +44,7 @@ export class SqlDataSourceHistory implements ISqlDataSourceHistory { this.state.history.splice(this.state.historyIndex + 1); } - this.state.historyIndex = this.state.history.push({ value, source, timestamp: Date.now() }) - 1; + this.state.historyIndex = this.state.history.push({ value, source, timestamp: Date.now(), cursor }) - 1; this.compressHistory(); } @@ -49,8 +53,8 @@ export class SqlDataSourceHistory implements ISqlDataSourceHistory { return; } this.state.historyIndex--; - const value = this.state.history[this.state.historyIndex]!.value; - this.onNavigate.execute(value); + const prevHistoryItem = this.state.history[this.state.historyIndex]!; + this.onNavigate.execute(prevHistoryItem); } redo(): void { @@ -59,8 +63,8 @@ export class SqlDataSourceHistory implements ISqlDataSourceHistory { } this.state.historyIndex++; - const value = this.state.history[this.state.historyIndex]!.value; - this.onNavigate.execute(value); + const prevHistoryItem = this.state.history[this.state.historyIndex]!; + this.onNavigate.execute(prevHistoryItem); } restore(state: ISqlDataSourceHistoryState): void { diff --git a/webapp/packages/plugin-sql-editor/src/SqlDataSource/SqlDataSourceHistory/createSqlDataSourceHistoryInitialState.ts b/webapp/packages/plugin-sql-editor/src/SqlDataSource/SqlDataSourceHistory/createSqlDataSourceHistoryInitialState.ts index 5dc7cfe9d4..c67ff547b7 100644 --- a/webapp/packages/plugin-sql-editor/src/SqlDataSource/SqlDataSourceHistory/createSqlDataSourceHistoryInitialState.ts +++ b/webapp/packages/plugin-sql-editor/src/SqlDataSource/SqlDataSourceHistory/createSqlDataSourceHistoryInitialState.ts @@ -1,6 +1,6 @@ /* * CloudBeaver - Cloud Database Manager - * Copyright (C) 2020-2024 DBeaver Corp and others + * Copyright (C) 2020-2025 DBeaver Corp and others * * Licensed under the Apache License, Version 2.0. * you may not use this file except in compliance with the License. @@ -9,7 +9,7 @@ import type { ISqlDataSourceHistoryState } from './ISqlDataSourceHistoryState.js export function createSqlDataSourceHistoryInitialState(value = ''): ISqlDataSourceHistoryState { return { - history: [{ value, source: 'initial', timestamp: Date.now() }], + history: [{ value, source: 'initial', timestamp: Date.now(), cursor: { anchor: 0, head: 0 } }], historyIndex: 0, }; } diff --git a/webapp/packages/plugin-sql-editor/src/SqlEditor/ISQLEditorData.ts b/webapp/packages/plugin-sql-editor/src/SqlEditor/ISQLEditorData.ts index 844a3db034..b32199b1db 100644 --- a/webapp/packages/plugin-sql-editor/src/SqlEditor/ISQLEditorData.ts +++ b/webapp/packages/plugin-sql-editor/src/SqlEditor/ISQLEditorData.ts @@ -1,6 +1,6 @@ /* * CloudBeaver - Cloud Database Manager - * Copyright (C) 2020-2024 DBeaver Corp and others + * Copyright (C) 2020-2025 DBeaver Corp and others * * Licensed under the Apache License, Version 2.0. * you may not use this file except in compliance with the License. @@ -42,7 +42,7 @@ export interface ISQLEditorData { readonly hintsLimitIsMet: boolean; updateParserScriptsDebounced(): Promise; - setScript(query: string): void; + setScript(query: string, source?: string, cursor?: ISqlEditorCursor): void; init(): void; destruct(): void; setCursor(begin: number, end?: number): void; @@ -51,12 +51,12 @@ export interface ISQLEditorData { executeQueryNewTab(): Promise; showExecutionPlan(): Promise; executeScript(): Promise; - switchEditing(): Promise; + switchEditing(): void; getHintProposals(position: number, simple: boolean): Promise; getResolvedSegment(): Promise; executeQueryAction( segment: ISQLScriptSegment | undefined, - action: (query: ISQLScriptSegment) => Promise, + action: (query: ISQLScriptSegment) => T | Promise, passEmpty?: boolean, passDisabled?: boolean, ): Promise; diff --git a/webapp/packages/plugin-sql-editor/src/SqlEditor/useSqlEditor.ts b/webapp/packages/plugin-sql-editor/src/SqlEditor/useSqlEditor.ts index 6a625e4be6..0a140a6797 100644 --- a/webapp/packages/plugin-sql-editor/src/SqlEditor/useSqlEditor.ts +++ b/webapp/packages/plugin-sql-editor/src/SqlEditor/useSqlEditor.ts @@ -1,6 +1,6 @@ /* * CloudBeaver - Cloud Database Manager - * Copyright (C) 2020-2024 DBeaver Corp and others + * Copyright (C) 2020-2025 DBeaver Corp and others * * Licensed under the Apache License, Version 2.0. * you may not use this file except in compliance with the License. @@ -251,7 +251,7 @@ export function useSqlEditor(state: ISqlEditorTabState): ISQLEditorData { await this.executeQueryAction( query, - async () => { + () => { if (this.dataSource?.databaseModels.length) { this.sqlQueryService.initDatabaseDataModels(this.state); } @@ -297,7 +297,7 @@ export function useSqlEditor(state: ISqlEditorTabState): ISQLEditorData { } catch {} }, - async switchEditing(): Promise { + switchEditing(): void { this.dataSource?.setEditing(!this.dataSource.isEditing()); }, @@ -360,8 +360,8 @@ export function useSqlEditor(state: ISqlEditorTabState): ISQLEditorData { } }, - setScript(query: string): void { - this.dataSource?.setScript(query); + setScript(query: string, source?: string, cursor?: ISqlEditorCursor): void { + this.dataSource?.setScript(query, source, cursor); }, updateParserScriptsDebounced: debounceAsync(async function updateParserScriptsThrottle() { diff --git a/webapp/packages/plugin-sql-editor/src/SqlEditorService.ts b/webapp/packages/plugin-sql-editor/src/SqlEditorService.ts index b2c4b3a8d2..b0ec6b1b4e 100644 --- a/webapp/packages/plugin-sql-editor/src/SqlEditorService.ts +++ b/webapp/packages/plugin-sql-editor/src/SqlEditorService.ts @@ -1,6 +1,6 @@ /* * CloudBeaver - Cloud Database Manager - * Copyright (C) 2020-2024 DBeaver Corp and others + * Copyright (C) 2020-2025 DBeaver Corp and others * * Licensed under the Apache License, Version 2.0. * you may not use this file except in compliance with the License. @@ -174,7 +174,7 @@ export class SqlEditorService { } } - async initEditorConnection(state: ISqlEditorTabState): Promise { + initEditorConnection(state: ISqlEditorTabState): Promise { return this.sqlDataSourceService.executeAction( state.editorId, async dataSource => {