Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tricky handling of a caret position in input element #1923

Merged
merged 2 commits into from
Jul 23, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `Image compression` definition mismatch (<https://github.com/opencv/cvat/issues/1900>)
- Points are dublicated during polygon interpolation sometimes (<https://github.com/opencv/cvat/pull/1892>)
- When redraw a shape with activated autobordering, previous points are visible (<https://github.com/opencv/cvat/pull/1892>)
- No mapping between side object element and context menu in some attributes (<https://github.com/opencv/cvat/pull/1923>)

### Security
-
Expand Down
2 changes: 1 addition & 1 deletion cvat-ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cvat-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cvat-ui",
"version": "1.6.2",
"version": "1.6.3",
"description": "CVAT single-page application",
"main": "src/index.tsx",
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function CanvasContextMenu(props: Props): JSX.Element | null {

return ReactDOM.createPortal(
<div className='cvat-canvas-context-menu' style={{ top, left }}>
<ObjectItemContainer clientID={activatedStateID} />
<ObjectItemContainer key={activatedStateID} clientID={activatedStateID} />
</div>,
window.document.body,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: MIT

import React from 'react';
import React, { useState, useEffect, useRef } from 'react';
import { Col } from 'antd/lib/grid';
import Select from 'antd/lib/select';
import Radio, { RadioChangeEvent } from 'antd/lib/radio';
Expand Down Expand Up @@ -124,7 +124,6 @@ function ItemAttributeComponent(props: Props): JSX.Element {

if (attrInputType === 'number') {
const [min, max, step] = attrValues.map((value: string): number => +value);

return (
<>
<Col span={8} style={attrNameStyle}>
Expand Down Expand Up @@ -153,6 +152,25 @@ function ItemAttributeComponent(props: Props): JSX.Element {
);
}

const ref = useRef<Input>(null);
const [selection, setSelection] = useState<{
start: number | null;
end: number | null;
direction: 'forward' | 'backward' | 'none' | null;
}>({
start: null,
end: null,
direction: null,
});

useEffect(() => {
if (ref.current && ref.current.input) {
ref.current.input.selectionStart = selection.start;
ref.current.input.selectionEnd = selection.end;
ref.current.input.selectionDirection = selection.direction;
}
}, [attrValue]);

return (
<>
<Col span={8} style={attrNameStyle}>
Expand All @@ -162,11 +180,20 @@ function ItemAttributeComponent(props: Props): JSX.Element {
</Col>
<Col span={16}>
<Input
ref={ref}
size='small'
onChange={(event: React.ChangeEvent<HTMLInputElement>): void => {
if (ref.current && ref.current.input) {
setSelection({
start: ref.current.input.selectionStart,
end: ref.current.input.selectionEnd,
direction: ref.current.input.selectionDirection,
});
}

changeAttribute(attrID, event.target.value);
}}
defaultValue={attrValue}
value={attrValue}
className='cvat-object-item-text-attribute'
/>
</Col>
Expand Down