mirror of
https://github.com/icecoder/ICEcoder.git
synced 2026-03-13 03:56:46 +01:00
Auto-indent lines you're pasting or moving
This commit is contained in:
@@ -583,6 +583,7 @@ var ICEcoder = {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Reset our array for next time and redo editor stats
|
||||
this.oppTagReplaceData = [];
|
||||
this.setEditorStats();
|
||||
@@ -661,6 +662,20 @@ var ICEcoder = {
|
||||
this.mouseDownInCM = "editor";
|
||||
},
|
||||
|
||||
// On paste
|
||||
cMonPaste: function(thisCM, cMinstance, evt, clipboardData) {
|
||||
// Get text from clipboard, the number of lines (excluding last)
|
||||
// and so the startLine and endLine and auto-indent for that range
|
||||
const text = clipboardData.getData('Text');
|
||||
const num = text.split("\n").length - 1;
|
||||
const startLine = thisCM.getCursor().line;
|
||||
const endLine = startLine + num;
|
||||
// Now auto-indent after a 0ms tickover
|
||||
setTimeout(() => {
|
||||
parent.ICEcoder.autoIndentLines(startLine, endLine);
|
||||
}, 0);
|
||||
},
|
||||
|
||||
// On context menu
|
||||
cMonContextMenu: function(thisCM, cMinstance, evt) {
|
||||
// Set cursor
|
||||
@@ -1109,6 +1124,13 @@ var ICEcoder = {
|
||||
}
|
||||
},
|
||||
|
||||
// Indent line range with smart indenting, falls back to indenting to prev line if no smart indenting for mode
|
||||
autoIndentLines: function(startLine, endLine) {
|
||||
for (let i = startLine; i <= endLine; i++) {
|
||||
this.getcMInstance().indentLine(i, "smart");
|
||||
}
|
||||
},
|
||||
|
||||
// Move current line up/down
|
||||
moveLines: function(dir) {
|
||||
let thisCM, lineStart, lineEnd, swapLineNo, swapLine;
|
||||
@@ -1146,6 +1168,9 @@ var ICEcoder = {
|
||||
);
|
||||
})
|
||||
}
|
||||
|
||||
// Auto-indent the lines we're moving (but not the swapped line)
|
||||
this.autoIndentLines(lineStart.line - ("up" === dir ? 1 : -1), lineEnd.line + ("up" === dir ? -1 : 1));
|
||||
},
|
||||
|
||||
// Highlight specified line
|
||||
|
||||
@@ -269,6 +269,7 @@ function createNewCMInstanceEvents(num, pane) {
|
||||
window['cM'+num+pane].on("inputRead", function(thisCM) {parent.ICEcoder.cMonInputRead(thisCM, 'cM' + num + pane)});
|
||||
window['cM'+num+pane].on("gutterClick", function(thisCM,line,gutter,evt) {parent.ICEcoder.cMonGutterClick(thisCM, line, gutter, evt, 'cM' + num + pane)});
|
||||
window['cM'+num+pane].on("mousedown", function(thisCM,evt) {parent.ICEcoder.cMonMouseDown(thisCM, 'cM' + num + pane, evt)});
|
||||
window['cM'+num+pane].on("paste", function(thisCM,evt) {parent.ICEcoder.cMonPaste(thisCM, 'cM' + num + pane, evt, (evt.clipboardData || window.clipboardData))});
|
||||
window['cM'+num+pane].on("contextmenu", function(thisCM,evt) {parent.ICEcoder.cMonContextMenu(thisCM, 'cM' + num + pane, evt)});
|
||||
window['cM'+num+pane].on("dragover", function(thisCM) {parent.ICEcoder.cMonDragOver(thisCM, event, 'cM' + num + pane)});
|
||||
window['cM'+num+pane].on("renderLine", function(thisCM, line, element) {parent.ICEcoder.cMonRenderLine(thisCM, 'cM' + num + pane, line, element)});
|
||||
|
||||
Reference in New Issue
Block a user