jump-to-line.js 1.14 KB
Newer Older
jose's avatar
jose committed
1
(function(a){if(typeof exports=="object"&&typeof module=="object"){a(require("../../lib/codemirror"),require("../dialog/dialog"))}else{if(typeof define=="function"&&define.amd){define(["../../lib/codemirror","../dialog/dialog"],a)}else{a(CodeMirror)}}})(function(a){function b(e,i,g,j,h){if(e.openDialog){e.openDialog(i,h,{value:j,selectValueOnOpen:true})}else{h(prompt(g,j))}}var d='Jump to line: <input type="text" style="width: 10em" class="CodeMirror-search-field"/> <span style="color: #888" class="CodeMirror-search-hint">(Use line:column or scroll% syntax)</span>';function c(e,g){var f=Number(g);if(/^[-+]/.test(g)){return e.getCursor().line+f}else{return f-1}}a.commands.jumpToLine=function(e){var f=e.getCursor();b(e,d,"Jump to line:",(f.line+1)+":"+f.ch,function(i){if(!i){return}var h;if(h=/^\s*([\+\-]?\d+)\s*\:\s*(\d+)\s*$/.exec(i)){e.setCursor(c(e,h[1]),Number(h[2]))}else{if(h=/^\s*([\+\-]?\d+(\.\d+)?)\%\s*/.exec(i)){var g=Math.round(e.lineCount()*Number(h[1])/100);if(/^[-+]/.test(h[1])){g=f.line+g+1}e.setCursor(g-1,f.ch)}else{if(h=/^\s*\:?\s*([\+\-]?\d+)\s*/.exec(i)){e.setCursor(c(e,h[1]),f.ch)}}}})};a.keyMap["default"]["Alt-G"]="jumpToLine"});