Skip to content

Commit

Permalink
Another fix for RTL typing on OS X
Browse files Browse the repository at this point in the history
NSTextView needs to set text typing direction in addition to the base
direction for typing to work as RTL users expect. This unfortunately
leads to insertion of POP DIRECTIONAL FORMATTING at the end of the next,
so we need to strip that from user-entered text as well.
  • Loading branch information
vslavik committed Aug 26, 2016
1 parent 18a6bcb commit 69be3f6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/text_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,8 +515,21 @@ void AnyTranslatableTextCtrl::SetLanguage(const Language& lang)

#ifdef __WXOSX__
NSTextView *text = TextView(this);
[text setBaseWritingDirection:lang.IsRTL() ? NSWritingDirectionRightToLeft : NSWritingDirectionLeftToRight];
if (lang.IsRTL())
{
[text setBaseWritingDirection:NSWritingDirectionRightToLeft];
if ([NSApp userInterfaceLayoutDirection] == NSUserInterfaceLayoutDirectionLeftToRight)
{
// extra nudge to make typing behave as expected:
[text makeTextWritingDirectionRightToLeft:nil];
}
}
else
{
[text setBaseWritingDirection:NSWritingDirectionLeftToRight];
}
#endif

#ifdef __WXMSW__
BIDIOPTIONS bidi;
::ZeroMemory(&bidi, sizeof(bidi));
Expand Down
8 changes: 8 additions & 0 deletions src/unicode_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ wxString strip_pointless_control_chars(const wxString& text, TextDirection dir)
return text;

const wchar_t first = *text.begin();
const wchar_t last = *text.rbegin();

// POP DIRECTIONAL FORMATTING at the end is pointless (can happen on OS X
// when editing RTL text under LTR locale:
if (last == PDF)
{
return strip_pointless_control_chars(text.substr(0, text.size() - 1), dir);
}

if (dir == TextDirection::LTR)
{
Expand Down

0 comments on commit 69be3f6

Please sign in to comment.