File tree Expand file tree Collapse file tree 3 files changed +18
-4
lines changed Expand file tree Collapse file tree 3 files changed +18
-4
lines changed Original file line number Diff line number Diff line change 173
173
var displayLine = line ;
174
174
var width = 0 ;
175
175
var lastIsEng = false ;
176
+ var lastSpaceIndex = - 1 ;
176
177
177
178
while ( displayLine -- ) {
178
179
var ext = displayLine ? '' : truncateText + ' ' + childText ;
196
197
truncatedText = text . substr ( startPos , currentPos - 1 ) ;
197
198
}
198
199
if ( lastIsEng ) {
199
- currentPos = truncatedText . lastIndexOf ( ' ' ) ;
200
- truncatedText = text . substr ( startPos , currentPos ) ;
200
+ lastSpaceIndex = truncatedText . lastIndexOf ( ' ' ) ;
201
+ if ( lastSpaceIndex > - 1 ) {
202
+ currentPos = lastSpaceIndex ;
203
+ truncatedText = text . substr ( startPos , currentPos ) ;
204
+ }
201
205
}
202
206
width = this . measureWidth ( truncatedText + ext ) ;
203
207
} while ( width >= scopeWidth ) ;
Original file line number Diff line number Diff line change @@ -92,6 +92,12 @@ export class App extends Component {
92
92
< h5 > 5. Block-level textTruncateChild</ h5 >
93
93
< TextTruncate { ...props } textTruncateChild = { < div > Block level child</ div > } />
94
94
</ div >
95
+ < div id = 'sample-6' >
96
+ < h5 > 6. Long words inside a small container</ h5 >
97
+ < div style = { {
98
+ width : 150
99
+ } } > < TextTruncate line = { 3 } text = "Национал-Большевизм. Сталинская массовая культура и формирование русского национального самосознания (1931-1956)" /> </ div >
100
+ </ div >
95
101
</ div >
96
102
</ div >
97
103
)
Original file line number Diff line number Diff line change @@ -88,6 +88,7 @@ export default class TextTruncate extends Component {
88
88
let displayLine = line ;
89
89
let width = 0 ;
90
90
let lastIsEng = false ;
91
+ let lastSpaceIndex = - 1 ;
91
92
92
93
while ( displayLine -- ) {
93
94
let ext = displayLine ? '' : truncateText + ' ' + childText ;
@@ -111,8 +112,11 @@ export default class TextTruncate extends Component {
111
112
truncatedText = text . substr ( startPos , currentPos - 1 ) ;
112
113
}
113
114
if ( lastIsEng ) {
114
- currentPos = truncatedText . lastIndexOf ( ' ' ) ;
115
- truncatedText = text . substr ( startPos , currentPos ) ;
115
+ lastSpaceIndex = truncatedText . lastIndexOf ( ' ' ) ;
116
+ if ( lastSpaceIndex > - 1 ) {
117
+ currentPos = lastSpaceIndex ;
118
+ truncatedText = text . substr ( startPos , currentPos ) ;
119
+ }
116
120
}
117
121
width = this . measureWidth ( truncatedText + ext ) ;
118
122
} while ( width >= scopeWidth ) ;
You can’t perform that action at this time.
0 commit comments