そろそろ本家にフィードバックしなくっちゃ.
diff -cr src.orig/MacVim/MMTextView.h src/MacVim/MMTextView.h
*** src.orig/MacVim/MMTextView.h Tue Feb 26 12:35:09 2008
--- src/MacVim/MMTextView.h Tue Feb 26 12:35:28 2008
***************
*** 25,31 ****
int insertionPointColumn;
int insertionPointShape;
int insertionPointFraction;
! NSTextField *markedTextField;
int preEditRow;
int preEditColumn;
}
--- 25,33 ----
int insertionPointColumn;
int insertionPointShape;
int insertionPointFraction;
! NSDictionary *markedTextAttributes;
! NSAttributedString *markedText;
! NSRange imRange;
int preEditRow;
int preEditColumn;
}
***************
*** 37,43 ****
- (void)setPreEditRow:(int)row column:(int)col;
- (void)drawInsertionPointAtRow:(int)row column:(int)col shape:(int)shape
fraction:(int)percent color:(NSColor *)color;
- - (void)hideMarkedTextField;
- (void)performBatchDrawWithData:(NSData *)data;
//
--- 39,44 ----
diff -cr src.orig/MacVim/MMTextView.m src/MacVim/MMTextView.m
*** src.orig/MacVim/MMTextView.m Tue Feb 26 12:35:09 2008
--- src/MacVim/MMTextView.m Tue Feb 26 12:40:23 2008
***************
*** 117,126 ****
{
//NSLog(@"MMTextView dealloc");
! if (markedTextField) {
! [[markedTextField window] autorelease];
! [markedTextField release];
! markedTextField = nil;
}
[lastMouseDownEvent release]; lastMouseDownEvent = nil;
--- 117,126 ----
{
//NSLog(@"MMTextView dealloc");
! if (markedText) {
! imRange = NSMakeRange(0, 0);
! [markedText release];
! markedText = nil;
}
[lastMouseDownEvent release]; lastMouseDownEvent = nil;
***************
*** 169,184 ****
[self setInsertionPointColor:color];
}
- - (void)hideMarkedTextField
- {
- if (markedTextField) {
- NSWindow *win = [markedTextField window];
- [win close];
- [markedTextField setStringValue:@""];
- }
- }
-
-
#define MM_DEBUG_DRAWING 0
- (void)performBatchDrawWithData:(NSData *)data
--- 169,174 ----
***************
*** 469,474 ****
--- 459,477 ----
// NSStringFromRect(ipRect), insertionPointShape,
// [self insertionPointColor]);
}
+
+ if ( [self hasMarkedText] ) {
+ int len = [markedText length];
+ MMTextStorage *ts = (MMTextStorage*)[self textStorage];
+ int wfrac = ([ts cellSize].width* insertionPointFraction + 99)/100 + 1;
+ int hfrac = ([ts cellSize].height* insertionPointFraction + 99)/100 + 1;
+
+ [markedText drawInRect:NSMakeRect(
+ insertionPointColumn*[ts cellSize].width+wfrac,
+ insertionPointRow*[ts cellSize].height,
+ [ts cellSize].width*2*len, [ts cellSize].height+hfrac)];
+ }
+
#if 0
// this code invalidates the shadow, so we don't
// get shifting ghost text on scroll and resize
***************
*** 499,504 ****
--- 502,518 ----
//
// TODO: Figure out a way to disable Cocoa key bindings entirely, without
// affecting input management.
+ [NSCursor setHiddenUntilMouseMoves: YES];
+ if ([self hasMarkedText]) {
+ NSString *unmod = [event charactersIgnoringModifiers];
+ if (([markedText length] == 1 && [unmod characterAtIndex:0] == 0x7f)
+ || [unmod characterAtIndex:0] == 0x1b || [unmod characterAtIndex:0] == 0x0d) {
+ [self unmarkText];
+ }
+ [super keyDown:event];
+ [self setNeedsDisplay: YES];
+ return;
+ }
int flags = [event modifierFlags];
if ((flags & NSControlKeyMask) ||
((flags & NSAlternateKeyMask) && (flags & NSFunctionKeyMask))) {
***************
*** 529,535 ****
// modifiers are already included and should not be added to the input
// buffer using CSI, K_MODIFIER).
! [self hideMarkedTextField];
NSEvent *event = [NSApp currentEvent];
--- 543,551 ----
// modifiers are already included and should not be added to the input
// buffer using CSI, K_MODIFIER).
! if([self hasMarkedText]) {
! [self unmarkText];
! }
NSEvent *event = [NSApp currentEvent];
***************
*** 678,691 ****
- (BOOL)hasMarkedText
{
//NSLog(@"%s", _cmd);
! return markedTextField && [[markedTextField stringValue] length] > 0;
}
! - (NSRange)markedRange
{
! //NSLog(@"%s", _cmd);
! unsigned len = [[markedTextField stringValue] length];
! return NSMakeRange(len > 0 ? 0 : NSNotFound, len);
}
- (void)setMarkedText:(id)text selectedRange:(NSRange)range
--- 694,705 ----
- (BOOL)hasMarkedText
{
//NSLog(@"%s", _cmd);
! return markedText && [markedText length] > 0;
}
! - (NSRange)selectedRange
{
! return NSMakeRange(NSNotFound, 0);
}
- (void)setMarkedText:(id)text selectedRange:(NSRange)range
***************
*** 693,759 ****
//NSLog(@"setMarkedText:'%@' selectedRange:%@", text,
// NSStringFromRange(range));
! MMTextStorage *ts = (MMTextStorage*)[self textStorage];
! if (!ts) return;
!
! if (!markedTextField) {
! // Create a text field and put it inside a floating panel. This field
! // is used to display marked text.
! NSSize cellSize = [ts cellSize];
! NSRect cellRect = { 0, 0, cellSize.width, cellSize.height };
!
! markedTextField = [[NSTextField alloc] initWithFrame:cellRect];
! [markedTextField setEditable:NO];
! [markedTextField setSelectable:NO];
! [markedTextField setBezeled:NO];
! [markedTextField setBordered:YES];
!
! // NOTE: The panel that holds the marked text field is allocated here
! // and released in dealloc. No pointer to the panel is kept, instead
! // [markedTextField window] is used to access the panel.
! NSPanel *panel = [[NSPanel alloc]
! initWithContentRect:cellRect
! styleMask:NSBorderlessWindowMask|NSUtilityWindowMask
! backing:NSBackingStoreBuffered
! defer:YES];
!
! //[panel setHidesOnDeactivate:NO];
! [panel setFloatingPanel:YES];
! [panel setBecomesKeyOnlyIfNeeded:YES];
! [panel setContentView:markedTextField];
! }
!
if (text && [text length] > 0) {
! [markedTextField setFont:[ts font]];
if ([text isKindOfClass:[NSAttributedString class]])
! [markedTextField setAttributedStringValue:text];
else
! [markedTextField setStringValue:text];
!
! [markedTextField sizeToFit];
! NSSize size = [markedTextField frame].size;
!
! // Convert coordinates (row,col) -> view -> window base -> screen
! NSPoint origin;
! if (![self convertRow:preEditRow+1 column:preEditColumn
! toPoint:&origin])
! return;
! origin = [self convertPoint:origin toView:nil];
! origin = [[self window] convertBaseToScreen:origin];
!
! NSWindow *win = [markedTextField window];
! [win setContentSize:size];
! [win setFrameOrigin:origin];
! [win orderFront:nil];
! } else {
! [self hideMarkedTextField];
}
}
- (void)unmarkText
{
//NSLog(@"%s", _cmd);
! [self hideMarkedTextField];
}
- (NSRect)firstRectForCharacterRange:(NSRange)range
--- 707,732 ----
//NSLog(@"setMarkedText:'%@' selectedRange:%@", text,
// NSStringFromRange(range));
! [self unmarkText];
if (text && [text length] > 0) {
! MMTextStorage *ts = (MMTextStorage*)[self textStorage];
if ([text isKindOfClass:[NSAttributedString class]])
! markedText=[[NSAttributedString alloc] initWithString:[text string]
! attributes:[self markedTextAttributes]];
else
! markedText=[[NSAttributedString alloc] initWithString:text
! attributes:[self markedTextAttributes]];
! imRange = NSMakeRange(0, [markedText length]);
! [self setNeedsDisplay: YES];
}
}
- (void)unmarkText
{
//NSLog(@"%s", _cmd);
! imRange = NSMakeRange(0, 0);
! [markedText release];
! markedText = nil;
}
- (NSRect)firstRectForCharacterRange:(NSRange)range
diff -cr src.orig/MacVim/MMWindowController.m src/MacVim/MMWindowController.m
*** src.orig/MacVim/MMWindowController.m Tue Feb 26 12:35:09 2008
--- src/MacVim/MMWindowController.m Tue Feb 26 12:35:28 2008
***************
*** 643,651 ****
- (void)windowDidResignMain:(NSNotification *)notification
{
[vimController sendMessage:LostFocusMsgID data:nil];
-
- if ([vimView textView])
- [[vimView textView] hideMarkedTextField];
}
- (BOOL)windowShouldClose:(id)sender
--- 643,648 ----
0 件のコメント:
コメントを投稿