Created
April 24, 2010 23:22
-
-
Save PatrickKennedy/378039 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
| var sci = ko.views.manager.currentView.scimoz; | |
| // If there's no block our cursor moves so we need to remember where it starts. | |
| var curLine = sci.lineFromPosition(sci.currentPos); | |
| ko.commands.doCommand("cmd_blockSelect"); | |
| if (sci.selText == sci.text) { | |
| // We have just a single line selected | |
| sci.gotoLine(curLine); | |
| sci.vCHome(); | |
| sci.lineEndExtend(); | |
| var line = sci.selText; | |
| line = line.replace(new RegExp("{ ", "g"), "{\n\t") | |
| .replace(new RegExp("; ", "g"), ";\n\t") | |
| .replace(new RegExp("\t}", "g"), "}"); | |
| sci.replaceSel(line); | |
| } else { | |
| // We have a block selected | |
| var line = sci.selText; | |
| line = line.replace(new RegExp(" ", "g"), "") | |
| // We need a negative look-ahead so we don't erase | |
| // the first bracket's indentation | |
| .replace(new RegExp("\t(?![{\t])", "g"), "") | |
| .replace(new RegExp("\n", "g"), " "); | |
| sci.replaceSel(line+"\n"); | |
| sci.lineUp(); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NOTE: This is an in-place operation. It's pseudo-folding but it works.
Also, this acts primarily on tabs. If you don't like tabs then replace all the
\t's with two spaces, or your preferred number of spaces.