Skip to content

Commit 2b77e8f

Browse files
authored
Merge pull request #895 from ychin/filename_sanitization_fixes
Fix opening files that have special chars like '$' in filename
2 parents 651ad8e + 4ef03ed commit 2b77e8f

7 files changed

Lines changed: 399 additions & 122 deletions

File tree

src/MacVim/MMAppController.m

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -976,21 +976,11 @@ - (BOOL)openFiles:(NSArray *)filenames withArguments:(NSDictionary *)args
976976
//
977977
// NOTE: Raise window before passing arguments, otherwise the
978978
// selection will be lost when selectionRange is set.
979-
firstFile = [firstFile stringByEscapingSpecialFilenameCharacters];
980-
981-
NSString *bufCmd = @"tab sb";
982-
switch (layout) {
983-
case MMLayoutHorizontalSplit: bufCmd = @"sb"; break;
984-
case MMLayoutVerticalSplit: bufCmd = @"vert sb"; break;
985-
case MMLayoutArglist: bufCmd = @"b"; break;
986-
}
987-
988-
NSString *input = [NSString stringWithFormat:@"<C-\\><C-N>"
989-
":let oldswb=&swb|let &swb=\"useopen,usetab\"|"
990-
"%@ %@|let &swb=oldswb|unl oldswb|"
991-
"cal foreground()<CR>", bufCmd, firstFile];
992-
993-
[vc addVimInput:input];
979+
NSDictionary *args = [NSDictionary dictionaryWithObjectsAndKeys:
980+
firstFile, @"filename",
981+
[NSNumber numberWithInt:layout], @"layout",
982+
nil];
983+
[vc sendMessage:SelectAndFocusOpenedFileMsgID data:[args dictionaryAsData]];
994984
}
995985

996986
[vc passArguments:arguments];
@@ -1465,16 +1455,15 @@ - (void)newFileHere:(NSPasteboard *)pboard userData:(NSString *)userData
14651455
if (!dirIndicator)
14661456
path = [path stringByDeletingLastPathComponent];
14671457

1468-
path = [path stringByEscapingSpecialFilenameCharacters];
1469-
14701458
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
14711459
BOOL openInCurrentWindow = [ud boolForKey:MMOpenInCurrentWindowKey];
14721460
MMVimController *vc;
14731461

14741462
if (openInCurrentWindow && (vc = [self topmostVimController])) {
1475-
NSString *input = [NSString stringWithFormat:@"<C-\\><C-N>"
1476-
":tabe|cd %@<CR>", path];
1477-
[vc addVimInput:input];
1463+
NSDictionary *args = [NSDictionary dictionaryWithObjectsAndKeys:
1464+
path, @"path",
1465+
nil];
1466+
[vc sendMessage:NewFileHereMsgID data:[args dictionaryAsData]];
14781467
} else {
14791468
[self launchVimProcessWithArguments:nil workingDirectory:path];
14801469
}

0 commit comments

Comments
 (0)