Jelajahi Sumber

Fortune: handle multibyte characters

Marco Hinz 9 tahun lalu
induk
melakukan
f3044c7f52
2 mengubah file dengan 3 tambahan dan 3 penghapusan
  1. 2 2
      autoload/startify/fortune.vim
  2. 1 1
      doc/startify.txt

+ 2 - 2
autoload/startify/fortune.vim

@@ -126,7 +126,7 @@ endfunction
 
 " Function: s:draw_box {{{1
 function! s:draw_box(lines) abort
-  let longest_line = max(map(copy(a:lines), 'len(v:val)'))
+  let longest_line = max(map(copy(a:lines), 'strwidth(v:val)'))
   if &encoding == 'utf-8' && get(g:, 'startify_fortune_use_unicode')
       let top_left_corner = '╭'
       let top_right_corner = '╮'
@@ -146,7 +146,7 @@ function! s:draw_box(lines) abort
   let bottom = bottom_left_corner . repeat(top_bottom_side, longest_line + 2) . bottom_right_corner
   let lines = [top]
   for l in a:lines
-    let offset = longest_line - len(l)
+    let offset = longest_line - strwidth(l)
     let lines += [side . ' '. l . repeat(' ', offset) .' ' . side]
   endfor
   let lines += [bottom]

+ 1 - 1
doc/startify.txt

@@ -838,7 +838,7 @@ How do I center my header/footer?~
 Try something along these lines:
 >
     function! s:filter_header(lines) abort
-        let longest_line   = max(map(copy(a:lines), 'len(v:val)'))
+        let longest_line   = max(map(copy(a:lines), 'strwidth(v:val)'))
         let centered_lines = map(copy(a:lines),
             \ 'repeat(" ", (&columns / 2) - (longest_line / 2)) . v:val')
         return centered_lines