From edbdca29e1e94de668174c79a7dda40c618d570d Mon Sep 17 00:00:00 2001 From: Bjorn Winckler Date: Tue, 23 Jun 2009 20:38:39 +0200 Subject: [PATCH] Normalize filenames to NFKC before opening Vim does not cope very well with Unicode decomposed form NFD (i.e. it does not normalize to composed form before rendering) which causes problems since HFS+ stores filenames in NFD. To work around this issue normalize to compatibility form C before passing filenames to Vim. (This is not a solution to the problem with NFD since files stored in NFD will still be problematic but at least a user can work around this issue by making sure files are in composed form before opening them.) --- src/MacVim/MMAppController.m | 4 ++++ src/MacVim/MMVimController.m | 4 ++++ src/MacVim/Miscellaneous.h | 7 +++++++ src/MacVim/Miscellaneous.m | 20 ++++++++++++++++++++ 4 files changed, 35 insertions(+) diff --git a/src/MacVim/MMAppController.m b/src/MacVim/MMAppController.m index 00d7f646cf..be710e5f91 100644 --- a/src/MacVim/MMAppController.m +++ b/src/MacVim/MMAppController.m @@ -819,6 +819,10 @@ fsEventCallback(ConstFSEventStreamRef streamRef, NSMutableDictionary *arguments = (args ? [[args mutableCopy] autorelease] : [NSMutableDictionary dictionary]); + // Filenames on HFS+ are in NFD but Vim does not handle this form very well + // so normalize to NFKC first. + filenames = normalizeFilenames(filenames); + // // a) Filter out any already open files // diff --git a/src/MacVim/MMVimController.m b/src/MacVim/MMVimController.m index 1ade6a4aba..f21044c064 100644 --- a/src/MacVim/MMVimController.m +++ b/src/MacVim/MMVimController.m @@ -263,6 +263,10 @@ static BOOL isUnsafeMessage(int msgid); if (splitVert && MMLayoutHorizontalSplit == layout) layout = MMLayoutVerticalSplit; + // Filenames on HFS+ are in NFD but Vim does not handle this form very well + // so normalize to NFKC first. + filenames = normalizeFilenames(filenames); + NSDictionary *args = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:layout], @"layout", filenames, @"filenames", diff --git a/src/MacVim/Miscellaneous.h b/src/MacVim/Miscellaneous.h index 9e8da0152b..0e41fda8d3 100644 --- a/src/MacVim/Miscellaneous.h +++ b/src/MacVim/Miscellaneous.h @@ -135,3 +135,10 @@ enum { // release it. NSView *showHiddenFilesView(); + +// Convert filenames (which are in decomposed form, NFD, on HFS+) to +// normalization form combatibility C (NFKC). (This is necessary because Vim +// does not automatically compose NFD. We choose NFKC instead of NFC for the +// somewhat random reason that this is what is used on Windows and hence +// hopefully Vim is better prepared for it.) +NSArray *normalizeFilenames(NSArray *filenames); diff --git a/src/MacVim/Miscellaneous.m b/src/MacVim/Miscellaneous.m index 44f662298a..bb386c9c25 100644 --- a/src/MacVim/Miscellaneous.m +++ b/src/MacVim/Miscellaneous.m @@ -290,3 +290,23 @@ showHiddenFilesView() return button; } + + + + + NSArray * +normalizeFilenames(NSArray *filenames) +{ + NSMutableArray *outnames = [NSMutableArray array]; + if (!filenames) + return outnames; + + unsigned i, count = [filenames count]; + for (i = 0; i < count; ++i) { + NSString *nfkc = [filenames objectAtIndex:i]; + nfkc = [nfkc precomposedStringWithCompatibilityMapping]; + [outnames addObject:nfkc]; + } + + return outnames; +}