Fix dialog deleting fullwidth characters #471
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Reline's dialog will delete fullwidth characters and fails to restore it in reset_dialog. This pull request fixes this.
In reset_dialog, what we want for
Reline::Unicode.take_range('一二三', 1, 4)
could be一二三
string covers range, needed for rerender bottom, rerender top in reset_dialog二三
rerender right in reset_dialog一二
render left in reset_dialog二
string inside range▫️二▫️
string inside range with paddingChanges
take_range will also return position(col and width)
take_range('一二三', 1, 4) #=> ['二', 2, 2]
need to determine where to render the string.
二
should be rendered atcol: 2, width: 2
, not atcol: 1, width: 4
add an option cover_begin, cover_end to take_range
take_range('一二三', 1, 4, cover_begin: true) #=> ['一二', 0, 4]
for render lefttake_range('一二三', 1, 4, cover_end: true) #=> ['二三', 2, 4]
for render rightadd an option padding to take_range
Delete
padding_space_with_escape_sequences
that only adds spaces at the end of the string.take_range will properly add spaces around the string.
take_range('一二三', 1, 4, padding: true) #=> ['▫️二▫️', 1, 4]
take_range('一二三', 1, 8, padding: true) #=> ['▫️二三▫️▫️▫️', 1, 8]
Refactored reset_dialog
To make the main change easier, I reduced if branches of render top, left, right and bottom.
This change will fix a potentially-bug in rerender left
Fixed inconsistency of take_range and calculate_width with special charactors \1 and \2
I Added some take_range tests for newly added option and regression test for escape sequence.
Found \1 and \2 is disappeared that will causes inconsistency of calculate_width and take_range.
calculate_width(take_range("a\1xxxxxxxx\2b", 0, 2), true) should be <=2, got 10
This might solve the root cause of #465 (I'm not sure, I cannot reproduce it).
Limitations
This pull request has a limitation. After document dialog is closed, right side of the completion dialog corrupts if there is full-width character between these dialogs.
Clearing dialog depends on adjacent dialog positions, and to fix this, dialog rendering and clearing algorithm might need update.