7
if (typeof exports == "object" && typeof module == "object")
8
mod(require("../../lib/codemirror"), require("../dialog/dialog"));
9
else if (typeof define == "function" && define.amd)
10
define(["../../lib/codemirror", "../dialog/dialog"], mod);
13
})(function(CodeMirror) {
17
CodeMirror.defineOption("search", {bottom: false});
19
function dialog(cm, text, shortText, deflt, f) {
20
if (cm.openDialog) cm.openDialog(text, f, {value: deflt, selectValueOnOpen: true, bottom: cm.options.search.bottom});
21
else f(prompt(shortText, deflt));
24
function getJumpDialog(cm) {
25
return cm.phrase("Jump to line:") + ' <input type="text" style="width: 10em" class="CodeMirror-search-field"/> <span style="color: #888" class="CodeMirror-search-hint">' + cm.phrase("(Use line:column or scroll% syntax)") + '</span>';
28
function interpretLine(cm, string) {
29
var num = Number(string)
30
if (/^[-+]/.test(string)) return cm.getCursor().line + num
34
CodeMirror.commands.jumpToLine = function(cm) {
35
var cur = cm.getCursor();
36
dialog(cm, getJumpDialog(cm), cm.phrase("Jump to line:"), (cur.line + 1) + ":" + cur.ch, function(posStr) {
40
if (match = /^\s*([\+\-]?\d+)\s*\:\s*(\d+)\s*$/.exec(posStr)) {
41
cm.setCursor(interpretLine(cm, match[1]), Number(match[2]))
42
} else if (match = /^\s*([\+\-]?\d+(\.\d+)?)\%\s*/.exec(posStr)) {
43
var line = Math.round(cm.lineCount() * Number(match[1]) / 100);
44
if (/^[-+]/.test(match[1])) line = cur.line + line + 1;
45
cm.setCursor(line - 1, cur.ch);
46
} else if (match = /^\s*\:?\s*([\+\-]?\d+)\s*/.exec(posStr)) {
47
cm.setCursor(interpretLine(cm, match[1]), cur.ch);
52
CodeMirror.keyMap["default"]["Alt-G"] = "jumpToLine";