FBI-1684: [MANTIS - 22275] Scroll in trigger editor jumps several lines up when
scrolling with the mouse scroll wheel resolve observations
This commit is contained in:
98
gulliver/js/codemirror/mode/ruby/ruby.js
vendored
98
gulliver/js/codemirror/mode/ruby/ruby.js
vendored
@@ -1,3 +1,16 @@
|
||||
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
||||
|
||||
(function(mod) {
|
||||
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
||||
mod(require("../../lib/codemirror"));
|
||||
else if (typeof define == "function" && define.amd) // AMD
|
||||
define(["../../lib/codemirror"], mod);
|
||||
else // Plain browser env
|
||||
mod(CodeMirror);
|
||||
})(function(CodeMirror) {
|
||||
"use strict";
|
||||
|
||||
CodeMirror.defineMode("ruby", function(config) {
|
||||
function wordObj(words) {
|
||||
var o = {};
|
||||
@@ -12,7 +25,7 @@ CodeMirror.defineMode("ruby", function(config) {
|
||||
"caller", "lambda", "proc", "public", "protected", "private", "require", "load",
|
||||
"require_relative", "extend", "autoload", "__END__", "__FILE__", "__LINE__", "__dir__"
|
||||
]);
|
||||
var indentWords = wordObj(["def", "class", "case", "for", "while", "module", "then",
|
||||
var indentWords = wordObj(["def", "class", "case", "for", "while", "until", "module", "then",
|
||||
"catch", "loop", "proc", "begin"]);
|
||||
var dedentWords = wordObj(["end", "until"]);
|
||||
var matching = {"[": "]", "{": "}", "(": ")"};
|
||||
@@ -24,7 +37,6 @@ CodeMirror.defineMode("ruby", function(config) {
|
||||
}
|
||||
|
||||
function tokenBase(stream, state) {
|
||||
curPunc = null;
|
||||
if (stream.sol() && stream.match("=begin") && stream.eol()) {
|
||||
state.tokenize.push(readBlockComment);
|
||||
return "comment";
|
||||
@@ -33,15 +45,18 @@ CodeMirror.defineMode("ruby", function(config) {
|
||||
var ch = stream.next(), m;
|
||||
if (ch == "`" || ch == "'" || ch == '"') {
|
||||
return chain(readQuoted(ch, "string", ch == '"' || ch == "`"), stream, state);
|
||||
} else if (ch == "/" && !stream.eol() && stream.peek() != " ") {
|
||||
return chain(readQuoted(ch, "string-2", true), stream, state);
|
||||
} else if (ch == "/") {
|
||||
if (regexpAhead(stream))
|
||||
return chain(readQuoted(ch, "string-2", true), stream, state);
|
||||
else
|
||||
return "operator";
|
||||
} else if (ch == "%") {
|
||||
var style = "string", embed = true;
|
||||
if (stream.eat("s")) style = "atom";
|
||||
else if (stream.eat(/[WQ]/)) style = "string";
|
||||
else if (stream.eat(/[r]/)) style = "string-2";
|
||||
else if (stream.eat(/[wxq]/)) { style = "string"; embed = false; }
|
||||
var delim = stream.eat(/[^\w\s]/);
|
||||
var delim = stream.eat(/[^\w\s=]/);
|
||||
if (!delim) return "operator";
|
||||
if (matching.propertyIsEnumerable(delim)) delim = matching[delim];
|
||||
return chain(readQuoted(delim, style, embed, true), stream, state);
|
||||
@@ -79,16 +94,16 @@ CodeMirror.defineMode("ruby", function(config) {
|
||||
}
|
||||
|
||||
// Symbols can't start by a digit
|
||||
if (stream.eat(/[a-zA-Z$@_]/)) {
|
||||
stream.eatWhile(/[\w]/);
|
||||
if (stream.eat(/[a-zA-Z$@_\xa1-\uffff]/)) {
|
||||
stream.eatWhile(/[\w$\xa1-\uffff]/);
|
||||
// Only one ? ! = is allowed and only as the last character
|
||||
stream.eat(/[\?\!\=]/);
|
||||
return "atom";
|
||||
}
|
||||
return "operator";
|
||||
} else if (ch == "@" && stream.match(/^@?[a-zA-Z_]/)) {
|
||||
} else if (ch == "@" && stream.match(/^@?[a-zA-Z_\xa1-\uffff]/)) {
|
||||
stream.eat("@");
|
||||
stream.eatWhile(/[\w]/);
|
||||
stream.eatWhile(/[\w\xa1-\uffff]/);
|
||||
return "variable-2";
|
||||
} else if (ch == "$") {
|
||||
if (stream.eat(/[a-zA-Z_]/)) {
|
||||
@@ -99,8 +114,8 @@ CodeMirror.defineMode("ruby", function(config) {
|
||||
stream.next(); // Must be a special global like $: or $!
|
||||
}
|
||||
return "variable-3";
|
||||
} else if (/[a-zA-Z_]/.test(ch)) {
|
||||
stream.eatWhile(/[\w]/);
|
||||
} else if (/[a-zA-Z_\xa1-\uffff]/.test(ch)) {
|
||||
stream.eatWhile(/[\w\xa1-\uffff]/);
|
||||
stream.eat(/[\?\!]/);
|
||||
if (stream.eat(":")) return "atom";
|
||||
return "ident";
|
||||
@@ -113,24 +128,48 @@ CodeMirror.defineMode("ruby", function(config) {
|
||||
} else if (ch == "-" && stream.eat(">")) {
|
||||
return "arrow";
|
||||
} else if (/[=+\-\/*:\.^%<>~|]/.test(ch)) {
|
||||
stream.eatWhile(/[=+\-\/*:\.^%<>~|]/);
|
||||
var more = stream.eatWhile(/[=+\-\/*:\.^%<>~|]/);
|
||||
if (ch == "." && !more) curPunc = ".";
|
||||
return "operator";
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function tokenBaseUntilBrace() {
|
||||
var depth = 1;
|
||||
function regexpAhead(stream) {
|
||||
var start = stream.pos, depth = 0, next, found = false, escaped = false
|
||||
while ((next = stream.next()) != null) {
|
||||
if (!escaped) {
|
||||
if ("[{(".indexOf(next) > -1) {
|
||||
depth++
|
||||
} else if ("]})".indexOf(next) > -1) {
|
||||
depth--
|
||||
if (depth < 0) break
|
||||
} else if (next == "/" && depth == 0) {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
escaped = next == "\\"
|
||||
} else {
|
||||
escaped = false
|
||||
}
|
||||
}
|
||||
stream.backUp(stream.pos - start)
|
||||
return found
|
||||
}
|
||||
|
||||
function tokenBaseUntilBrace(depth) {
|
||||
if (!depth) depth = 1;
|
||||
return function(stream, state) {
|
||||
if (stream.peek() == "}") {
|
||||
depth--;
|
||||
if (depth == 0) {
|
||||
if (depth == 1) {
|
||||
state.tokenize.pop();
|
||||
return state.tokenize[state.tokenize.length-1](stream, state);
|
||||
} else {
|
||||
state.tokenize[state.tokenize.length - 1] = tokenBaseUntilBrace(depth - 1);
|
||||
}
|
||||
} else if (stream.peek() == "{") {
|
||||
depth++;
|
||||
state.tokenize[state.tokenize.length - 1] = tokenBaseUntilBrace(depth + 1);
|
||||
}
|
||||
return tokenBase(stream, state);
|
||||
};
|
||||
@@ -202,22 +241,28 @@ CodeMirror.defineMode("ruby", function(config) {
|
||||
},
|
||||
|
||||
token: function(stream, state) {
|
||||
curPunc = null;
|
||||
if (stream.sol()) state.indented = stream.indentation();
|
||||
var style = state.tokenize[state.tokenize.length-1](stream, state), kwtype;
|
||||
var thisTok = curPunc;
|
||||
if (style == "ident") {
|
||||
var word = stream.current();
|
||||
style = keywords.propertyIsEnumerable(stream.current()) ? "keyword"
|
||||
style = state.lastTok == "." ? "property"
|
||||
: keywords.propertyIsEnumerable(stream.current()) ? "keyword"
|
||||
: /^[A-Z]/.test(word) ? "tag"
|
||||
: (state.lastTok == "def" || state.lastTok == "class" || state.varList) ? "def"
|
||||
: "variable";
|
||||
if (indentWords.propertyIsEnumerable(word)) kwtype = "indent";
|
||||
else if (dedentWords.propertyIsEnumerable(word)) kwtype = "dedent";
|
||||
else if ((word == "if" || word == "unless") && stream.column() == stream.indentation())
|
||||
kwtype = "indent";
|
||||
else if (word == "do" && state.context.indented < state.indented)
|
||||
kwtype = "indent";
|
||||
if (style == "keyword") {
|
||||
thisTok = word;
|
||||
if (indentWords.propertyIsEnumerable(word)) kwtype = "indent";
|
||||
else if (dedentWords.propertyIsEnumerable(word)) kwtype = "dedent";
|
||||
else if ((word == "if" || word == "unless") && stream.column() == stream.indentation())
|
||||
kwtype = "indent";
|
||||
else if (word == "do" && state.context.indented < state.indented)
|
||||
kwtype = "indent";
|
||||
}
|
||||
}
|
||||
if (curPunc || (style && style != "comment")) state.lastTok = word || curPunc || style;
|
||||
if (curPunc || (style && style != "comment")) state.lastTok = thisTok;
|
||||
if (curPunc == "|") state.varList = !state.varList;
|
||||
|
||||
if (kwtype == "indent" || /[\(\[\{]/.test(curPunc))
|
||||
@@ -240,10 +285,11 @@ CodeMirror.defineMode("ruby", function(config) {
|
||||
(state.continuedLine ? config.indentUnit : 0);
|
||||
},
|
||||
|
||||
electricChars: "}de", // enD and rescuE
|
||||
electricInput: /^\s*(?:end|rescue|elsif|else|\})$/,
|
||||
lineComment: "#"
|
||||
};
|
||||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-ruby", "ruby");
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user