|
420 | 420 |
|
421 | 421 | map[cK + ctrl + "Backspace"] = "delLineLeft"; |
422 | 422 |
|
| 423 | + cmds[map["Backspace"] = "smartBackspace"] = function(cm) { |
| 424 | + if (cm.somethingSelected()) return CodeMirror.Pass; |
| 425 | + |
| 426 | + cm.operation(function() { |
| 427 | + var cursors = cm.listSelections(); |
| 428 | + var indentUnit = cm.getOption("indentUnit"); |
| 429 | + |
| 430 | + for (var i = cursors.length - 1; i >= 0; i--) { |
| 431 | + var cursor = cursors[i].head; |
| 432 | + var toStartOfLine = cm.getRange({line: cursor.line, ch: 0}, cursor); |
| 433 | + var column = CodeMirror.countColumn(toStartOfLine, null, cm.getOption("tabSize")); |
| 434 | + |
| 435 | + // Delete by one character by default |
| 436 | + var deletePos = cm.findPosH(cursor, -1, "char", false); |
| 437 | + |
| 438 | + if (toStartOfLine && !/\S/.test(toStartOfLine) && column % indentUnit == 0) { |
| 439 | + var prevIndent = new Pos(cursor.line, |
| 440 | + CodeMirror.findColumn(toStartOfLine, column - indentUnit, indentUnit)); |
| 441 | + |
| 442 | + // Smart delete only if we found a valid prevIndent location |
| 443 | + if (prevIndent.ch != cursor.ch) deletePos = prevIndent; |
| 444 | + } |
| 445 | + |
| 446 | + cm.replaceRange("", deletePos, cursor, "+delete"); |
| 447 | + } |
| 448 | + }); |
| 449 | + }; |
| 450 | + |
423 | 451 | cmds[map[cK + ctrl + "K"] = "delLineRight"] = function(cm) { |
424 | 452 | cm.operation(function() { |
425 | 453 | var ranges = cm.listSelections(); |
|
0 commit comments