Created
March 5, 2010 02:28
-
-
Save mooz/322393 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ============================================================ // | |
// Inside of PRESERVE area. | |
// ============================================================ // | |
function transposeSubString(input, beg, end, to) { | |
let txt = input.value; | |
let head = txt.slice(0, beg); | |
let left = txt.slice(beg, end); | |
let right = txt.slice(end, to); | |
let tail = txt.slice(to); | |
let {scrollTop, scrollLeft} = input; | |
input.value = head + right + left + tail; | |
input.selectionStart = input.selectionEnd = txt.length - tail.length; | |
if (scrollTop === scrollLeft === 0) | |
command.inputScrollSelectionIntoView(input); | |
else | |
input.scrollTop = scrollTop, input.scrollLeft = scrollLeft; | |
} | |
function transposeChars(ev, arg) { | |
let input = ev.originalTarget; | |
let begin = input.selectionEnd - 1; | |
let end = begin + 1; | |
let to = end + (typeof arg === 'number' ? Math.max(arg, 1) : 1); | |
transposeSubString(input, begin, end, to); | |
} | |
ext.add("transpose-chars", transposeChars, "Interchange characters around point"); | |
// ============================================================ // | |
// Bottom of the .keysnail.js | |
// ============================================================ // | |
key.setEditKey("C-t", function (ev, arg) { ext.exec("transpose-chars", arg, ev); }, "Transpose chars", true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment