Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/dhasl002/master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
pebble8888 committed Jun 9, 2019
2 parents 6fed166 + a93b8db commit 36aec01
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 7 deletions.
8 changes: 8 additions & 0 deletions XVim2/UnitTest/XVimTester+Register.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ - (NSArray*)register_testcases
@"ddd e-e fff\n"
@"ggg hhh i_i\n"
@" jjj kkk";

static NSString* register_visual_paste_result = @"aa bbb ccc\n"
@"ddd e-e fff\n"
@"ggg hhh i_i\n"
@" jjj kkk";

return @[
// Operation using registers
Expand Down Expand Up @@ -65,6 +70,9 @@ - (NSArray*)register_testcases

// Repeat by @@
XVimMakeTestCase(@"aaa bbb ccc", 0, 0, @"qallq@a2@@", @"aaa bbb ccc", 8, 0),

//pasting from register in visual mode does not modify the pasting register
XVimMakeTestCase(text, 0, 0, @"\"adwvw\"aP\"aP", register_visual_paste_result, 0, 0),
];
}

Expand Down
4 changes: 2 additions & 2 deletions XVim2/XVim/Evaluator/XVimEvaluator.m
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ - (void)textView:(id)view didYank:(NSString*)yankedText withType:(XVIM_TEXT_TYPE
[XVIM.registerManager yank:yankedText withType:type onRegister:self.yankRegister];
}

- (void)textView:(id)view didDelete:(NSString*)deletedText withType:(XVIM_TEXT_TYPE)type
- (void)textView:(id)view didDelete:(NSString*)deletedText withType:(XVIM_TEXT_TYPE)type shouldReplaceRegister:(BOOL)isReplacing
{
[XVIM.registerManager delete:deletedText withType:type onRegister:self.yankRegister];
[XVIM.registerManager delete:deletedText withType:type onRegister:self.yankRegister shouldReplaceRegister:isReplacing];
}

- (XVimCommandLineEvaluator*)searchEvaluatorForward:(BOOL)forward
Expand Down
2 changes: 1 addition & 1 deletion XVim2/XVim/SourceViewProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ typedef NS_ENUM(char, CursorStyle) {

@protocol XVimTextViewDelegateProtocol
- (void)textView:(id)view didYank:(NSString*)yankedText withType:(XVIM_TEXT_TYPE)type;
- (void)textView:(id)view didDelete:(NSString*)deletedText withType:(XVIM_TEXT_TYPE)type;
- (void)textView:(id)view didDelete:(NSString*)deletedText withType:(XVIM_TEXT_TYPE)type shouldReplaceRegister:(bool)isReplacing;
@end

@protocol SourceViewProtocol <NSObject>
Expand Down
2 changes: 1 addition & 1 deletion XVim2/XVim/XVimRegister.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
**/
- (XVimString*)xvimStringForRegister:(NSString*)name;
- (void)yank:(XVimString*)string withType:(XVIM_TEXT_TYPE)type onRegister:(NSString*)name;
- (void)delete:(XVimString*)string withType:(XVIM_TEXT_TYPE)type onRegister:(NSString*)name;
- (void)delete:(XVimString*)string withType:(XVIM_TEXT_TYPE)type onRegister:(NSString*)name shouldReplaceRegister:(BOOL)isReplacing;
- (void)textInserted:(XVimString*)string withType:(XVIM_TEXT_TYPE)type;
- (void)commandExecuted:(XVimString*)string withType:(XVIM_TEXT_TYPE)type;
- (void)registerExecuted:(NSString*)name;
Expand Down
8 changes: 6 additions & 2 deletions XVim2/XVim/XVimRegister.m
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ - (void)yank:(XVimString*)string withType:(XVIM_TEXT_TYPE)type onRegister:(NSStr
}
}

- (void) delete:(XVimString*)string withType:(XVIM_TEXT_TYPE)type onRegister:(NSString*)name
- (void) delete:(XVimString*)string withType:(XVIM_TEXT_TYPE)type onRegister:(NSString*)name shouldReplaceRegister:(BOOL)isReplacing
{
// TODO: use "- when deleting does not include \n
NSAssert([self isValidForYank:name], @"Must be valid register for yank/delete");
Expand All @@ -314,7 +314,11 @@ - (void) delete:(XVimString*)string withType:(XVIM_TEXT_TYPE)type onRegister:(NS
[self appendXVimString:string forReg:name];
}
else {
[self setXVimString:string withType:type forReg:name];
if (isReplacing) {
[self setXVimString:string withType:type forReg:name];
} else {
[self setXVimString:string withType:type forReg:@"0"];
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion XVim2/Xcode/SourceCodeEditorViewProxy+Operations.m
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ - (BOOL)xvim_delete:(XVimMotion*)motion withMotionPoint:(NSUInteger)motionPoint
return NO;
}
NSUInteger newPos = NSNotFound;
BOOL isYankingFromVisual = false;

[self xvim_beginEditTransaction];
xvim_on_exit { [self xvim_endEditTransaction]; };
Expand Down Expand Up @@ -168,6 +169,7 @@ - (BOOL)xvim_delete:(XVimMotion*)motion withMotionPoint:(NSUInteger)motionPoint
{
XVimSelection sel = [self _xvim_selectedBlock];
if (yank) {
isYankingFromVisual = true;
[self _xvim_yankSelection:sel];
}
[self _xvim_killSelection:sel];
Expand All @@ -184,6 +186,7 @@ - (BOOL)xvim_delete:(XVimMotion*)motion withMotionPoint:(NSUInteger)motionPoint
// This is because of the fact that NSTextView does not allow select EOF

if (yank) {
isYankingFromVisual = true;
[self _xvim_yankRange:range withType:DEFAULT_MOTION_TYPE];
}
[self insertText:@"" replacementRange:range];
Expand All @@ -199,7 +202,7 @@ - (BOOL)xvim_delete:(XVimMotion*)motion withMotionPoint:(NSUInteger)motionPoint
break;
}

[self.xvimTextViewDelegate textView:self didDelete:self.lastYankedText withType:self.lastYankedType];
[self.xvimTextViewDelegate textView:self didDelete:self.lastYankedText withType:self.lastYankedType shouldReplaceRegister:!isYankingFromVisual];
[self xvim_changeSelectionMode:XVIM_VISUAL_NONE];
if (newPos != NSNotFound) {
[self xvim_moveCursor:newPos preserveColumn:NO];
Expand Down

0 comments on commit 36aec01

Please sign in to comment.