Merge pull request #1079 from ajaxorg/requestAnimationFrame
use request animation frame
This commit is contained in:
commit
d5039f75c6
4 changed files with 23 additions and 11 deletions
|
|
@ -348,7 +348,7 @@ var Editor = function(renderer, session) {
|
||||||
var range = new Range(pos.row, pos.column, pos.row, pos.column+1);
|
var range = new Range(pos.row, pos.column, pos.row, pos.column+1);
|
||||||
self.session.$bracketHighlight = self.session.addMarker(range, "ace_bracket", "text");
|
self.session.$bracketHighlight = self.session.addMarker(range, "ace_bracket", "text");
|
||||||
}
|
}
|
||||||
}, 10);
|
}, 50);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
*
|
*
|
||||||
* Copyright (c) 2010, Ajax.org B.V.
|
* Copyright (c) 2010, Ajax.org B.V.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
* * Redistributions of source code must retain the above copyright
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
* * Neither the name of Ajax.org B.V. nor the
|
* * Neither the name of Ajax.org B.V. nor the
|
||||||
* names of its contributors may be used to endorse or promote products
|
* names of its contributors may be used to endorse or promote products
|
||||||
* derived from this software without specific prior written permission.
|
* derived from this software without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
|
@ -287,7 +287,7 @@ if (window.postMessage && !useragent.isOldIE) {
|
||||||
var postMessageId = 1;
|
var postMessageId = 1;
|
||||||
exports.nextTick = function(callback, win) {
|
exports.nextTick = function(callback, win) {
|
||||||
win = win || window;
|
win = win || window;
|
||||||
var messageName = "zero-timeout-message-" + postMessageId;
|
var messageName = "zero-timeout-message-" + postMessageId;
|
||||||
exports.addListener(win, "message", function listener(e) {
|
exports.addListener(win, "message", function listener(e) {
|
||||||
if (e.data == messageName) {
|
if (e.data == messageName) {
|
||||||
exports.stopPropagation(e);
|
exports.stopPropagation(e);
|
||||||
|
|
@ -298,11 +298,18 @@ if (window.postMessage && !useragent.isOldIE) {
|
||||||
win.postMessage(messageName, "*");
|
win.postMessage(messageName, "*");
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
exports.nextTick = function(callback, win) {
|
|
||||||
win = win || window;
|
|
||||||
window.setTimeout(callback, 0);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
exports.nextFrame = window.requestAnimationFrame ||
|
||||||
|
window.oRequestAnimationFrame ||
|
||||||
|
window.msRequestAnimationFrame ||
|
||||||
|
window.mozRequestAnimationFrame ||
|
||||||
|
window.webkitRequestAnimationFrame;
|
||||||
|
|
||||||
|
if (exports.nextFrame)
|
||||||
|
exports.nextFrame = exports.nextFrame.bind(window);
|
||||||
|
else
|
||||||
|
exports.nextFrame = function(callback) {
|
||||||
|
setTimeout(callback, 17);
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ var RenderLoop = function(onRender, win) {
|
||||||
if (!this.pending) {
|
if (!this.pending) {
|
||||||
this.pending = true;
|
this.pending = true;
|
||||||
var _self = this;
|
var _self = this;
|
||||||
event.nextTick(function() {
|
event.nextFrame(function() {
|
||||||
_self.pending = false;
|
_self.pending = false;
|
||||||
var changes;
|
var changes;
|
||||||
while (changes = _self.changes) {
|
while (changes = _self.changes) {
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,9 @@ var SearchHighlight = function(regExp, clazz, type) {
|
||||||
};
|
};
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
// needed to prevent long lines from freezing the browser
|
||||||
|
this.MAX_RANGES = 500;
|
||||||
|
|
||||||
this.setRegexp = function(regExp) {
|
this.setRegexp = function(regExp) {
|
||||||
if (this.regExp+"" == regExp+"")
|
if (this.regExp+"" == regExp+"")
|
||||||
return;
|
return;
|
||||||
|
|
@ -58,6 +61,8 @@ var SearchHighlight = function(regExp, clazz, type) {
|
||||||
var ranges = this.cache[i];
|
var ranges = this.cache[i];
|
||||||
if (ranges == null) {
|
if (ranges == null) {
|
||||||
ranges = lang.getMatchOffsets(session.getLine(i), this.regExp);
|
ranges = lang.getMatchOffsets(session.getLine(i), this.regExp);
|
||||||
|
if (ranges.length > this.MAX_RANGES)
|
||||||
|
ranges = ranges.slice(0, this.MAX_RANGES);
|
||||||
ranges = ranges.map(function(match) {
|
ranges = ranges.map(function(match) {
|
||||||
return new Range(i, match.offset, i, match.offset + match.length);
|
return new Range(i, match.offset, i, match.offset + match.length);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue