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

Delay before hover preview #3531

Merged
merged 9 commits into from
Apr 23, 2013
24 changes: 16 additions & 8 deletions src/editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -789,18 +789,26 @@ define(function (require, exports, module) {
};

/**
* Returns true if pos is between start and end (inclusive at both ends)
* Returns true if pos is between start and end (INclusive at start; EXclusive at end by default,
* but overridable via the endInclusive flag).
* @param {{line:number, ch:number}} pos
* @param {{line:number, ch:number}} start
* @param {{line:number, ch:number}} end
* @param {boolean} endInclusive
*
*/
Editor.prototype.posWithinRange = function (pos, start, end) {
var startIndex = this.indexFromPos(start),
endIndex = this.indexFromPos(end),
posIndex = this.indexFromPos(pos);

return posIndex >= startIndex && posIndex <= endIndex;
Editor.prototype.posWithinRange = function (pos, start, end, endInclusive) {
if (start.line <= pos.line && end.line >= pos.line) {
if (endInclusive) {
return (start.line < pos.line || start.ch <= pos.ch) && // inclusive
(end.line > pos.line || end.ch >= pos.ch); // inclusive
} else {
return (start.line < pos.line || start.ch <= pos.ch) && // inclusive
(end.line > pos.line || end.ch > pos.ch); // exclusive
}

}
return false;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It felt a little weird leaving this as an instance method of Editor given that it no longer has any dependency on Editor... but there didn't seem to be many cleaner homes for it (a static method on either Editor or Document feels imperfect too... and usually adds a module import that wasn't needed otherwise... but I'm open to moving it there if preferred).

};

/**
Expand Down Expand Up @@ -1336,7 +1344,7 @@ define(function (require, exports, module) {
_setEditorOption(value, cmOption);
_prefs.setValue(prefName, value);
}
/**
* Sets whether to use tab characters (vs. spaces) when inserting new text. Affects all Editors.
* @param {boolean} value
Expand Down
6 changes: 3 additions & 3 deletions src/editor/EditorCommandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,15 +326,15 @@ define(function (require, exports, module) {
// If we are in a selection starting and ending in invalid tokens and with no content (not considering spaces),
// find if we are inside a block-comment.
} else if (startCtx.token.className === null && endCtx.token.className === null &&
!editor.posWithinRange(ctx.pos, startCtx.pos, endCtx.pos)) {
!editor.posWithinRange(ctx.pos, startCtx.pos, endCtx.pos, true)) {
result = TokenUtils.moveSkippingWhitespace(TokenUtils.moveNextToken, startCtx);

// We found a comment, find the start and end and check if the selection is inside the block-comment.
if (startCtx.token.className === "comment") {
prefixPos = _findCommentStart(startCtx, prefixExp);
suffixPos = _findCommentEnd(startCtx, suffixExp, suffix.length);

if (prefixPos !== null && suffix !== null && !editor.posWithinRange(sel.start, prefixPos, suffixPos)) {
if (prefixPos !== null && suffix !== null && !editor.posWithinRange(sel.start, prefixPos, suffixPos, true)) {
canComment = true;
}
} else {
Expand Down Expand Up @@ -366,7 +366,7 @@ define(function (require, exports, module) {
// Search if there is another comment in the selection. Do nothing if there is one.
if (!canComment && !invalidComment && !lineUncomment && suffixPos) {
var start = {line: suffixPos.line, ch: suffixPos.ch + suffix.length + 1};
if (editor.posWithinRange(start, sel.start, sel.end)) {
if (editor.posWithinRange(start, sel.start, sel.end, true)) {
// Start searching at the next token, if there is one.
result = TokenUtils.moveSkippingWhitespace(TokenUtils.moveNextToken, ctx) &&
_findNextBlockComment(ctx, sel.end, prefixExp);
Expand Down
Loading