Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
  • 5 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 43 additions and 6 deletions.
  1. +42 −5 SwipeShiftCaret.x
  2. +1 −1  layout/DEBIAN/control
View
47 SwipeShiftCaret.x
@@ -1,4 +1,5 @@
#import <UIKit/UIKit.h>
+#import <UIKit/UIGestureRecognizerSubclass.h>
%config(generator=internal);
@@ -15,11 +16,18 @@ static BOOL panGestureEnabled;
- (BOOL)callLayoutIsShiftKeyBeingHeld;
@end
+@interface UIFieldEditor : NSObject
++ (id)sharedFieldEditor;
+- (void)revealSelection;
+@end
+
@interface SCSwipeGestureRecognizer : UISwipeGestureRecognizer
@end
@implementation SCSwipeGestureRecognizer
- (BOOL)canBePreventedByGestureRecognizer:(UIGestureRecognizer *)gesture {
+ if ([gesture isKindOfClass:[UIPanGestureRecognizer class]])
+ self.state = UIGestureRecognizerStateFailed;
if ([gesture isMemberOfClass:[SCSwipeGestureRecognizer class]])
return YES;
return NO;
@@ -39,6 +47,8 @@ static BOOL panGestureEnabled;
@implementation SCPanGestureRecognizer
- (BOOL)canBePreventedByGestureRecognizer:(UIGestureRecognizer *)gesture {
+ if ([gesture isKindOfClass:[UIPanGestureRecognizer class]])
+ self.state = UIGestureRecognizerStateCancelled;
if ([gesture isMemberOfClass:[SCPanGestureRecognizer class]])
return YES;
return NO;
@@ -93,6 +103,7 @@ static void ShiftCaret(BOOL isLeftSwipe)
return;
UITextRange *range = [tv textRangeFromPosition:position toPosition:position];
tv.selectedTextRange = range;
+ [[%c(UIFieldEditor) sharedFieldEditor] revealSelection];
}
%hook UIView
@@ -109,6 +120,13 @@ static void ShiftCaret(BOOL isLeftSwipe)
return tmp;
}
+- (BOOL)resignFirstResponder
+{
+ if (tv == self)
+ tv = nil;
+ return %orig;
+}
+
%new(v@:@)
- (void)leftSwipeShiftCaret:(UISwipeGestureRecognizer *)gesture
{
@@ -143,6 +161,7 @@ static void ShiftCaret(BOOL isLeftSwipe)
shiftHeldDown = [keyboardImpl callLayoutIsShiftKeyBeingHeld];
if (gesture.state == UIGestureRecognizerStateEnded || gesture.state == UIGestureRecognizerStateCancelled) {
+ // cleanup
numberOfTouches = 0;
shiftHeldDown = NO;
isLeftPanning = YES;
@@ -150,13 +169,24 @@ static void ShiftCaret(BOOL isLeftSwipe)
gesture.cancelsTouchesInView = NO;
[startTextRange release];
startTextRange = nil;
+ // auto pop-up menu.
+ UITextRange *range = tv.selectedTextRange;
+ if (range && !range.isEmpty) {
+ UIMenuController *mc = [UIMenuController sharedMenuController];
+ [mc setTargetRect:[tv firstRectForRange:range] inView:tv];
+ [mc setMenuVisible:YES animated:YES];
+ }
} else if (gesture.state == UIGestureRecognizerStateBegan) {
if ([tv respondsToSelector:@selector(positionFromPosition:inDirection:offset:)])
startTextRange = [tv.selectedTextRange retain];
} else if (gesture.state == UIGestureRecognizerStateChanged) {
CGPoint offset = [gesture translationInView:self];
- if (!hasStarted && offset.x < 5 && offset.x > -5)
+ if (!hasStarted && abs(offset.x) < 16)
+ return;
+ if (!hasStarted && abs(offset.x) < abs(offset.y)) {
+ gesture.state = UIGestureRecognizerStateEnded;
return;
+ }
if (!hasStarted)
isLeftPanning = offset.x < 0 ? YES : NO;
gesture.cancelsTouchesInView = YES;
@@ -189,6 +219,7 @@ static void ShiftCaret(BOOL isLeftSwipe)
range = [tv textRangeFromPosition:isLeftPanning ? startTextRange.end : startTextRange.start toPosition:position];
}
tv.selectedTextRange = range;
+ [[%c(UIFieldEditor) sharedFieldEditor] revealSelection];
}
}
%end
@@ -198,10 +229,16 @@ static void LoadSettings()
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:PREF_PATH];
id existPanGesture = [dict objectForKey:@"PanGestureEnabled"];
panGestureEnabled = existPanGesture ? [existPanGesture boolValue] : YES;
- if (panGestureEnabled)
- InstallPanGestureRecognizer();
- else
- InstallSwipeGestureRecognizer();
+ if (tv) {
+ if (panGestureEnabled) {
+ InstallPanGestureRecognizer();
+ } else {
+ InstallSwipeGestureRecognizer();
+ for (UIGestureRecognizer *gesture in [tv gestureRecognizers])
+ if ([gesture isMemberOfClass:[SCPanGestureRecognizer class]])
+ [tv removeGestureRecognizer:gesture];
+ }
+ }
}
static void PostNotification(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo)
View
2  layout/DEBIAN/control
@@ -1,7 +1,7 @@
Package: jp.r-plus.swipeshiftcaret
Name: SwipeShiftCaret
Depends: mobilesubstrate, preferenceloader, firmware (>= 5.0)
-Version: 1.0
+Version: 1.0.1
Architecture: iphoneos-arm
Description: caret micromanager via swipes
Maintainer: BigBoss <bigboss@thebigboss.org>

No commit comments for this range

Something went wrong with that request. Please try again.