First thought solution for #7
Might not be perfect because of multiple cursor placement
This commit is contained in:
parent
9143b7b8c3
commit
1006d1c243
|
@ -74,6 +74,30 @@ function cleanOptions(data, types) {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getCursors(editor) {
|
||||||
|
var cursors = editor.getCursors();
|
||||||
|
var posArray = [];
|
||||||
|
for (var idx = 0; idx < cursors.length; idx++) {
|
||||||
|
var cursor = cursors[idx];
|
||||||
|
var bufferPosition = cursor.getBufferPosition();
|
||||||
|
console.log('order, row:', idx, bufferPosition.row);
|
||||||
|
posArray.push([bufferPosition.row, bufferPosition.column]);
|
||||||
|
}
|
||||||
|
return posArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
function setCursors(editor, posArray) {
|
||||||
|
for (var idx = posArray.length - 1; idx >= 0; idx--) {
|
||||||
|
var bufferPosition = posArray[idx];
|
||||||
|
console.log('setting row:', bufferPosition[0]);
|
||||||
|
if (idx === posArray.length - 1) {
|
||||||
|
editor.setCursorBufferPosition(bufferPosition);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
editor.addCursorAtBufferPosition(bufferPosition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function beautify() {
|
function beautify() {
|
||||||
var text;
|
var text;
|
||||||
var editor = atom.workspace.getActiveEditor();
|
var editor = atom.workspace.getActiveEditor();
|
||||||
|
@ -103,6 +127,7 @@ function beautify() {
|
||||||
}
|
}
|
||||||
// Override the indenting options from the editor
|
// Override the indenting options from the editor
|
||||||
beautifyOptions = extend(collectedConfig, beautifyOptions);
|
beautifyOptions = extend(collectedConfig, beautifyOptions);
|
||||||
|
var posArray = getCursors(editor);
|
||||||
|
|
||||||
if (isSelection) {
|
if (isSelection) {
|
||||||
text = editor.getSelectedText();
|
text = editor.getSelectedText();
|
||||||
|
@ -133,6 +158,7 @@ function beautify() {
|
||||||
} else {
|
} else {
|
||||||
editor.setText(text);
|
editor.setText(text);
|
||||||
}
|
}
|
||||||
|
setCursors(editor, posArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleSafeEvent() {
|
function handleSafeEvent() {
|
||||||
|
|
Loading…
Reference in New Issue