@@ -107,18 +107,30 @@ public struct EditorInformation {
107107 }
108108 var content = rangeLines
109109 if !content. isEmpty {
110- let dropLastCount = max (
111- 0 ,
112- content [ content. endIndex - 1 ] . utf16. count - range. end. character
113- )
114- content [ content. endIndex - 1 ] = String (
115- content [ content. endIndex - 1 ] . utf16. dropLast ( dropLastCount)
116- ) ?? String (
117- content [ content. endIndex - 1 ] . dropLast ( dropLastCount)
118- )
119- let dropFirstCount = max ( 0 , range. start. character)
120- content [ 0 ] = String ( content [ 0 ] . utf16. dropFirst ( dropFirstCount) )
121- ?? String ( content [ 0 ] . dropFirst ( dropFirstCount) )
110+ let lastLine = content [ content. endIndex - 1 ]
111+ let droppedEndIndex = lastLine. utf16. index (
112+ lastLine. utf16. startIndex,
113+ offsetBy: range. end. character,
114+ limitedBy: lastLine. utf16. endIndex
115+ ) ?? lastLine. utf16. endIndex
116+ content [ content. endIndex - 1 ] = if droppedEndIndex > lastLine. utf16. startIndex {
117+ String ( lastLine [ ..< droppedEndIndex] )
118+ } else {
119+ " "
120+ }
121+
122+ let firstLine = content [ 0 ]
123+ let droppedStartIndex = firstLine. utf16. index (
124+ firstLine. utf16. startIndex,
125+ offsetBy: range. start. character,
126+ limitedBy: firstLine. utf16. endIndex
127+ ) ?? firstLine. utf16. endIndex
128+
129+ content [ 0 ] = if droppedStartIndex < firstLine. utf16. endIndex {
130+ String ( firstLine [ droppedStartIndex... ] )
131+ } else {
132+ " "
133+ }
122134 }
123135 return ( content. joined ( ) , rangeLines)
124136 }
0 commit comments