Skip to content

Commit 3a480cf

Browse files
rtibblesbotclaude
andcommitted
Resize images by the handle's computed direction
The handle is placed with inset-inline-end, so under the editor's dir="auto" it follows the content direction, which can differ from the page's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 2a23d02 commit 3a480cf

2 files changed

Lines changed: 78 additions & 8 deletions

File tree

‎contentcuration/contentcuration/frontend/shared/views/TipTapEditor/TipTapEditor/components/image/ImageNodeView.vue‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,6 @@
169169
}
170170
};
171171
172-
const isRtl = computed(() => {
173-
// Cache the RTL check result to avoid repeated DOM traversal
174-
return props.editor.view.dom.closest('[dir="rtl"]') !== null;
175-
});
176-
177172
const styleWidth = computed(() => (width.value ? `${width.value}px` : 'auto'));
178173
const isCompact = computed(() => width.value < compactThreshold);
179174
@@ -196,14 +191,17 @@
196191
return null;
197192
};
198193
194+
const isHandleRtl = () => getComputedStyle(resizeHandleRef.value).direction === 'rtl';
195+
199196
const onResizeStart = startEvent => {
197+
const isRtl = isHandleRtl();
200198
const startX = startEvent.clientX;
201199
const startWidth = width.value || containerRef.value.offsetWidth;
202200
203201
const onMouseMove = moveEvent => {
204202
const deltaX = moveEvent.clientX - startX;
205203
206-
const newWidth = isRtl.value
204+
const newWidth = isRtl
207205
? startWidth - deltaX // In RTL, moving right should decrease width
208206
: startWidth + deltaX; // In LTR, moving right should increase width
209207
@@ -244,8 +242,9 @@
244242
let newWidth = currentWidth;
245243
246244
// Invert keyboard controls for RTL
247-
const rightKey = isRtl.value ? 'ArrowLeft' : 'ArrowRight';
248-
const leftKey = isRtl.value ? 'ArrowRight' : 'ArrowLeft';
245+
const isRtl = isHandleRtl();
246+
const rightKey = isRtl ? 'ArrowLeft' : 'ArrowRight';
247+
const leftKey = isRtl ? 'ArrowRight' : 'ArrowLeft';
249248
250249
if (event.key === rightKey) {
251250
newWidth = currentWidth + step;
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { fireEvent, render, screen, waitFor } from '@testing-library/vue';
2+
import VueRouter from 'vue-router';
3+
import TipTapEditor from '../TipTapEditor/TipTapEditor.vue';
4+
5+
async function renderImage() {
6+
render(TipTapEditor, {
7+
props: {
8+
value: '<img src="x" width="300">',
9+
mode: 'edit',
10+
format: 'html',
11+
imageProcessor: { ACCEPTED_MIME_TYPES: ['image/png'] },
12+
},
13+
router: new VueRouter(),
14+
});
15+
return screen.findByRole('slider', { name: 'Resize image' });
16+
}
17+
18+
async function dragRight(slider) {
19+
await fireEvent.mouseDown(slider, { clientX: 0 });
20+
await fireEvent.mouseMove(document, { clientX: 20 });
21+
await fireEvent.mouseUp(document);
22+
}
23+
24+
describe('ImageNodeView resize', () => {
25+
afterEach(() => {
26+
delete window.isRTL;
27+
});
28+
29+
it('grows the image when dragged to the right in LTR content', async () => {
30+
const slider = await renderImage();
31+
32+
await dragRight(slider);
33+
34+
await waitFor(() => expect(slider).toHaveAttribute('aria-valuenow', '320'));
35+
});
36+
37+
it('grows the image on ArrowRight in LTR content', async () => {
38+
const slider = await renderImage();
39+
40+
await fireEvent.keyDown(slider, { key: 'ArrowRight' });
41+
42+
await waitFor(() => expect(slider).toHaveAttribute('aria-valuenow', '310'));
43+
});
44+
45+
it('shrinks the image when dragged to the right in RTL content', async () => {
46+
const slider = await renderImage();
47+
slider.style.direction = 'rtl';
48+
49+
await dragRight(slider);
50+
51+
await waitFor(() => expect(slider).toHaveAttribute('aria-valuenow', '280'));
52+
});
53+
54+
it('grows the image on ArrowLeft in RTL content', async () => {
55+
const slider = await renderImage();
56+
slider.style.direction = 'rtl';
57+
58+
await fireEvent.keyDown(slider, { key: 'ArrowLeft' });
59+
60+
await waitFor(() => expect(slider).toHaveAttribute('aria-valuenow', '310'));
61+
});
62+
63+
it('follows the content direction, not the page direction', async () => {
64+
window.isRTL = true;
65+
const slider = await renderImage();
66+
67+
await dragRight(slider);
68+
69+
await waitFor(() => expect(slider).toHaveAttribute('aria-valuenow', '320'));
70+
});
71+
});

0 commit comments

Comments
 (0)