Permalink
Browse files

Updated Brackets plugin structure and builder

  • Loading branch information...
1 parent c8583d5 commit a3a17f2e6b2274a1920c86cd44a154a3ea762a04 @sergeche sergeche committed Jan 22, 2013
Showing with 107 additions and 106 deletions.
  1. +5 −15 build.xml
  2. +5 −0 javascript/core.js
  3. +4 −1 plugins/brackets/editor.js
  4. +93 −90 plugins/brackets/main.js
View
@@ -281,42 +281,32 @@
<target name="plugin.brackets" depends="plugin.generic">
<mkdir dir="${emmet_build_dir}/brackets"/>
- <compile-js destfile="${emmet_build_dir}/brackets/_main.js" useclosure="no" force="yes">
+ <compile-js destfile="${emmet_build_dir}/brackets/emmet.js" useclosure="no" force="yes">
<filelist dir="${emmet_build_dir}">
<file name="emmet.js"/>
</filelist>
<filelist dir="${emmet_javascript}/actions">
<file name="selectLine.js"/>
</filelist>
- <filelist dir="${emmet_plugins_source}/brackets">
- <file name="editor.js"/>
- <file name="main.js"/>
- </filelist>
</compile-js>
- <concat destfile="${emmet_build_dir}/brackets/main.js" force="yes">
- <string>define(function(require, exports, module) {</string>
- <filelist dir="${emmet_build_dir}/brackets">
- <file name="_main.js"/>
- </filelist>
- <string>});</string>
- </concat>
-
<copy todir="${emmet_build_dir}/brackets">
<filelist dir="${emmet_plugins_source}/brackets">
<file name="keymap.json"/>
+ <file name="editor.js"/>
+ <file name="main.js"/>
</filelist>
<filelist dir="${basedir}">
<file name="snippets.json"/>
</filelist>
</copy>
- <zip
+ <!-- <zip
basedir="${emmet_build_dir}/brackets"
compress="yes"
level="9"
destfile="${emmet_build_dir}/brackets/Emmet-Brackets-v${emmet_version}.zip"
- excludes="*.zip,_main.js"/>
+ excludes="*.zip,_main.js"/> -->
</target>
<!-- Main build routine -->
View
@@ -218,4 +218,9 @@ if (typeof exports !== 'undefined') {
exports = module.exports = emmet;
}
exports.emmet = emmet;
+}
+
+// export as Require.js module
+if (typeof define !== 'undefined') {
+ define(emmet);
}
@@ -1,4 +1,7 @@
-emmet.define('brackets-editor', function(require, _) {
+define(['./emmet'], function(emmet) {
+ var require = emmet.require;
+ var _ = require('_');
+
var modeMap = {
"text/html": "html",
"application/xml": "xml",
View
@@ -1,99 +1,102 @@
-emmet.exec(function(r, _) {
- var CommandManager = brackets.getModule("command/CommandManager"),
- KeyBindingManager = brackets.getModule("command/KeyBindingManager"),
- Menus = brackets.getModule("command/Menus"),
- EditorManager = brackets.getModule("editor/EditorManager"),
-
- editorProxy = r("brackets-editor"),
- skippedActions = ['update_image_size', 'encode_decode_data_url'];
-
-
- /**
- * The following function included from Brackets to handle Tab key
- * when abbreviation cannot be expanded (https://github.com/adobe/brackets/blob/master/LICENSE).
- * @private
- * Handle Tab key press.
- * @param {!CodeMirror} instance CodeMirror instance.
- */
- function _handleTabKey(instance) {
- // Tab key handling is done as follows:
- // 1. If the selection is before any text and the indentation is to the left of
- // the proper indentation then indent it to the proper place. Otherwise,
- // add another tab. In either case, move the insertion point to the
- // beginning of the text.
- // 2. If the selection is after the first non-space character, and is not an
- // insertion point, indent the entire line(s).
- // 3. If the selection is after the first non-space character, and is an
- // insertion point, insert a tab character or the appropriate number
- // of spaces to pad to the nearest tab boundary.
- var from = instance.getCursor(true),
- to = instance.getCursor(false),
- line = instance.getLine(from.line),
- indentAuto = false,
- insertTab = false;
-
- if (from.line === to.line) {
- if (line.search(/\S/) > to.ch || to.ch === 0) {
- indentAuto = true;
- }
- }
-
- if (indentAuto) {
- var currentLength = line.length;
- CodeMirror.commands.indentAuto(instance);
- // If the amount of whitespace didn't change, insert another tab
- if (instance.getLine(from.line).length === currentLength) {
- insertTab = true;
- to.ch = 0;
+define(
+ ['emmet', 'editor', "text!keymap.json", "text!snippets.json"],
+ function(emmet, editorProxy, keymap, snippets) {
+ var r = emmet.require;
+ var _ = r('_');
+
+ var CommandManager = brackets.getModule("command/CommandManager"),
+ KeyBindingManager = brackets.getModule("command/KeyBindingManager"),
+ Menus = brackets.getModule("command/Menus"),
+ EditorManager = brackets.getModule("editor/EditorManager"),
+
+ skippedActions = ['update_image_size', 'encode_decode_data_url'];
+
+
+ /**
+ * The following function included from Brackets to handle Tab key
+ * when abbreviation cannot be expanded (https://github.com/adobe/brackets/blob/master/LICENSE).
+ * @private
+ * Handle Tab key press.
+ * @param {!CodeMirror} instance CodeMirror instance.
+ */
+ function _handleTabKey(instance) {
+ // Tab key handling is done as follows:
+ // 1. If the selection is before any text and the indentation is to the left of
+ // the proper indentation then indent it to the proper place. Otherwise,
+ // add another tab. In either case, move the insertion point to the
+ // beginning of the text.
+ // 2. If the selection is after the first non-space character, and is not an
+ // insertion point, indent the entire line(s).
+ // 3. If the selection is after the first non-space character, and is an
+ // insertion point, insert a tab character or the appropriate number
+ // of spaces to pad to the nearest tab boundary.
+ var from = instance.getCursor(true),
+ to = instance.getCursor(false),
+ line = instance.getLine(from.line),
+ indentAuto = false,
+ insertTab = false;
+
+ if (from.line === to.line) {
+ if (line.search(/\S/) > to.ch || to.ch === 0) {
+ indentAuto = true;
+ }
}
- } else if (instance.somethingSelected()) {
- CodeMirror.commands.indentMore(instance);
- } else {
- insertTab = true;
- }
-
- if (insertTab) {
- if (instance.getOption("indentWithTabs")) {
- CodeMirror.commands.insertTab(instance);
- } else {
- var i, ins = "", numSpaces = _indentUnit;
- numSpaces -= to.ch % numSpaces;
- for (i = 0; i < numSpaces; i++) {
- ins += " ";
+
+ if (indentAuto) {
+ var currentLength = line.length;
+ CodeMirror.commands.indentAuto(instance);
+ // If the amount of whitespace didn't change, insert another tab
+ if (instance.getLine(from.line).length === currentLength) {
+ insertTab = true;
+ to.ch = 0;
}
- instance.replaceSelection(ins, "end");
+ } else if (instance.somethingSelected()) {
+ CodeMirror.commands.indentMore(instance);
+ } else {
+ insertTab = true;
}
- }
- }
-
- function runAction(action) {
- var df = new $.Deferred();
-
- var editor = EditorManager.getFocusedEditor();
- if (editor) {
- editorProxy.setupContext(editor._codeMirror, editor.document.file.fullPath);
- if (action.name == 'expand_abbreviation_with_tab' && editorProxy.getSelection()) {
- var extraKeys = editor._codeMirror.getOption('extraKeys');
- if (extraKeys && extraKeys.Tab) {
- extraKeys.Tab(editor._codeMirror);
+
+ if (insertTab) {
+ if (instance.getOption("indentWithTabs")) {
+ CodeMirror.commands.insertTab(instance);
} else {
- _handleTabKey(editor._codeMirror);
+ var i, ins = "", numSpaces = _indentUnit;
+ numSpaces -= to.ch % numSpaces;
+ for (i = 0; i < numSpaces; i++) {
+ ins += " ";
+ }
+ instance.replaceSelection(ins, "end");
}
-
- return df.resolve().promise();
}
}
-
- if (editor && r("actions").run(action.name, editorProxy)) {
- df.resolve();
- } else {
- df.reject();
+
+ function runAction(action) {
+ var df = new $.Deferred();
+
+ var editor = EditorManager.getFocusedEditor();
+ if (editor) {
+ editorProxy.setupContext(editor._codeMirror, editor.document.file.fullPath);
+ if (action.name == 'expand_abbreviation_with_tab' && editorProxy.getSelection()) {
+ var extraKeys = editor._codeMirror.getOption('extraKeys');
+ if (extraKeys && extraKeys.Tab) {
+ extraKeys.Tab(editor._codeMirror);
+ } else {
+ _handleTabKey(editor._codeMirror);
+ }
+
+ return df.resolve().promise();
+ }
+ }
+
+ if (editor && r("actions").run(action.name, editorProxy)) {
+ df.resolve();
+ } else {
+ df.reject();
+ }
+
+ return df.promise();
}
-
- return df.promise();
- }
-
- require(["text!keymap.json", "text!snippets.json"], function(keymap, snippets) {
+
// load default snippets
r('resources').setVocabulary(JSON.parse(snippets), 'system');
@@ -118,5 +121,5 @@ emmet.exec(function(r, _) {
KeyBindingManager.addBinding(id, shortcut);
}
});
- });
-});
+ }
+);

0 comments on commit a3a17f2

Please sign in to comment.