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 173173 var displayLine = line ;
174174 var width = 0 ;
175175 var lastIsEng = false ;
176+ var lastSpaceIndex = - 1 ;
176177
177178 while ( displayLine -- ) {
178179 var ext = displayLine ? '' : truncateText + ' ' + childText ;
196197 truncatedText = text . substr ( startPos , currentPos - 1 ) ;
197198 }
198199 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+ }
201205 }
202206 width = this . measureWidth ( truncatedText + ext ) ;
203207 } while ( width >= scopeWidth ) ;
Original file line number Diff line number Diff line change @@ -92,6 +92,12 @@ export class App extends Component {
9292 < h5 > 5. Block-level textTruncateChild</ h5 >
9393 < TextTruncate { ...props } textTruncateChild = { < div > Block level child</ div > } />
9494 </ 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 >
95101 </ div >
96102 </ div >
97103 )
Original file line number Diff line number Diff line change @@ -88,6 +88,7 @@ export default class TextTruncate extends Component {
8888 let displayLine = line ;
8989 let width = 0 ;
9090 let lastIsEng = false ;
91+ let lastSpaceIndex = - 1 ;
9192
9293 while ( displayLine -- ) {
9394 let ext = displayLine ? '' : truncateText + ' ' + childText ;
@@ -111,8 +112,11 @@ export default class TextTruncate extends Component {
111112 truncatedText = text . substr ( startPos , currentPos - 1 ) ;
112113 }
113114 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+ }
116120 }
117121 width = this . measureWidth ( truncatedText + ext ) ;
118122 } while ( width >= scopeWidth ) ;
You can’t perform that action at this time.
0 commit comments