From 4fd4a0372cd6c72cbb042e6f180d0c64976326ae Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Mon, 11 Apr 2016 09:55:53 +0100 Subject: [PATCH 1/4] In Safari, limit iterations of the command-parsing loop. --- .../auto-complete/SuggestionManager.coffee | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SuggestionManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SuggestionManager.coffee index e0c3710358..914f43ee6b 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SuggestionManager.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SuggestionManager.coffee @@ -1,11 +1,30 @@ define [], () -> + + browserIsSafari = () -> + userAgent = navigator.userAgent + ( + userAgent.match(/.*Safari\/.*/) && + !userAgent.match(/.*Chrome\/.*/) && + !userAgent.match(/.*Chromium\/.*/) + ) + + class Parser constructor: (@doc) -> parse: () -> + limit = null + if browserIsSafari() + limit = 100 + commands = [] seen = {} + iterations = 0 while command = @nextCommand() + iterations += 1 + if limit && iterations > limit + return commands + docState = @doc optionalArgs = 0 From 8d6003dcc5b5b5c29a93ed773937ac7b4a39f7e1 Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Mon, 11 Apr 2016 09:58:37 +0100 Subject: [PATCH 2/4] Add commentary --- .../directives/aceEditor/auto-complete/SuggestionManager.coffee | 2 ++ 1 file changed, 2 insertions(+) diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SuggestionManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SuggestionManager.coffee index 914f43ee6b..3e5066d5d8 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SuggestionManager.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SuggestionManager.coffee @@ -13,6 +13,8 @@ define [], () -> constructor: (@doc) -> parse: () -> + # Safari regex is super slow, freezes browser for minutes on end, + # hacky solution: limit iterations limit = null if browserIsSafari() limit = 100 From e3b2ec997749f8e40c04e79ccde446f0e5d868d0 Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Mon, 11 Apr 2016 14:35:59 +0100 Subject: [PATCH 3/4] Add a `ide.browserIsSafari` boolean flag. --- services/web/public/coffee/ide.coffee | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/services/web/public/coffee/ide.coffee b/services/web/public/coffee/ide.coffee index 161289d055..af6111cd44 100644 --- a/services/web/public/coffee/ide.coffee +++ b/services/web/public/coffee/ide.coffee @@ -112,4 +112,17 @@ define [ ide.localStorage = localStorage + ide.browserIsSafari = false + try + userAgent = navigator.userAgent + ide.browserIsSafari = ( + userAgent && + userAgent.match(/.*Safari\/.*/) && + !userAgent.match(/.*Chrome\/.*/) && + !userAgent.match(/.*Chromium\/.*/) + ) + catch err + console.error err + + angular.bootstrap(document.body, ["SharelatexApp"]) From 76697599aeb70ccb3233bf5be619f959e8cbc4d1 Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Mon, 11 Apr 2016 14:45:26 +0100 Subject: [PATCH 4/4] Use the _ide version of browserIsSafari --- .../aceEditor/auto-complete/SuggestionManager.coffee | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SuggestionManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SuggestionManager.coffee index 3e5066d5d8..97241a90ce 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SuggestionManager.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/SuggestionManager.coffee @@ -1,14 +1,5 @@ define [], () -> - browserIsSafari = () -> - userAgent = navigator.userAgent - ( - userAgent.match(/.*Safari\/.*/) && - !userAgent.match(/.*Chrome\/.*/) && - !userAgent.match(/.*Chromium\/.*/) - ) - - class Parser constructor: (@doc) -> @@ -16,7 +7,7 @@ define [], () -> # Safari regex is super slow, freezes browser for minutes on end, # hacky solution: limit iterations limit = null - if browserIsSafari() + if window?._ide?.browserIsSafari limit = 100 commands = []