Skip to content

Commit 350b532

Browse files
+ Unit testing for diacriticsSensitive feature (diacritics insensitive test).
+ Added asset data text with diacritics as example. + Added case senstive and diacritics sensitive options as checkboxes on app.
1 parent 9cd6a30 commit 350b532

File tree

4 files changed

+104
-21
lines changed

4 files changed

+104
-21
lines changed

test/unit/specs/highlightChunks.spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,25 @@ describe('highlightChunks', () => {
9696
]);
9797
});
9898

99+
test('should match diacritics insensitive', () => {
100+
const text = 'aBocd';
101+
const string = 'abóc';
102+
103+
const chunks = highlightChunks(text, string, false, false);
104+
105+
expect(chunks).toEqual([
106+
{
107+
isHighlighted: true,
108+
text: 'aBoc',
109+
highlightIndex: 0,
110+
},
111+
{
112+
isHighlighted: false,
113+
text: 'd',
114+
},
115+
]);
116+
});
117+
99118
test('should accept string as queries', () => {
100119
const text = 'aBcd';
101120
const object = { test: 'abc' };

web/App.vue

Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,41 @@
1212
@input="updateSearch"
1313
label="Search"
1414
class="textField"></input-field>
15-
<check-box
16-
:defaultValue="split"
17-
@onchange="updateSplit"
18-
class="checkBox">Split by space</check-box>
19-
<check-box
20-
:defaultValue="custom"
21-
@onchange="updateCustom"
22-
class="checkBox">Custom component</check-box>
15+
<div class="row">
16+
<div class="column">
17+
<check-box
18+
:defaultValue="split"
19+
@onchange="updateSplit"
20+
class="checkBox">Split by space</check-box>
21+
</div>
22+
<div class="column">
23+
<check-box
24+
:defaultValue="custom"
25+
@onchange="updateCustom"
26+
class="checkBox">Custom component</check-box>
27+
</div>
28+
</div>
29+
<div class="row">
30+
<div class="column">
31+
<check-box
32+
:defaultValue="caseSensitive"
33+
@onchange="updateCaseSensitive"
34+
class="checkBox">Case sensitive</check-box>
35+
</div>
36+
<div class="column">
37+
<check-box
38+
:defaultValue="diacriticsSensitive"
39+
@onchange="updateDiacriticsSensitive"
40+
class="checkBox">Diacritics sensitive</check-box>
41+
</div>
42+
</div>
2343
</div>
2444
<example-document
2545
:search="search"
2646
:split="split"
27-
:custom="custom"></example-document>
47+
:custom="custom"
48+
:caseSensitive="caseSensitive"
49+
:diacriticsSensitive="diacriticsSensitive"></example-document>
2850
</div>
2951
</div>
3052
</template>
@@ -50,6 +72,8 @@ export default {
5072
search: '',
5173
split: false,
5274
custom: false,
75+
caseSensitive: false,
76+
diacriticsSensitive: false,
5377
};
5478
},
5579
methods: {
@@ -62,6 +86,12 @@ export default {
6286
updateCustom(val) {
6387
this.custom = val;
6488
},
89+
updateCaseSensitive(val) {
90+
this.caseSensitive = val;
91+
},
92+
updateDiacriticsSensitive(val) {
93+
this.diacriticsSensitive = val;
94+
},
6595
},
6696
};
6797
</script>
@@ -77,7 +107,7 @@ body {
77107
-moz-osx-font-smoothing: grayscale;
78108
text-align: center;
79109
color: #2c3e50;
80-
margin-top: calc(10vh + 5%);
110+
margin-top: calc(5vh + 5%);
81111
.titleHighlight {
82112
background-color: #42b983;
83113
color: #FFFFFFF0;
@@ -95,21 +125,27 @@ body {
95125
box-shadow: 0 20px 50px rgba(0,0,0,.1);
96126
}
97127
.inputs {
98-
display: flex;
99-
align-items: center;
100-
justify-content: space-between;
101128
margin-bottom: 20px;
102129
padding: 15px;
103130
border-bottom: 1px solid rgba(0, 0, 0, .1);
104-
flex-wrap: wrap;
105-
.checkBox {
106-
margin: 0 10px;
107-
}
108131
.textField {
109132
flex-grow: 1;
110133
padding-bottom: 10px;
111134
width: 100%;
112135
}
136+
.row {
137+
display: flex;
138+
flex-direction: row;
139+
flex-wrap: wrap;
140+
margin-bottom: 5px;
141+
width: 100%;
142+
}
143+
144+
.column {
145+
display: flex;
146+
flex-direction: column;
147+
flex-basis: 50%;
148+
}
113149
}
114150
}
115151
</style>

web/assets/data.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
export const texts = `Tropical birds scattered as Drake veered the Jeep onto an old rutted track,
1+
export const texts = {
2+
english: `Tropical birds scattered as Drake veered the Jeep onto an old rutted track,
23
snapping branches and tearing away vines, plowing through the rain forest with killers in pursuit,
34
bullets flying, a gorgeous but pouty girl in the passenger’s seat, and a bitch of a headache.
45
With only one of his arms on the wheel, the Jeep slewed to the left, and the pouty girl screamed as
5-
he forced the vehicle back onto the trail just before they would have crashed into a felled tree.`;
6+
he forced the vehicle back onto the trail just before they would have crashed into a felled tree.`,
7+
spanish: `Las aves tropicales se dispersaron cuando Drake desvió el Jeep hacia una vieja pista llena de baches,
8+
cortando ramas y arrancando enredaderas, surcando la selva tropical con asesinos persiguiéndolos,
9+
las balas volando, y una chica hermosa pero con mala cara en el asiento del pasajero con dolor de cabeza.
10+
Con un solo brazo en el volante, el Jeep giró hacia la izquierda, y la chica gruñona gritó obligando
11+
al vehículo a regresar al camino justo antes de que se estrellaran contra un árbol talado.`,
12+
};
613

714
export const html = '<script>vue-text-highlight is also safe against possible html injection</script>';

web/components/ExampleDocument.vue

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,24 @@
1717
@leave="unsetActiveIndex"
1818
:activeIndex="activeIndex"
1919
:displayHoverMe="true"
20+
:caseSensitive="caseSensitive"
21+
:diacriticsSensitive="diacriticsSensitive"
2022
>
21-
{{ texts }}
23+
{{ textEnglish }}
24+
</text-highlight>
25+
</div>
26+
<div class="text">
27+
<text-highlight
28+
:queries="queries"
29+
:highlightComponent="highlightComponent"
30+
@enter="setActiveIndex"
31+
@leave="unsetActiveIndex"
32+
:activeIndex="activeIndex"
33+
:displayHoverMe="true"
34+
:caseSensitive="caseSensitive"
35+
:diacriticsSensitive="diacriticsSensitive"
36+
>
37+
{{ textSpanish }}
2238
</text-highlight>
2339
</div>
2440
<div class="html">
@@ -28,6 +44,8 @@
2844
@enter="setActiveIndex"
2945
@leave="unsetActiveIndex"
3046
:activeIndex="activeIndex"
47+
:caseSensitive="caseSensitive"
48+
:diacriticsSensitive="diacriticsSensitive"
3149
>
3250
{{ html }}
3351
</text-highlight>
@@ -45,13 +63,16 @@ export default {
4563
search: String,
4664
split: Boolean,
4765
custom: Boolean,
66+
caseSensitive: Boolean,
67+
diacriticsSensitive: Boolean,
4868
},
4969
components: {
5070
TextHighlight,
5171
},
5272
data() {
5373
return {
54-
texts,
74+
textEnglish: texts.english,
75+
textSpanish: texts.spanish,
5576
html,
5677
activeIndex: null,
5778
};

0 commit comments

Comments
 (0)