From a334a64691b0ac9be5823bcd2d5e3316b0ee4e42 Mon Sep 17 00:00:00 2001 From: nightwing Date: Sat, 27 Oct 2012 22:19:55 +0400 Subject: [PATCH 1/3] prevent higlight_word from freezing the browser on long lines --- lib/ace/search_highlight.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/ace/search_highlight.js b/lib/ace/search_highlight.js index 8f2f5102..64cd43b7 100644 --- a/lib/ace/search_highlight.js +++ b/lib/ace/search_highlight.js @@ -42,6 +42,9 @@ var SearchHighlight = function(regExp, clazz, type) { }; (function() { + // needed to prevent long lines from freezing the browser + this.MAX_RANGES = 500; + this.setRegexp = function(regExp) { if (this.regExp+"" == regExp+"") return; @@ -58,6 +61,8 @@ var SearchHighlight = function(regExp, clazz, type) { var ranges = this.cache[i]; if (ranges == null) { 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) { return new Range(i, match.offset, i, match.offset + match.length); }); From ca26a82ef9825cdcad3157b17a159f87c38252c1 Mon Sep 17 00:00:00 2001 From: nightwing Date: Thu, 1 Nov 2012 21:40:06 +0400 Subject: [PATCH 2/3] increase timeout for bracket highlighting --- lib/ace/editor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ace/editor.js b/lib/ace/editor.js index 65d31201..4bdb01f0 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -348,7 +348,7 @@ var Editor = function(renderer, session) { var range = new Range(pos.row, pos.column, pos.row, pos.column+1); self.session.$bracketHighlight = self.session.addMarker(range, "ace_bracket", "text"); } - }, 10); + }, 50); }; /** From 6dddfe8edd80958a08906451360aa857538e9723 Mon Sep 17 00:00:00 2001 From: nightwing Date: Sun, 4 Nov 2012 16:25:36 +0400 Subject: [PATCH 3/3] use requestAnimationFrame --- lib/ace/lib/event.js | 25 ++++++++++++++++--------- lib/ace/renderloop.js | 2 +- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/ace/lib/event.js b/lib/ace/lib/event.js index 530da0cd..06574425 100644 --- a/lib/ace/lib/event.js +++ b/lib/ace/lib/event.js @@ -3,7 +3,7 @@ * * Copyright (c) 2010, Ajax.org B.V. * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright @@ -14,7 +14,7 @@ * * Neither the name of Ajax.org B.V. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. - * + * * 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 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -287,7 +287,7 @@ if (window.postMessage && !useragent.isOldIE) { var postMessageId = 1; exports.nextTick = function(callback, win) { win = win || window; - var messageName = "zero-timeout-message-" + postMessageId; + var messageName = "zero-timeout-message-" + postMessageId; exports.addListener(win, "message", function listener(e) { if (e.data == messageName) { exports.stopPropagation(e); @@ -298,11 +298,18 @@ if (window.postMessage && !useragent.isOldIE) { 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); + }; }); diff --git a/lib/ace/renderloop.js b/lib/ace/renderloop.js index dc3876f6..6accca49 100644 --- a/lib/ace/renderloop.js +++ b/lib/ace/renderloop.js @@ -68,7 +68,7 @@ var RenderLoop = function(onRender, win) { if (!this.pending) { this.pending = true; var _self = this; - event.nextTick(function() { + event.nextFrame(function() { _self.pending = false; var changes; while (changes = _self.changes) {