Skip to content

Commit

Permalink
Added non-blocking beautify
Browse files Browse the repository at this point in the history
  • Loading branch information
salmanul committed Jan 28, 2022
1 parent 8a991cc commit 8e24460
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions lib/ace/ext/beautify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 = [{
Expand Down

0 comments on commit 8e24460

Please sign in to comment.