From c3d6490efba2f5a846fb8f60b893736a445a71d4 Mon Sep 17 00:00:00 2001 From: Alexey Date: Tue, 28 Nov 2023 15:58:05 +0300 Subject: [PATCH] CB-3975 fix: selection out of boundaries (#2173) Co-authored-by: Daria Marutkina <125263541+dariamarutkina@users.noreply.github.com> --- .../src/SQLEditor/SQLCodeEditorPanel/SQLCodeEditorPanel.tsx | 4 ++-- .../packages/plugin-sql-editor/src/SqlEditor/useSqlEditor.ts | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/webapp/packages/plugin-sql-editor-new/src/SQLEditor/SQLCodeEditorPanel/SQLCodeEditorPanel.tsx b/webapp/packages/plugin-sql-editor-new/src/SQLEditor/SQLCodeEditorPanel/SQLCodeEditorPanel.tsx index 6f8e6c0955..a85dd247c7 100644 --- a/webapp/packages/plugin-sql-editor-new/src/SQLEditor/SQLCodeEditorPanel/SQLCodeEditorPanel.tsx +++ b/webapp/packages/plugin-sql-editor-new/src/SQLEditor/SQLCodeEditorPanel/SQLCodeEditorPanel.tsx @@ -43,10 +43,10 @@ export const SQLCodeEditorPanel: TabContainerPanelComponent useEffect(() => { editorRef?.view?.dispatch({ - selection: { anchor: localState.selection.from, head: localState.selection.to }, + selection: { anchor: Math.min(localState.selection.to, data.value.length), head: Math.min(localState.selection.to, data.value.length) }, scrollIntoView: true, }); - }, [editorRef?.view, localState]); + }, [editorRef?.view, localState, data]); useEffect(() => { if (!editorRef?.selection) { diff --git a/webapp/packages/plugin-sql-editor/src/SqlEditor/useSqlEditor.ts b/webapp/packages/plugin-sql-editor/src/SqlEditor/useSqlEditor.ts index 19194d93bd..4e01986fb5 100644 --- a/webapp/packages/plugin-sql-editor/src/SqlEditor/useSqlEditor.ts +++ b/webapp/packages/plugin-sql-editor/src/SqlEditor/useSqlEditor.ts @@ -26,7 +26,6 @@ import { SqlEditorService } from '../SqlEditorService'; import { ISQLScriptSegment, SQLParser } from '../SQLParser'; import { SqlExecutionPlanService } from '../SqlResultTabs/ExecutionPlan/SqlExecutionPlanService'; import { OUTPUT_LOGS_TAB_ID } from '../SqlResultTabs/OutputLogs/OUTPUT_LOGS_TAB_ID'; -import { OutputLogsService } from '../SqlResultTabs/OutputLogs/OutputLogsService'; import { SqlQueryService } from '../SqlResultTabs/SqlQueryService'; import { SqlResultTabsService } from '../SqlResultTabs/SqlResultTabsService'; import type { ICursor, ISQLEditorData } from './ISQLEditorData'; @@ -69,7 +68,6 @@ export function useSqlEditor(state: ISqlEditorTabState): ISQLEditorData { const sqlResultTabsService = useService(SqlResultTabsService); const commonDialogService = useService(CommonDialogService); const sqlDataSourceService = useService(SqlDataSourceService); - const sqlOutputLogsService = useService(OutputLogsService); const data = useObservableRef( () => ({