Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nightwing committed Aug 9, 2014
1 parent 1086034 commit 9b489c7
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 69 deletions.
10 changes: 7 additions & 3 deletions lib/ace/edit_session.js
Expand Up @@ -950,6 +950,9 @@ var EditSession = function(text, mode) {


if (!$isPlaceholder) {
// experimental method, used by c9 findiniles
if (mode.attachToSession)
mode.attachToSession(this);
this.$options.wrapMethod.set.call(this, this.$wrapMethod);
this.$setFolding(mode.foldingRules);
this.bgTokenizer.start(0);
Expand Down Expand Up @@ -1731,9 +1734,10 @@ var EditSession = function(text, mode) {
// Inside of the foldLine range. Need to split stuff up.
if (cmp == 0) {
foldLine = foldLine.split(start.row, start.column);
foldLine.shiftRow(len);
foldLine.addRemoveChars(
lastRow, 0, end.column - start.column);
if (foldLine) {
foldLine.shiftRow(len);
foldLine.addRemoveChars(lastRow, 0, end.column - start.column);
}
} else
// Infront of the foldLine but same row. Need to shift column.
if (cmp == -1) {
Expand Down
99 changes: 50 additions & 49 deletions lib/ace/editor.js
Expand Up @@ -525,32 +525,33 @@ var Editor = function(renderer, session) {
this.$highlightPending = true;
setTimeout(function() {
self.$highlightPending = false;

var pos = self.session.findMatchingBracket(self.getCursorPosition());
var session = self.session;
if (!session || !session.bgTokenizer) return;
var pos = session.findMatchingBracket(self.getCursorPosition());
if (pos) {
var range = new Range(pos.row, pos.column, pos.row, pos.column+1);
} else if (self.session.$mode.getMatching) {
var range = self.session.$mode.getMatching(self.session);
var range = new Range(pos.row, pos.column, pos.row, pos.column + 1);
} else if (session.$mode.getMatching) {
var range = session.$mode.getMatching(self.session);
}
if (range)
self.session.$bracketHighlight = self.session.addMarker(range, "ace_bracket", "text");
session.$bracketHighlight = session.addMarker(range, "ace_bracket", "text");
}, 50);
};

// todo: move to mode.getMatching
this.$highlightTags = function() {
var session = this.session;

if (this.$highlightTagPending) {
if (this.$highlightTagPending)
return;
}

// perform highlight async to not block the browser during navigation
var self = this;
this.$highlightTagPending = true;
setTimeout(function() {
self.$highlightTagPending = false;

var session = self.session;
if (!session || !session.bgTokenizer) return;

var pos = self.getCursorPosition();
var iterator = new TokenIterator(self.session, pos.row, pos.column);
var token = iterator.getCurrentToken();
Expand Down Expand Up @@ -2005,17 +2006,13 @@ var Editor = function(renderer, session) {
* Moves the cursor's row and column to the next matching bracket or HTML tag.
*
**/
this.jumpToMatching = function(select) {
this.jumpToMatching = function(select, expand) {
var cursor = this.getCursorPosition();
var iterator = new TokenIterator(this.session, cursor.row, cursor.column);
var prevToken = iterator.getCurrentToken();
var token = prevToken;
var token = prevToken || iterator.stepForward();

if (!token)
token = iterator.stepForward();

if (!token)
return;
if (!token) return;

//get next closing tag or bracket
var matchType;
Expand All @@ -2034,12 +2031,12 @@ var Editor = function(renderer, session) {

do {
if (token.value.match(/[{}()\[\]]/g)) {
for (; i<token.value.length && !found; i++) {
for (; i < token.value.length && !found; i++) {
if (!brackets[token.value[i]]) {
continue;
}

bracketType = brackets[token.value[i]]+'.'+token.type.replace("rparen", "lparen");
bracketType = brackets[token.value[i]] + '.' + token.type.replace("rparen", "lparen");

if (isNaN(depth[bracketType])) {
depth[bracketType] = 0;
Expand All @@ -2050,27 +2047,29 @@ var Editor = function(renderer, session) {
case '[':
case '{':
depth[bracketType]++;
break;
break;
case ')':
case ']':
case '}':
depth[bracketType]--;
if (depth[bracketType]===-1) {

if (depth[bracketType] === -1) {
matchType = 'bracket';
found = true;
}
break;
}
}
} else if (token && token.type.indexOf('tag-name') !== -1) {
}
else if (token && token.type.indexOf('tag-name') !== -1) {
if (isNaN(depth[token.value])) {
depth[token.value] = 0;
}

if (prevToken.value === '<') {
depth[token.value]++;
} else if (prevToken.value === '</') {
}
else if (prevToken.value === '</') {
depth[token.value]--;
}

Expand All @@ -2088,37 +2087,35 @@ var Editor = function(renderer, session) {
} while (token && !found);

//no match found
if (!matchType) {
if (!matchType)
return;
}

var range;
if (matchType==='bracket') {
var range, pos;
if (matchType === 'bracket') {
range = this.session.getBracketRange(cursor);
if (!range) {
range = new Range(
iterator.getCurrentTokenRow(),
iterator.getCurrentTokenColumn()+i-1,
iterator.getCurrentTokenRow(),
iterator.getCurrentTokenColumn()+i-1
iterator.getCurrentTokenRow(),
iterator.getCurrentTokenColumn() + i - 1,
iterator.getCurrentTokenRow(),
iterator.getCurrentTokenColumn() + i - 1
);
if (!range)
return;
var pos = range.start;
if (pos.row === cursor.row && Math.abs(pos.column - cursor.column) < 2)
pos = range.start;
if (expand || pos.row === cursor.row && Math.abs(pos.column - cursor.column) < 2)
range = this.session.getBracketRange(pos);
}
} else if(matchType==='tag') {
if (token && token.type.indexOf('tag-name') !== -1)
}
else if (matchType === 'tag') {
if (token && token.type.indexOf('tag-name') !== -1)
var tag = token.value;
else
return;

var range = new Range(
iterator.getCurrentTokenRow(),
iterator.getCurrentTokenColumn()-2,
iterator.getCurrentTokenRow(),
iterator.getCurrentTokenColumn()-2
range = new Range(
iterator.getCurrentTokenRow(),
iterator.getCurrentTokenColumn() - 2,
iterator.getCurrentTokenRow(),
iterator.getCurrentTokenColumn() - 2
);

//find matching tag
Expand All @@ -2130,17 +2127,18 @@ var Editor = function(renderer, session) {

if (prevToken) {
if (prevToken.type.indexOf('tag-close') !== -1) {
range.setEnd(iterator.getCurrentTokenRow(), iterator.getCurrentTokenColumn()+1);
range.setEnd(iterator.getCurrentTokenRow(), iterator.getCurrentTokenColumn() + 1);
}

if (token.value === tag && token.type.indexOf('tag-name') !== -1) {
if (prevToken.value === '<') {
depth[tag]++;
} else if ( prevToken.value === '</') {
}
else if (prevToken.value === '</') {
depth[tag]--;
}

if (depth[tag]===0)
if (depth[tag] === 0)
found = true;
}
}
Expand All @@ -2149,7 +2147,7 @@ var Editor = function(renderer, session) {

//we found it
if (token && token.type.indexOf('tag-name')) {
var pos = range.start;
pos = range.start;
if (pos.row == cursor.row && Math.abs(pos.column - cursor.column) < 2)
pos = range.end;
}
Expand All @@ -2158,10 +2156,13 @@ var Editor = function(renderer, session) {
pos = range && range.cursor || pos;
if (pos) {
if (select) {
if (range && range.isEqual(this.getSelectionRange()))
if (range && expand) {
this.selection.setRange(range);
} else if (range && range.isEqual(this.getSelectionRange())) {
this.clearSelection();
else
} else {
this.selection.selectTo(pos.row, pos.column);
}
} else {
this.selection.moveTo(pos.row, pos.column);
}
Expand Down
9 changes: 6 additions & 3 deletions lib/ace/ext/whitespace.js
Expand Up @@ -76,11 +76,14 @@ exports.$detectIndentation = function(lines, fallback) {
var first = {score: 0, length: 0};
var spaceIndents = 0;
for (var i = 1; i < 12; i++) {
var score = getScore(i);
if (i == 1) {
spaceIndents = getScore(i);
var score = stats.length && 1;
spaceIndents = score;
score = stats[1] ? 0.9 : 0.8;
if (!stats.length)
score = 0
} else
var score = getScore(i) / spaceIndents;
score /= spaceIndents;

if (changes[i])
score += changes[i] / changesTotal;
Expand Down
10 changes: 5 additions & 5 deletions lib/ace/keyboard/vim/maps/motions.js
Expand Up @@ -426,7 +426,7 @@ module.exports = {
var column = util.getRightNthChar(editor, cursor, param, count || 1);

if (isRepeat && column == 0 && !(count > 1))
var column = util.getRightNthChar(editor, cursor, param, 2);
column = util.getRightNthChar(editor, cursor, param, 2);

if (typeof column === "number") {
cursor.column += column + (isSel ? 1 : 0);
Expand All @@ -444,8 +444,8 @@ module.exports = {
var cursor = editor.getCursorPosition();
var column = util.getLeftNthChar(editor, cursor, param, count || 1);

if (isRepeat && column == 0 && !(count > 1))
var column = util.getLeftNthChar(editor, cursor, param, 2);
if (isRepeat && column === 0 && !(count > 1))
column = util.getLeftNthChar(editor, cursor, param, 2);

if (typeof column === "number") {
cursor.column -= column;
Expand Down Expand Up @@ -558,7 +558,7 @@ module.exports = {
content += "\n";

if (content.length) {
editor.navigateLineEnd()
editor.navigateLineEnd();
editor.insert(content);
util.insertMode(editor);
}
Expand All @@ -575,7 +575,7 @@ module.exports = {
if (content.length) {
if(row > 0) {
editor.navigateUp();
editor.navigateLineEnd()
editor.navigateLineEnd();
editor.insert(content);
} else {
editor.session.insert({row: 0, column: 0}, content);
Expand Down
2 changes: 1 addition & 1 deletion lib/ace/lib/dom.js
Expand Up @@ -49,7 +49,7 @@ exports.createElement = function(tag, ns) {
};

exports.hasCssClass = function(el, name) {
var classes = el.className.split(/\s+/g);
var classes = (el.className || "").split(/\s+/g);
return classes.indexOf(name) !== -1;
};

Expand Down
6 changes: 3 additions & 3 deletions lib/ace/multi_select.js
Expand Up @@ -720,7 +720,7 @@ var Editor = require("./editor").Editor;
* @param {Boolean} skip If `true`, removes the active selection range
* @method Editor.selectMore
**/
this.selectMore = function(dir, skip) {
this.selectMore = function(dir, skip, stopAtFirst) {
var session = this.session;
var sel = session.multiSelect;

Expand All @@ -729,8 +729,8 @@ var Editor = require("./editor").Editor;
range = session.getWordRange(range.start.row, range.start.column);
range.cursor = dir == -1 ? range.start : range.end;
this.multiSelect.addRange(range);
// todo add option for sublime like behavior
// return;
if (stopAtFirst)
return;
}
var needle = session.getTextRange(range);

Expand Down
13 changes: 9 additions & 4 deletions lib/ace/placeholder.js
Expand Up @@ -37,7 +37,6 @@ var oop = require("./lib/oop");
/**
* @class PlaceHolder
*
*
**/

/**
Expand All @@ -47,7 +46,6 @@ var oop = require("./lib/oop");
* - others (String):
* - mainClass (String):
* - othersClass (String):
*
*
* @constructor
**/
Expand Down Expand Up @@ -93,6 +91,10 @@ var PlaceHolder = function(session, length, pos, others, mainClass, othersClass)
var doc = this.doc;
var session = this.session;
var pos = this.$pos;

this.selectionBefore = session.selection.toJSON();
if (session.selection.inMultiSelectMode)
session.selection.toSingleRange();

this.pos = doc.createAnchor(pos.row, pos.column);
this.markerId = session.addMarker(new Range(pos.row, pos.column, pos.row, pos.column + this.length), this.mainClass, null, false);
Expand Down Expand Up @@ -218,9 +220,9 @@ var PlaceHolder = function(session, length, pos, others, mainClass, othersClass)
**/

this.onCursorChange = function(event) {
if (this.$updating) return;
if (this.$updating || !this.session) return;
var pos = this.session.selection.getCursor();
if(pos.row === this.pos.row && pos.column >= this.pos.column && pos.column <= this.pos.column + this.length) {
if (pos.row === this.pos.row && pos.column >= this.pos.column && pos.column <= this.pos.column + this.length) {
this.showOtherMarkers();
this._emit("cursorEnter", event);
} else {
Expand All @@ -245,6 +247,7 @@ var PlaceHolder = function(session, length, pos, others, mainClass, othersClass)
this.others[i].detach();
}
this.session.setUndoSelect(true);
this.session = null;
};

/**
Expand All @@ -261,6 +264,8 @@ var PlaceHolder = function(session, length, pos, others, mainClass, othersClass)
for (var i = 0; i < undosRequired; i++) {
undoManager.undo(true);
}
if (this.selectionBefore)
this.session.selection.fromJSON(this.selectionBefore);
};
}).call(PlaceHolder.prototype);

Expand Down

0 comments on commit 9b489c7

Please sign in to comment.