diff --git a/lib/ace/ext/beautify.js b/lib/ace/ext/beautify.js index 9fa23399701..41fb1357c7c 100644 --- a/lib/ace/ext/beautify.js +++ b/lib/ace/ext/beautify.js @@ -103,7 +103,7 @@ exports.beautify = function(session) { breakBefore = false; }; - while (token !== null) { + var prettify = function (){ curRow = iterator.getCurrentTokenRow(); rowTokens = iterator.$rowTokens; nextToken = iterator.stepForward(); @@ -409,9 +409,29 @@ exports.beautify = function(session) { token = nextToken; } - - code = code.trim(); - session.doc.setValue(code); + var id; + if(window.requestAnimationFrame){ + id = requestAnimationFrame(function loop (){ + if(token !== null) { + try{ + prettify(); + id = requestAnimationFrame(loop); + }catch(e){ + console.warn('requestAnimationFrame has been interupted',id); + cancelAnimationFrame(id); + } + }else{ + code = code.trim(); + session.doc.setValue(code); + } + }) + }else{ + while(token !== null) { + step(); + } + code = code.trim(); + session.doc.setValue(code); + } }; exports.commands = [{