1
0
Fork 0
mirror of https://github.com/overleaf/overleaf.git synced 2025-04-17 10:18:42 +00:00

Add in some basic snippets

This commit is contained in:
James Allen 2014-03-05 11:05:59 +00:00
parent d221e336f0
commit 06831e555e
5 changed files with 114 additions and 10 deletions

View file

@ -1,9 +1,10 @@
define [
"auto-complete/SuggestionManager"
"auto-complete/Snippets"
"ace/autocomplete/util"
"ace/range"
"ace/ext/language_tools"
], (SuggestionManager, Util) ->
], (SuggestionManager, Snippets, Util) ->
Range = require("ace/range").Range
Util.retrievePrecedingIdentifier = (text, pos, regex) ->
@ -24,14 +25,18 @@ define [
class AutoCompleteManager
constructor: (@ide) ->
@suggestionManager = new SuggestionManager()
@aceEditor = @ide.editor.aceEditor
@aceEditor.setOptions({
enableBasicAutocompletion: true,
enableSnippets: true
})
@aceEditor.completers = [@suggestionManager]
SnippetCompleter =
getCompletions: (editor, session, pos, prefix, callback) ->
callback null, Snippets
@suggestionManager = new SuggestionManager()
@aceEditor.completers = [@suggestionManager, SnippetCompleter]
@bindToEditorEvents()
@ -50,10 +55,7 @@ define [
lineUpToCursor = @aceSession.getTextRange(range)
commandFragment = getLastCommandFragment(lineUpToCursor)
if commandFragment?
if commandFragment? and commandFragment.length > 2
setTimeout () =>
@aceEditor.execCommand("startAutocomplete")
$(@aceEditor.completer.popup.container)
.find(".ace_content")
.css("font-size": window.userSettings.fontSize + "px")
, 0

View file

@ -0,0 +1,92 @@
define () ->
environments = [
"abstract",
"align", "align*",
"equation", "equation*",
"gather", "gather*",
"mutliline", "multiline*",
"split",
"verbatim"
]
snippets = for env in environments
{
caption: "\\begin{#{env}}..."
snippet: """
\\begin{#{env}}
$1
\\end{#{env}}
"""
meta: "env"
}
snippets = snippets.concat [{
caption: "\\begin{array}..."
snippet: """
\\begin{array}{${1:cc}}
$2 & $3 \\\\\\\\
$4 & $5
\\end{array}"
"""
meta: "env"
}, {
caption: "\\begin{figure}..."
snippet: """
\\begin{figure}
\\centering
\\includegraphics{$1}
\\caption{${2:Caption}}
\\label{${3:fig:my_label}}
\\end{figure}
"""
meta: "env"
}, {
caption: "\\begin{tabular}..."
snippet: """
\\begin{tabular}{${1:c|c}}
$2 & $3 \\\\\\\\
$4 & $5
\\end{tabular}
"""
meta: "env"
}, {
caption: "\\begin{table}..."
snippet: """
\\begin{table}[$1]
\\centering
\\begin{tabular}{${2:c|c}}
$3 & $4 \\\\\\\\
$5 & $6
\\end{tabular}
\\caption{${7:Caption}}
\\label{${8:tab:my_label}}
\\end{table}
"""
meta: "env"
}, {
caption: "\\begin{list}..."
snippet: """
\\begin{list}
\\item $1
\\end{list}
"""
meta: "env"
}, {
caption: "\\begin{enumerate}..."
snippet: """
\\begin{enumerate}
\\item $1
\\end{enumerate}
"""
meta: "env"
}, {
caption: "\\begin{frame}..."
snippet: """
\\begin{frame}{${1:Frame Title}}
$2
\\end{frame}
"""
meta: "env"
}]
return snippets

View file

@ -88,6 +88,7 @@ define [
completions.push {
caption: caption
snippet: snippet
meta: "cmd"
}
callback null, completions

View file

@ -125,12 +125,10 @@ define [
mode = window.userSettings.mode
theme = window.userSettings.theme
fontSize = window.userSettings.fontSize
chosenKeyBindings = keybindings[mode]
aceEditor.setKeyboardHandler(chosenKeyBindings)
aceEditor.setTheme("ace/theme/#{window.userSettings.theme}")
document.getElementById('editor').style.fontSize = fontSize+'px'
aceEditor.setShowPrintMargin(false)
# Prevert Ctrl|Cmd-S from triggering save dialog

View file

@ -17,6 +17,8 @@ define [
new DropboxSettingsManager @ide
@setFontSize()
if @ide?
@ide.on "afterJoinProject", (project) =>
@project = project
@ -102,6 +104,15 @@ define [
$confirm.off 'click'
$modal.find('.cancel').click (e)->
$modal.modal('hide')
setFontSize: () ->
@fontSizeCss = $("<style/>")
@fontSizeCss.text """
.ace_editor, .ace_content {
font-size: #{window.userSettings.fontSize}px;
}
"""
$(document.body).append(@fontSizeCss)
bindToProjectName: () ->
@project.on "change:name", (project, newName) ->