Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed multicursor backspacing #4880

Merged
merged 1 commit into from
Jun 3, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 28 additions & 18 deletions notebook/static/notebook/js/codecell.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,35 @@ define([
* @private
*/
CodeMirror.commands.delSpaceToPrevTabStop = function(cm){
var from = cm.getCursor(true), to = cm.getCursor(false), sel = !posEq(from, to);
if (sel) {
var ranges = cm.listSelections();
for (var i = ranges.length - 1; i >= 0; i--) {
var head = ranges[i].head;
var anchor = ranges[i].anchor;
cm.replaceRange("", CodeMirror.Pos(head.line, head.ch), CodeMirror.Pos(anchor.line, anchor.ch));
var tabSize = cm.getOption('tabSize');
var ranges = cm.listSelections(); // handle multicursor
for (var i = ranges.length - 1; i >= 0; i--) { // iterate reverse so any deletions don't overlap
var head = ranges[i].head;
var anchor = ranges[i].anchor;
var sel = !posEq(head, anchor);
if (sel) {
// range is selection
cm.replaceRange("", anchor, head);
} else {
// range is cursor
var line = cm.getLine(head.line).substring(0, head.ch);
if( line.match(/^\ +$/) !== null){
// delete tabs
var prevTabStop = (Math.ceil(head.ch/tabSize)-1)*tabSize;
var from = {
ch: prevTabStop,
line: head.line
};
cm.replaceRange("", from, head);
} else {
// delete non-tabs
var from = {
ch: head.ch-1,
line: head.line
};
cm.replaceRange("", from, head);
}
}
return;
}
var cur = cm.getCursor(), line = cm.getLine(cur.line);
var tabsize = cm.getOption('tabSize');
var chToPrevTabStop = cur.ch-(Math.ceil(cur.ch/tabsize)-1)*tabsize;
from = {ch:cur.ch-chToPrevTabStop,line:cur.line};
var select = cm.getRange(from,cur);
if( select.match(/^\ +$/) !== null){
cm.replaceRange("",from,cur);
} else {
cm.deleteH(-1,"char");
}
};

Expand Down