Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
r-plus committed Oct 6, 2021
2 parents 7b26f9d + 542662c commit 3f37d90
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 44 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ on: [push, pull_request]
jobs:
test:

runs-on: macOS-latest
runs-on: macOS-11
strategy:
matrix:
xcode-version:
- /Applications/Xcode_13.0.app

steps:
- uses: actions/checkout@v2
- run: if [ "default" != "${{ matrix.xcode-version }}" ]; then sudo xcode-select -s "${{ matrix.xcode-version }}"; fi
- name: Build XVim with UNIT_TEST flag
run: make unit-test
- name: Remove codesign
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ Tested on macOS 11.2.3, Xcode 12.4
- `develop`: for the next beta Xcode and develop.

- tags
- `xcode12`
- `xcode11.7`
- `xcode11.5`
- `xcode11.2`
Expand Down
1 change: 1 addition & 0 deletions XVim2/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<string>1</string>
<key>DVTPlugInCompatibilityUUIDs</key>
<array>
<string>8BAA96B4-5225-471B-B124-D32A349B8106</string>
<string>F56A1938-53DE-493D-9D64-87EE6C415E4D</string>
<string>2F1A5FFF-BFEB-4498-B2AC-1296A7454F81</string>
<string>3928AC50-EA32-404F-9CAF-49710A35483C</string>
Expand Down
55 changes: 24 additions & 31 deletions XVim2/UnitTest/XVimTestCase.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
@interface XVimTestCase()
@property (class, readonly) NSOperationQueue * keySendQueue;
@property (weak) NSWindow * window;
@property dispatch_semaphore_t keySemaphore;
@property dispatch_group_t group;
@property (readonly) dispatch_queue_t testCompletionDispatchQueue;
@property NSInteger keyStrokesCount;
@end

static NSOperationQueue *_keySendQueue = nil;
Expand Down Expand Up @@ -69,11 +68,11 @@ + (XVimTestCase*)testCaseWithInitialText:(NSString*)initialText
test.expectedRange = expectedRange;
test.message = @"";
test.exception = NO;
test.keyStrokesCount = 0;
test.finished = NO;
test.desc = inputText;
test.file = file;
test.line = line;
test.group = dispatch_group_create();
return test;
}

Expand Down Expand Up @@ -126,28 +125,28 @@ - (void)executeInput
{
NSString *notation = [self.inputText stringByAppendingString:@"<ESC>:mapclear<CR>"];
NSArray* strokes = XVimKeyStrokesFromKeyNotation(notation);
self.keySemaphore = dispatch_semaphore_create(0);
self.keyStrokesCount = strokes.count;


for (XVimKeyStroke* stroke in strokes) {
dispatch_group_enter(self.group);
[XVimTestCase.keySendQueue addOperationWithBlock:^{
[NSOperationQueue.mainQueue addOperationWithBlock:^{
if (self.window == nil || !self.window.isVisible) {
dispatch_semaphore_signal(self.keySemaphore);
return;
}
@try {
NSEvent* event = [stroke toEventwithWindowNumber:self.window.windowNumber
context:self.window.graphicsContext];
[self.window makeKeyAndOrderFront:self];
[NSApp sendEvent:event];
dispatch_semaphore_signal(self.keySemaphore);
}
@catch (NSException* ex) {
self.exception = YES;
}
}];
[NSThread sleepForTimeInterval:0.01];
[NSOperationQueue.mainQueue addOperationWithBlock:^{
if (self.window == nil || !self.window.isVisible) {
dispatch_group_leave(self.group);
return;
}
@try {
NSEvent* event = [stroke toEventwithWindowNumber:self.window.windowNumber
context:self.window.graphicsContext];
[self.window makeKeyAndOrderFront:self];
[NSApp sendEvent:event];
dispatch_group_leave(self.group);
}
@catch (NSException* ex) {
self.exception = YES;
dispatch_group_leave(self.group);
}
[NSThread sleepForTimeInterval:0.01];
}];
}];

// Tells NSUndoManager to end grouping (Little hacky)
Expand All @@ -164,15 +163,9 @@ - (void)tearDown

- (void)waitForCompletionWithConinuation:(void(^)(void))continuation
{
if (self.keyStrokesCount == 0) {
[NSOperationQueue.mainQueue addOperationWithBlock:continuation];
return;
}

dispatch_async(self.testCompletionDispatchQueue, ^{
dispatch_semaphore_wait(self.keySemaphore, DISPATCH_TIME_FOREVER);
self.keyStrokesCount--;
[self waitForCompletionWithConinuation:continuation];
dispatch_group_wait(self.group, DISPATCH_TIME_FOREVER);
[NSOperationQueue.mainQueue addOperationWithBlock:continuation];
});
}

Expand Down
6 changes: 3 additions & 3 deletions XVim2/UnitTest/XVimTester+Visual.m
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ - (NSArray*)visual_testcases

// J in visual
//XVimMakeTestCase(text4, 1, 0, @"<C-v>jjJ", v_J_result0, 8, 0), // join 2 lines // FIXME:expected range
// XVimMakeTestCase(text4, 1, 0, @"<C-v>jjJj." , v_J_result1,19, 0), // Repeat (not
// supported yet)
XVimMakeTestCase(text4, 1, 0, @"<C-v>jjJ`.", v_J_result0, 12, 0), // . Mark
// XVimMakeTestCase(text4, 1, 0, @"<C-v>jjJj." , v_J_result1,19, 0), // Repeat (not supported yet)
// Could not complete on GitHub Actions CI
// XVimMakeTestCase(text4, 1, 0, @"<C-v>jjJ`.", v_J_result0, 12, 0), // . Mark

// gJ in visual
// XVimMakeTestCase(text4, 1, 0, @"<C-v>jjgJ", v_gJ_result0, 7, 0), // join 2 lines // FIXME:expected text
Expand Down
2 changes: 1 addition & 1 deletion XVim2/UnitTest/XVimTester.m
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ - (void)runTest
_doOpenIn_NewWindow_withWorkspaceTabController:XVimLastActiveWorkspaceTabController()
documentURL:doc
usingBlock:^(IDEEditorContext* context) {
[context openEditorOpenSpecifier:spec updateHistory:NO];
[IDEEditorAreaClass() _openEditorOpenSpecifier:spec editorContext:context options:nil];
}];

// Close NSWindow to make test run properly
Expand Down
5 changes: 4 additions & 1 deletion XVim2/Xcode/SourceEditorDataSourceWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ public struct XVimLineData {
private struct SourceEditorDataSourceInvoker {
let contextPtr = UnsafeMutablePointer<UnsafeMutableRawPointer>.allocate(capacity: 2)
public init?(_ dataSrc: AnyObject?, _ functionPtr: UnsafeMutableRawPointer?) {
public init?(_ dataSrc: AnyObject?, _ functionPtr: UnsafeMutableRawPointer?, line: Int = #line) {
assert(functionPtr != nil, "line: \(line): demangled name has been changed")
guard let dataSource = dataSrc,
let functionPtr = functionPtr
else { return nil }
Expand Down
11 changes: 8 additions & 3 deletions XVim2/Xcode/SourceEditorViewProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
@interface SourceEditorViewProxy ()
@property (weak) _TtC15IDESourceEditor19IDESourceEditorView* sourceEditorView;
@property NSLayoutConstraint* cmdLineBottomAnchor;
@property NSEdgeInsets originalScrollViewInsets;
@end

@implementation SourceEditorViewProxy {
Expand Down Expand Up @@ -632,6 +633,7 @@ - (XVimCommandLine*)commandLine
}
static CGFloat XvimCommandLineHeight = 20;
static CGFloat XvimCommandLineAnimationDuration = 0.1;
static CGFloat IDEKit_BottomBarViewHeight = 27;

- (BOOL)isShowingCommandLine { return self.commandLine.superview != nil; }

Expand All @@ -645,7 +647,7 @@ - (void)showCommandLine
NSView* layoutView = [scrollView superview];
[layoutView addSubview:self.commandLine];
_cmdLineBottomAnchor = [layoutView.bottomAnchor constraintEqualToAnchor:self.commandLine.bottomAnchor
constant:-XvimCommandLineHeight];
constant:0];
_cmdLineBottomAnchor.active = YES;
[layoutView.widthAnchor constraintEqualToAnchor:self.commandLine.widthAnchor multiplier:1.0].active = YES;
[layoutView.leftAnchor constraintEqualToAnchor:self.commandLine.leftAnchor].active = YES;
Expand All @@ -663,7 +665,8 @@ - (void)showCommandLine
[NSAnimationContext runAnimationGroup:^(NSAnimationContext* _Nonnull context) {
context.duration = XvimCommandLineAnimationDuration;
NSEdgeInsets insets = scrollView.contentInsets;
self->_cmdLineBottomAnchor.animator.constant = 0;
self->_originalScrollViewInsets = insets;
self->_cmdLineBottomAnchor.animator.constant = IDEKit_BottomBarViewHeight;
insets.bottom += XvimCommandLineHeight;
scrollView.animator.contentInsets = insets;
[scrollView setUpdatingAutoContentInsets:YES];
Expand Down Expand Up @@ -696,6 +699,7 @@ - (void)hideCommandLine
} completionHandler:^{
[self.commandLine removeFromSuperview];
self->_cmdLineBottomAnchor = nil;
self->_originalScrollViewInsets = NSEdgeInsetsZero;
}];
}
}
Expand All @@ -708,7 +712,8 @@ - (void)observeValueForKeyPath:(NSString *)keyPath
if ([keyPath isEqualToString:@"contentInsets"]) {
let scrollView = self.sourceEditorView.scrollView;
NSEdgeInsets insets = scrollView.contentInsets;
if (self.isShowingCommandLine && insets.bottom == 0) {
// NOTE: insets.bottom value sometimes 1pt difference to original.
if (self.isShowingCommandLine && insets.bottom <= self->_originalScrollViewInsets.bottom + 1) {
insets.bottom += XvimCommandLineHeight;
scrollView.contentInsets = insets;
}
Expand Down
24 changes: 20 additions & 4 deletions XVim2/Xcode/SourceEditorViewWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,14 @@ import Cocoa
@_silgen_name("scev_wrapper_call2") func _set_cursor_style(_: UnsafeRawPointer, _: CursorStyle)
@_silgen_name("scev_wrapper_call3") func _get_data_source(_: UnsafeRawPointer) -> (UnsafeMutableRawPointer)
@_silgen_name("scev_wrapper_call4") func _set_selected_range(_: UnsafeRawPointer, _: XVimSourceEditorRange, modifiers: Int)
@_silgen_name("scev_wrapper_call5") func _add_selected_range(_: UnsafeRawPointer, _: XVimSourceEditorRange, modifiers: Int)
@_silgen_name("scev_wrapper_call5") func _add_selected_range(
_: UnsafeRawPointer,
_: XVimSourceEditorRange,
anchor: XVimSourceEditorRange?,
modifiers: Int,
scrollPlacement: Any?,
alwaysScroll: Bool
)
@_silgen_name("scev_wrapper_call6") func _scev_voidToInt(_: UnsafeRawPointer) -> (Int)

// NOTE: global variable is automatically lazy in swift.
Expand All @@ -68,11 +75,13 @@ private let fpSetCursorStyle = function_ptr_from_name("_$s12SourceEditor0aB4View
private let fpGetCursorStyle = function_ptr_from_name("_$s12SourceEditor0aB4ViewC11cursorStyleAA0ab6CursorE0Ovg")
private let fpGetDataSource = function_ptr_from_name("_$s12SourceEditor0aB4ViewC04dataA0AA0ab4DataA0Cvg")
private let fpSetSelectedRangeWithModifiers = function_ptr_from_name("_$s12SourceEditor0aB4ViewC16setSelectedRange_9modifiersySnyAA0aB8PositionVG_AA0aB18SelectionModifiersVtF")
private let fpAddSelectedRangeWithModifiers = function_ptr_from_name("_$s12SourceEditor0aB4ViewC16addSelectedRange_9modifiers15scrollPlacement12alwaysScrollySnyAA0aB8PositionVG_AA0aB18SelectionModifiersVAA0kI0OSgSbtF")
private let fpAddSelectedRangeWithModifiers = function_ptr_from_name("_$s12SourceEditor0aB4ViewC16addSelectedRange_6anchor9modifiers15scrollPlacement12alwaysScrollySnyAA0aB8PositionVG_AKSgAA0aB18SelectionModifiersVAA0lJ0OSgSbtF")

private struct SourceEditorViewInvoker {
let contextPtr = UnsafeMutablePointer<UnsafeMutableRawPointer>.allocate(capacity: 2)
init?(_ view: AnyObject?, _ functionPtr: UnsafeMutableRawPointer?) {
init?(_ view: AnyObject?, _ functionPtr: UnsafeMutableRawPointer?, line: Int = #line) {

assert(functionPtr != nil, "line: \(line): demangled name has been changed")

guard let view = view,
let functionPtr = functionPtr else { return nil }
Expand Down Expand Up @@ -102,7 +111,14 @@ private struct SourceEditorViewInvoker {
}

func addSelectedRange(_ range: XVimSourceEditorRange, modifiers: XVimSelectionModifiers) {
_add_selected_range(contextPtr, range, modifiers: modifiers.rawValue)
_add_selected_range(
contextPtr,
range,
anchor: nil,
modifiers: modifiers.rawValue,
scrollPlacement: nil,
alwaysScroll: false
)
}
}

Expand Down
1 change: 1 addition & 0 deletions XVim2/Xcode/XcodeUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ static inline Class DVTDocumentLocationClass() { return NSClassFromString(@"DVTD
static inline Class IDEWorkspaceWindowClass() { return NSClassFromString(@"IDEWorkspaceWindow"); }
static inline Class DVTTextPreferencesClass() { return NSClassFromString(@"DVTTextPreferences"); }
static inline Class IDEEditorCoordinatorClass() { return NSClassFromString(@"IDEEditorCoordinator"); }
static inline Class IDEEditorAreaClass() { return NSClassFromString(@"IDEEditorArea"); }
1 change: 1 addition & 0 deletions XVim2/XcodeHeader/IDEKit/IDEEditorArea.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
+ (BOOL)automaticallyNotifiesObserversOfLastActiveEditorContext;
+ (id)keyPathsForValuesAffectingLastActiveEditorAreaSplit;
+ (BOOL)_newEditorsHaveEmptyContent;
+ (BOOL)_openEditorOpenSpecifier:(id)arg1 editorContext:(id)arg2 options:(id)arg3;
//- (void).cxx_destruct;
@property BOOL isRestoringState; // @synthesize isRestoringState=_isRestoringState;
@property long long maximizedState; // @synthesize maximizedState=_maximizedState;
Expand Down

0 comments on commit 3f37d90

Please sign in to comment.