Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option click with shell type processes. #139

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 72 additions & 29 deletions PTYTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -3989,6 +3989,9 @@ - (void)selectPreviousPaneWithEvent:(NSEvent *)event

- (void)placeCursorOnCurrentLineWithEvent:(NSEvent *)event
{
static NSArray *shellProcesses = nil;
if (shellProcesses==nil)
shellProcesses = [[NSArray alloc] initWithObjects:@"bash", @"Shell", @"sh", @"sqlite3", @"mysql", nil];
BOOL debugKeyDown = [[[NSUserDefaults standardUserDefaults] objectForKey:@"DebugKeyDown"] boolValue];

if (debugKeyDown) {
Expand All @@ -4005,35 +4008,75 @@ - (void)placeCursorOnCurrentLineWithEvent:(NSEvent *)event
VT100Terminal *terminal = [dataSource terminal];
PTYSession* session = [dataSource session];

int i = abs(cursorX - x);
int j = abs(cursorY - y);

if (cursorX > x) {
// current position is right of going-to-be x,
// so first move to left, and (if necessary)
// up or down afterwards
while (i > 0) {
[session writeTask:[terminal keyArrowLeft:0]];
i--;
}
}
while (j > 0) {
if (cursorY > y) {
[session writeTask:[terminal keyArrowUp:0]];
} else {
[session writeTask:[terminal keyArrowDown:0]];
}
j--;
}
if (cursorX < x) {
// current position is left of going-to-be x
// so first moved up/down (if necessary)
// and then/now to the right
while (i > 0) {
[session writeTask:[terminal keyArrowRight:0]];
i--;
}
}
if ([shellProcesses containsObject:[session name]]) {
if (cursorY > y) {
// Cursor needs to be placed to the right of the line
// wanted as the user is going up.
int left = ((width*(cursorY-y))-width)+cursorX;
while (left > 0) {
[session writeTask:[terminal keyArrowLeft:0]];
left--;
}
// Cursor should now be at the righter most point.
cursorX = width;
} else if (cursorY < y) {
// Curosor needs to be placed to the left of the line
// wanted as the user is going down.
int right = ((width*(y-cursorY))-cursorX)+1;
while (right > 0) {
[session writeTask:[terminal keyArrowRight:0]];
right--;
}
// Cursor should now be at point 1.
cursorX = 1;
}

if (cursorX > x) {
// Move cursor left.
int left = cursorX-x;
while (left > 0) {
[session writeTask:[terminal keyArrowLeft:0]];
left--;
}
} else if (cursorX < x) {
// Move cursor right.
int right = x-cursorX;
while (right > 0) {
[session writeTask:[terminal keyArrowRight:0]];
right--;
}
}
} else {
int i = abs(cursorX - x);
int j = abs(cursorY - y);

if (cursorX > x) {
// current position is right of going-to-be x,
// so first move to left, and (if necessary)
// up or down afterwards
while (i > 0) {
[session writeTask:[terminal keyArrowLeft:0]];
i--;
}
}
while (j > 0) {
if (cursorY > y) {
[session writeTask:[terminal keyArrowUp:0]];
} else {
[session writeTask:[terminal keyArrowDown:0]];
}
j--;
}
if (cursorX < x) {
// current position is left of going-to-be x
// so first moved up/down (if necessary)
// and then/now to the right
while (i > 0) {
[session writeTask:[terminal keyArrowRight:0]];
i--;
}
}
}
if (debugKeyDown) {
NSLog(@"cursor at %d,%d (x,y) moved to %d,%d (x,y) [window width: %d]",
cursorX, cursorY, x, y, width);
Expand Down