Closed nemesis closed 7 years ago
Hey @nemesis thanks for the effort in reporting that :) I'll look into it!
@nemesis, I can repro this 100% 👍
I found that when I move the cursor up and down after cmd + z
it works fine 😬
The stack trace implies that this is a bug in Xcode?
Process: Xcode [36107]
Path: /Applications/Xcode.app/Contents/MacOS/Xcode
Identifier: com.apple.dt.Xcode
Version: 8.0 (11246)
Build Info: IDEFrameworks-11246000000000000~3
App Item ID: 497799835
App External ID: 818744938
Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: Xcode [36107]
User ID: 501
Date/Time: 2016-10-08 19:17:27.632 +0200
OS Version: Mac OS X 10.12.1 (16B2338c)
Report Version: 12
Anonymous UUID: 7BBE7C56-3381-6840-8E4D-8238A0E38E08
Sleep/Wake UUID: A9024F58-43D4-4E6C-B2B6-637579234FF0
Time Awake Since Boot: 100000 seconds
Time Since Wake: 45000 seconds
System Integrity Protection: enabled
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Application Specific Information:
ProductBuildVersion: 8A218a
UNCAUGHT EXCEPTION (NSInvalidArgumentException): *** +[NSSelectionArray newWithArray:]: no ranges
UserInfo: (null)
Hints: None
Backtrace:
0 __exceptionPreprocess (in CoreFoundation)
1 DVTFailureHintExceptionPreprocessor (in DVTFoundation)
2 objc_exception_throw (in libobjc.A.dylib)
3 +[NSException raise:format:] (in CoreFoundation)
4 +[NSSelectionArray newWithArray:] (in AppKit)
5 +[NSSelectionArray arrayWithArray:] (in AppKit)
6 -[NSTextView(NSSharing) _fixedSelectionRangesForRanges:affinity:] (in AppKit)
7 -[NSTextView(NSSharing) setSelectedRanges:affinity:stillSelecting:] (in AppKit)
8 -[DVTCompletingTextView setSelectedRanges:affinity:stillSelecting:] (in DVTKit)
9 -[DVTSourceTextView setSelectedRanges:affinity:stillSelecting:] (in DVTKit)
10 __63-[IDESourceCodeEditor _invokeTrueSourceEditorExtensionCommand:]_block_invoke_3 (in IDESourceEditor)
11 -[_DVTTimeSlicedMainThreadOrderedNonUniquingWorkQueue _processWorkItemsWithDeadline:] (in DVTFoundation)
12 -[DVTTimeSlicedMainThreadWorkQueue _processWithDeadline:] (in DVTFoundation)
13 -[_DVTTimeSlicedMainThreadActiveWorkQueues _processWorkQueuesOnDeadline] (in DVTFoundation)
14 __NSFireDelayedPerform (in Foundation)
15 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ (in CoreFoundation)
16 __CFRunLoopDoTimer (in CoreFoundation)
17 __CFRunLoopDoTimers (in CoreFoundation)
18 __CFRunLoopRun (in CoreFoundation)
19 CFRunLoopRunSpecific (in CoreFoundation)
20 RunCurrentEventLoopInMode (in HIToolbox)
21 ReceiveNextEventCommon (in HIToolbox)
22 _BlockUntilNextEventMatchingListInModeWithFilter (in HIToolbox)
23 _DPSNextEvent (in AppKit)
24 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] (in AppKit)
25 -[DVTApplication nextEventMatchingMask:untilDate:inMode:dequeue:] (in DVTKit)
26 -[NSApplication run] (in AppKit)
27 NSApplicationMain (in AppKit)
28 start (in libdyld.dylib)
abort() called
I will investigate this a bit more, but I think this is a radar material.
Same here
It seems to be when the import is selected - I thought this was how I was meant to use it, and it therefore crashed every time for me until I realised otherwise.
Moving the cursor in the instance mentioned above would therefore de-select the import, and it would not crash.
These codes may be solve your problem.
func execute() {
let selection = self.buffer.selections.firstObject as! XCSourceTextRange
let selectionLine = selection.start.line
let importString = (self.buffer.lines[selectionLine] as! String).trimmingCharacters(in: CharacterSet.whitespaces)
guard isValid(importString: importString) else {
return
}
let line = appropriateLine(ignoringLine: selectionLine)
guard line != NSNotFound else {
return
}
self.buffer.lines.removeObject(at: selectionLine)
self.buffer.lines.insert(importString, at: line)
//add new selection
let selectionPosition = XCSourceTextRange.init(start: XCSourceTextPosition.init(line: 0, column: 0), end: XCSourceTextPosition.init(line: 0, column: 0))
self.buffer.selections.removeAllObjects()
self.buffer.selections.insert(selectionPosition, at: 0)
}
@keepyounger would you like to make a pull request?
@markohlebar Yes, I'd love to. I have made a pull request.
I was able to reproduce this more times but it could be a problem with my Xcode? (which is Version 8.0, 8A218a) To reproduce: 1) Import something with CTRL + CMD + P 2) Undo that with CMD + Z 3) Import that again