From eaf020c6bc8e56aaf97d92cd66061bd9e4ac8ae0 Mon Sep 17 00:00:00 2001 From: Bjorn Winckler Date: Tue, 29 Jan 2008 19:27:14 +0100 Subject: [PATCH] Send cursor position on each batch draw The cursor position is used to set the selected range in the MMTextView. This provides some support for voice over (enable with Mac+F5). --- src/MacVim/MMBackend.m | 5 +++++ src/MacVim/MMTextView.m | 13 +++++++++++++ src/MacVim/MacVim.h | 3 ++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/MacVim/MMBackend.m b/src/MacVim/MMBackend.m index 5e4272af..5fea7e73 100644 --- a/src/MacVim/MMBackend.m +++ b/src/MacVim/MMBackend.m @@ -441,6 +441,11 @@ static NSString *MMSymlinkWarningString = [self setWideFont:oldWideFont]; } + int type = SetCursorPosDrawType; + [drawData appendBytes:&type length:sizeof(type)]; + [drawData appendBytes:&gui.row length:sizeof(gui.row)]; + [drawData appendBytes:&gui.col length:sizeof(gui.col)]; + [self queueMessage:BatchDrawMsgID data:[drawData copy]]; [drawData setLength:0]; } diff --git a/src/MacVim/MMTextView.m b/src/MacVim/MMTextView.m index 70ef1185..08fd5944 100644 --- a/src/MacVim/MMTextView.m +++ b/src/MacVim/MMTextView.m @@ -195,6 +195,7 @@ enum { const void *bytes = [data bytes]; const void *end = bytes + [data length]; + int cursorRow = -1, cursorCol = 0; #if MM_DEBUG_DRAWING NSLog(@"====> BEGIN %s", _cmd); @@ -304,6 +305,9 @@ enum { [self drawInsertionPointAtRow:row column:col shape:shape fraction:percent color:[NSColor colorWithRgbInt:color]]; + } else if (SetCursorPosDrawType == type) { + cursorRow = *((int*)bytes); bytes += sizeof(int); + cursorCol = *((int*)bytes); bytes += sizeof(int); } else { NSLog(@"WARNING: Unknown draw type (type=%d)", type); } @@ -311,6 +315,15 @@ enum { [textStorage endEditing]; + if (cursorRow >= 0) { + unsigned off = [textStorage characterIndexForRow:cursorRow + column:cursorCol]; + unsigned maxoff = [[textStorage string] length]; + if (off > maxoff) off = maxoff; + + [self setSelectedRange:NSMakeRange(off, 0)]; + } + // NOTE: During resizing, Cocoa only sends draw messages before Vim's rows // and columns are changed (due to ipc delays). Force a redraw here. [self displayIfNeeded]; diff --git a/src/MacVim/MacVim.h b/src/MacVim/MacVim.h index 98aee703..4fc596ae 100644 --- a/src/MacVim/MacVim.h +++ b/src/MacVim/MacVim.h @@ -171,7 +171,8 @@ enum { DeleteLinesDrawType, DrawStringDrawType, InsertLinesDrawType, - DrawCursorDrawType + DrawCursorDrawType, + SetCursorPosDrawType, }; enum { -- 2.11.4.GIT