Skip to content

Commit

Permalink
Fix a bunch of bugs in the IME. First, it crashed if the marked text …
Browse files Browse the repository at this point in the history
…had a double width character starting at the end of a line. The colors were wrong. The cursor was to narrow. It drew garbage on the last lines when the marked text caused the screen contents to scroll up.
  • Loading branch information
gnachman committed Oct 17, 2018
1 parent 405bf8a commit 482dbf0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
11 changes: 10 additions & 1 deletion sources/Metal/Renderers/iTermCursorRenderer.m
Original file line number Diff line number Diff line change
Expand Up @@ -353,16 +353,25 @@ @implementation iTermBarCursorRenderer

- (void)initializeTransientState:(iTermCursorRendererTransientState *)tState {
[super initializeTransientState:tState];
const CGFloat width = [iTermAdvancedSettingsModel verticalBarCursorWidth];
const CGFloat width = [self barCursorWidth];
tState.vertexBuffer =
[_cellRenderer newQuadOfSize:CGSizeMake(tState.configuration.scale * width,
tState.cellConfiguration.cellSize.height)
poolContext:tState.poolContext];
}

- (CGFloat)barCursorWidth {
return [iTermAdvancedSettingsModel verticalBarCursorWidth];
}

@end

@implementation iTermIMECursorRenderer

- (CGFloat)barCursorWidth {
return 2;
}

@end

@implementation iTermBlockCursorRenderer
Expand Down
5 changes: 1 addition & 4 deletions sources/Metal/Renderers/iTermTextRendererTransientState.mm
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,6 @@ - (void)addASCIICellToPIUsForCode:(char)code
vector_float4 textColor = attributes[x].foregroundColor;
if (inMarkedRange) {
// Marked range gets a yellow underline.
underlineColor = iTermIMEColor;
textColor = iTermIMEColor;
underlineStyle = iTermMetalGlyphAttributesUnderlineSingle;
}

Expand Down Expand Up @@ -770,8 +768,7 @@ - (void)setGlyphKeysData:(iTermGlyphKeyData *)glyphKeysData
piu->underlineColor = iTermAnnotationUnderlineColor;
} else if (inMarkedRange) {
piu->underlineStyle = iTermMetalGlyphAttributesUnderlineSingle;
piu->underlineColor = iTermIMEColor;
piu->textColor = iTermIMEColor;
piu->underlineColor = _nonAsciiUnderlineDescriptor.color.w > 1 ? _nonAsciiUnderlineDescriptor.color : piu->textColor;
} else {
piu->underlineStyle = attributes[x].underlineStyle;
piu->underlineColor = _nonAsciiUnderlineDescriptor.color.w > 1 ? _nonAsciiUnderlineDescriptor.color : piu->textColor;
Expand Down
25 changes: 19 additions & 6 deletions sources/iTermMetalGlue.m
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,19 @@ - (void)copyMarkedText:(NSString *)str
BOOL foundCursor = NO;
BOOL justWrapped = NO;
BOOL foundStart = NO;
if (coord.x == gridWidth) {
coord.x = 0;
coord.y++;
justWrapped = YES;
}

// If the screen contents are getting moved up to make room for a multi-row IME line, clear out the lines at the bottom it adds.
for (int i = 0; i < numberOfIMELines; i++) {
const int y = _screenCharLines.count - i - 1;
const iTermData *lineData = _screenCharLines[y];
screen_char_t *line = (screen_char_t *)lineData.mutableBytes;
memset(line, 0, sizeof(screen_char_t) * gridWidth);
}
_imeInfo = [[iTermMetalIMEInfo alloc] init];
for (int i = 0; i < len; i++) {
if (coord.y >= 0 && coord.y < _screenCharLines.count) {
Expand All @@ -715,10 +728,10 @@ - (void)copyMarkedText:(NSString *)str
const iTermData *lineData = _screenCharLines[coord.y];
screen_char_t *line = (screen_char_t *)lineData.mutableBytes;
screen_char_t c = buf[i];
c.foregroundColor = iTermIMEColor.x * 255;
c.fgGreen = iTermIMEColor.y * 255;
c.fgBlue = iTermIMEColor.z * 255;
c.foregroundColorMode = ColorMode24bit;
c.foregroundColor = ALTSEM_DEFAULT;
c.fgGreen = 0;
c.fgBlue = 0;
c.foregroundColorMode = ColorModeAlternate;

c.backgroundColor = ALTSEM_DEFAULT;
c.bgGreen = 0;
Expand All @@ -729,8 +742,8 @@ - (void)copyMarkedText:(NSString *)str

if (i + 1 < len &&
coord.x == gridWidth -1 &&
line[i+1].code == DWC_RIGHT &&
!line[i+1].complexChar) {
buf[i+1].code == DWC_RIGHT &&
!buf[i+1].complexChar) {
// Bump DWC to start of next line instead of splitting it
c.code = ' ';
c.complexChar = NO;
Expand Down

0 comments on commit 482dbf0

Please sign in to comment.