1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-04-30 15:49:41 +02:00

Bug 2699 - Cannot edit labels with emoji in them correctly.

Fixed on Windows 10.
Probably still broken on mac and linux.
This commit is contained in:
James Crook 2021-03-23 16:41:08 +00:00
parent be704db581
commit 5d28d6989e

View File

@ -936,6 +936,11 @@ int LabelTrackView::FindCursorPosition(wxCoord xPos)
const int length = title.length();
while (!finished && (charIndex < length + 1))
{
int unichar = (int)title.at( charIndex-1 );
if( (0xDC00 <= unichar) && (unichar <= 0xDFFF)){
charIndex++;
continue;
}
subString = title.Left(charIndex);
// Get the width of substring
dc.GetTextExtent(subString, &partWidth, NULL);
@ -1460,6 +1465,9 @@ bool LabelTrackView::DoKeyDown(
if ( HasSelection( project ) ) {
auto labelStruct = mLabels[mSelIndex];
auto &title = labelStruct.title;
wxUniChar wchar;
bool more=true;
switch (keyCode) {
case WXK_BACK:
@ -1474,11 +1482,15 @@ bool LabelTrackView::DoKeyDown(
RemoveSelectedText();
else
{
// DELETE one letter
if (mCurrentCursorPos > 0) {
// DELETE one codepoint leftwards
while ((mCurrentCursorPos > 0) && more) {
wchar = title.at( mCurrentCursorPos-1 );
title.erase(mCurrentCursorPos-1, 1);
mCurrentCursorPos--;
pTrack->SetLabel(mSelIndex, labelStruct);
if( ((int)wchar > 0xDFFF) || ((int)wchar <0xDC00)){
pTrack->SetLabel(mSelIndex, labelStruct);
more = false;
}
}
}
}
@ -1505,10 +1517,14 @@ bool LabelTrackView::DoKeyDown(
RemoveSelectedText();
else
{
// DELETE one letter
if (mCurrentCursorPos < len) {
// DELETE one codepoint rightwards
while ((mCurrentCursorPos < len) && more) {
wchar = title.at( mCurrentCursorPos );
title.erase(mCurrentCursorPos, 1);
pTrack->SetLabel(mSelIndex, labelStruct);
if( ((int)wchar > 0xDBFF) || ((int)wchar <0xD800)){
pTrack->SetLabel(mSelIndex, labelStruct);
more = false;
}
}
}
}
@ -1545,7 +1561,10 @@ bool LabelTrackView::DoKeyDown(
case WXK_LEFT:
case WXK_NUMPAD_LEFT:
// Moving cursor left
if (mCurrentCursorPos > 0) {
while ((mCurrentCursorPos > 0) && more) {
wchar = title.at( mCurrentCursorPos-1 );
more = !( ((int)wchar > 0xDFFF) || ((int)wchar <0xDC00));
mCurrentCursorPos--;
if (mods == wxMOD_SHIFT)
;
@ -1558,7 +1577,10 @@ bool LabelTrackView::DoKeyDown(
case WXK_RIGHT:
case WXK_NUMPAD_RIGHT:
// Moving cursor right
if (mCurrentCursorPos < (int)title.length()) {
while ((mCurrentCursorPos < (int)title.length())&& more) {
wchar = title.at( mCurrentCursorPos );
more = !( ((int)wchar > 0xDBFF) || ((int)wchar <0xD800));
mCurrentCursorPos++;
if (mods == wxMOD_SHIFT)
;