@@ -58,15 +58,15 @@ -(void) addSettingMenu
5858 if (editMenuItem) {
5959 [[editMenuItem submenu ] addItem: [NSMenuItem separatorItem ]];
6060
61- NSMenuItem *newMenuItem = [[NSMenuItem alloc ] initWithTitle: @" VVDocumenter" action: @selector (showSettingPanle : ) keyEquivalent: @" " ];
61+ NSMenuItem *newMenuItem = [[NSMenuItem alloc ] initWithTitle: @" VVDocumenter" action: @selector (showSettingPanel : ) keyEquivalent: @" " ];
6262
6363 [newMenuItem setTarget: self ];
6464 [[editMenuItem submenu ] addItem: newMenuItem];
6565 [newMenuItem release ];
6666 }
6767}
6868
69- -(void ) showSettingPanle : (NSNotification *)noti {
69+ -(void ) showSettingPanel : (NSNotification *)noti {
7070 VVDSettingPanelWindowController *panelController = [[VVDSettingPanelWindowController alloc ] initWithWindowNibName: @" VVDSettingPanelWindowController" ];
7171 [panelController showWindow: panelController];
7272}
@@ -92,12 +92,12 @@ - (void) textStorageDidChange:(NSNotification *)noti {
9292 if ([currentLineResult.string vv_matchesPatternRegexPattern: [NSString stringWithFormat: @" ^\\ s*%@ $" ,[NSRegularExpression escapedPatternForString: triggerString]]] && self.prefixTyped ) {
9393 self.prefixTyped = NO ;
9494 // Get a @"///" typed in by user. Do work!
95-
95+ __block BOOL shouldReplace = NO ;
9696 // Decide which is closer to the cursor. A semicolon or a half brace.
9797 // We just want to document the next valid line.
9898 VVTextResult *resultUntilSemiColon = [textView textResultUntilNextString: @" ;" ];
9999 VVTextResult *resultUntilBrace = [textView textResultUntilNextString: @" {" ];
100-
100+
101101 VVTextResult *resultToDocument = nil ;
102102
103103 if (resultUntilSemiColon && resultUntilBrace) {
@@ -108,6 +108,11 @@ - (void) textStorageDidChange:(NSNotification *)noti {
108108 resultToDocument = resultUntilSemiColon;
109109 }
110110
111+ if ([resultToDocument.string vv_isEnum ]) {
112+ resultToDocument = resultUntilSemiColon;
113+ shouldReplace = YES ;
114+ }
115+
111116 VVDocumenter *doc = [[VVDocumenter alloc ] initWithCode: resultToDocument.string];
112117
113118 // Now we are using a simulation of keyboard event to insert the docs, instead of using the IDE's private method.
@@ -120,14 +125,16 @@ - (void) textStorageDidChange:(NSNotification *)noti {
120125 // Set the doc comments in it
121126 [pasteBoard declareTypes: [NSArray arrayWithObject: NSStringPboardType ] owner: nil ];
122127 [pasteBoard setString: [doc document ] forType: NSStringPboardType ];
123-
128+
124129 // Begin to simulate keyborad pressing
125130 VVKeyboardEventSender *kes = [[VVKeyboardEventSender alloc ] init ];
126131 [kes beginKeyBoradEvents ];
127132 // Cmd+delete Delete current line
128133 [kes sendKeyCode: kVK_Delete withModifierCommand: YES alt: NO shift: NO control: NO ];
134+ // if (shouldReplace) [textView setSelectedRange:resultToDocument.range];
129135 // Cmd+V, paste
130136 [kes sendKeyCode: kVK_ANSI_V withModifierCommand: YES alt: NO shift: NO control: NO ];
137+
131138 // The key down is just a defined finish signal by me. When we receive this key, we know operation above is finished.
132139 [kes sendKeyCode: kVK_F20 ];
133140
@@ -140,6 +147,14 @@ - (void) textStorageDidChange:(NSNotification *)noti {
140147 // Restore previois patse board content
141148 [pasteBoard setString: originPBString forType: NSStringPboardType ];
142149
150+ if (shouldReplace) {
151+ // Quick fix for newline and bad position with NS_ENUM
152+ // Should be fixed better
153+ [kes sendKeyCode: kVK_Delete withModifierCommand: NO alt: NO shift: NO control: NO ];
154+ [kes sendKeyCode: kVK_DownArrow withModifierCommand: NO alt: NO shift: NO control: NO ];
155+ [kes sendKeyCode: kVK_LeftArrow withModifierCommand: YES alt: NO shift: NO control: NO ];
156+ }
157+
143158 // Set cursor before the inserted documentation. So we can use tab to begin edit.
144159 int baseIndentationLength = (int )[doc baseIndentation ].length ;
145160 [textView setSelectedRange: NSMakeRange (currentLineResult.range.location + baseIndentationLength, 0 )];
@@ -148,8 +163,14 @@ - (void) textStorageDidChange:(NSNotification *)noti {
148163 [kes sendKeyCode: kVK_Tab ];
149164 [kes endKeyBoradEvents ];
150165
166+ shouldReplace = NO ;
167+
151168 // Invalidate the finish signal, in case you set it to do some other thing.
152169 return nil ;
170+ } else if ([incomingEvent type ] == NSKeyDown && [incomingEvent keyCode ] == kVK_ANSI_V && shouldReplace == YES ) {
171+
172+ [textView setSelectedRange: [textView textResultUntilNextString: @" ;" ].range];
173+ return incomingEvent;
153174 } else {
154175 return incomingEvent;
155176 }
0 commit comments