diff options
author | Michele Calgaro <michele.calgaro@yahoo.it> | 2025-02-16 22:19:27 +0900 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2025-03-14 22:30:17 +0900 |
commit | 78e4f41622d44d771318edc208d9e619100e97ee (patch) | |
tree | c6f935fff7ea60a0a837390129dc6adc077c1c46 /kate/part/katedocument.cpp | |
parent | 7d3bf3e611cf7638426b69564ba1786c307893fb (diff) | |
download | tdelibs-78e4f416.tar.gz tdelibs-78e4f416.zip |
Add support for unicode surrogate characters to Kate/KWrite
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
(cherry picked from commit 1aa4271c122eb4dbbe4568418923ec04123c7474)
Diffstat (limited to 'kate/part/katedocument.cpp')
-rw-r--r-- | kate/part/katedocument.cpp | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/kate/part/katedocument.cpp b/kate/part/katedocument.cpp index a125c2c85..367f70d64 100644 --- a/kate/part/katedocument.cpp +++ b/kate/part/katedocument.cpp @@ -2411,7 +2411,7 @@ bool KateDocument::openFile(TDEIO::Job * job) // read dir config (if possible and wanted) if (!m_reloading) - readDirConfig (); + readDirConfig (); // do we have success ? bool success = m_buffer->openFile (m_file); @@ -3135,15 +3135,27 @@ void KateDocument::backspace( KateView *view, const KateTextCursor& c ) if ((col == 0) && (line == 0)) return; + KateTextLine::Ptr tl = m_buffer->plainLine(line); + if (!tl) + { + return; + } + + // Make sure to handle surrogate pairs correctly + uint fromCol = col - 1; + TQChar prevChar = tl->getChar(col - 1); + if (prevChar.isLowSurrogate() && tl->getChar(col - 2).isHighSurrogate()) + { + fromCol = col - 2; + prevChar = tl->getChar(col - 2); + } + int complement = 0; if (col > 0) { if (config()->configFlags() & KateDocument::cfAutoBrackets) { // if inside empty (), {}, [], '', "" delete both - KateTextLine::Ptr tl = m_buffer->plainLine(line); - if(!tl) return; - TQChar prevChar = tl->getChar(col-1); TQChar nextChar = tl->getChar(col); if ( (prevChar == '"' && nextChar == '"') || @@ -3158,8 +3170,7 @@ void KateDocument::backspace( KateView *view, const KateTextCursor& c ) if (!(config()->configFlags() & KateDocument::cfBackspaceIndents)) { // ordinary backspace - //c.cursor.col--; - removeText(line, col-1, line, col+complement); + removeText(line, fromCol, line, col+complement); } else { @@ -3215,9 +3226,23 @@ void KateDocument::del( KateView *view, const KateTextCursor& c ) return; } - if( c.col() < (int) m_buffer->plainLine(c.line())->length()) + KateTextLine::Ptr tl = m_buffer->plainLine(c.line()); + if (!tl) { - removeText(c.line(), c.col(), c.line(), c.col()+1); + return; + } + uint lineLen = tl->length(); + uint col = (uint)c.col(); + if (col < lineLen) + { + // Make sure to handle surrogate pairs correctly + uint toCol = col + 1; + if (tl->getChar(col).isHighSurrogate() && tl->getChar(col + 1).isLowSurrogate()) + { + toCol = col + 2; + } + + removeText(c.line(), col, c.line(), toCol); } else if ( (uint)c.line() < lastLine() ) { |