Skip to content

Commit c9bee49

Browse files
committed
Actually using only selected source when sending buffer from extension to app
1 parent 030e50d commit c9bee49

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

PlayAwaysExtension/Commands.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,18 @@ final class Commander {
1414

1515
class func perform(with invocation: XCSourceEditorCommandInvocation, for platform: PAInvocation.Platform) {
1616
do {
17-
try PAInvocation.invoke(with: invocation.buffer.completeBuffer, platform: platform)
17+
var text = ""
18+
19+
invocation.buffer.selections.forEach { selection in
20+
guard let range = selection as? XCSourceTextRange else { return }
21+
22+
for l in range.start.line...range.end.line {
23+
guard let line = invocation.buffer.lines[l] as? String else { continue }
24+
text.append(line)
25+
}
26+
}
27+
28+
try PAInvocation.invoke(with: text, platform: platform)
1829
} catch {
1930
NSAlert(error: error).runModal()
2031
}

0 commit comments

Comments
 (0)