From f057f788e3270130678261e3bef34c5ca3d75c3e Mon Sep 17 00:00:00 2001 From: Shane Kilkelly Date: Mon, 31 Jul 2017 14:51:22 +0100 Subject: [PATCH] Autocomplete for graphics --- .../ide/editor/directives/aceEditor.coffee | 2 +- .../auto-complete/AutoCompleteManager.coffee | 19 ++++++++++--------- .../ide/file-tree/FileTreeManager.coffee | 2 -- .../ide/graphics/services/graphics.coffee | 8 +++++--- .../ide/preamble/services/preamble.coffee | 2 -- .../web/public/stylesheets/app/editor.less | 5 +++++ 6 files changed, 21 insertions(+), 17 deletions(-) diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor.coffee index 19c34142c5..9b272841be 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor.coffee @@ -103,7 +103,7 @@ define [ cursorPositionManager = new CursorPositionManager(scope, editor, element, localStorage) trackChangesManager = new TrackChangesManager(scope, editor, element) labelsManager = new LabelsManager(scope, editor, element, labels) - autoCompleteManager = new AutoCompleteManager(scope, editor, element, labelsManager, graphics) + autoCompleteManager = new AutoCompleteManager(scope, editor, element, labelsManager, graphics, preamble) # Prevert Ctrl|Cmd-S from triggering save dialog diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager.coffee index 6259e893ab..7cc89c785a 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager.coffee @@ -17,7 +17,7 @@ define [ commandFragment?.match(/\\(\w+)\{/)?[1] class AutoCompleteManager - constructor: (@$scope, @editor, @element, @labelsManager, @graphics) -> + constructor: (@$scope, @editor, @element, @labelsManager, @graphics, @preamble) -> @suggestionManager = new SuggestionManager() @monkeyPatchAutocomplete() @@ -45,6 +45,7 @@ define [ SnippetCompleter = new SnippetManager() Graphics = @graphics + Preamble = @preamble GraphicsCompleter = getCompletions: (editor, session, pos, prefix, callback) -> upToCursorRange = new Range(pos.row, 0, pos.row, pos.column) @@ -58,17 +59,17 @@ define [ needsClosingBrace = !lineBeyondCursor.match(/^[^{]*}/) commandName = match[1] currentArg = match[3] + graphicsPaths = Preamble.getGraphicsPaths() result = [] - # result.push { - # caption: "\\#{commandName}{}", - # snippet: "\\#{commandName}{}", - # meta: "graphic", - # score: 60 - # } for graphic in Graphics.getGraphicsFiles() + path = graphic.path + for graphicsPath in graphicsPaths + if path.indexOf(graphicsPath) == 0 + path = path.slice(graphicsPath.length) + break result.push { - caption: "\\#{commandName}{#{graphic.path}#{if needsClosingBrace then '}' else ''}", - value: "\\#{commandName}{#{graphic.path}#{if needsClosingBrace then '}' else ''}", + caption: "\\#{commandName}{#{path}#{if needsClosingBrace then '}' else ''}", + value: "\\#{commandName}{#{path}#{if needsClosingBrace then '}' else ''}", meta: "graphic", score: 50 } diff --git a/services/web/public/coffee/ide/file-tree/FileTreeManager.coffee b/services/web/public/coffee/ide/file-tree/FileTreeManager.coffee index f6b8a92710..0881e75cc8 100644 --- a/services/web/public/coffee/ide/file-tree/FileTreeManager.coffee +++ b/services/web/public/coffee/ide/file-tree/FileTreeManager.coffee @@ -202,8 +202,6 @@ define [ childPath = path + "/" + entity.name else childPath = entity.name - # FIXME: this is a hack - entity.path = childPath callback(entity, folder, childPath) if entity.children? @_forEachEntityInFolder(entity, childPath, callback) diff --git a/services/web/public/coffee/ide/graphics/services/graphics.coffee b/services/web/public/coffee/ide/graphics/services/graphics.coffee index fdd4126b16..355614b7f4 100644 --- a/services/web/public/coffee/ide/graphics/services/graphics.coffee +++ b/services/web/public/coffee/ide/graphics/services/graphics.coffee @@ -7,9 +7,11 @@ define [ Graphics = getGraphicsFiles: () -> graphicsFiles = [] - ide.fileTreeManager.forEachEntity (f) -> - if f?.name?.match?(/.*\.(png|jpg|jpeg)/) - graphicsFiles.push f + ide.fileTreeManager.forEachEntity (entity, folder, path) -> + if entity.type == 'file' && entity?.name?.match?(/.*\.(png|jpg|jpeg|pdf|eps)/) + cloned = _.clone(entity) + cloned.path = path + graphicsFiles.push cloned return graphicsFiles return Graphics diff --git a/services/web/public/coffee/ide/preamble/services/preamble.coffee b/services/web/public/coffee/ide/preamble/services/preamble.coffee index a8312ca4d7..f95cfd9bbe 100644 --- a/services/web/public/coffee/ide/preamble/services/preamble.coffee +++ b/services/web/public/coffee/ide/preamble/services/preamble.coffee @@ -19,6 +19,4 @@ define [ paths.push(match[1]) return paths - window.Preamble = Preamble - return Preamble diff --git a/services/web/public/stylesheets/app/editor.less b/services/web/public/stylesheets/app/editor.less index 3c3aae945a..979bdd2bf6 100644 --- a/services/web/public/stylesheets/app/editor.less +++ b/services/web/public/stylesheets/app/editor.less @@ -504,3 +504,8 @@ height: auto; border-bottom: 1px solid @modal-header-border-color; } + +// Widen autocomplete popup +.ace_autocomplete { + width: 380px !important; +}