-
Notifications
You must be signed in to change notification settings - Fork 11
/
transpose.js
38 lines (35 loc) · 926 Bytes
/
transpose.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
* Run this macro to swaps the positions of the character at the current caret
* position and the next character in the line.
*
* Type: On Demand
*
* @source https://github.com/Komodo/macros
* @author Carey Hoffman
* @version 0.1
*/
view = ko.views.manager.currentView;
scimoz = view.scimoz;
curPos = scimoz.currentPos;
transpose();
function transpose(){
forePos = scimoz.positionBefore(curPos);
aftPos = scimoz.currentPos;
foreChar = scimoz.getWCharAt(forePos);
aftChar = scimoz.getWCharAt(aftPos);
scimoz.beginUndoAction();
try {
replace(forePos, aftChar);
replace(aftPos, foreChar);
} catch(e) {
alert("FAIL: " + e)
}
finally {
scimoz.endUndoAction();
}
scimoz.gotoPos(scimoz.positionAfter(curPos))
}
function replace(pos, character) {
scimoz.deleteRange(pos,1);
scimoz.insertText(pos, character);
}