mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-07-09 06:23:29 +08:00
Compare commits
14 Commits
fix/oceanb
...
fix/query-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9e52397732 | ||
|
|
20ff4f3687 | ||
|
|
73ce3039ce | ||
|
|
61296bc855 | ||
|
|
78da0076cf | ||
|
|
279b38fec3 | ||
|
|
0e348fcca4 | ||
|
|
7d79fae84d | ||
|
|
f642e0325d | ||
|
|
43a408f1c9 | ||
|
|
b97b5cf6e2 | ||
|
|
6c269a99cf | ||
|
|
24841f2dd9 | ||
|
|
c2e60c1e52 |
@@ -24,6 +24,14 @@ const sameEditorPosition = (left: any, right: any): boolean => (
|
||||
&& Number(left?.column) === Number(right?.column)
|
||||
);
|
||||
|
||||
const isSelectionEmpty = (selection: any): boolean => (
|
||||
!selection
|
||||
|| (
|
||||
Number(selection.startLineNumber) === Number(selection.endLineNumber)
|
||||
&& Number(selection.startColumn) === Number(selection.endColumn)
|
||||
)
|
||||
);
|
||||
|
||||
const stripSqlIdentifierQuotes = (value: string): string => {
|
||||
const text = String(value || '').trim();
|
||||
if (!text) return '';
|
||||
@@ -126,10 +134,11 @@ const installOceanBaseOracleNavigationFallback = (editor: any) => {
|
||||
}
|
||||
|
||||
const parts = splitSqlIdentifierPath(identifier.text);
|
||||
if (parts.length !== 2) {
|
||||
if (parts.length < 2) {
|
||||
return;
|
||||
}
|
||||
const [schemaName, tableName] = parts;
|
||||
const schemaName = parts[parts.length - 2];
|
||||
const tableName = parts[parts.length - 1];
|
||||
if (!schemaName || !tableName) {
|
||||
return;
|
||||
}
|
||||
@@ -193,6 +202,72 @@ const patchQueryEditorAiInlineRightArrowFallback = (editor: any, monaco: any) =>
|
||||
};
|
||||
};
|
||||
|
||||
const installPrintableInputFallback = (editor: any, monaco: any) => {
|
||||
const editorDomNode = editor?.getDomNode?.();
|
||||
if (!editorDomNode || editor.__gonaviPrintableInputFallbackInstalled) {
|
||||
return;
|
||||
}
|
||||
const input = editorDomNode.querySelector?.('textarea.inputarea, .inputarea textarea, textarea') as HTMLTextAreaElement | null;
|
||||
if (!(input instanceof HTMLTextAreaElement)) {
|
||||
return;
|
||||
}
|
||||
Object.defineProperty(editor, '__gonaviPrintableInputFallbackInstalled', {
|
||||
value: true,
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
const isReadOnly = (): boolean => {
|
||||
try {
|
||||
const optionId = monaco?.editor?.EditorOption?.readOnly;
|
||||
return optionId !== undefined ? editor.getOption?.(optionId) === true : false;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleBeforeInput = (event: InputEvent) => {
|
||||
const text = String(event.data || '');
|
||||
if (
|
||||
event.defaultPrevented
|
||||
|| event.isComposing
|
||||
|| event.inputType !== 'insertText'
|
||||
|| !text
|
||||
|| text.length > 8
|
||||
|| isReadOnly()
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const selectionBefore = editor.getSelection?.();
|
||||
if (!isSelectionEmpty(selectionBefore)) {
|
||||
return;
|
||||
}
|
||||
const beforeValue = String(editor.getValue?.() ?? '');
|
||||
const beforePosition = editor.getPosition?.();
|
||||
|
||||
window.setTimeout(() => {
|
||||
const domNode = editor.getDomNode?.();
|
||||
if (!(domNode instanceof HTMLElement) || !domNode.isConnected || isReadOnly()) {
|
||||
return;
|
||||
}
|
||||
if (document.activeElement && !domNode.contains(document.activeElement)) {
|
||||
return;
|
||||
}
|
||||
const afterValue = String(editor.getValue?.() ?? '');
|
||||
const afterPosition = editor.getPosition?.();
|
||||
if (afterValue !== beforeValue || !sameEditorPosition(beforePosition, afterPosition)) {
|
||||
return;
|
||||
}
|
||||
editor.trigger?.('gonavi-printable-input-fallback', 'type', { text });
|
||||
}, 16);
|
||||
};
|
||||
|
||||
input.addEventListener('beforeinput', handleBeforeInput);
|
||||
editor.onDidDispose?.(() => {
|
||||
input.removeEventListener('beforeinput', handleBeforeInput);
|
||||
});
|
||||
};
|
||||
|
||||
export const registerGonaviMonacoThemes: BeforeMount = (monaco) => {
|
||||
if (transparentThemesRegistered) {
|
||||
return;
|
||||
@@ -290,6 +365,7 @@ const MonacoEditor: React.FC<MonacoEditorProps> = ({
|
||||
const handleMount: OnMount = useCallback((editor, monaco) => {
|
||||
installOceanBaseOracleNavigationFallback(editor);
|
||||
patchQueryEditorAiInlineRightArrowFallback(editor, monaco);
|
||||
installPrintableInputFallback(editor, monaco);
|
||||
onMount?.(editor, monaco);
|
||||
}, [onMount]);
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ const legacyLiterals = [
|
||||
'选择连接',
|
||||
'选择数据库',
|
||||
'最大返回行数',
|
||||
'最大行数:100',
|
||||
'最大行数:500',
|
||||
'最大行数:1000',
|
||||
'最大行数:5000',
|
||||
@@ -64,6 +65,7 @@ describe('QueryEditorToolbar i18n', () => {
|
||||
expect(source).toContain("import { useOptionalI18n } from '../i18n/provider';");
|
||||
expect(source).toContain('const i18n = useOptionalI18n();');
|
||||
expect(source).toContain('const t = i18n?.t ?? defaultTranslate;');
|
||||
expect(source).toContain("{ label: '100', value: 100 }");
|
||||
|
||||
for (const key of requiredKeys) {
|
||||
expect(source).toContain(key);
|
||||
|
||||
@@ -291,6 +291,7 @@ const QueryEditorToolbar: React.FC<QueryEditorToolbarProps> = ({
|
||||
value={maxRows}
|
||||
onChange={(val) => onMaxRowsChange(Number(val))}
|
||||
options={[
|
||||
{ label: '100', value: 100 },
|
||||
{ label: t("query_editor.max_rows.option_500"), value: 500 },
|
||||
{ label: t("query_editor.max_rows.option_1000"), value: 1000 },
|
||||
{ label: t("query_editor.max_rows.option_5000"), value: 5000 },
|
||||
|
||||
Reference in New Issue
Block a user