Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 2d920f5

Browse files
author
Marcel Gerber
committed
editor -> cm, Remove unused CodeMirror require
1 parent 6776bc0 commit 2d920f5

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

src/utils/TokenUtils.js

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,27 @@
3333
define(function (require, exports, module) {
3434
"use strict";
3535

36-
var _ = require("thirdparty/lodash"),
37-
CodeMirror = require("thirdparty/CodeMirror2/lib/codemirror");
36+
var _ = require("thirdparty/lodash");
3837

3938
var cache,
4039
CACHE_MAX_AGE = 1000; // cache for 1 second
4140

4241

4342
/*
4443
* Caches the tokens for the given editor/line if needed
45-
* @param {!CodeMirror} editor
44+
* @param {!CodeMirror} cm
4645
* @param {!number} line
4746
* @return {Array.<Object>} (Cached) array of tokens
4847
*/
49-
function _manageCache(editor, line) {
50-
if (!cache || !cache.tokens || cache.line !== line || cache.editor !== editor ||
48+
function _manageCache(cm, line) {
49+
if (!cache || !cache.tokens || cache.line !== line || cache.cm !== cm ||
5150
cache.timeStamp < Date.now() - CACHE_MAX_AGE) {
5251
// Cache is outdated/no longer matching -> Update
53-
var tokens = editor.getLineTokens(line, false);
52+
var tokens = cm.getLineTokens(line, false);
5453
// Add empty beginning-of-line token for backwards compatibility
55-
tokens.unshift(editor.getTokenAt({line: line, ch: 0}, false));
54+
tokens.unshift(cm.getTokenAt({line: line, ch: 0}, false));
5655
cache = {
57-
editor: editor,
56+
cm: cm,
5857
line: line,
5958
timeStamp: Date.now(),
6059
tokens: tokens
@@ -65,34 +64,34 @@ define(function (require, exports, module) {
6564

6665
/*
6766
* Like cm.getTokenAt, but with caching
68-
* @param {!CodeMirror} editor
67+
* @param {!CodeMirror} cm
6968
* @param {!{ch:number, line:number}} pos
7069
* @param {boolean} precise If given, results in more current results. Suppresses caching.
7170
* @return {Object} Token for position
7271
*/
73-
function _getToken(editor, pos, precise) {
72+
function _getToken(cm, pos, precise) {
7473
if (precise) {
7574
cache = null; // reset cache
76-
return editor.getTokenAt(pos, precise);
75+
return cm.getTokenAt(pos, precise);
7776
}
78-
var cachedTokens = _manageCache(editor, pos.line),
77+
var cachedTokens = _manageCache(cm, pos.line),
7978
tokenIndex = _.sortedIndex(cachedTokens, {end: pos.ch}, "end"), // binary search is faster for long arrays
8079
token = cachedTokens[tokenIndex];
81-
return token || editor.getTokenAt(pos, precise); // fall back to CMs getTokenAt, for example in an empty line
80+
return token || cm.getTokenAt(pos, precise); // fall back to CMs getTokenAt, for example in an empty line
8281
}
8382

8483
/**
8584
* Creates a context object for the given editor and position, suitable for passing to the
8685
* move functions.
87-
* @param {!CodeMirror} editor
86+
* @param {!CodeMirror} cm
8887
* @param {!{ch:number, line:number}} pos
8988
* @return {!{editor:!CodeMirror, pos:!{ch:number, line:number}, token:Object}}
9089
*/
91-
function getInitialContext(editor, pos) {
90+
function getInitialContext(cm, pos) {
9291
return {
93-
"editor": editor,
92+
"editor": cm,
9493
"pos": pos,
95-
"token": editor.getTokenAt(pos, true)
94+
"token": cm.getTokenAt(pos, true)
9695
};
9796
}
9897

0 commit comments

Comments
 (0)