11use crate :: compositor:: { Component , Compositor , Context , Event , EventResult } ;
22use crate :: { alt, ctrl, key, shift, ui} ;
33use arc_swap:: ArcSwap ;
4- use helix_core:: syntax;
4+ use helix_core:: { syntax, unicode } ;
55use helix_view:: document:: Mode ;
66use helix_view:: input:: KeyEvent ;
77use helix_view:: keyboard:: KeyCode ;
@@ -13,7 +13,6 @@ use tui::widgets::{Block, Widget};
1313
1414use helix_core:: {
1515 unicode:: segmentation:: { GraphemeCursor , UnicodeSegmentation } ,
16- unicode:: width:: UnicodeWidthStr ,
1716 Position ,
1817} ;
1918use helix_view:: {
@@ -544,7 +543,7 @@ impl Prompt {
544543 } else {
545544 let line_width = self . line_area . width as usize ;
546545
547- if self . line . width ( ) < line_width {
546+ if unicode :: width ( & self . line ) < line_width {
548547 self . anchor = 0 ;
549548 } else if self . cursor <= self . anchor {
550549 // Ensure the grapheme under the cursor is in view.
@@ -553,14 +552,14 @@ impl Prompt {
553552 . next_back ( )
554553 . map ( |( i, _) | i)
555554 . unwrap_or_default ( ) ;
556- } else if self . line [ self . anchor ..self . cursor ] . width ( ) > line_width {
555+ } else if unicode :: width ( & self . line [ self . anchor ..self . cursor ] ) > line_width {
557556 // Set the anchor to the last grapheme cluster before the width is exceeded.
558557 let mut width = 0 ;
559558 self . anchor = self . line [ ..self . cursor ]
560559 . grapheme_indices ( true )
561560 . rev ( )
562561 . find_map ( |( idx, g) | {
563- width += g . width ( ) ;
562+ width += unicode :: width ( g ) ;
564563 if width > line_width {
565564 Some ( idx + g. len ( ) )
566565 } else {
@@ -571,16 +570,18 @@ impl Prompt {
571570 }
572571
573572 self . truncate_start = self . anchor > 0 ;
574- self . truncate_end = self . line [ self . anchor ..] . width ( ) > line_width;
573+ self . truncate_end = unicode :: width ( & self . line [ self . anchor ..] ) > line_width;
575574
576575 // if we keep inserting characters just before the end elipsis, we move the anchor
577576 // so that those new characters are displayed
578- if self . truncate_end && self . line [ self . anchor ..self . cursor ] . width ( ) >= line_width {
577+ if self . truncate_end
578+ && unicode:: width ( & self . line [ self . anchor ..self . cursor ] ) >= line_width
579+ {
579580 // Move the anchor forward by one non-zero-width grapheme.
580581 self . anchor += self . line [ self . anchor ..]
581582 . grapheme_indices ( true )
582583 . find_map ( |( idx, g) | {
583- if g . width ( ) > 0 {
584+ if unicode :: width ( g ) > 0 {
584585 Some ( idx + g. len ( ) )
585586 } else {
586587 None
@@ -771,11 +772,11 @@ impl Component for Prompt {
771772 . clip_left ( self . prompt . len ( ) as u16 )
772773 . clip_right ( if self . prompt . is_empty ( ) { 2 } else { 0 } ) ;
773774
774- let mut col = area. left ( ) as usize + self . line [ self . anchor ..self . cursor ] . width ( ) ;
775+ let mut col = area. left ( ) as usize + unicode :: width ( & self . line [ self . anchor ..self . cursor ] ) ;
775776
776777 // ensure the cursor does not go beyond elipses
777778 if self . truncate_end
778- && self . line [ self . anchor ..self . cursor ] . width ( ) >= self . line_area . width as usize
779+ && unicode :: width ( & self . line [ self . anchor ..self . cursor ] ) >= self . line_area . width as usize
779780 {
780781 col -= 1 ;
781782 }
@@ -784,7 +785,7 @@ impl Component for Prompt {
784785 col += self . line [ self . cursor ..]
785786 . graphemes ( true )
786787 . next ( )
787- . map_or ( 0 , |g| g . width ( ) ) ;
788+ . map_or ( 0 , unicode :: width) ;
788789 }
789790
790791 let line = area. height as usize - 1 ;
0 commit comments