File tree Expand file tree Collapse file tree
Core/Sources/Service/SuggestionCommandHandler Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -323,7 +323,21 @@ extension WindowBaseCommandHandler {
323323 guard var selection = editor. selections. last,
324324 selection. start != selection. end
325325 else { return ( " " , . cursor( editor. cursorPosition) ) }
326- if selection. start. line != selection. end. line {
326+
327+ let isMultipleLine = selection. start. line != selection. end. line
328+ let isSpaceOnlyBeforeStartPositionOnTheSameLine = {
329+ guard selection. start. line >= 0 , selection. start. line < editor. lines. count else {
330+ return false
331+ }
332+ let line = editor. lines [ selection. start. line]
333+ guard selection. start. character > 0 , selection. start. character < line. count else {
334+ return false
335+ }
336+ let substring = line [ line. startIndex..< line. index ( line. startIndex, offsetBy: selection. start. character) ]
337+ return substring. allSatisfy ( { $0. isWhitespace } )
338+ } ( )
339+
340+ if isMultipleLine || isSpaceOnlyBeforeStartPositionOnTheSameLine {
327341 // when there are multiple lines start from char 0 so that it can keep the
328342 // indentation.
329343 selection. start = . init( line: selection. start. line, character: 0 )
You can’t perform that action at this time.
0 commit comments