From 60b955e779574f296c6e3d808da14b01fd78e483 Mon Sep 17 00:00:00 2001 From: Alexander Belozerov Date: Sat, 9 Nov 2019 23:45:19 +0600 Subject: [PATCH] [Fix #675] Correct indentation for double-byte characters (#676) --- lib/annotate/annotate_models.rb | 2 +- spec/lib/annotate/annotate_models_spec.rb | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/annotate/annotate_models.rb b/lib/annotate/annotate_models.rb index 0be4dc127..d5ffa0328 100644 --- a/lib/annotate/annotate_models.rb +++ b/lib/annotate/annotate_models.rb @@ -920,7 +920,7 @@ def format_default(col_name, max_size, col_type, bare_type_allowance, attrs) end def width(string) - string.chars.inject(0) { |acc, elem| acc + (elem.bytesize == 1 ? 1 : 2) } + string.chars.inject(0) { |acc, elem| acc + (elem.bytesize == 3 ? 2 : 1) } end def mb_chars_ljust(string, length) diff --git a/spec/lib/annotate/annotate_models_spec.rb b/spec/lib/annotate/annotate_models_spec.rb index e596c0288..76539f13e 100644 --- a/spec/lib/annotate/annotate_models_spec.rb +++ b/spec/lib/annotate/annotate_models_spec.rb @@ -1006,6 +1006,9 @@ def self.when_called_with(options = {}) [:active, :boolean, { limit: 1, comment: 'ACTIVE' }], [:name, :string, { limit: 50, comment: 'NAME' }], [:notes, :text, { limit: 55, comment: 'NOTES' }], + [:cyrillic, :text, { limit: 30, comment: 'Кириллица' }], + [:japanese, :text, { limit: 60, comment: '熊本大学 イタリア 宝島' }], + [:arabic, :text, { limit: 20, comment: 'لغة' }], [:no_comment, :text, { limit: 20, comment: nil }], [:location, :geometry_collection, { limit: nil, comment: nil }] ] @@ -1017,12 +1020,15 @@ def self.when_called_with(options = {}) # # Table name: users # - # id(ID) :integer not null, primary key - # active(ACTIVE) :boolean not null - # name(NAME) :string(50) not null - # notes(NOTES) :text(55) not null - # no_comment :text(20) not null - # location :geometry_collect not null + # id(ID) :integer not null, primary key + # active(ACTIVE) :boolean not null + # name(NAME) :string(50) not null + # notes(NOTES) :text(55) not null + # cyrillic(Кириллица) :text(30) not null + # japanese(熊本大学 イタリア 宝島) :text(60) not null + # arabic(لغة) :text(20) not null + # no_comment :text(20) not null + # location :geometry_collect not null # EOS