fix(editor): UI enhancements and fixes for expression inputs (#8996)

This commit is contained in:
Elias Meire
2024-03-29 16:01:32 +01:00
committed by GitHub
parent 1cbd044e41
commit 8788e2a35b
12 changed files with 41 additions and 86 deletions

View File

@@ -28,9 +28,6 @@ vi.mock('@/stores/n8nRoot.store', () => ({
}));
describe('useAutocompleteTelemetry', () => {
const originalRangeGetBoundingClientRect = Range.prototype.getBoundingClientRect;
const originalRangeGetClientRects = Range.prototype.getClientRects;
beforeEach(() => {
setActivePinia(createTestingPinia());
});
@@ -39,20 +36,6 @@ describe('useAutocompleteTelemetry', () => {
vi.clearAllMocks();
});
beforeAll(() => {
Range.prototype.getBoundingClientRect = vi.fn();
Range.prototype.getClientRects = () => ({
item: vi.fn(),
length: 0,
[Symbol.iterator]: vi.fn(),
});
});
afterAll(() => {
Range.prototype.getBoundingClientRect = originalRangeGetBoundingClientRect;
Range.prototype.getClientRects = originalRangeGetClientRects;
});
const getEditor = (defaultDoc = '') => {
const extensionCompartment = new Compartment();
const state = EditorState.create({

View File

@@ -21,9 +21,6 @@ vi.mock('@/stores/ndv.store', () => ({
}));
describe('useExpressionEditor', () => {
const originalRangeGetBoundingClientRect = Range.prototype.getBoundingClientRect;
const originalRangeGetClientRects = Range.prototype.getClientRects;
const mockResolveExpression = () => {
const mock = vi.fn();
vi.spyOn(workflowHelpers, 'useWorkflowHelpers').mockReturnValueOnce({
@@ -42,20 +39,6 @@ describe('useExpressionEditor', () => {
vi.clearAllMocks();
});
beforeAll(() => {
Range.prototype.getBoundingClientRect = vi.fn();
Range.prototype.getClientRects = () => ({
item: vi.fn(),
length: 0,
[Symbol.iterator]: vi.fn(),
});
});
afterAll(() => {
Range.prototype.getBoundingClientRect = originalRangeGetBoundingClientRect;
Range.prototype.getClientRects = originalRangeGetClientRects;
});
test('should create an editor', async () => {
const root = ref<HTMLElement>();
const { editor } = useExpressionEditor({

View File

@@ -185,7 +185,7 @@ export const useExpressionEditor = ({
if (editor.value) {
editor.value.destroy();
}
editor.value = new EditorView({ parent, state });
editor.value = new EditorView({ parent, state, scrollTo: EditorView.scrollIntoView(0) });
debouncedUpdateSegments();
});
@@ -385,7 +385,8 @@ export const useExpressionEditor = ({
function setCursorPosition(pos: number | 'lastExpression' | 'end'): void {
if (pos === 'lastExpression') {
const END_OF_EXPRESSION = ' }}';
pos = Math.max(readEditorValue().lastIndexOf(END_OF_EXPRESSION), 0);
const endOfLastExpression = readEditorValue().lastIndexOf(END_OF_EXPRESSION);
pos = endOfLastExpression !== -1 ? endOfLastExpression : editor.value?.state.doc.length ?? 0;
} else if (pos === 'end') {
pos = editor.value?.state.doc.length ?? 0;
}