@@ -170,12 +170,41 @@ export class DeleteOperations {
170
170
}
171
171
172
172
private static getDeleteRange ( selection : Selection , model : ICursorSimpleModel , config : CursorConfiguration , ) : Range {
173
+ const position = selection . getPosition ( ) ;
174
+ const startPosition = selection . getSelectionStart ( ) ;
175
+
176
+ const startLineNumber = Math . min ( startPosition . lineNumber , position . lineNumber ) ;
177
+ const endLineNumber = Math . max ( startPosition . lineNumber , position . lineNumber ) ;
178
+ let startColumn = position . column ;
179
+ let endColumn = startPosition . column ;
180
+ if ( startLineNumber == startPosition . lineNumber ) {
181
+ //top down deletion
182
+ startColumn = startPosition . column ;
183
+ endColumn = position . column ;
184
+ }
185
+ let firstNonWhiteSpaceColumn = model . getLineFirstNonWhitespaceColumn ( endLineNumber ) ;
186
+ let lastNonWhiteSpaceColumn = model . getLineLastNonWhitespaceColumn ( startLineNumber ) ;
187
+ if ( startLineNumber != endLineNumber && model . getLineContent ( startLineNumber ) . length > 0 ) {
188
+ //deleting new line character + trimming white space
189
+ if ( startColumn < lastNonWhiteSpaceColumn ) {
190
+ lastNonWhiteSpaceColumn = startColumn ;
191
+ }
192
+ if ( endColumn > firstNonWhiteSpaceColumn ) {
193
+ firstNonWhiteSpaceColumn = endColumn ;
194
+ }
195
+ if ( / ^ [ \t ] * $ / . test ( model . getLineContent ( startLineNumber ) ) ) {
196
+ //if line with '\n' character has only spaces/tabs -- no need to trim left side
197
+ return Range . fromPositions ( new Position ( startLineNumber , startColumn ) ,
198
+ new Position ( endLineNumber , firstNonWhiteSpaceColumn ) ) ;
199
+ }
200
+ return Range . fromPositions ( new Position ( startLineNumber , lastNonWhiteSpaceColumn ) ,
201
+ new Position ( endLineNumber , firstNonWhiteSpaceColumn ) ) ;
202
+ }
203
+
173
204
if ( ! selection . isEmpty ( ) ) {
174
205
return selection ;
175
206
}
176
207
177
- const position = selection . getPosition ( ) ;
178
-
179
208
// Unintend when using tab stops and cursor is within indentation
180
209
if ( config . useTabStops && position . column > 1 ) {
181
210
const lineContent = model . getLineContent ( position . lineNumber ) ;
0 commit comments