mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-24 03:33:27 +00:00
Autocomplete for graphics
This commit is contained in:
parent
eeabac7698
commit
f057f788e3
6 changed files with 21 additions and 17 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -19,6 +19,4 @@ define [
|
|||
paths.push(match[1])
|
||||
return paths
|
||||
|
||||
window.Preamble = Preamble
|
||||
|
||||
return Preamble
|
||||
|
|
|
@ -504,3 +504,8 @@
|
|||
height: auto;
|
||||
border-bottom: 1px solid @modal-header-border-color;
|
||||
}
|
||||
|
||||
// Widen autocomplete popup
|
||||
.ace_autocomplete {
|
||||
width: 380px !important;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue