fix(editor): UI enhancements and fixes for expression inputs (#8996)
This commit is contained in:
@@ -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({
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user