@@ -409,162 +409,9 @@ pub(super) fn push_writeback_editable_text_regions(
409409
410410pub ( super ) fn split_editable_text_segments < ' a > (
411411 text : & ' a str ,
412- presentation : & Option < TextPresentation > ,
412+ _presentation : & Option < TextPresentation > ,
413413) -> Vec < ( & ' a str , bool ) > {
414- let mut segments = Vec :: new ( ) ;
415- for ( segment_text, allow_rewrite) in split_structured_text_segments ( text, presentation) {
416- if !allow_rewrite {
417- segments. push ( ( segment_text, false ) ) ;
418- continue ;
419- }
420- extend_url_locked_segments ( & mut segments, segment_text) ;
421- }
422- segments
423- }
424-
425- pub ( super ) fn split_structured_text_segments < ' a > (
426- text : & ' a str ,
427- presentation : & Option < TextPresentation > ,
428- ) -> Vec < ( & ' a str , bool ) > {
429- if !presentation. as_ref ( ) . is_some_and ( |item| item. underline ) || !text_has_visible_content ( text)
430- {
431- return vec ! [ ( text, text_has_visible_content( text) ) ] ;
432- }
433- let Some ( ( content_start, content_end) ) = text_content_bounds ( text) else {
434- return vec ! [ ( text, false ) ] ;
435- } ;
436- if content_start == 0 && content_end == text. len ( ) {
437- return vec ! [ ( text, true ) ] ;
438- }
439- let mut segments = Vec :: with_capacity ( 3 ) ;
440- if content_start > 0 {
441- segments. push ( ( & text[ ..content_start] , false ) ) ;
442- }
443- segments. push ( ( & text[ content_start..content_end] , true ) ) ;
444- if content_end < text. len ( ) {
445- segments. push ( ( & text[ content_end..] , false ) ) ;
446- }
447- segments
448- }
449-
450- pub ( super ) fn text_content_bounds ( text : & str ) -> Option < ( usize , usize ) > {
451- let start = text. char_indices ( ) . find ( |( _, ch) | !ch. is_whitespace ( ) ) ?. 0 ;
452- let ( end_start, end_ch) = text
453- . char_indices ( )
454- . rev ( )
455- . find ( |( _, ch) | !ch. is_whitespace ( ) ) ?;
456- Some ( ( start, end_start + end_ch. len_utf8 ( ) ) )
457- }
458-
459- pub ( super ) fn extend_url_locked_segments < ' a > ( segments : & mut Vec < ( & ' a str , bool ) > , text : & ' a str ) {
460- let spans = bare_url_spans ( text) ;
461- if spans. is_empty ( ) {
462- segments. push ( ( text, true ) ) ;
463- return ;
464- }
465-
466- let mut cursor = 0usize ;
467- for ( start, end) in spans {
468- if cursor < start {
469- let prefix = & text[ cursor..start] ;
470- segments. push ( ( prefix, text_has_visible_content ( prefix) ) ) ;
471- }
472- segments. push ( ( & text[ start..end] , false ) ) ;
473- cursor = end;
474- }
475- if cursor < text. len ( ) {
476- let suffix = & text[ cursor..] ;
477- segments. push ( ( suffix, text_has_visible_content ( suffix) ) ) ;
478- }
479- }
480-
481- pub ( super ) fn bare_url_spans ( text : & str ) -> Vec < ( usize , usize ) > {
482- let mut spans = Vec :: new ( ) ;
483- let mut index = 0usize ;
484- while index < text. len ( ) {
485- let slice = & text[ index..] ;
486- let prefix_len = if slice. starts_with ( "https://" ) {
487- Some ( "https://" . len ( ) )
488- } else if slice. starts_with ( "http://" ) {
489- Some ( "http://" . len ( ) )
490- } else if slice. starts_with ( "www." ) {
491- Some ( "www." . len ( ) )
492- } else {
493- None
494- } ;
495- let Some ( prefix_len) = prefix_len else {
496- index += text[ index..]
497- . chars ( )
498- . next ( )
499- . map ( |ch| ch. len_utf8 ( ) )
500- . unwrap_or ( 1 ) ;
501- continue ;
502- } ;
503- if !url_start_allowed ( text, index) {
504- index += prefix_len;
505- continue ;
506- }
507- let end = find_bare_url_end ( text, index, prefix_len) ;
508- if end > index + prefix_len {
509- spans. push ( ( index, end) ) ;
510- index = end;
511- } else {
512- index += prefix_len;
513- }
514- }
515- spans
516- }
517-
518- pub ( super ) fn url_start_allowed ( text : & str , start : usize ) -> bool {
519- let Some ( prev) = text[ ..start] . chars ( ) . next_back ( ) else {
520- return true ;
521- } ;
522- !( prev. is_ascii_alphanumeric ( ) || matches ! ( prev, '/' | '.' | '_' | '-' | '@' ) )
523- }
524-
525- pub ( super ) fn find_bare_url_end ( text : & str , start : usize , prefix_len : usize ) -> usize {
526- let bytes = text. as_bytes ( ) ;
527- let mut end = start;
528- while end < bytes. len ( ) && !bytes[ end] . is_ascii_whitespace ( ) {
529- end += 1 ;
530- }
531- while end > start + prefix_len && url_trailing_punctuation ( text[ ..end] . chars ( ) . next_back ( ) ) {
532- end -= text[ ..end]
533- . chars ( )
534- . next_back ( )
535- . map ( |ch| ch. len_utf8 ( ) )
536- . unwrap_or ( 1 ) ;
537- }
538- end
539- }
540-
541- pub ( super ) fn url_trailing_punctuation ( ch : Option < char > ) -> bool {
542- matches ! (
543- ch,
544- Some (
545- '.' | ','
546- | ';'
547- | ':'
548- | '!'
549- | '?'
550- | ')'
551- | ']'
552- | '}'
553- | '"'
554- | '\''
555- | '。'
556- | ','
557- | ';'
558- | ':'
559- | '!'
560- | '?'
561- | ')'
562- | '】'
563- | '」'
564- | '』'
565- | '、'
566- )
567- )
414+ vec ! [ ( text, true ) ]
568415}
569416
570417pub ( super ) fn parse_writeback_formula_region (
0 commit comments