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

allow whitespace characters to work with replace mode #770

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions XVim/XVimKeyStroke.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ NSString* XVimKeyNotationFromXVimString(XVimString* string);
@property unsigned char modifier;
@property (nonatomic, readonly) BOOL isNumeric;
@property (nonatomic, readonly) BOOL isPrintable;
@property (nonatomic, readonly) BOOL isWhitespace;

- (id)initWithCharacter:(unichar)c modifier:(unsigned char)mod;

Expand Down
12 changes: 12 additions & 0 deletions XVim/XVimKeyStroke.m
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,13 @@ NS_INLINE BOOL isPrintable(unichar c)
return !isNSFunctionKey(c) && iswprint_l(c, s_locale);
}

NS_INLINE BOOL isWhitespace(unichar c)
{
init_maps();

return !isNSFunctionKey(c) && iswspace_l(c, s_locale);
}

NS_INLINE BOOL isValidKey(NSString *key)
{
init_maps();
Expand Down Expand Up @@ -619,6 +626,11 @@ - (BOOL)isPrintable
return !_modifier && isPrintable(_character);
}

- (BOOL)isWhitespace
{
return !_modifier && isWhitespace(_character);
}

- (NSString*)keyNotation{
NSMutableString *keyStr = [[NSMutableString alloc] init];
unichar charcode = _character;
Expand Down
4 changes: 2 additions & 2 deletions XVim/XVimReplaceEvaluator.m
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ - (XVimEvaluator*)eval:(XVimKeyStroke*)keyStroke{
// Here we pass the key input to original text view.
// The input coming to this method is already handled by "Input Method"
// and the input maight be non ascii like 'あ'
if (self.oneCharMode || keyStroke.isPrintable) {
if (!keyStroke.isPrintable) {
if (self.oneCharMode || keyStroke.isPrintable || keyStroke.isWhitespace) {
if (!keyStroke.isPrintable && !keyStroke.isWhitespace) {
nextEvaluator = [XVimEvaluator invalidEvaluator];
} else if (![self.sourceView xvim_replaceCharacters:keyStroke.character count:1]) {
nextEvaluator = [XVimEvaluator invalidEvaluator];
Expand Down