Skip to content

Commit c62ba14

Browse files
committed
change active to include selected word
1 parent 6602a46 commit c62ba14

File tree

6 files changed

+20
-7
lines changed

6 files changed

+20
-7
lines changed

src/components/Alignment/Sentence/Sentence.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,10 @@ const WrappedSentence = ({ n, json, children }) => {
106106
if (active && active[lnum] && active[lnum].has(wordId)) {
107107
setActive(null);
108108
} else if (idMap[lnum] && idMap[lnum][wordId]) {
109-
setActive(idMap[lnum][wordId]);
109+
setActive({
110+
selected: { lnum, n },
111+
aligned: idMap[lnum][wordId],
112+
});
110113
}
111114
};
112115

src/components/Segment/Segment.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const wordSpans = (words, lnum, active, toggleActive) => {
1313
const classes = [styles.word];
1414
const innerText = text.map(({ _ }) => _).join(<br />);
1515

16-
if (active && active[lnum] && active[lnum].has(n)) {
16+
if (active && active.aligned && active.aligned[lnum] && active.aligned[lnum].has(n)) {
1717
classes.push(styles.active);
1818
}
1919
const onClick = () => {

src/components/Segment/Segment.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ it('renders a sentence', () => {
4949

5050
it('displays active words differently', () => {
5151
const active = {
52-
L1: new Set(['1-2']),
52+
selected: { lnum: 'L1', n: '1-1' },
53+
aligned: { L1: new Set(['1-2']) },
5354
};
5455

5556
const component = (

src/components/Xml/Xml.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ const renderWord = (word, key, lnum, active, toggleActive, indent) => {
102102
}
103103
};
104104

105-
if (active && active[lnum] && active[lnum].has(n)) {
105+
if (active && active.aligned && active.aligned[lnum] && active.aligned[lnum].has(n)) {
106106
classes.push(styles.active);
107107
}
108108

src/components/Xml/Xml.test.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,11 @@ it('renders a sentence as XML', () => {
4949

5050
it('displays active words differently', () => {
5151
const active = {
52-
L1: new Set(['1-2']),
53-
L2: new Set(['1-2', '1-3']),
52+
selected: { lnum: 'L1', n: '1-1' },
53+
aligned: {
54+
L1: new Set(['1-2']),
55+
L2: new Set(['1-2', '1-3']),
56+
},
5457
};
5558

5659
const component = (

src/types/types.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,13 @@ const alignmentType = shape({
5151
}).isRequired,
5252
});
5353

54-
const activeType = objectOf(instanceOf(Set));
54+
const activeType = shape({
55+
selected: shape({
56+
lnum: string.isRequired,
57+
n: string.isRequired,
58+
}).isRequired,
59+
aligned: objectOf(instanceOf(Set)).isRequired,
60+
});
5561

5662
export {
5763
commentType,

0 commit comments

Comments
 (0)