Skip to content

Commit cd7bc71

Browse files
committed
Bug fixes re line wrapping
1 parent 2ff6873 commit cd7bc71

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

doc.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,30 +1631,35 @@ Unicode range UTF-8 bytes
16311631

16321632
// do auto line wrapping here
16331633

1634-
// see if we can split at a multibyte character
1634+
// see if we can split at a multibyte character or a space (whichever comes last)
16351635

16361636
if (m_pCurrentLine->len >= m_nWrapColumn &&
1637-
m_pCurrentLine->len >= 10 &&
1638-
!m_bUTF_8) // not for UTF-8
1637+
m_pCurrentLine->len >= 2)
16391638
{
16401639
for (int i = 0; i < m_pCurrentLine->len - 1; i++)
16411640
{
16421641
unsigned char c1 = m_pCurrentLine->text [i];
16431642
unsigned char c2 = m_pCurrentLine->text [i + 1];
1644-
if (c1 >= 0x81 && c1 <= 0xFE && // first Big5 character
1645-
((c2 >= 0x40 && c2 <= 0x7E) || (c2 >= 0xA1 && c2 <= 0xFE))) // second Big5 character
1643+
// don't test for Big5 if output buffer is UTF-8 (the tests would be wrong)
1644+
if (c1 >= 0x81 && c1 <= 0xFE && // first Big5 character
1645+
((c2 >= 0x40 && c2 <= 0x7E) || (c2 >= 0xA1 && c2 <= 0xFE)) // second Big5 character
1646+
&& !m_bUTF_8) // not for UTF-8
16461647
last_space = i++; // remember position, skip the second byte
1647-
else if (c1 >= 0xA1 && c1 <= 0xF7 &&
1648-
c2 >= 0xA1 && c2 <= 0xFE) // GB2132
1648+
else if (c1 >= 0xA1 && c1 <= 0xF7 && // first GB2132 character
1649+
c2 >= 0xA1 && c2 <= 0xFE && // second GB2132 character
1650+
!m_bUTF_8) // // not for UTF-8
16491651
last_space = i++; // remember position, skip the second byte
16501652
else if (c1 == ' ' && m_wrap)
16511653
last_space = i; // or split at a space
16521654
}
16531655

1654-
} // end of checking for a Big5 or GB2132 break point
1656+
// allow for space being the final thing on the line
1657+
if (m_pCurrentLine->text [m_pCurrentLine->len - 1] == ' ' && m_wrap)
1658+
last_space = m_pCurrentLine->len - 1;
16551659

1656-
if (!m_wrap ||
1657-
last_space < 0 ||
1660+
} // end of checking for a space, Big5 or GB2132 break point
1661+
1662+
if (last_space < 0 || // if no break point found, break anyway at end of line
16581663
(m_pCurrentLine->len - last_space) >= m_nWrapColumn)
16591664
StartNewLine_KeepPreviousStyle (flags);
16601665
else

0 commit comments

Comments
 (0)