浏览代码

Merge pull request #690 from sharelatex/as-autocomplete

Autocomplete
Alasdair Smith 8 年之前
父节点
当前提交
cf92783a1b

+ 1 - 1
services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/CommandManager.coffee

@@ -1,5 +1,5 @@
 define [
-	"./top_hundred_snippets"
+	"./snippets/TopHundredSnippets"
 ], (topHundred) ->
 
 	class Parser

+ 5 - 29
services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/EnvironmentManager.coffee

@@ -1,31 +1,7 @@
-define () ->
-	environments = [
-		"abstract",
-		"align", "align*",
-		"equation", "equation*",
-		"gather", "gather*",
-		"multline", "multline*",
-		"split",
-		"verbatim",
-		"quote",
-		"center"
-	]
-
-	snippetNames = [
-		"array",
-		"figure",
-		"tabular",
-		"table",
-		"list",
-		"enumerate",
-		"itemize",
-		"frame",
-		"thebibliography"
-	]
-
-	environmentNames = snippetNames.concat(environments)
-
-	staticSnippets = for env in environments
+define [
+	'ide/editor/directives/aceEditor/auto-complete/snippets/Environments'
+], (Environments) ->
+	staticSnippets = for env in Environments.withoutSnippets
 		{
 			caption: "\\begin{#{env}}..."
 			snippet: """
@@ -151,7 +127,7 @@ define () ->
 		result = []
 		iterations = 0
 		while match = re.exec(text)
-			if match[1] not in environmentNames and match[1] != "document"
+			if match[1] not in Environments.all and match[1] != "document"
 				result.push {name: match[1], whitespace: match[2]}
 				iterations += 1
 				if iterations >= 1000

+ 29 - 0
services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/snippets/Environments.coffee

@@ -0,0 +1,29 @@
+define () ->
+	envs = [
+		"abstract",
+		"align", "align*",
+		"equation", "equation*",
+		"gather", "gather*",
+		"multline", "multline*",
+		"split",
+		"verbatim",
+		"quote",
+		"center"
+	]
+
+	envsWithSnippets = [
+		"array",
+		"figure",
+		"tabular",
+		"table",
+		"list",
+		"enumerate",
+		"itemize",
+		"frame",
+		"thebibliography"
+	]
+
+	return {
+		all: envs.concat(envsWithSnippets)
+		withoutSnippets: envs
+	}

+ 0 - 0
services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/top_hundred_snippets.coffee → services/web/public/coffee/ide/editor/directives/aceEditor/auto-complete/snippets/TopHundredSnippets.coffee


+ 1 - 20
services/web/public/coffee/ide/editor/directives/aceEditor/metadata/MetadataManager.coffee

@@ -53,31 +53,12 @@ define [
 					lastCommandFragmentIsReqPack
 
 				if linesContainMeta or lastCommandFragmentIsMeta
-					@scheduleLoadCurrentDocMetaFromServer()
+					@Metadata.scheduleLoadDocMetaFromServer @$scope.docId
 
 			@editor.on "changeSession", (e) =>
 				e.oldSession.off "change", onChange
 				e.session.on "change", onChange
 
-
-		loadDocMetaFromServer: (docId) ->
-			@Metadata.loadDocMetaFromServer docId
-
-		scheduleLoadCurrentDocMetaFromServer: () ->
-			# De-bounce loading labels with a timeout
-			currentDocId = @$scope.docId
-			existingTimeout = @debouncer[currentDocId]
-			if existingTimeout?
-				clearTimeout(existingTimeout)
-				delete @debouncer[currentDocId]
-			@debouncer[currentDocId] = setTimeout(
-				() =>
-					@loadDocMetaFromServer currentDocId
-					delete @debouncer[currentDocId]
-				, 1000
-				, this
-			)
-
 		getAllLabels: () ->
 			@Metadata.getAllLabels()
 

+ 16 - 0
services/web/public/coffee/ide/metadata/services/metadata.coffee

@@ -3,6 +3,7 @@ define [
 ], (App) ->
 
 	App.factory 'metadata', ($http, ide) ->
+		debouncer = {}  # DocId => Timeout
 
 		state = {documents: {}}
 
@@ -46,4 +47,19 @@ define [
 					{_csrf: window.csrfToken}
 				)
 
+		metadata.scheduleLoadDocMetaFromServer = (docId) ->
+			# De-bounce loading labels with a timeout
+			existingTimeout = debouncer[docId]
+
+			if existingTimeout?
+				clearTimeout(existingTimeout)
+				delete debouncer[docId]
+
+			debouncer[docId] = setTimeout(
+				() =>
+					metadata.loadDocMetaFromServer docId
+					delete debouncer[docId]
+				, 1000
+			)
+
 		return metadata

+ 2 - 1
services/web/public/stylesheets/_style_includes.less

@@ -91,4 +91,5 @@
 @import	"../js/libs/pdfListView/HighlightsLayer.css";
 @import	"../js/libs/select/select.css";
 @import "vendor/codemirror.css";
-@import "vendor/codemirror-dialog.css";
+@import "vendor/codemirror-dialog.css";
+@import "vendor/codemirror-show-hint.css";

+ 36 - 0
services/web/public/stylesheets/vendor/codemirror-show-hint.css

@@ -0,0 +1,36 @@
+.CodeMirror-hints {
+  position: absolute;
+  z-index: 10;
+  overflow: hidden;
+  list-style: none;
+
+  margin: 0;
+  padding: 2px;
+
+  -webkit-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
+  -moz-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
+  box-shadow: 2px 3px 5px rgba(0,0,0,.2);
+  border-radius: 3px;
+  border: 1px solid silver;
+
+  background: white;
+  font-size: 90%;
+  font-family: monospace;
+
+  max-height: 20em;
+  overflow-y: auto;
+}
+
+.CodeMirror-hint {
+  margin: 0;
+  padding: 0 4px;
+  border-radius: 2px;
+  white-space: pre;
+  color: black;
+  cursor: pointer;
+}
+
+li.CodeMirror-hint-active {
+  background: #08f;
+  color: white;
+}