Skip to content

Commit

Permalink
Merge branch 'master' into v4
Browse files Browse the repository at this point in the history
Conflicts:
	mode/rst/rst.js
  • Loading branch information
marijnh committed Feb 6, 2014
2 parents cdece7b + d4bc448 commit a506d85
Show file tree
Hide file tree
Showing 17 changed files with 702 additions and 621 deletions.
1 change: 1 addition & 0 deletions addon/dialog/dialog.js
Expand Up @@ -46,6 +46,7 @@
CodeMirror.on(inp, "keydown", function(e) {
if (options && options.onKeyDown && options.onKeyDown(e, inp.value, close)) { return; }
if (e.keyCode == 13 || e.keyCode == 27) {
inp.blur();
CodeMirror.e_stop(e);
close();
me.focus();
Expand Down
4 changes: 2 additions & 2 deletions addon/hint/anyword-hint.js
Expand Up @@ -22,8 +22,8 @@
var list = [], seen = {};
var re = new RegExp(word.source, "g");
for (var dir = -1; dir <= 1; dir += 2) {
var line = cur.line, end = Math.min(Math.max(line + dir * range, editor.firstLine()), editor.lastLine()) + dir;
for (; line != end; line += dir) {
var line = cur.line, endLine = Math.min(Math.max(line + dir * range, editor.firstLine()), editor.lastLine()) + dir;
for (; line != endLine; line += dir) {
var text = editor.getLine(line), m;
while (m = re.exec(text)) {
if (line == cur.line && m[0] === curWord) continue;
Expand Down
34 changes: 20 additions & 14 deletions addon/hint/show-hint.js
Expand Up @@ -200,34 +200,40 @@
var winW = window.innerWidth || Math.max(document.body.offsetWidth, document.documentElement.offsetWidth);
var winH = window.innerHeight || Math.max(document.body.offsetHeight, document.documentElement.offsetHeight);
(options.container || document.body).appendChild(hints);
var box = hints.getBoundingClientRect();
var overlapX = box.right - winW, overlapY = box.bottom - winH;
var box = hints.getBoundingClientRect(), overlapY = box.bottom - winH;
if (overlapY > 0) {
var height = box.bottom - box.top, curTop = box.top - (pos.bottom - pos.top);
if (curTop - height > 0) { // Fits above cursor
hints.style.top = (top = curTop - height) + "px";
below = false;
} else if (height > winH) {
hints.style.height = (winH - 5) + "px";
hints.style.top = (top = pos.bottom - box.top) + "px";
var cursor = cm.getCursor();
if (data.from.ch != cursor.ch) {
pos = cm.cursorCoords(cursor);
hints.style.left = (left = pos.left) + "px";
box = hints.getBoundingClientRect();
}
}
}
var overlapX = box.left - winW;
if (overlapX > 0) {
if (box.right - box.left > winW) {
hints.style.width = (winW - 5) + "px";
overlapX -= (box.right - box.left) - winW;
}
hints.style.left = (left = pos.left - overlapX) + "px";
}
if (overlapY > 0) {
var height = box.bottom - box.top;
if (box.top - (pos.bottom - pos.top) - height > 0) {
overlapY = height + (pos.bottom - pos.top);
below = false;
} else if (height > winH) {
hints.style.height = (winH - 5) + "px";
overlapY -= height - winH;
}
hints.style.top = (top = pos.bottom - overlapY) + "px";
}

cm.addKeyMap(this.keyMap = buildKeyMap(options, {
moveFocus: function(n, avoidWrap) { widget.changeActive(widget.selectedHint + n, avoidWrap); },
setFocus: function(n) { widget.changeActive(n); },
menuSize: function() { return widget.screenAmount(); },
length: completions.length,
close: function() { completion.close(); },
pick: function() { widget.pick(); }
pick: function() { widget.pick(); },
data: data
}));

if (options.closeOnUnfocus !== false) {
Expand Down
2 changes: 1 addition & 1 deletion addon/runmode/runmode.node.js
Expand Up @@ -94,7 +94,7 @@ exports.resolveMode = function(spec) {
else return spec || {name: "null"};
};
exports.getMode = function(options, spec) {
spec = exports.resolveMode(mimeModes[spec]);
spec = exports.resolveMode(spec);
var mfactory = modes[spec.name];
if (!mfactory) throw new Error("Unknown mode: " + spec);
return mfactory(options, spec);
Expand Down
2 changes: 1 addition & 1 deletion bin/source-highlight
Expand Up @@ -40,7 +40,7 @@ function ensureMode(name) {
ensureMode(modeName);

function esc(str) {
return str.replace(/[<&]/, function(ch) { return ch == "&" ? "&amp;" : "&lt;"; });
return str.replace(/[<&]/g, function(ch) { return ch == "&" ? "&amp;" : "&lt;"; });
}

var code = fs.readFileSync("/dev/stdin", "utf8");
Expand Down
12 changes: 6 additions & 6 deletions demo/variableheight.html
Expand Up @@ -11,12 +11,12 @@
<style type="text/css">
.CodeMirror {border: 1px solid silver; border-width: 1px 2px; }
.cm-header { font-family: arial; }
.cm-header1 { font-size: 150%; }
.cm-header2 { font-size: 130%; }
.cm-header3 { font-size: 120%; }
.cm-header4 { font-size: 110%; }
.cm-header5 { font-size: 100%; }
.cm-header6 { font-size: 90%; }
.cm-header-1 { font-size: 150%; }
.cm-header-2 { font-size: 130%; }
.cm-header-3 { font-size: 120%; }
.cm-header-4 { font-size: 110%; }
.cm-header-5 { font-size: 100%; }
.cm-header-6 { font-size: 90%; }
.cm-strong { font-size: 140%; }
</style>
<div id=nav>
Expand Down
6 changes: 5 additions & 1 deletion doc/manual.html
Expand Up @@ -2162,7 +2162,11 @@ <h2>Addons</h2>
has <code>moveFocus(n)</code>, <code>setFocus(n)</code>, <code>pick()</code>,
and <code>close()</code> methods (see the source for details),
that can be used to change the focused element, pick the
current element or close the menu.</dd>
current element or close the menu. Additionnaly <code>menuSize()</code>
can give you access to the size of the current dropdown menu,
<code>length</code> give you the number of availlable completions, and
<code>data</code> give you full access to the completion returned by the
hinting function.</dd>
<dt><code><strong>extraKeys</strong>: keymap</code></dt>
<dd>Like <code>customKeys</code> above, but the bindings will
be added to the set of default bindings, instead of replacing
Expand Down
1 change: 1 addition & 0 deletions doc/realworld.html
Expand Up @@ -74,6 +74,7 @@ <h2>CodeMirror real-world uses</h2>
<li><a href="http://haxpad.com/">HaxPad</a> (editor for Win RT)</li>
<li><a href="http://megafonweblab.github.com/histone-javascript/">Histone template engine playground</a></li>
<li><a href="http://icecoder.net">ICEcoder</a> (web IDE)</li>
<li><a href="http://i-mos.org/imos/">i-MOS</a> (modeling and simulation platform)</li>
<li><a href="http://www.janvas.com/">Janvas</a> (vector graphics editor)</li>
<li><a href="http://extensions.joomla.org/extensions/edition/editors/8723">Joomla plugin</a></li>
<li><a href="http://jqfundamentals.com/">jQuery fundamentals</a> (interactive tutorial)</li>
Expand Down
82 changes: 43 additions & 39 deletions keymap/vim.js
Expand Up @@ -81,7 +81,7 @@
{ keys: ['<S-BS>'], type: 'keyToKey', toKeys: ['b'] },
{ keys: ['<C-n>'], type: 'keyToKey', toKeys: ['j'] },
{ keys: ['<C-p>'], type: 'keyToKey', toKeys: ['k'] },
{ keys: ['C-['], type: 'keyToKey', toKeys: ['<Esc>'] },
{ keys: ['<C-[>'], type: 'keyToKey', toKeys: ['<Esc>'] },
{ keys: ['<C-c>'], type: 'keyToKey', toKeys: ['<Esc>'] },
{ keys: ['s'], type: 'keyToKey', toKeys: ['c', 'l'], context: 'normal' },
{ keys: ['s'], type: 'keyToKey', toKeys: ['x', 'i'], context: 'visual'},
Expand Down Expand Up @@ -1542,22 +1542,44 @@
findFirstNonWhiteSpaceCharacter(cm.getLine(lineNum)));
},
textObjectManipulation: function(cm, motionArgs) {
// TODO: lots of possible exceptions that can be thrown here. Try da(
// outside of a () block.

// TODO: adding <> >< to this map doesn't work, presumably because
// they're operators
var mirroredPairs = {'(': ')', ')': '(',
'{': '}', '}': '{',
'[': ']', ']': '['};
var selfPaired = {'\'': true, '"': true};

var character = motionArgs.selectedCharacter;

// Inclusive is the difference between a and i
// TODO: Instead of using the additional text object map to perform text
// object operations, merge the map into the defaultKeyMap and use
// motionArgs to define behavior. Define separate entries for 'aw',
// 'iw', 'a[', 'i[', etc.
var inclusive = !motionArgs.textObjectInner;
if (!textObjects[character]) {

var tmp;
if (mirroredPairs[character]) {
tmp = selectCompanionObject(cm, mirroredPairs[character], inclusive);
} else if (selfPaired[character]) {
tmp = findBeginningAndEnd(cm, character, inclusive);
} else if (character === 'W') {
tmp = expandWordUnderCursor(cm, inclusive, true /** forward */,
true /** bigWord */);
} else if (character === 'w') {
tmp = expandWordUnderCursor(cm, inclusive, true /** forward */,
false /** bigWord */);
} else {
// No text object defined for this, don't move.
return null;
}
var tmp = textObjects[character](cm, inclusive);
var start = tmp.start;
var end = tmp.end;
return [start, end];

return [tmp.start, tmp.end];
},

repeatLastCharacterSearch: function(cm, motionArgs) {
var lastSearch = vimGlobalState.lastChararacterSearch;
var repeat = motionArgs.repeat;
Expand Down Expand Up @@ -2025,36 +2047,6 @@
}
};

var textObjects = {
// TODO: lots of possible exceptions that can be thrown here. Try da(
// outside of a () block.
// TODO: implement text objects for the reverse like }. Should just be
// an additional mapping after moving to the defaultKeyMap.
'w': function(cm, inclusive) {
return expandWordUnderCursor(cm, inclusive, true /** forward */,
false /** bigWord */);
},
'W': function(cm, inclusive) {
return expandWordUnderCursor(cm, inclusive,
true /** forward */, true /** bigWord */);
},
'{': function(cm, inclusive) {
return selectCompanionObject(cm, '}', inclusive);
},
'(': function(cm, inclusive) {
return selectCompanionObject(cm, ')', inclusive);
},
'[': function(cm, inclusive) {
return selectCompanionObject(cm, ']', inclusive);
},
'\'': function(cm, inclusive) {
return findBeginningAndEnd(cm, "'", inclusive);
},
'"': function(cm, inclusive) {
return findBeginningAndEnd(cm, '"', inclusive);
}
};

/*
* Below are miscellaneous utility functions used by vim.js
*/
Expand Down Expand Up @@ -2644,13 +2636,25 @@
return cur;
}

// TODO: perhaps this finagling of start and end positions belonds
// in codmirror/replaceRange?
function selectCompanionObject(cm, revSymb, inclusive) {
var cur = cm.getCursor();

var end = findMatchedSymbol(cm, cur, revSymb);
var start = findMatchedSymbol(cm, end);
start.ch += inclusive ? 1 : 0;
end.ch += inclusive ? 0 : 1;

if((start.line == end.line && start.ch > end.ch)
|| (start.line > end.line)) {
var tmp = start;
start = end;
end = tmp;
}

if(inclusive) {
end.ch += 1;
} else {
start.ch += 1;
}

return { start: start, end: end };
}
Expand Down
2 changes: 2 additions & 0 deletions lib/codemirror.css
Expand Up @@ -36,6 +36,8 @@
min-width: 20px;
text-align: right;
color: #999;
-moz-box-sizing: content-box;
box-sizing: content-box;
}

/* CURSOR */
Expand Down
1 change: 1 addition & 0 deletions lib/codemirror.js
Expand Up @@ -2409,6 +2409,7 @@
}
if (clickInGutter(cm, e)) return;
var start = posFromMouse(cm, e);
window.focus();

switch (e_button(e)) {
case 1:
Expand Down

0 comments on commit a506d85

Please sign in to comment.