Use angular $http service for spellcheck

This commit is contained in:
Shane Kilkelly 2017-09-29 14:55:06 +01:00
parent f74da0e6cf
commit a66cb15f48
2 changed files with 8 additions and 15 deletions

View file

@ -35,7 +35,7 @@ define [
url = ace.config._moduleUrl(args...) + "?fingerprint=#{window.aceFingerprint}"
return url
App.directive "aceEditor", ($timeout, $compile, $rootScope, event_tracking, localStorage, $cacheFactory, labels, graphics, preamble) ->
App.directive "aceEditor", ($timeout, $compile, $rootScope, event_tracking, localStorage, $cacheFactory, labels, graphics, preamble, $http) ->
monkeyPatchSearch($rootScope, $compile)
return {
@ -97,7 +97,7 @@ define [
if scope.spellCheck # only enable spellcheck when explicitly required
spellCheckCache = $cacheFactory("spellCheck-#{scope.name}", {capacity: 1000})
spellCheckManager = new SpellCheckManager(scope, editor, element, spellCheckCache)
spellCheckManager = new SpellCheckManager(scope, editor, element, spellCheckCache, $http)
undoManager = new UndoManager(scope, editor, element)
highlightsManager = new HighlightsManager(scope, editor, element)
cursorPositionManager = new CursorPositionManager(scope, editor, element, localStorage)

View file

@ -5,7 +5,7 @@ define [
Range = ace.require("ace/range").Range
class SpellCheckManager
constructor: (@$scope, @editor, @element, @cache) ->
constructor: (@$scope, @editor, @element, @cache, @$http) ->
$(document.body).append @element.find(".spell-check-menu")
@updatedLines = []
@ -235,18 +235,11 @@ define [
apiRequest: (endpoint, data, callback = (error, result) ->)->
data.token = window.user.id
data._csrf = window.csrfToken
options =
url: "/spelling" + endpoint
type: "POST"
dataType: "json"
headers:
"Content-Type": "application/json"
data: JSON.stringify data
success: (data, status, xhr) ->
callback null, data
error: (xhr, status, error) ->
callback error
return $.ajax options
@$http.post("/spelling" + endpoint, data)
.then (response) =>
callback(null, response.data)
.catch (response) =>
callback(new Error('api failure'))
blacklistedCommandRegex: ///
\\ # initial backslash