mirror of
https://github.com/macvim-dev/macvim.git
synced 2026-06-07 15:37:14 +02:00
Fix open from Xcode with selection range
This is an initial attempt to fix a problem where double clicking a search result in Xcode would select an incorrect range of characters when the file opened in MacVim. It only works the file uses an 8 bit encoding.
This commit is contained in:
@@ -903,6 +903,43 @@ fsEventCallback(ConstFSEventStreamRef streamRef,
|
|||||||
NSDictionary *openFilesDict = nil;
|
NSDictionary *openFilesDict = nil;
|
||||||
filenames = [self filterOpenFiles:filenames openFilesDict:&openFilesDict];
|
filenames = [self filterOpenFiles:filenames openFilesDict:&openFilesDict];
|
||||||
|
|
||||||
|
// The meaning of "layout" is defined by the WIN_* defines in main.c.
|
||||||
|
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
|
||||||
|
int layout = [ud integerForKey:MMOpenLayoutKey];
|
||||||
|
BOOL splitVert = [ud boolForKey:MMVerticalSplitKey];
|
||||||
|
BOOL openInCurrentWindow = [ud boolForKey:MMOpenInCurrentWindowKey];
|
||||||
|
|
||||||
|
if (splitVert && MMLayoutHorizontalSplit == layout)
|
||||||
|
layout = MMLayoutVerticalSplit;
|
||||||
|
if (layout < 0 || (layout > MMLayoutTabs && openInCurrentWindow))
|
||||||
|
layout = MMLayoutTabs;
|
||||||
|
|
||||||
|
if ([filenames count] == 0) {
|
||||||
|
// Raise the window containing the first file that was already open,
|
||||||
|
// and make sure that the tab containing that file is selected. Only
|
||||||
|
// do this when there are no more files to open, otherwise sometimes
|
||||||
|
// the window with 'firstFile' will be raised, other times it might be
|
||||||
|
// the window that will open with the files in the 'filenames' array.
|
||||||
|
//
|
||||||
|
// NOTE: Raise window before passing arguments, otherwise the selection
|
||||||
|
// will be lost when selectionRange is set.
|
||||||
|
firstFile = [firstFile stringByEscapingSpecialFilenameCharacters];
|
||||||
|
|
||||||
|
NSString *bufCmd = @"tab sb";
|
||||||
|
switch (layout) {
|
||||||
|
case MMLayoutHorizontalSplit: bufCmd = @"sb"; break;
|
||||||
|
case MMLayoutVerticalSplit: bufCmd = @"vert sb"; break;
|
||||||
|
case MMLayoutArglist: bufCmd = @"b"; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
NSString *input = [NSString stringWithFormat:@"<C-\\><C-N>"
|
||||||
|
":let oldswb=&swb|let &swb=\"useopen,usetab\"|"
|
||||||
|
"%@ %@|let &swb=oldswb|unl oldswb|"
|
||||||
|
"cal foreground()<CR>", bufCmd, firstFile];
|
||||||
|
|
||||||
|
[firstController addVimInput:input];
|
||||||
|
}
|
||||||
|
|
||||||
// Pass arguments to vim controllers that had files open.
|
// Pass arguments to vim controllers that had files open.
|
||||||
id key;
|
id key;
|
||||||
NSEnumerator *e = [openFilesDict keyEnumerator];
|
NSEnumerator *e = [openFilesDict keyEnumerator];
|
||||||
@@ -922,42 +959,6 @@ fsEventCallback(ConstFSEventStreamRef streamRef,
|
|||||||
firstController = vc;
|
firstController = vc;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The meaning of "layout" is defined by the WIN_* defines in main.c.
|
|
||||||
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
|
|
||||||
int layout = [ud integerForKey:MMOpenLayoutKey];
|
|
||||||
BOOL splitVert = [ud boolForKey:MMVerticalSplitKey];
|
|
||||||
BOOL openInCurrentWindow = [ud boolForKey:MMOpenInCurrentWindowKey];
|
|
||||||
|
|
||||||
if (splitVert && MMLayoutHorizontalSplit == layout)
|
|
||||||
layout = MMLayoutVerticalSplit;
|
|
||||||
if (layout < 0 || (layout > MMLayoutTabs && openInCurrentWindow))
|
|
||||||
layout = MMLayoutTabs;
|
|
||||||
|
|
||||||
if ([filenames count] == 0) {
|
|
||||||
// Raise the window containing the first file that was already open,
|
|
||||||
// and make sure that the tab containing that file is selected. Only
|
|
||||||
// do this when there are no more files to open, otherwise sometimes
|
|
||||||
// the window with 'firstFile' will be raised, other times it might be
|
|
||||||
// the window that will open with the files in the 'filenames' array.
|
|
||||||
firstFile = [firstFile stringByEscapingSpecialFilenameCharacters];
|
|
||||||
|
|
||||||
NSString *bufCmd = @"tab sb";
|
|
||||||
switch (layout) {
|
|
||||||
case MMLayoutHorizontalSplit: bufCmd = @"sb"; break;
|
|
||||||
case MMLayoutVerticalSplit: bufCmd = @"vert sb"; break;
|
|
||||||
case MMLayoutArglist: bufCmd = @"b"; break;
|
|
||||||
}
|
|
||||||
|
|
||||||
NSString *input = [NSString stringWithFormat:@"<C-\\><C-N>"
|
|
||||||
":let oldswb=&swb|let &swb=\"useopen,usetab\"|"
|
|
||||||
"%@ %@|let &swb=oldswb|unl oldswb|"
|
|
||||||
"cal foreground()<CR>", bufCmd, firstFile];
|
|
||||||
|
|
||||||
[firstController addVimInput:input];
|
|
||||||
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add filenames to "Recent Files" menu, unless they are being edited
|
// Add filenames to "Recent Files" menu, unless they are being edited
|
||||||
// remotely (using ODB).
|
// remotely (using ODB).
|
||||||
if ([arguments objectForKey:@"remoteID"] == nil) {
|
if ([arguments objectForKey:@"remoteID"] == nil) {
|
||||||
@@ -965,6 +966,9 @@ fsEventCallback(ConstFSEventStreamRef streamRef,
|
|||||||
noteNewRecentFilePaths:filenames];
|
noteNewRecentFilePaths:filenames];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ([filenames count] == 0)
|
||||||
|
return YES; // No files left to open (all were already open)
|
||||||
|
|
||||||
//
|
//
|
||||||
// b) Open any remaining files
|
// b) Open any remaining files
|
||||||
//
|
//
|
||||||
@@ -1757,9 +1761,10 @@ fsEventCallback(ConstFSEventStreamRef streamRef,
|
|||||||
sr->unused2, sr->theDate);
|
sr->unused2, sr->theDate);
|
||||||
|
|
||||||
if (sr->lineNum < 0) {
|
if (sr->lineNum < 0) {
|
||||||
// Should select a range of lines.
|
// Should select a range of characters.
|
||||||
range.location = sr->startRange + 1;
|
range.location = sr->startRange + 1;
|
||||||
range.length = sr->endRange - sr->startRange + 1;
|
range.length = sr->endRange > sr->startRange
|
||||||
|
? sr->endRange - sr->startRange : 1;
|
||||||
} else {
|
} else {
|
||||||
// Should only move cursor to a line.
|
// Should only move cursor to a line.
|
||||||
range.location = sr->lineNum + 1;
|
range.location = sr->lineNum + 1;
|
||||||
@@ -2338,11 +2343,12 @@ fsEventCallback(ConstFSEventStreamRef streamRef,
|
|||||||
NSRange r = NSRangeFromString(rangeString);
|
NSRange r = NSRangeFromString(rangeString);
|
||||||
[a addObject:@"-c"];
|
[a addObject:@"-c"];
|
||||||
if (r.length > 0) {
|
if (r.length > 0) {
|
||||||
// Select given range.
|
// Select given range of characters.
|
||||||
[a addObject:[NSString stringWithFormat:@"norm %dGV%dGz.0",
|
// TODO: This only works for encodings where 1 byte == 1 character
|
||||||
NSMaxRange(r), r.location]];
|
[a addObject:[NSString stringWithFormat:@"norm %dgov%dgo",
|
||||||
|
r.location, NSMaxRange(r)-1]];
|
||||||
} else {
|
} else {
|
||||||
// Position cursor on start of range.
|
// Position cursor on line at start of range.
|
||||||
[a addObject:[NSString stringWithFormat:@"norm %dGz.0",
|
[a addObject:[NSString stringWithFormat:@"norm %dGz.0",
|
||||||
r.location]];
|
r.location]];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2626,7 +2626,7 @@ static void netbeansReadCallback(CFSocketRef s,
|
|||||||
// filenames list of filenames
|
// filenames list of filenames
|
||||||
// dontOpen don't open files specified in above argument
|
// dontOpen don't open files specified in above argument
|
||||||
// layout which layout to use to open files
|
// layout which layout to use to open files
|
||||||
// selectionRange range of lines to select
|
// selectionRange range of characters to select
|
||||||
// searchText string to search for
|
// searchText string to search for
|
||||||
// cursorLine line to position the cursor on
|
// cursorLine line to position the cursor on
|
||||||
// cursorColumn column to position the cursor on
|
// cursorColumn column to position the cursor on
|
||||||
@@ -2811,13 +2811,14 @@ static void netbeansReadCallback(CFSocketRef s,
|
|||||||
NSString *rangeString = [args objectForKey:@"selectionRange"];
|
NSString *rangeString = [args objectForKey:@"selectionRange"];
|
||||||
if (rangeString) {
|
if (rangeString) {
|
||||||
// Build a command line string that will select the given range of
|
// Build a command line string that will select the given range of
|
||||||
// lines. If range.length == 0, then position the cursor on the given
|
// characters. If range.length == 0, then position the cursor on the
|
||||||
// line but do not select.
|
// line at start of range but do not select.
|
||||||
NSRange range = NSRangeFromString(rangeString);
|
NSRange range = NSRangeFromString(rangeString);
|
||||||
NSString *cmd;
|
NSString *cmd;
|
||||||
if (range.length > 0) {
|
if (range.length > 0) {
|
||||||
cmd = [NSString stringWithFormat:@"<C-\\><C-N>%dGV%dGz.0",
|
// TODO: This only works for encodings where 1 byte == 1 character
|
||||||
NSMaxRange(range), range.location];
|
cmd = [NSString stringWithFormat:@"<C-\\><C-N>%dgov%dgo",
|
||||||
|
range.location, NSMaxRange(range)-1];
|
||||||
} else {
|
} else {
|
||||||
cmd = [NSString stringWithFormat:@"<C-\\><C-N>%dGz.0",
|
cmd = [NSString stringWithFormat:@"<C-\\><C-N>%dGz.0",
|
||||||
range.location];
|
range.location];
|
||||||
|
|||||||
Reference in New Issue
Block a user