@@ -85,30 +85,30 @@ class SourceEditorCommand: NSObject, XCSourceEditorCommand {
8585 return newRange
8686 }
8787
88- func getSelectedText( currentSelectionRange : XCSourceTextRange ) -> String {
88+ func getSelectedText( selectionRange : XCSourceTextRange , buffer : XCSourceTextBuffer ) -> String {
8989 var selectedText = " "
9090
91- if ( isInsertionPoint ( range: currentSelectionRange ) ) {
91+ if ( isInsertionPoint ( range: selectionRange ) ) {
9292 return selectedText
9393 }
9494
9595 //all on same line
96- if ( currentSelectionRange . start. line == currentSelectionRange . end. line) {
97- let lineStr = buffer. lines [ currentSelectionRange . start. line] as! String
98- let startIndex = lineStr. index ( lineStr. startIndex, offsetBy: currentSelectionRange . start. column)
99- let endIndex = lineStr. index ( lineStr. startIndex, offsetBy: currentSelectionRange . end. column)
96+ if ( selectionRange . start. line == selectionRange . end. line) {
97+ let lineStr = buffer. lines [ selectionRange . start. line] as! String
98+ let startIndex = lineStr. index ( lineStr. startIndex, offsetBy: selectionRange . start. column)
99+ let endIndex = lineStr. index ( lineStr. startIndex, offsetBy: selectionRange . end. column)
100100 let range = startIndex..< endIndex
101101 selectedText. append ( lineStr. substring ( with: range) )
102102 }
103103 else {
104- for index in currentSelectionRange . start. line... currentSelectionRange . end. line {
104+ for index in selectionRange . start. line... selectionRange . end. line {
105105 let lineStr = buffer. lines [ index] as! String
106- if index == currentSelectionRange . start. line {
107- let startIndex = lineStr. index ( lineStr. startIndex, offsetBy: currentSelectionRange . start. column)
106+ if index == selectionRange . start. line {
107+ let startIndex = lineStr. index ( lineStr. startIndex, offsetBy: selectionRange . start. column)
108108 selectedText. append ( lineStr. substring ( from: startIndex) )
109109 }
110- else if index == currentSelectionRange . end. line{
111- let endIndex = lineStr. index ( lineStr. startIndex, offsetBy: currentSelectionRange . end. column)
110+ else if index == selectionRange . end. line{
111+ let endIndex = lineStr. index ( lineStr. startIndex, offsetBy: selectionRange . end. column)
112112 selectedText. append ( lineStr. substring ( to: endIndex) )
113113 }
114114 else {
@@ -165,7 +165,7 @@ class SourceEditorCommand: NSObject, XCSourceEditorCommand {
165165
166166 let message : JSON = [
167167 " id " : " setSelectedText " ,
168- " text " : getSelectedText ( currentSelectionRange)
168+ " text " : getSelectedText ( selectionRange : currentSelectionRange, buffer : buffer )
169169 ]
170170
171171 service. sendMessage ( message: message. rawString ( ) !)
@@ -234,7 +234,7 @@ class SourceEditorCommand: NSObject, XCSourceEditorCommand {
234234 // MARK: Selection overrides
235235 case " selection:previous-occurrence " :
236236 let range = buffer. selections [ 0 ] as! XCSourceTextRange
237- let selectedText = getSelectedText ( currentSelectionRange : range)
237+ let selectedText = getSelectedText ( selectionRange : range, buffer : buffer )
238238
239239
240240 break
0 commit comments