aboutsummaryrefslogtreecommitdiffstats
path: root/ftplugin
diff options
context:
space:
mode:
authorchoplin <choplin.public@gmail.com>2011-10-01 20:17:49 +0900
committerchoplin <choplin.public@gmail.com>2011-10-01 20:17:49 +0900
commit4189dce16ecfb7a680b45333995eec9a0fdb844d (patch)
treef68fffe7675be70e190c916191ed6cf3676d4f74 /ftplugin
parent8db3e1740fce3232616509002b43b91e29b7769f (diff)
downloadvim-rst-tables-4189dce16ecfb7a680b45333995eec9a0fdb844d.tar.gz
vim-rst-tables-4189dce16ecfb7a680b45333995eec9a0fdb844d.tar.bz2
vim-rst-tables-4189dce16ecfb7a680b45333995eec9a0fdb844d.zip
fixed bug : doesn't work properly with East Asian Language
calculate string length as unicode type, not str type
Diffstat (limited to 'ftplugin')
-rw-r--r--ftplugin/rst_tables.vim14
1 files changed, 12 insertions, 2 deletions
diff --git a/ftplugin/rst_tables.vim b/ftplugin/rst_tables.vim
index e042157..a77bafe 100644
--- a/ftplugin/rst_tables.vim
+++ b/ftplugin/rst_tables.vim
@@ -20,6 +20,7 @@ python << endpython
import vim
import re
import textwrap
+import unicodedata
from vim_bridge import bridged
@@ -160,8 +161,17 @@ def table_line(widths, header=False):
def get_field_width(field_text):
- return max(map(lambda s: len(s), field_text.split('\n')))
-
+ return max(map(get_string_width, field_text.split('\n')))
+
+def get_string_width(string):
+ width = 0
+ for char in list(string.decode('utf-8')):
+ eaw = unicodedata.east_asian_width(char)
+ if eaw == 'Na' or eaw == 'H':
+ width += 1
+ else:
+ width += 2
+ return width
def split_row_into_lines(row):
row = map(lambda field: field.split('\n'), row)