|
150 | 150 | for (var i = 0; i < linesToMove.length; i += 2) {
|
151 | 151 | var from = linesToMove[i], to = linesToMove[i + 1];
|
152 | 152 | var line = cm.getLine(from);
|
153 |
| - cm.replaceRange("", Pos(from, 0), Pos(from + 1, 0)); |
154 |
| - cm.replaceRange(line + "\n", Pos(to, 0)); |
| 153 | + cm.replaceRange("", Pos(from, 0), Pos(from + 1, 0), "+swapLine"); |
| 154 | + if (to > cm.lastLine()) { |
| 155 | + cm.replaceRange("\n" + line, Pos(cm.lastLine()), null, "+swapLine"); |
| 156 | + var sels = cm.listSelections(), last = sels[sels.length - 1]; |
| 157 | + var head = last.head.line == to ? Pos(to - 1) : last.head; |
| 158 | + var anchor = last.anchor.line == to ? Pos(to - 1) : last.anchor; |
| 159 | + cm.setSelections(sels.slice(0, sels.length - 1).concat([{head: head, anchor: anchor}])); |
| 160 | + } else { |
| 161 | + cm.replaceRange(line + "\n", Pos(to, 0), null, "+swapLine"); |
| 162 | + } |
155 | 163 | }
|
156 | 164 | });
|
157 | 165 | };
|
|
169 | 177 | var from = linesToMove[i], to = linesToMove[i + 1];
|
170 | 178 | var line = cm.getLine(from);
|
171 | 179 | if (from == cm.lastLine())
|
172 |
| - cm.replaceRange("", Pos(from - 1), Pos(from)); |
| 180 | + cm.replaceRange("", Pos(from - 1), Pos(from), "+swapLine"); |
173 | 181 | else
|
174 |
| - cm.replaceRange("", Pos(from, 0), Pos(from + 1, 0)); |
175 |
| - cm.replaceRange(line + "\n", Pos(to, 0)); |
| 182 | + cm.replaceRange("", Pos(from, 0), Pos(from + 1, 0), "+swapLine"); |
| 183 | + cm.replaceRange(line + "\n", Pos(to, 0), null, "+swapLine"); |
176 | 184 | }
|
177 | 185 | });
|
178 | 186 | };
|
|
0 commit comments