Skip to content

Commit

Permalink
Fixed bug with selecting UTF-8 text with the mouse
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgammon committed Jun 12, 2014
1 parent e9ed85e commit 545d2fd
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions mushview.cpp
Expand Up @@ -1820,14 +1820,27 @@ long pixel;
// calculate which column we must be at

for (col = 0, pixel = pLine->m_iPreambleOffset;
pixel < point.x && col <= pLine->len;
col++)
pixel < point.x && col <= pLine->len; col++)
{
lastx = pixel;
pixel = calculate_width (line, col, pDoc, dc) + pDoc->m_iPixelOffset + pLine->m_iPreambleOffset;

// for a UTF-8 character, bypass the whole character not just one byte
if (pDoc->m_bUTF_8)
{
int c = pLine->text [col];
if (c >= 128)
col += _pcre_utf8_table4 [c & 0x3f]; // number of additional bytes
}


}

col--; // columns are zero-relative
// don't stop half-way through a UTF-8 character
if (pDoc->m_bUTF_8)
while (col && (pLine->text [col] & 0xC0) == 0x80)
col--;

// if we are 50% through this character, take the next one, otherwise take the previous one

Expand All @@ -1836,7 +1849,13 @@ long pixel;
lastx += (pixel - lastx) / 2;

if (point.x < lastx)
{
col--;
// don't stop half-way through a UTF-8 character
if (pDoc->m_bUTF_8)
while (col && (pLine->text [col] & 0xC0) == 0x80)
col--;
}
}

// make sure column is reasonable
Expand Down

0 comments on commit 545d2fd

Please sign in to comment.