MacDownApp / macdown

Open source Markdown editor for macOS.
https://macdown.uranusjr.com/
9.44k stars 1.09k forks source link

Font fails to switch back after switching to Chinese font #1199

Open charmhe opened 4 years ago

charmhe commented 4 years ago
  1. Set font. e.g., Monaco
  2. Switch to Chinese input. Type some Chinese characters, type some English letters through Chinese input

Result: the newly typed latin characters is not in Monaco, but Helevitica. It's sesonable.

  1. Switch back to English input. Type some letters.

Result: the newly typed letters are still in Helevitica instead of Monaco. Expected Result: the letters should be in Monaco.

Xuezenghuigithub commented 4 years ago

image

Is this the case?

shankerwangmiao commented 4 years ago

I also have this issue. By bi-searching, it turns out that the issue is introduced in commit https://github.com/MacDownApp/macdown/commit/04cf2b8568562e2f1c2992b470e827c029c1e319 and can be resolved by applying the following patch

diff --git a/MacDown/Code/Document/MPDocument.m b/MacDown/Code/Document/MPDocument.m
index acbc77f..79dee7c 100644
--- a/MacDown/Code/Document/MPDocument.m
+++ b/MacDown/Code/Document/MPDocument.m
@@ -729,17 +729,6 @@ static void (^MPGetPreviewLoadingCompletionHandler(MPDocument *doc))()
                                           strikethroughEnabled:strikethrough])
             return NO;
     }
-    
-   // For every change, set the typing attributes
-   if (range.location > 0) {
-       NSRange prevRange = range;
-       prevRange.location -= 1;
-       prevRange.length = 1;
-
-       NSDictionary *attr = [[textView attributedString] fontAttributesInRange:prevRange];
-       [textView setTypingAttributes:attr];
-   }
-
     return YES;
 }
shankerwangmiao commented 4 years ago

I have no idea about the function of that code. However, removing them does work.