@@ -13,6 +13,11 @@ import {clamp, debounce, t, tryURL} from './util';
1313
1414const SPLIT_BTN_MENU = '.split-btn-menu' ;
1515const tooltips = new WeakMap ( ) ;
16+ /** Strips html tags but allows <invalid-html-tags> which we use to emphasize stuff */
17+ const rxTag = / ( \n \s * ) ? < \/ ? [ a - z ] + (?: \s + [ a - z ] + = [ ^ > ] * ) ? > / g;
18+ const rxLong1 = / ( [ . ? ! ] \s + | [ . 。 ? ! ] \s * | .{ 55 , 70 } , ) \s + / gu;
19+ const rxLong2 = / ( .{ 55 , 70 } (? = .{ 50 , } ) ) \s + / gu;
20+
1621splitLongTooltips ( ) ;
1722addTooltipsToEllipsized ( ) ;
1823window . on ( 'mousedown' , suppressFocusRingOnClick , { passive : true } ) ;
@@ -224,20 +229,18 @@ function splitLongTooltips() {
224229 if ( tooltips . has ( el ) )
225230 continue ;
226231 const old = el . title ;
227- // Strip html tags but allow <invalid-html-tags> which we use to emphasize stuff
228- const title = old . replace ( / ( \n \s * ) ? < \/ ? [ a - z ] + ( \s + [ a - z ] + = [ ^ > ] * ?) ? > ( \n \s * ) ? / g, ' ' ) ;
229232 tooltips . set ( el , old ) ;
230- let tmp = '' ;
231- if ( title . length < 50 ) {
232- tmp = title ;
233- } else {
234- for ( const s of title . split ( / \n + / ) ) {
235- tmp += s . replace ( / ( [ . ? ! ] \s + | [ . 。 ? ! ] \s * | . { 50 , 60 } , ) \s + / gu , '$1 \n')
236- . replace ( / ( . { 50 , 80 } (? = . { 40 , } ) ) \s + / gu , '$1\n' ) ;
237- tmp += '\n\n' ;
233+ let res = old . includes ( '<' ) ? old . replace ( rxTag , '$1' ) : old ;
234+ if ( res . length > 60 ) {
235+ for ( let arr = res . split ( / \n + / ) , a = res = '' , b , cut , i = 0 ; i < arr . length ; i ++ ) {
236+ a = arr [ i ] ;
237+ b = a . length <= 60 ? a : a . replace ( rxLong1 , '$1\n' ) . replace ( rxLong2 , '$1\n' ) ;
238+ res += cut || i && b !== a ? '\n\n' : ' \n';
239+ res += b ;
240+ cut = b !== a ;
238241 }
239242 }
240- if ( tmp !== old )
241- el . title = tmp ;
243+ if ( res !== old )
244+ el . title = res ;
242245 }
243246}
0 commit comments