Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

fix: LSDV-5560: Fix plus and minus hotkeys #1561

Merged
merged 6 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/core/Hotkey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ keymaster.filter = function(event) {
return true;
};

const ALIASES = {
'plus': '=',
Gondragos marked this conversation as resolved.
Show resolved Hide resolved
'minus': '-',
};

export const Hotkey = (
namespace = 'global',
description = 'Hotkeys',
Expand Down Expand Up @@ -159,6 +164,15 @@ export const Hotkey = (
_destructors.push(unbind);

return {
applyAliases(key: string) {
return key
.split(',')
.map(k => {
return k.split('+').map(k => ALIASES[k.trim()] ?? k).join('+');
},
)
Gondragos marked this conversation as resolved.
Show resolved Hide resolved
.join(',');
},
/**
* Add key
*/
Expand All @@ -169,7 +183,7 @@ export const Hotkey = (
console.warn(`Key already added: ${key}. It's possibly a bug.`);
}

const keyName = key.toLowerCase();
const keyName = this.applyAliases(key.toLowerCase());

_hotkeys_map[keyName] = func;
if (desc) _hotkeys_desc[keyName] = desc;
Expand Down
12 changes: 12 additions & 0 deletions tests/functional/data/image_segmentation/tools/zoom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const simpleConfig = `
<View>
<Image name="img" value="$image"/>
<RectangleLabels name="tag" toName="img">
<Label value="Label 1" background="purple"/>
</RectangleLabels>
</View>
`;

export const simpleImageData = {
image: 'https://htx-misc.s3.amazonaws.com/opensource/label-studio/examples/images/nick-owuor-astro-nic-visuals-wDifg5xc9Z4-unsplash.jpg',
};
2 changes: 1 addition & 1 deletion tests/functional/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"cvg:summary": "nyc report --temp-dir=.nyc_output --reporter=text-summary --cwd=. --exclude-after-remap false"
},
"dependencies": {
"@heartexlabs/ls-test": "git+ssh://[email protected]/heartexlabs/ls-frontend-test#522adf318dce98b535fc8f9646791b3a1a2aeebb"
"@heartexlabs/ls-test": "git+ssh://[email protected]/heartexlabs/ls-frontend-test#36fc7ffc2cddc4e77aa785ec3304900b27163f72"
},
"devDependencies": {
"ts-loader": "^9.4.2",
Expand Down
32 changes: 32 additions & 0 deletions tests/functional/specs/image_segmentation/tools/zoom.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { ImageView, LabelStudio } from '@heartexlabs/ls-test/helpers/LSF';
import { simpleConfig, simpleImageData } from 'data/image_segmentation/tools/zoom';

describe('Zoom tool', () => {
it('should zoom on hotkey', () => {
LabelStudio.params()
.config(simpleConfig)
.data(simpleImageData)
.withResult([])
.init();

ImageView.waitForImage();

const sizes = ImageView.image.then((img) => {
return {
width: parseFloat(img.css('width')),
height: parseFloat(img.css('height')),
};
});

for (let i = 0; i < 10; i++) {
ImageView.zoomInWithHotkey();
}

ImageView.image.then((img) => {
sizes.then((sizes) => {
expect(parseFloat(img.css('width'))).to.be.greaterThan(sizes.width);
expect(parseFloat(img.css('height'))).to.be.greaterThan(sizes.height);
});
});
});
});
22 changes: 22 additions & 0 deletions tests/functional/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,28 @@
resolved "https://registry.yarnpkg.com/@discoveryjs/json-ext/-/json-ext-0.5.7.tgz#1d572bfbbe14b7704e0ba0f39b74815b84870d70"
integrity sha512-dBVuXR082gk3jsFp7Rd/JI4kytwGHecnCoTtXFb7DB6CNHp4rg5k1bhg0nWdLGLnOV71lmDzGQaLMy8iPLY0pw==

"@heartexlabs/ls-test@git+ssh://[email protected]/heartexlabs/ls-frontend-test#36fc7ffc2cddc4e77aa785ec3304900b27163f72":
hlomzik marked this conversation as resolved.
Show resolved Hide resolved
version "1.0.8"
resolved "git+ssh://[email protected]/heartexlabs/ls-frontend-test#36fc7ffc2cddc4e77aa785ec3304900b27163f72"
dependencies:
"@cypress/code-coverage" "^3.10.0"
"@cypress/webpack-preprocessor" "^5.17.0"
chai "^4.3.7"
cypress "^12.9.0"
cypress-image-snapshot "^4.0.1"
cypress-multi-reporters "^1.6.2"
cypress-parallel "^0.12.0"
cypress-plugin-snapshots "^1.4.4"
cypress-terminal-report "^5.1.1"
pixelmatch "^5.3.0"
pngjs "^7.0.0"
proper-lockfile "^4.1.2"
ts-loader "^9.4.2"
typescript "^4.9.5"
webpack "^5.77.0"
webpack-cli "^5.0.1"
yargs "^17.7.1"

"@heartexlabs/ls-test@git+ssh://[email protected]/heartexlabs/ls-frontend-test#522adf318dce98b535fc8f9646791b3a1a2aeebb":
version "1.0.8"
resolved "git+ssh://[email protected]/heartexlabs/ls-frontend-test#522adf318dce98b535fc8f9646791b3a1a2aeebb"
Expand Down
Loading