File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed
Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -654,10 +654,14 @@ extension CodeView {
654654 }
655655
656656 func insertTab( in range: NSRange ) -> NSRange {
657+ guard let firstLine = codeStorageDelegate. lineMap. lineOf ( index: range. location) ,
658+ let lineInfo = codeStorageDelegate. lineMap. lookup ( line: firstLine)
659+ else { return range }
657660
658- let nextTabStopIndex = ( range. location / indentation. tabWidth + 1 ) * indentation. tabWidth
659- let replacementString = if indentation. preference == . preferTabs { " \t " }
660- else { String ( repeating: " " , count: nextTabStopIndex - range. location) }
661+ let column = range. location - lineInfo. range. location,
662+ nextTabStopIndex = ( column / indentation. tabWidth + 1 ) * indentation. tabWidth,
663+ replacementString = if indentation. preference == . preferTabs { " \t " }
664+ else { String ( repeating: " " , count: nextTabStopIndex - column) }
661665 codeStorage. replaceCharacters ( in: range, with: replacementString)
662666
663667 return NSRange ( location: range. location + replacementString. utf16. count, length: 0 )
You can’t perform that action at this time.
0 commit comments