Skip to content

Commit b07c1b8

Browse files
Gabriel Moradorsanticomp2014
authored andcommitted
fix: code review copilot
1 parent 0b22251 commit b07c1b8

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

src/annotator/draw-tool.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export class DrawTool implements Destroyable {
105105
/** Increment for keyboard movement (pixels) */
106106
private readonly _keyboardMoveIncrement = 10;
107107

108-
/** Increment for keyboard movement with Ctrl (Windows) or Cmd (Mac) (pixels) */
108+
/** Increment for keyboard movement with Ctrl or Cmd (pixels) */
109109
private readonly _keyboardMoveIncrementLarge = 50;
110110

111111
/** Default size for rectangle when initialized via keyboard (pixels) */
@@ -290,6 +290,8 @@ export class DrawTool implements Destroyable {
290290
this._waitingForSecondClick = false;
291291
this._firstClickPoint = undefined;
292292
this._hasMoved = false;
293+
// Deactivate keyboard mode since user is switching to mouse interaction
294+
this._deactivateKeyboardMode();
293295
this._renderSurface();
294296
return;
295297
}
@@ -458,7 +460,7 @@ export class DrawTool implements Destroyable {
458460
return;
459461
}
460462

461-
// Arrow keys: Move or resize. Fast movement: Ctrl (Windows) or Cmd (Mac)
463+
// Arrow keys: Move or resize. Fast movement: Ctrl or Cmd
462464
if (
463465
['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'].includes(e.key)
464466
) {

src/annotator/guest.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,12 @@ export class Guest
537537

538538
this._hostRPC.on('createAnnotation', ({ tool }) => {
539539
if (tool) {
540+
// When creating rect annotation via sidebar (mouse click), default to 'move'
541+
// mode so the rectangle appears on canvas. Keyboard shortcuts set
542+
// _pendingKeyboardMode themselves before calling createAnnotation.
543+
if (tool === 'rect' && this._pendingKeyboardMode === undefined) {
544+
this._pendingKeyboardMode = 'move';
545+
}
540546
return this.createAnnotation(tool);
541547
} else {
542548
this._drawTool.cancel();
@@ -1045,12 +1051,8 @@ export class Guest
10451051
this._hostRPC.call('activeToolChanged', tool);
10461052

10471053
// Draw the shape for the new annotation's region.
1048-
// Pass pending keyboard mode if set (from hotkey). For rect, default to
1049-
// 'move' so the rectangle appears on canvas when started via mouse (sidebar icon).
1050-
const initialMode =
1051-
tool === 'rect'
1052-
? (this._pendingKeyboardMode ?? 'move')
1053-
: this._pendingKeyboardMode;
1054+
// Pass pending keyboard mode if set (from hotkey or sidebar click).
1055+
const initialMode = this._pendingKeyboardMode;
10541056
this._pendingKeyboardMode = undefined;
10551057
const shape = await this._drawTool.draw(tool, initialMode);
10561058

src/annotator/test/draw-tool-test.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1101,14 +1101,17 @@ describe('DrawTool', () => {
11011101
assert.equal(shape.type, 'rect');
11021102
});
11031103

1104-
it('clears keyboard-initiated rectangle on first mouse move', async () => {
1104+
it('clears keyboard-initiated rectangle on first mouse move and deactivates keyboard mode', async () => {
11051105
const shapePromise = tool.draw('rect', 'move');
11061106
await delay(0);
11071107

11081108
// Verify rectangle was created and marked as keyboard-initiated
11091109
assert.ok(tool._shape);
11101110
assert.equal(tool._shape.type, 'rect');
11111111
assert.isTrue(tool._rectInitiatedByKeyboard);
1112+
// Verify keyboard mode is active
1113+
const initialState = tool.getKeyboardModeState();
1114+
assert.isTrue(initialState.keyboardActive);
11121115

11131116
// Simulate mouse move - should clear the keyboard-initiated rectangle
11141117
sendPointerEvent('pointermove', 50, 50);
@@ -1120,6 +1123,10 @@ describe('DrawTool', () => {
11201123
assert.isFalse(tool._waitingForSecondClick);
11211124
assert.isUndefined(tool._firstClickPoint);
11221125
assert.isFalse(tool._hasMoved);
1126+
// Verify keyboard mode was deactivated
1127+
const stateAfterMove = tool.getKeyboardModeState();
1128+
assert.isFalse(stateAfterMove.keyboardActive);
1129+
assert.isNull(stateAfterMove.keyboardMode);
11231130

11241131
// Now user can draw with mouse - simulate click to create new rectangle
11251132
sendPointerEvent('pointerdown', 10, 10);

0 commit comments

Comments
 (0)