Version Notes
First public release. Please let us know if you have any feedback!
The GitHub repo can be found at: https://github.com/e-sites/magento-advanced-html-editor
Download this release
Release Info
| Developer | Boye Oomens |
| Extension | Esites_Editor |
| Version | 0.1.0 |
| Comparing to | |
| See all releases | |
Version 0.1.0
- app/code/local/Esites/.DS_Store +0 -0
- app/code/local/Esites/Editor/Helper/Data.php +22 -0
- app/code/local/Esites/Editor/Model/Config.php +66 -0
- app/code/local/Esites/Editor/Model/Observer.php +48 -0
- app/code/local/Esites/Editor/Model/Source/Status.php +17 -0
- app/code/local/Esites/Editor/Model/System/Config/Source/IndentUnit/Values.php +41 -0
- app/code/local/Esites/Editor/Model/System/Config/Source/Keymap/Values.php +43 -0
- app/code/local/Esites/Editor/Model/System/Config/Source/Theme/Values.php +73 -0
- app/code/local/Esites/Editor/etc/config.xml +103 -0
- app/code/local/Esites/Editor/etc/system.xml +207 -0
- app/etc/modules/Esites_Editor.xml +29 -0
- js/tiny_mce/plugins/esites_editor/.DS_Store +0 -0
- js/tiny_mce/plugins/esites_editor/css/styles.css +18 -0
- js/tiny_mce/plugins/esites_editor/esites_editor.html +26 -0
- js/tiny_mce/plugins/esites_editor/esites_editor_plugin.js +1 -0
- js/tiny_mce/plugins/esites_editor/esites_editor_plugin_src.js +94 -0
- js/tiny_mce/plugins/esites_editor/img/icon-esites-editor.png +0 -0
- js/tiny_mce/plugins/esites_editor/js/app.js +26 -0
- js/tiny_mce/plugins/esites_editor/js/app/main.js +107 -0
- js/tiny_mce/plugins/esites_editor/js/app/module/editor.js +46 -0
- js/tiny_mce/plugins/esites_editor/js/app/module/popup.js +42 -0
- js/tiny_mce/plugins/esites_editor/js/app/module/util.js +84 -0
- js/tiny_mce/plugins/esites_editor/js/app/var/addons.js +69 -0
- js/tiny_mce/plugins/esites_editor/js/app/var/cmOptions.js +9 -0
- js/tiny_mce/plugins/esites_editor/js/app/var/deps.js +3 -0
- js/tiny_mce/plugins/esites_editor/js/app/var/plugin.js +3 -0
- js/tiny_mce/plugins/esites_editor/js/app/var/textarea.js +5 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/comment/comment.js +183 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/comment/continuecomment.js +85 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/dialog/dialog.css +32 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/dialog/dialog.js +157 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/display/fullscreen.css +6 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/display/fullscreen.js +41 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/display/panel.js +112 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/display/placeholder.js +58 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/display/rulers.js +63 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/edit/closebrackets.js +185 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/edit/closetag.js +166 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/edit/continuelist.js +51 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/edit/matchbrackets.js +120 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/edit/matchtags.js +66 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/edit/trailingspace.js +27 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/fold/brace-fold.js +105 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/fold/comment-fold.js +57 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/fold/foldcode.js +149 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/fold/foldgutter.css +20 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/fold/foldgutter.js +146 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/fold/indent-fold.js +44 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/fold/markdown-fold.js +49 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/fold/xml-fold.js +182 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/hint/anyword-hint.js +41 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/hint/css-hint.js +60 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/hint/html-hint.js +348 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/hint/javascript-hint.js +146 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/hint/show-hint.css +38 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/hint/show-hint.js +383 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/hint/sql-hint.js +254 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/hint/xml-hint.js +110 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/lint/coffeescript-lint.js +41 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/lint/css-lint.js +35 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/lint/javascript-lint.js +136 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/lint/json-lint.js +31 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/lint/lint.css +73 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/lint/lint.js +207 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/lint/yaml-lint.js +28 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/merge/merge.css +112 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/merge/merge.js +775 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/mode/loadmode.js +64 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/mode/multiplex.js +123 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/mode/multiplex_test.js +33 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/mode/overlay.js +85 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/mode/simple.js +213 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/runmode/colorize.js +40 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/runmode/runmode-standalone.js +157 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/runmode/runmode.js +72 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/runmode/runmode.node.js +120 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/scroll/annotatescrollbar.js +115 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/scroll/scrollpastend.js +46 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/scroll/simplescrollbars.css +66 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/scroll/simplescrollbars.js +147 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/search/match-highlighter.js +128 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/search/matchesonscrollbar.css +8 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/search/matchesonscrollbar.js +97 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/search/search.js +167 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/search/searchcursor.js +189 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/selection/active-line.js +71 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/selection/mark-selection.js +118 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/selection/selection-pointer.js +98 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/tern/tern.css +86 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/tern/tern.js +697 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/tern/worker.js +44 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/wrap/hardwrap.js +139 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/keymap/emacs.js +412 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/keymap/sublime.js +553 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/keymap/vim.js +5029 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/lib/codemirror.css +325 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/lib/codemirror.js +8747 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/mode/css/css.js +754 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/mode/htmlmixed/htmlmixed.js +121 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/mode/javascript/javascript.js +701 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/mode/xml/xml.js +384 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/theme/3024-day.css +40 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/theme/3024-night.css +39 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/theme/ambiance-mobile.css +5 -0
- js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/theme/ambiance.css +8 -0
app/code/local/Esites/.DS_Store
ADDED
|
Binary file
|
app/code/local/Esites/Editor/Helper/Data.php
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Magento
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
| 8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
| 9 |
+
* It is also available through the world-wide-web at this URL:
|
| 10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
| 11 |
+
* If you did not receive a copy of the license and are unable to
|
| 12 |
+
* obtain it through the world-wide-web, please send an email
|
| 13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
| 14 |
+
*
|
| 15 |
+
* @category Esites
|
| 16 |
+
* @package Esites_Editor
|
| 17 |
+
* @copyright Copyright (c) 2015 E-sites (http://www.e-sites.nl)
|
| 18 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
| 19 |
+
*/
|
| 20 |
+
class Esites_Editor_Helper_Data extends Mage_Core_Helper_Abstract
|
| 21 |
+
{
|
| 22 |
+
}
|
app/code/local/Esites/Editor/Model/Config.php
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Magento
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
| 8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
| 9 |
+
* It is also available through the world-wide-web at this URL:
|
| 10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
| 11 |
+
* If you did not receive a copy of the license and are unable to
|
| 12 |
+
* obtain it through the world-wide-web, please send an email
|
| 13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
| 14 |
+
*
|
| 15 |
+
* @category Esites
|
| 16 |
+
* @package Esites_Editor
|
| 17 |
+
* @copyright Copyright (c) 2015 E-sites (http://www.e-sites.nl)
|
| 18 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
| 19 |
+
*/
|
| 20 |
+
|
| 21 |
+
/**
|
| 22 |
+
* Widgets Plugin Config for Emmet
|
| 23 |
+
*
|
| 24 |
+
* @category Esites
|
| 25 |
+
* @package Esites_Editor
|
| 26 |
+
*/
|
| 27 |
+
class Esites_Editor_Model_Config extends Varien_Object
|
| 28 |
+
{
|
| 29 |
+
/**
|
| 30 |
+
* Return config settings for widgets insertion plugin based on editor element config
|
| 31 |
+
*
|
| 32 |
+
* @param Varien_Object $config
|
| 33 |
+
*
|
| 34 |
+
* @return array
|
| 35 |
+
*/
|
| 36 |
+
public function getPluginSettings($config)
|
| 37 |
+
{
|
| 38 |
+
$store = Mage::app()->getStore();
|
| 39 |
+
$configPlugins = $config->getData('plugins');
|
| 40 |
+
$EsitesEditorPlugin = array(
|
| 41 |
+
array(
|
| 42 |
+
'name' => 'esites_editor',
|
| 43 |
+
'src' => Mage::getBaseUrl('js') . 'tiny_mce/plugins/esites_editor/esites_editor_plugin.js',
|
| 44 |
+
'config' => array(
|
| 45 |
+
'theme' => (string) Mage::getStoreConfig('editor/appearance/theme', $store),
|
| 46 |
+
'emmet' => (bool) Mage::getStoreConfig('editor/prefs/emmet', $store),
|
| 47 |
+
'activeLine' => (bool) Mage::getStoreConfig('editor/prefs/activeLine', $store),
|
| 48 |
+
'codeFolding' => (bool) Mage::getStoreConfig('editor/prefs/codeFolding', $store),
|
| 49 |
+
'indentUnit' => (int) Mage::getStoreConfig('editor/prefs/indentUnit', $store),
|
| 50 |
+
'lineWrapping' => (bool) Mage::getStoreConfig('editor/prefs/lineWrapping', $store),
|
| 51 |
+
'autoFormat' => (bool) Mage::getStoreConfig('editor/appearance/autoFormat', $store),
|
| 52 |
+
'matchTags' => (bool) Mage::getStoreConfig('editor/prefs/matchTags', $store),
|
| 53 |
+
'matchHighlight' => (bool) Mage::getStoreConfig('editor/prefs/matchHighlight', $store),
|
| 54 |
+
'closeTags' => (bool) Mage::getStoreConfig('editor/prefs/closeTags', $store),
|
| 55 |
+
'search' => (bool) Mage::getStoreConfig('editor/prefs/search', $store),
|
| 56 |
+
'fontSize' => (string) Mage::getStoreConfig('editor/appearance/fontSize', $store),
|
| 57 |
+
'keymap' => (string) Mage::getStoreConfig('editor/prefs/keymap', $store)
|
| 58 |
+
)
|
| 59 |
+
)
|
| 60 |
+
);
|
| 61 |
+
|
| 62 |
+
$variableConfig['plugins'] = array_merge($EsitesEditorPlugin, $configPlugins);
|
| 63 |
+
|
| 64 |
+
return $variableConfig;
|
| 65 |
+
}
|
| 66 |
+
}
|
app/code/local/Esites/Editor/Model/Observer.php
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Magento
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
| 8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
| 9 |
+
* It is also available through the world-wide-web at this URL:
|
| 10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
| 11 |
+
* If you did not receive a copy of the license and are unable to
|
| 12 |
+
* obtain it through the world-wide-web, please send an email
|
| 13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
| 14 |
+
*
|
| 15 |
+
* @category Esites
|
| 16 |
+
* @package Esites_Editor
|
| 17 |
+
* @copyright Copyright (c) 2015 E-sites (http://www.e-sites.nl)
|
| 18 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
| 19 |
+
*/
|
| 20 |
+
|
| 21 |
+
/**
|
| 22 |
+
* Esites Cms Observer
|
| 23 |
+
*
|
| 24 |
+
* @category Esites
|
| 25 |
+
* @package Esites_Editor
|
| 26 |
+
*/
|
| 27 |
+
|
| 28 |
+
class Esites_Editor_Model_Observer
|
| 29 |
+
{
|
| 30 |
+
/**
|
| 31 |
+
* Add additional settings to wysiwyg config (Emmet)
|
| 32 |
+
*
|
| 33 |
+
* @param Varien_Event_Observer $observer
|
| 34 |
+
*
|
| 35 |
+
* @return Mage_Widget_Model_Observer
|
| 36 |
+
*/
|
| 37 |
+
public function prepareWidgetsPluginConfig(Varien_Event_Observer $observer)
|
| 38 |
+
{
|
| 39 |
+
$config = $observer->getEvent()->getConfig();
|
| 40 |
+
|
| 41 |
+
if ($config->getData('add_widgets') && Mage::getStoreConfig('editor/general/enabled', Mage::app()->getStore())) {
|
| 42 |
+
$settings = Mage::getModel('editor/config')->getPluginSettings($config);
|
| 43 |
+
$config->addData($settings);
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
return $this;
|
| 47 |
+
}
|
| 48 |
+
}
|
app/code/local/Esites/Editor/Model/Source/Status.php
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class Esites_Editor_Model_Source_Status extends Varien_Object
|
| 4 |
+
{
|
| 5 |
+
const STATUS_QUEUED = -1;
|
| 6 |
+
const STATUS_RUNNING = 1;
|
| 7 |
+
const STATUS_DISABLED = 2;
|
| 8 |
+
const STATUS_ENDED = 3;
|
| 9 |
+
|
| 10 |
+
static public function getOptionArray()
|
| 11 |
+
{
|
| 12 |
+
return array(
|
| 13 |
+
self::STATUS_RUNNING => Mage::helper('catalog')->__('Enabled'),
|
| 14 |
+
self::STATUS_DISABLED => Mage::helper('catalog')->__('Disabled')
|
| 15 |
+
);
|
| 16 |
+
}
|
| 17 |
+
}
|
app/code/local/Esites/Editor/Model/System/Config/Source/IndentUnit/Values.php
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Magento
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
| 8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
| 9 |
+
* It is also available through the world-wide-web at this URL:
|
| 10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
| 11 |
+
* If you did not receive a copy of the license and are unable to
|
| 12 |
+
* obtain it through the world-wide-web, please send an email
|
| 13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
| 14 |
+
*
|
| 15 |
+
* @category Esites
|
| 16 |
+
* @package Esites_Editor
|
| 17 |
+
* @copyright Copyright (c) 2015 E-sites (http://www.e-sites.nl)
|
| 18 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
| 19 |
+
*/
|
| 20 |
+
|
| 21 |
+
class Esites_Editor_Model_System_Config_Source_IndentUnit_Values extends Varien_Object
|
| 22 |
+
{
|
| 23 |
+
protected $indentUnits = array(
|
| 24 |
+
'2' => '2',
|
| 25 |
+
'4' => '4'
|
| 26 |
+
);
|
| 27 |
+
|
| 28 |
+
public function toOptionArray()
|
| 29 |
+
{
|
| 30 |
+
$values = array();
|
| 31 |
+
|
| 32 |
+
foreach ($this->indentUnits as $key => $label) {
|
| 33 |
+
$values[] = array(
|
| 34 |
+
'value' => $key,
|
| 35 |
+
'label' => $label
|
| 36 |
+
);
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
return $values;
|
| 40 |
+
}
|
| 41 |
+
}
|
app/code/local/Esites/Editor/Model/System/Config/Source/Keymap/Values.php
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Magento
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
| 8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
| 9 |
+
* It is also available through the world-wide-web at this URL:
|
| 10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
| 11 |
+
* If you did not receive a copy of the license and are unable to
|
| 12 |
+
* obtain it through the world-wide-web, please send an email
|
| 13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
| 14 |
+
*
|
| 15 |
+
* @category Esites
|
| 16 |
+
* @package Esites_Editor
|
| 17 |
+
* @copyright Copyright (c) 2015 E-sites (http://www.e-sites.nl)
|
| 18 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
| 19 |
+
*/
|
| 20 |
+
|
| 21 |
+
class Esites_Editor_Model_System_Config_Source_Keymap_Values extends Varien_Object
|
| 22 |
+
{
|
| 23 |
+
protected $keymaps = array(
|
| 24 |
+
'default' => 'Default',
|
| 25 |
+
'emacs' => 'Emacs',
|
| 26 |
+
'vim' => 'Vim',
|
| 27 |
+
'sublime' => 'Sublime Text'
|
| 28 |
+
);
|
| 29 |
+
|
| 30 |
+
public function toOptionArray()
|
| 31 |
+
{
|
| 32 |
+
$values = array();
|
| 33 |
+
|
| 34 |
+
foreach ($this->keymaps as $key => $label) {
|
| 35 |
+
$values[] = array(
|
| 36 |
+
'value' => $key,
|
| 37 |
+
'label' => $label
|
| 38 |
+
);
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
return $values;
|
| 42 |
+
}
|
| 43 |
+
}
|
app/code/local/Esites/Editor/Model/System/Config/Source/Theme/Values.php
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Magento
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
| 8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
| 9 |
+
* It is also available through the world-wide-web at this URL:
|
| 10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
| 11 |
+
* If you did not receive a copy of the license and are unable to
|
| 12 |
+
* obtain it through the world-wide-web, please send an email
|
| 13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
| 14 |
+
*
|
| 15 |
+
* @category Esites
|
| 16 |
+
* @package Esites_Editor
|
| 17 |
+
* @copyright Copyright (c) 2015 E-sites (http://www.e-sites.nl)
|
| 18 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
| 19 |
+
*/
|
| 20 |
+
|
| 21 |
+
class Esites_Editor_Model_System_Config_Source_Theme_Values extends Varien_Object
|
| 22 |
+
{
|
| 23 |
+
protected $themes = array(
|
| 24 |
+
'default',
|
| 25 |
+
'3024-day',
|
| 26 |
+
'3024-night',
|
| 27 |
+
'ambiance',
|
| 28 |
+
'base16-dark',
|
| 29 |
+
'base16-light',
|
| 30 |
+
'blackboard',
|
| 31 |
+
'cobalt',
|
| 32 |
+
'colorforth',
|
| 33 |
+
'eclipse',
|
| 34 |
+
'elegant',
|
| 35 |
+
'erlang-dark',
|
| 36 |
+
'lesser-dark',
|
| 37 |
+
'liquibyte',
|
| 38 |
+
'mbo',
|
| 39 |
+
'mdn-like',
|
| 40 |
+
'midnight',
|
| 41 |
+
'monokai',
|
| 42 |
+
'neat',
|
| 43 |
+
'neo',
|
| 44 |
+
'night',
|
| 45 |
+
'paraiso-dark',
|
| 46 |
+
'paraiso-light',
|
| 47 |
+
'pastel-on-dark',
|
| 48 |
+
'rubyblue',
|
| 49 |
+
'solarized dark',
|
| 50 |
+
'solarized light',
|
| 51 |
+
'the-matrix',
|
| 52 |
+
'tomorrow-night-bright',
|
| 53 |
+
'tomorrow-night-eighties',
|
| 54 |
+
'ttcn',
|
| 55 |
+
'twilight',
|
| 56 |
+
'vibrant-ink',
|
| 57 |
+
'xq-dark',
|
| 58 |
+
'xq-light',
|
| 59 |
+
'zenburn'
|
| 60 |
+
);
|
| 61 |
+
|
| 62 |
+
public function toOptionArray()
|
| 63 |
+
{
|
| 64 |
+
$values = array_map(function ($val) {
|
| 65 |
+
return array(
|
| 66 |
+
'value' => $val,
|
| 67 |
+
'label' => $val
|
| 68 |
+
);
|
| 69 |
+
}, $this->themes);
|
| 70 |
+
|
| 71 |
+
return $values;
|
| 72 |
+
}
|
| 73 |
+
}
|
app/code/local/Esites/Editor/etc/config.xml
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<!--
|
| 3 |
+
/**
|
| 4 |
+
* Magento
|
| 5 |
+
*
|
| 6 |
+
* NOTICE OF LICENSE
|
| 7 |
+
*
|
| 8 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
| 9 |
+
* that is bundled with this package in the file LICENSE.txt.
|
| 10 |
+
* It is also available through the world-wide-web at this URL:
|
| 11 |
+
* http://opensource.org/licenses/osl-3.0.php
|
| 12 |
+
* If you did not receive a copy of the license and are unable to
|
| 13 |
+
* obtain it through the world-wide-web, please send an email
|
| 14 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
| 15 |
+
*
|
| 16 |
+
* @category Esites
|
| 17 |
+
* @package Esites_Editor
|
| 18 |
+
* @copyright Copyright (c) 2015 E-sites (http://www.e-sites.nl)
|
| 19 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
| 20 |
+
*/
|
| 21 |
+
-->
|
| 22 |
+
<config>
|
| 23 |
+
<modules>
|
| 24 |
+
<Esites_Editor>
|
| 25 |
+
<version>0.1.0</version>
|
| 26 |
+
</Esites_Editor>
|
| 27 |
+
</modules>
|
| 28 |
+
|
| 29 |
+
<global>
|
| 30 |
+
<models>
|
| 31 |
+
<editor>
|
| 32 |
+
<class>Esites_Editor_Model</class>
|
| 33 |
+
</editor>
|
| 34 |
+
</models>
|
| 35 |
+
<helpers>
|
| 36 |
+
<editor>
|
| 37 |
+
<class>Esites_Editor_Helper</class>
|
| 38 |
+
</editor>
|
| 39 |
+
</helpers>
|
| 40 |
+
</global>
|
| 41 |
+
|
| 42 |
+
<default>
|
| 43 |
+
<editor>
|
| 44 |
+
<general>
|
| 45 |
+
<enabled>0</enabled>
|
| 46 |
+
</general>
|
| 47 |
+
<prefs>
|
| 48 |
+
<keymap>default</keymap>
|
| 49 |
+
<emmet>1</emmet>
|
| 50 |
+
<activeLine>1</activeLine>
|
| 51 |
+
<codeFolding>0</codeFolding>
|
| 52 |
+
<indentUnit>4</indentUnit>
|
| 53 |
+
<lineWrapping>1</lineWrapping>
|
| 54 |
+
<matchTags>1</matchTags>
|
| 55 |
+
<matchHighlight>0</matchHighlight>
|
| 56 |
+
<closeTags>1</closeTags>
|
| 57 |
+
<search>1</search>
|
| 58 |
+
</prefs>
|
| 59 |
+
<appearance>
|
| 60 |
+
<theme>default</theme>
|
| 61 |
+
<fontSize>12</fontSize>
|
| 62 |
+
<autoFormat>1</autoFormat>
|
| 63 |
+
</appearance>
|
| 64 |
+
</editor>
|
| 65 |
+
</default>
|
| 66 |
+
|
| 67 |
+
<adminhtml>
|
| 68 |
+
<events>
|
| 69 |
+
<cms_wysiwyg_config_prepare>
|
| 70 |
+
<observers>
|
| 71 |
+
<wysiwyg_observer>
|
| 72 |
+
<type>singleton</type>
|
| 73 |
+
<class>editor/observer</class>
|
| 74 |
+
<method>prepareWidgetsPluginConfig</method>
|
| 75 |
+
</wysiwyg_observer>
|
| 76 |
+
</observers>
|
| 77 |
+
</cms_wysiwyg_config_prepare>
|
| 78 |
+
</events>
|
| 79 |
+
<acl>
|
| 80 |
+
<resources>
|
| 81 |
+
<all>
|
| 82 |
+
<title>Allow Everything</title>
|
| 83 |
+
</all>
|
| 84 |
+
<admin>
|
| 85 |
+
<children>
|
| 86 |
+
<system>
|
| 87 |
+
<children>
|
| 88 |
+
<config>
|
| 89 |
+
<children>
|
| 90 |
+
<editor>
|
| 91 |
+
<title>E-sites - All</title>
|
| 92 |
+
</editor>
|
| 93 |
+
</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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<!--
|
| 3 |
+
/**
|
| 4 |
+
* Magento
|
| 5 |
+
*
|
| 6 |
+
* NOTICE OF LICENSE
|
| 7 |
+
*
|
| 8 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
| 9 |
+
* that is bundled with this package in the file LICENSE.txt.
|
| 10 |
+
* It is also available through the world-wide-web at this URL:
|
| 11 |
+
* http://opensource.org/licenses/osl-3.0.php
|
| 12 |
+
* If you did not receive a copy of the license and are unable to
|
| 13 |
+
* obtain it through the world-wide-web, please send an email
|
| 14 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
| 15 |
+
*
|
| 16 |
+
* @category Esites
|
| 17 |
+
* @package Esites_Editor
|
| 18 |
+
* @copyright Copyright (c) 2015 E-sites (http://www.e-sites.nl)
|
| 19 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
| 20 |
+
*/
|
| 21 |
+
-->
|
| 22 |
+
<config>
|
| 23 |
+
<tabs>
|
| 24 |
+
<esites translate="label" module="editor">
|
| 25 |
+
<label><![CDATA[<img width="14" style="vertical-align:middle;display:inline-block;" src="http://frontend.e-sites.nl/img/esites-symbol.png" alt="" border="0"> E-sites]]></label>
|
| 26 |
+
<sort_order>1000</sort_order>
|
| 27 |
+
</esites>
|
| 28 |
+
</tabs>
|
| 29 |
+
<sections>
|
| 30 |
+
<editor translate="label" module="editor">
|
| 31 |
+
<label>Advanced HTML Editor</label>
|
| 32 |
+
<tab>esites</tab>
|
| 33 |
+
<frontend_type>text</frontend_type>
|
| 34 |
+
<sort_order>10</sort_order>
|
| 35 |
+
<show_in_default>1</show_in_default>
|
| 36 |
+
<show_in_website>1</show_in_website>
|
| 37 |
+
<show_in_store>1</show_in_store>
|
| 38 |
+
<groups>
|
| 39 |
+
<general translate="label" module="editor">
|
| 40 |
+
<label>General</label>
|
| 41 |
+
<sort_order>1</sort_order>
|
| 42 |
+
<show_in_default>1</show_in_default>
|
| 43 |
+
<show_in_website>1</show_in_website>
|
| 44 |
+
<show_in_store>1</show_in_store>
|
| 45 |
+
<fields>
|
| 46 |
+
<enabled translate="label">
|
| 47 |
+
<label>Enable</label>
|
| 48 |
+
<frontend_type>select</frontend_type>
|
| 49 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 50 |
+
<sort_order>0</sort_order>
|
| 51 |
+
<show_in_default>1</show_in_default>
|
| 52 |
+
<show_in_website>1</show_in_website>
|
| 53 |
+
<show_in_store>0</show_in_store>
|
| 54 |
+
<comment><![CDATA[By enabling this feature a more advanced HTML editor, based on <a href="http://codemirror.net/" target="_blank">CodeMirror</a>, will appear]]></comment>
|
| 55 |
+
</enabled>
|
| 56 |
+
</fields>
|
| 57 |
+
</general>
|
| 58 |
+
<prefs translate="label" module="editor">
|
| 59 |
+
<label>Preferences</label>
|
| 60 |
+
<sort_order>2</sort_order>
|
| 61 |
+
<show_in_default>1</show_in_default>
|
| 62 |
+
<show_in_website>1</show_in_website>
|
| 63 |
+
<show_in_store>1</show_in_store>
|
| 64 |
+
<fields>
|
| 65 |
+
<codeFolding>
|
| 66 |
+
<label>Code folding</label>
|
| 67 |
+
<frontend_type>select</frontend_type>
|
| 68 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 69 |
+
<sort_order>0</sort_order>
|
| 70 |
+
<show_in_default>1</show_in_default>
|
| 71 |
+
<show_in_website>1</show_in_website>
|
| 72 |
+
<show_in_store>0</show_in_store>
|
| 73 |
+
</codeFolding>
|
| 74 |
+
<emmet translate="label">
|
| 75 |
+
<label>Emmet plugin</label>
|
| 76 |
+
<frontend_type>select</frontend_type>
|
| 77 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 78 |
+
<sort_order>0</sort_order>
|
| 79 |
+
<show_in_default>1</show_in_default>
|
| 80 |
+
<show_in_website>1</show_in_website>
|
| 81 |
+
<show_in_store>0</show_in_store>
|
| 82 |
+
<comment><![CDATA[By enabling this plugin the HTML editor will be extended with <a href="https://github.com/emmetio/codemirror" target="_blank">Emmet</a> functionality]]></comment>
|
| 83 |
+
</emmet>
|
| 84 |
+
<activeLine translate="label">
|
| 85 |
+
<label>Active line</label>
|
| 86 |
+
<frontend_type>select</frontend_type>
|
| 87 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 88 |
+
<sort_order>0</sort_order>
|
| 89 |
+
<show_in_default>1</show_in_default>
|
| 90 |
+
<show_in_website>1</show_in_website>
|
| 91 |
+
<show_in_store>0</show_in_store>
|
| 92 |
+
<comment><![CDATA[Styles the current cursor line]]></comment>
|
| 93 |
+
</activeLine>
|
| 94 |
+
<keymap>
|
| 95 |
+
<label>Keymap</label>
|
| 96 |
+
<frontend_type>select</frontend_type>
|
| 97 |
+
<source_model>editor/system_config_source_keymap_values</source_model>
|
| 98 |
+
<sort_order>1</sort_order>
|
| 99 |
+
<show_in_default>1</show_in_default>
|
| 100 |
+
<show_in_website>1</show_in_website>
|
| 101 |
+
<show_in_store>0</show_in_store>
|
| 102 |
+
<comment><![CDATA[Key maps are ways to associate keys with functionality.]]></comment>
|
| 103 |
+
</keymap>
|
| 104 |
+
<indentUnit>
|
| 105 |
+
<label>Indent unit</label>
|
| 106 |
+
<frontend_type>select</frontend_type>
|
| 107 |
+
<source_model>editor/system_config_source_indentunit_values</source_model>
|
| 108 |
+
<sort_order>1</sort_order>
|
| 109 |
+
<show_in_default>1</show_in_default>
|
| 110 |
+
<show_in_website>1</show_in_website>
|
| 111 |
+
<show_in_store>0</show_in_store>
|
| 112 |
+
<comment><![CDATA[How many spaces a block should be indented.]]></comment>
|
| 113 |
+
</indentUnit>
|
| 114 |
+
<lineWrapping>
|
| 115 |
+
<label>Line wrapping</label>
|
| 116 |
+
<frontend_type>select</frontend_type>
|
| 117 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 118 |
+
<sort_order>3</sort_order>
|
| 119 |
+
<show_in_default>1</show_in_default>
|
| 120 |
+
<show_in_website>1</show_in_website>
|
| 121 |
+
<show_in_store>0</show_in_store>
|
| 122 |
+
<comment><![CDATA[Whether to show line numbers to the left of the editor.]]></comment>
|
| 123 |
+
</lineWrapping>
|
| 124 |
+
<matchTags>
|
| 125 |
+
<label>Match tags</label>
|
| 126 |
+
<frontend_type>select</frontend_type>
|
| 127 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 128 |
+
<sort_order>4</sort_order>
|
| 129 |
+
<show_in_default>1</show_in_default>
|
| 130 |
+
<show_in_website>1</show_in_website>
|
| 131 |
+
<show_in_store>0</show_in_store>
|
| 132 |
+
<comment><![CDATA[Will cause HTML tags around the cursor to be highlighted]]></comment>
|
| 133 |
+
</matchTags>
|
| 134 |
+
<matchHighlight>
|
| 135 |
+
<label>Match highlight</label>
|
| 136 |
+
<frontend_type>select</frontend_type>
|
| 137 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 138 |
+
<sort_order>4</sort_order>
|
| 139 |
+
<show_in_default>1</show_in_default>
|
| 140 |
+
<show_in_website>1</show_in_website>
|
| 141 |
+
<show_in_store>0</show_in_store>
|
| 142 |
+
<comment><![CDATA[Search and highlight occurences of the selected text]]></comment>
|
| 143 |
+
</matchHighlight>
|
| 144 |
+
<closeTags>
|
| 145 |
+
<label>Close tags</label>
|
| 146 |
+
<frontend_type>select</frontend_type>
|
| 147 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 148 |
+
<sort_order>4</sort_order>
|
| 149 |
+
<show_in_default>1</show_in_default>
|
| 150 |
+
<show_in_website>1</show_in_website>
|
| 151 |
+
<show_in_store>0</show_in_store>
|
| 152 |
+
<comment><![CDATA[Will auto-close HTML tags]]></comment>
|
| 153 |
+
</closeTags>
|
| 154 |
+
<search>
|
| 155 |
+
<label>Search</label>
|
| 156 |
+
<frontend_type>select</frontend_type>
|
| 157 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 158 |
+
<sort_order>5</sort_order>
|
| 159 |
+
<show_in_default>1</show_in_default>
|
| 160 |
+
<show_in_website>1</show_in_website>
|
| 161 |
+
<show_in_store>0</show_in_store>
|
| 162 |
+
<comment><![CDATA[Provides a dialog to search through the code]]></comment>
|
| 163 |
+
</search>
|
| 164 |
+
</fields>
|
| 165 |
+
</prefs>
|
| 166 |
+
<appearance translate="label" module="editor">
|
| 167 |
+
<label>Appearance</label>
|
| 168 |
+
<sort_order>3</sort_order>
|
| 169 |
+
<show_in_default>1</show_in_default>
|
| 170 |
+
<show_in_website>1</show_in_website>
|
| 171 |
+
<show_in_store>1</show_in_store>
|
| 172 |
+
<fields>
|
| 173 |
+
<fontSize translate="label">
|
| 174 |
+
<label>Font size</label>
|
| 175 |
+
<frontend_type>text</frontend_type>
|
| 176 |
+
<sort_order>0</sort_order>
|
| 177 |
+
<show_in_default>1</show_in_default>
|
| 178 |
+
<show_in_website>1</show_in_website>
|
| 179 |
+
<show_in_store>0</show_in_store>
|
| 180 |
+
<comment><![CDATA[Font size of the editor (in pixels)]]></comment>
|
| 181 |
+
</fontSize>
|
| 182 |
+
<theme translate="label">
|
| 183 |
+
<label>Theme</label>
|
| 184 |
+
<frontend_type>select</frontend_type>
|
| 185 |
+
<source_model>editor/system_config_source_theme_values</source_model>
|
| 186 |
+
<sort_order>1</sort_order>
|
| 187 |
+
<show_in_default>1</show_in_default>
|
| 188 |
+
<show_in_website>1</show_in_website>
|
| 189 |
+
<show_in_store>0</show_in_store>
|
| 190 |
+
<comment><![CDATA[<a href="https://codemirror.net/demo/theme.html" target="_blank">Click here for a demo of all available themes</a>]]></comment>
|
| 191 |
+
</theme>
|
| 192 |
+
<autoFormat translate="label">
|
| 193 |
+
<label>Auto format</label>
|
| 194 |
+
<frontend_type>select</frontend_type>
|
| 195 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 196 |
+
<sort_order>1</sort_order>
|
| 197 |
+
<show_in_default>1</show_in_default>
|
| 198 |
+
<show_in_website>1</show_in_website>
|
| 199 |
+
<show_in_store>0</show_in_store>
|
| 200 |
+
<comment><![CDATA[Whether the HTML code should be auto formatted or not]]></comment>
|
| 201 |
+
</autoFormat>
|
| 202 |
+
</fields>
|
| 203 |
+
</appearance>
|
| 204 |
+
</groups>
|
| 205 |
+
</editor>
|
| 206 |
+
</sections>
|
| 207 |
+
</config>
|
app/etc/modules/Esites_Editor.xml
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<!--
|
| 3 |
+
/**
|
| 4 |
+
* Magento
|
| 5 |
+
*
|
| 6 |
+
* NOTICE OF LICENSE
|
| 7 |
+
*
|
| 8 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
| 9 |
+
* that is bundled with this package in the file LICENSE.txt.
|
| 10 |
+
* It is also available through the world-wide-web at this URL:
|
| 11 |
+
* http://opensource.org/licenses/osl-3.0.php
|
| 12 |
+
* If you did not receive a copy of the license and are unable to
|
| 13 |
+
* obtain it through the world-wide-web, please send an email
|
| 14 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
| 15 |
+
*
|
| 16 |
+
* @category Esites
|
| 17 |
+
* @package Esites_Editor
|
| 18 |
+
* @copyright Copyright (c) 2015 E-sites (http://www.e-sites.nl)
|
| 19 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
| 20 |
+
*/
|
| 21 |
+
-->
|
| 22 |
+
<config>
|
| 23 |
+
<modules>
|
| 24 |
+
<Esites_Editor>
|
| 25 |
+
<active>true</active>
|
| 26 |
+
<codePool>local</codePool>
|
| 27 |
+
</Esites_Editor>
|
| 28 |
+
</modules>
|
| 29 |
+
</config>
|
js/tiny_mce/plugins/esites_editor/.DS_Store
ADDED
|
Binary file
|
js/tiny_mce/plugins/esites_editor/css/styles.css
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Basic styling and extending CodeMirror's default CSS
|
| 3 |
+
*/
|
| 4 |
+
|
| 5 |
+
textarea {
|
| 6 |
+
opacity: 0;
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
.CodeMirror {
|
| 10 |
+
font-size: 12px;
|
| 11 |
+
font-family: 'Source Code Pro', Menlo, Monaco, consolas, monospace;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
.CodeMirror-focused .cm-matchhighlight {
|
| 15 |
+
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAFklEQVQI12NgYGBgkKzc8x9CMDAwAAAmhwSbidEoSQAAAABJRU5ErkJggg==);
|
| 16 |
+
background-position: bottom;
|
| 17 |
+
background-repeat: repeat-x;
|
| 18 |
+
}
|
js/tiny_mce/plugins/esites_editor/esites_editor.html
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="utf-8">
|
| 5 |
+
<title>Advanced HTML Editor</title>
|
| 6 |
+
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Source+Code+Pro:400,700">
|
| 7 |
+
<link rel="stylesheet" href="js/vendor/codemirror/lib/codemirror.css">
|
| 8 |
+
<link rel="stylesheet" href="css/styles.css">
|
| 9 |
+
</head>
|
| 10 |
+
<body>
|
| 11 |
+
<form name="source" id="form-editor">
|
| 12 |
+
<textarea name="htmlSource" id="htmlSource" rows="15" cols="100" dir="ltr"></textarea>
|
| 13 |
+
<div class="mceActionPanel">
|
| 14 |
+
<input type="submit" role="button" name="insert" value="{#update}" id="insert">
|
| 15 |
+
<input type="button" role="button" name="cancel" value="{#cancel}" id="cancel">
|
| 16 |
+
</div>
|
| 17 |
+
</form>
|
| 18 |
+
<script src="js/vendor/requirejs/require.min.js"></script>
|
| 19 |
+
<script src="../../tiny_mce_popup.js"></script>
|
| 20 |
+
<script>
|
| 21 |
+
tinyMCEPopup.onInit.add(function () {
|
| 22 |
+
requirejs(['js/app'])
|
| 23 |
+
});
|
| 24 |
+
</script>
|
| 25 |
+
</body>
|
| 26 |
+
</html>
|
js/tiny_mce/plugins/esites_editor/esites_editor_plugin.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
| 1 |
+
!function(){"use strict";var i,e="esites_editor",t=wysiwygpage_content.config.plugins,n=tinymce.each;tinymce.PluginManager.requireLangPack(e),tinymce.create("tinymce.plugins.EsitesEditorPlugin",{defaults:{emmet:!1,theme:"default",codeFolding:!1},settings:{},init:function(o,d){i=this,i.editor=o,i.url=d,n(t,function(t){t.name===e&&(i.settings=tinymce.extend(i.defaults,t.config))}),i.editor.addCommand("mceEsitesEditor",i.showSourceEditor),i.editor.addButton(e,{image:i.url+"/img/icon-esites-editor.png",title:e+".editor_button",cmd:"mceEsitesEditor"})},showSourceEditor:function(){i.editor.windowManager.open({width:i.editor.getParam("code_dialog_width",900),height:i.editor.getParam("code_dialog_height",600),inline:!0,maximizable:!0,file:i.url+"/esites_editor.html"},{plugin_url:i.url})}}),tinymce.PluginManager.add("esites_editor",tinymce.plugins.EsitesEditorPlugin)}();
|
js/tiny_mce/plugins/esites_editor/esites_editor_plugin_src.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Magento Advanced HTML Editor
|
| 3 |
+
* This is the TinyMCE plugin of the Magento extension that incorporates the CodeMirror library
|
| 4 |
+
*
|
| 5 |
+
* @author : Boye Oomens <boye@e-sites.nl>
|
| 6 |
+
* @version : 0.1.0
|
| 7 |
+
* @license : MIT
|
| 8 |
+
* @see : http://github.e-sites.nl/magento-advanced-html-editor/
|
| 9 |
+
* @see : http://codemirror.net/
|
| 10 |
+
* @see : http://emmet.io/
|
| 11 |
+
*/
|
| 12 |
+
|
| 13 |
+
/*global tinymce, wysiwygpage_content */
|
| 14 |
+
(function () {
|
| 15 |
+
|
| 16 |
+
'use strict';
|
| 17 |
+
|
| 18 |
+
var pluginName = 'esites_editor',
|
| 19 |
+
/*jshint camelcase:false */
|
| 20 |
+
plugins = wysiwygpage_content.config.plugins,
|
| 21 |
+
each = tinymce.each,
|
| 22 |
+
tiny;
|
| 23 |
+
|
| 24 |
+
tinymce.PluginManager.requireLangPack(pluginName);
|
| 25 |
+
|
| 26 |
+
tinymce.create('tinymce.plugins.EsitesEditorPlugin', {
|
| 27 |
+
|
| 28 |
+
/**
|
| 29 |
+
* Default plugin configuration
|
| 30 |
+
*
|
| 31 |
+
* @type {Object}
|
| 32 |
+
*/
|
| 33 |
+
defaults: {
|
| 34 |
+
emmet: false,
|
| 35 |
+
theme: 'default',
|
| 36 |
+
codeFolding: false
|
| 37 |
+
},
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* Plugin settings
|
| 41 |
+
* Will be populated with the Magento config values
|
| 42 |
+
*
|
| 43 |
+
* @type {Object}
|
| 44 |
+
*/
|
| 45 |
+
settings: {},
|
| 46 |
+
|
| 47 |
+
/**
|
| 48 |
+
* Main init method that kickstarts all plugin logic
|
| 49 |
+
*
|
| 50 |
+
* @param {Object} ed editor instance
|
| 51 |
+
* @param {String} url plugin url
|
| 52 |
+
*/
|
| 53 |
+
init: function (ed, url) {
|
| 54 |
+
tiny = this;
|
| 55 |
+
tiny.editor = ed;
|
| 56 |
+
tiny.url = url;
|
| 57 |
+
|
| 58 |
+
// Loop through the available plugins in `wysiwygpage_content`
|
| 59 |
+
// to extract and extend the config options from the Magento back-end
|
| 60 |
+
// It feels a bit hacky, I am not sure if there is better way to do this...
|
| 61 |
+
each(plugins, function (el) {
|
| 62 |
+
if ( el.name === pluginName ) {
|
| 63 |
+
tiny.settings = tinymce.extend(tiny.defaults, el.config);
|
| 64 |
+
}
|
| 65 |
+
});
|
| 66 |
+
|
| 67 |
+
// Finally, register the command and add the button
|
| 68 |
+
tiny.editor.addCommand('mceEsitesEditor', tiny.showSourceEditor);
|
| 69 |
+
tiny.editor.addButton(pluginName, {
|
| 70 |
+
image: tiny.url + '/img/icon-esites-editor.png',
|
| 71 |
+
title: pluginName + '.editor_button',
|
| 72 |
+
cmd: 'mceEsitesEditor'
|
| 73 |
+
});
|
| 74 |
+
},
|
| 75 |
+
|
| 76 |
+
/**
|
| 77 |
+
* Calls TinyMCE's windowManager to actually open the editor
|
| 78 |
+
*/
|
| 79 |
+
showSourceEditor: function () {
|
| 80 |
+
tiny.editor.windowManager.open({
|
| 81 |
+
width: tiny.editor.getParam('code_dialog_width', 900),
|
| 82 |
+
height: tiny.editor.getParam('code_dialog_height', 600),
|
| 83 |
+
inline: true,
|
| 84 |
+
maximizable: true,
|
| 85 |
+
file: tiny.url + '/esites_editor.html'
|
| 86 |
+
}, {
|
| 87 |
+
plugin_url : tiny.url
|
| 88 |
+
});
|
| 89 |
+
}
|
| 90 |
+
});
|
| 91 |
+
|
| 92 |
+
// Register plugin
|
| 93 |
+
tinymce.PluginManager.add('esites_editor', tinymce.plugins.EsitesEditorPlugin);
|
| 94 |
+
}());
|
js/tiny_mce/plugins/esites_editor/img/icon-esites-editor.png
ADDED
|
Binary file
|
js/tiny_mce/plugins/esites_editor/js/app.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* App entrypoint that handles some basic config and loads the main module
|
| 3 |
+
*
|
| 4 |
+
* @author Boye Oomens <boye@e-sites.nl>
|
| 5 |
+
*/
|
| 6 |
+
|
| 7 |
+
/*global requirejs */
|
| 8 |
+
(function (requirejs) {
|
| 9 |
+
|
| 10 |
+
'use strict';
|
| 11 |
+
|
| 12 |
+
requirejs.config({
|
| 13 |
+
baseUrl: 'js/vendor',
|
| 14 |
+
map: {
|
| 15 |
+
'*': {
|
| 16 |
+
'css': 'requirejs/css.min'
|
| 17 |
+
}
|
| 18 |
+
},
|
| 19 |
+
paths: {
|
| 20 |
+
app: '../app'
|
| 21 |
+
}
|
| 22 |
+
});
|
| 23 |
+
|
| 24 |
+
requirejs(['app/main']);
|
| 25 |
+
|
| 26 |
+
}(requirejs));
|
js/tiny_mce/plugins/esites_editor/js/app/main.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Main module that incorporates basic editor stuff
|
| 3 |
+
*
|
| 4 |
+
* @author Boye Oomens <boye@e-sites.nl>
|
| 5 |
+
*/
|
| 6 |
+
|
| 7 |
+
/*global requirejs, define, tinymce, tinyMCEPopup */
|
| 8 |
+
(function (document, tinyMCEPopup) {
|
| 9 |
+
|
| 10 |
+
'use strict';
|
| 11 |
+
|
| 12 |
+
/**
|
| 13 |
+
* Reserved for the CodeMirror instance
|
| 14 |
+
*
|
| 15 |
+
* @type {Object}
|
| 16 |
+
*/
|
| 17 |
+
var cm = null;
|
| 18 |
+
|
| 19 |
+
define([
|
| 20 |
+
'../app/var/textarea',
|
| 21 |
+
'../app/var/addons',
|
| 22 |
+
'../app/var/cmOptions',
|
| 23 |
+
'../app/var/plugin',
|
| 24 |
+
'../app/var/deps',
|
| 25 |
+
'../app/module/popup',
|
| 26 |
+
'../app/module/util',
|
| 27 |
+
'../app/module/editor',
|
| 28 |
+
'codemirror/lib/codemirror',
|
| 29 |
+
'codemirror/mode/htmlmixed/htmlmixed',
|
| 30 |
+
'css!codemirror/addon/fold/foldgutter.css',
|
| 31 |
+
'css!codemirror/addon/search/matchesonscrollbar.css',
|
| 32 |
+
'css!codemirror/addon/dialog/dialog.css',
|
| 33 |
+
'css!codemirror/addon/hint/show-hint.css'
|
| 34 |
+
], function (textarea, addons, cmOptions, plugin, deps, popup, util, editor, CodeMirror) {
|
| 35 |
+
|
| 36 |
+
// Expose to global scope (needed for the formatting util)
|
| 37 |
+
window.CodeMirror = CodeMirror;
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* Preps the editor by handling the proper value
|
| 41 |
+
*
|
| 42 |
+
* @private
|
| 43 |
+
*/
|
| 44 |
+
function _prepareEditor() {
|
| 45 |
+
/*jshint camelcase:false */
|
| 46 |
+
textarea.value = tinyMCEPopup.editor.getContent({source_view : true});
|
| 47 |
+
|
| 48 |
+
// Set custom font-size if it differs from the default value
|
| 49 |
+
if ( plugin.settings.fontSize !== '12' ) {
|
| 50 |
+
util.addCSS('.CodeMirror {font-size: ' + plugin.settings.fontSize + 'px}');
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
// Resizes the dialog to the inner size of the window.
|
| 54 |
+
// This is needed since various browsers have different border sizes on windows.
|
| 55 |
+
tinyMCEPopup.resizeToInnerSize();
|
| 56 |
+
popup.resize();
|
| 57 |
+
|
| 58 |
+
// Load custom theme
|
| 59 |
+
if ( plugin.settings.theme !== 'default' ) {
|
| 60 |
+
requirejs(['css!codemirror/theme/' + plugin.settings.theme + '.css']);
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
// Determine what addons to load
|
| 64 |
+
tinymce.each(plugin.settings, function (value, setting) {
|
| 65 |
+
if ( addons.hasOwnProperty(setting) && !!value ) {
|
| 66 |
+
deps = deps.concat(addons[setting].deps);
|
| 67 |
+
cmOptions = tinymce.extend(cmOptions, addons[setting].options);
|
| 68 |
+
}
|
| 69 |
+
});
|
| 70 |
+
|
| 71 |
+
// Load all dependencies and initialize CodeMirror
|
| 72 |
+
requirejs(deps, _initCodeMirror);
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
/**
|
| 76 |
+
* Initializes CodeMirror and some related actions
|
| 77 |
+
*
|
| 78 |
+
* @private
|
| 79 |
+
*/
|
| 80 |
+
function _initCodeMirror() {
|
| 81 |
+
cm = CodeMirror.fromTextArea(textarea, cmOptions);
|
| 82 |
+
cm.setSize(null, tinyMCEPopup.dom.getViewPort(window).h - 65);
|
| 83 |
+
|
| 84 |
+
// Auto-format code
|
| 85 |
+
if ( plugin.settings.autoFormat ) {
|
| 86 |
+
editor.formatCode(cm);
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
// Load Emmet separately (if necessary)
|
| 90 |
+
if ( plugin.settings.emmet ) {
|
| 91 |
+
requirejs(['emmet/emmet'], function (emmetCodeMirror) {
|
| 92 |
+
emmetCodeMirror(cm);
|
| 93 |
+
});
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
// Handle a few basic editor interactions
|
| 97 |
+
tinymce.DOM.bind(window, 'resize', popup.resize);
|
| 98 |
+
tinymce.DOM.bind(util.getElem('form-editor'), 'submit', util.proxy(popup.save, cm));
|
| 99 |
+
tinymce.DOM.bind(util.getElem('cancel'), 'click', popup.close);
|
| 100 |
+
|
| 101 |
+
cm.focus();
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
_prepareEditor();
|
| 105 |
+
});
|
| 106 |
+
|
| 107 |
+
})(document, tinyMCEPopup);
|
js/tiny_mce/plugins/esites_editor/js/app/module/editor.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
define([
|
| 2 |
+
'codemirror/lib/codemirror'
|
| 3 |
+
], function (CodeMirror) {
|
| 4 |
+
return {
|
| 5 |
+
|
| 6 |
+
/**
|
| 7 |
+
* Returns the selected range of the give editor instance
|
| 8 |
+
*
|
| 9 |
+
* @param {Object} editor CodeMirror instance
|
| 10 |
+
* @return {Object}
|
| 11 |
+
*/
|
| 12 |
+
getSelectedRange: function (editor) {
|
| 13 |
+
return {
|
| 14 |
+
from: editor.getCursor(true),
|
| 15 |
+
to: editor.getCursor(false)
|
| 16 |
+
};
|
| 17 |
+
},
|
| 18 |
+
|
| 19 |
+
/**
|
| 20 |
+
* Handles all logic that's needed for code formatting
|
| 21 |
+
*
|
| 22 |
+
* @param {Object} editor CodeMirror instance
|
| 23 |
+
*/
|
| 24 |
+
formatCode: function (editor) {
|
| 25 |
+
var range, off,
|
| 26 |
+
charWidth = editor.defaultCharWidth();
|
| 27 |
+
basePadding = 4;
|
| 28 |
+
|
| 29 |
+
CodeMirror.commands['selectAll'](editor);
|
| 30 |
+
|
| 31 |
+
range = this.getSelectedRange(editor);
|
| 32 |
+
|
| 33 |
+
editor.autoFormatRange(range.from, range.to);
|
| 34 |
+
editor.scrollTo(0,0);
|
| 35 |
+
editor.setCursor(0);
|
| 36 |
+
|
| 37 |
+
editor.on('renderLine', function (editor, line, elt) {
|
| 38 |
+
off = CodeMirror.countColumn(line.text, null, editor.getOption('tabSize')) * charWidth;
|
| 39 |
+
elt.style.textIndent = '-' + off + 'px';
|
| 40 |
+
elt.style.paddingLeft = (basePadding + off) + 'px';
|
| 41 |
+
});
|
| 42 |
+
|
| 43 |
+
editor.refresh();
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/app/module/popup.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
(function (tinyMCEPopup) {
|
| 2 |
+
|
| 3 |
+
'use strict';
|
| 4 |
+
|
| 5 |
+
define(['../var/textarea'], function (textarea) {
|
| 6 |
+
return {
|
| 7 |
+
|
| 8 |
+
/**
|
| 9 |
+
* Resizes the editor
|
| 10 |
+
*/
|
| 11 |
+
resize: function () {
|
| 12 |
+
var vp = tinyMCEPopup.dom.getViewPort(window);
|
| 13 |
+
|
| 14 |
+
if ( textarea ) {
|
| 15 |
+
textarea.style.height = (vp.h - 65) + 'px';
|
| 16 |
+
}
|
| 17 |
+
},
|
| 18 |
+
|
| 19 |
+
/**
|
| 20 |
+
* Closes the popup
|
| 21 |
+
*
|
| 22 |
+
* @return {Boolean}
|
| 23 |
+
*/
|
| 24 |
+
close: function () {
|
| 25 |
+
tinyMCEPopup.close();
|
| 26 |
+
return false;
|
| 27 |
+
},
|
| 28 |
+
|
| 29 |
+
/**
|
| 30 |
+
* Saves the actual content
|
| 31 |
+
*
|
| 32 |
+
* @return {Boolean}
|
| 33 |
+
*/
|
| 34 |
+
save: function () {
|
| 35 |
+
tinyMCEPopup.editor.setContent(this.getValue(), {source_view: true});
|
| 36 |
+
tinyMCEPopup.close();
|
| 37 |
+
return false;
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
});
|
| 41 |
+
|
| 42 |
+
}(tinyMCEPopup));
|
js/tiny_mce/plugins/esites_editor/js/app/module/util.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
define(function () {
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Small collection of helper utilities
|
| 5 |
+
*
|
| 6 |
+
* @type {Object}
|
| 7 |
+
*/
|
| 8 |
+
var util = {
|
| 9 |
+
|
| 10 |
+
/**
|
| 11 |
+
* Small wrapper around `document.getElementById`
|
| 12 |
+
*
|
| 13 |
+
* @param {String} id
|
| 14 |
+
* @return {Object}
|
| 15 |
+
*/
|
| 16 |
+
getElem: function (id) {
|
| 17 |
+
return document.getElementById(id);
|
| 18 |
+
},
|
| 19 |
+
|
| 20 |
+
/**
|
| 21 |
+
* Adds the given CSS to the `<head>`
|
| 22 |
+
*
|
| 23 |
+
* @param {String} css
|
| 24 |
+
*/
|
| 25 |
+
addCSS: function (css) {
|
| 26 |
+
var head = document.getElementsByTagName('head')[0],
|
| 27 |
+
s = document.createElement('style');
|
| 28 |
+
|
| 29 |
+
if ( s.styleSheet ) {
|
| 30 |
+
s.styleSheet.cssText = css;
|
| 31 |
+
} else {
|
| 32 |
+
s.appendChild(document.createTextNode(css));
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
head.appendChild(s);
|
| 36 |
+
},
|
| 37 |
+
|
| 38 |
+
/**
|
| 39 |
+
* Whether the given object is a function
|
| 40 |
+
*
|
| 41 |
+
* @param {Mixed} obj
|
| 42 |
+
* @return {Boolean}
|
| 43 |
+
*/
|
| 44 |
+
isFunction: function (obj) {
|
| 45 |
+
return 'function' === typeof obj;
|
| 46 |
+
},
|
| 47 |
+
|
| 48 |
+
/**
|
| 49 |
+
* Bind a function to a context
|
| 50 |
+
* Courtesy of jQuery
|
| 51 |
+
*
|
| 52 |
+
* @param {Function} fn
|
| 53 |
+
* @param {Object} context
|
| 54 |
+
* @return {Function}
|
| 55 |
+
*/
|
| 56 |
+
proxy: function (fn, context) {
|
| 57 |
+
var slice = [].slice,
|
| 58 |
+
tmp, args, proxy;
|
| 59 |
+
|
| 60 |
+
if ( typeof context === 'string' ) {
|
| 61 |
+
tmp = fn[ context ];
|
| 62 |
+
context = fn;
|
| 63 |
+
fn = tmp;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
// Quick check to determine if target is callable, in the spec
|
| 67 |
+
// this throws a TypeError, but we will just return undefined.
|
| 68 |
+
if ( !util.isFunction( fn ) ) {
|
| 69 |
+
return undefined;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
// Simulated bind
|
| 73 |
+
args = slice.call(arguments, 2);
|
| 74 |
+
|
| 75 |
+
proxy = function () {
|
| 76 |
+
return fn.apply(context || this, args.concat(slice.call(arguments)));
|
| 77 |
+
};
|
| 78 |
+
|
| 79 |
+
return proxy;
|
| 80 |
+
}
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
return util;
|
| 84 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/app/var/addons.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
define(function () {
|
| 2 |
+
return {
|
| 3 |
+
'activeLine': {
|
| 4 |
+
deps: [
|
| 5 |
+
'codemirror/addon/selection/active-line'
|
| 6 |
+
],
|
| 7 |
+
options: {
|
| 8 |
+
styleActiveLine: true
|
| 9 |
+
}
|
| 10 |
+
},
|
| 11 |
+
'codeFolding': {
|
| 12 |
+
deps: [
|
| 13 |
+
'codemirror/addon/fold/foldcode',
|
| 14 |
+
'codemirror/addon/fold/foldgutter',
|
| 15 |
+
'codemirror/addon/fold/xml-fold'
|
| 16 |
+
],
|
| 17 |
+
options: {
|
| 18 |
+
foldGutter: true,
|
| 19 |
+
gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter']
|
| 20 |
+
}
|
| 21 |
+
},
|
| 22 |
+
'lineWrapping': {
|
| 23 |
+
deps: [
|
| 24 |
+
'codemirror/addon/wrap/hardwrap'
|
| 25 |
+
],
|
| 26 |
+
options: {
|
| 27 |
+
lineWrapping: true
|
| 28 |
+
}
|
| 29 |
+
},
|
| 30 |
+
'matchHighlight': {
|
| 31 |
+
deps: [
|
| 32 |
+
'codemirror/addon/search/searchcursor',
|
| 33 |
+
'codemirror/addon/search/match-highlighter'
|
| 34 |
+
],
|
| 35 |
+
options: {
|
| 36 |
+
highlightSelectionMatches: {
|
| 37 |
+
showToken: /\w/
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
},
|
| 41 |
+
'matchTags': {
|
| 42 |
+
deps: [
|
| 43 |
+
'codemirror/addon/edit/matchtags'
|
| 44 |
+
],
|
| 45 |
+
options: {
|
| 46 |
+
matchTags: {
|
| 47 |
+
bothTags: true
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
},
|
| 51 |
+
'closeTags': {
|
| 52 |
+
deps: [
|
| 53 |
+
'codemirror/addon/edit/closetag'
|
| 54 |
+
],
|
| 55 |
+
options: {
|
| 56 |
+
autoCloseTags: true
|
| 57 |
+
}
|
| 58 |
+
},
|
| 59 |
+
'search': {
|
| 60 |
+
deps: [
|
| 61 |
+
'codemirror/addon/dialog/dialog',
|
| 62 |
+
'codemirror/addon/search/searchcursor',
|
| 63 |
+
'codemirror/addon/search/search',
|
| 64 |
+
'codemirror/addon/scroll/annotatescrollbar',
|
| 65 |
+
'codemirror/addon/search/matchesonscrollbar'
|
| 66 |
+
]
|
| 67 |
+
}
|
| 68 |
+
};
|
| 69 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/app/var/cmOptions.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
define(['./plugin'], function (plugin) {
|
| 2 |
+
return {
|
| 3 |
+
mode: 'text/html',
|
| 4 |
+
lineNumbers: true,
|
| 5 |
+
indentUnit: plugin.settings.indentUnit,
|
| 6 |
+
theme: plugin.settings.theme,
|
| 7 |
+
showCursorWhenSelecting: true
|
| 8 |
+
};
|
| 9 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/app/var/deps.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
define(function () {
|
| 2 |
+
return ['codemirror/util/formatting'];
|
| 3 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/app/var/plugin.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
define(function () {
|
| 2 |
+
return tinyMCEPopup.editor.plugins.esites_editor;
|
| 3 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/app/var/textarea.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
define([
|
| 2 |
+
'../module/util'
|
| 3 |
+
], function (util) {
|
| 4 |
+
return util.getElem('htmlSource');
|
| 5 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/comment/comment.js
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
"use strict";
|
| 13 |
+
|
| 14 |
+
var noOptions = {};
|
| 15 |
+
var nonWS = /[^\s\u00a0]/;
|
| 16 |
+
var Pos = CodeMirror.Pos;
|
| 17 |
+
|
| 18 |
+
function firstNonWS(str) {
|
| 19 |
+
var found = str.search(nonWS);
|
| 20 |
+
return found == -1 ? 0 : found;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
CodeMirror.commands.toggleComment = function(cm) {
|
| 24 |
+
var minLine = Infinity, ranges = cm.listSelections(), mode = null;
|
| 25 |
+
for (var i = ranges.length - 1; i >= 0; i--) {
|
| 26 |
+
var from = ranges[i].from(), to = ranges[i].to();
|
| 27 |
+
if (from.line >= minLine) continue;
|
| 28 |
+
if (to.line >= minLine) to = Pos(minLine, 0);
|
| 29 |
+
minLine = from.line;
|
| 30 |
+
if (mode == null) {
|
| 31 |
+
if (cm.uncomment(from, to)) mode = "un";
|
| 32 |
+
else { cm.lineComment(from, to); mode = "line"; }
|
| 33 |
+
} else if (mode == "un") {
|
| 34 |
+
cm.uncomment(from, to);
|
| 35 |
+
} else {
|
| 36 |
+
cm.lineComment(from, to);
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
};
|
| 40 |
+
|
| 41 |
+
CodeMirror.defineExtension("lineComment", function(from, to, options) {
|
| 42 |
+
if (!options) options = noOptions;
|
| 43 |
+
var self = this, mode = self.getModeAt(from);
|
| 44 |
+
var commentString = options.lineComment || mode.lineComment;
|
| 45 |
+
if (!commentString) {
|
| 46 |
+
if (options.blockCommentStart || mode.blockCommentStart) {
|
| 47 |
+
options.fullLines = true;
|
| 48 |
+
self.blockComment(from, to, options);
|
| 49 |
+
}
|
| 50 |
+
return;
|
| 51 |
+
}
|
| 52 |
+
var firstLine = self.getLine(from.line);
|
| 53 |
+
if (firstLine == null) return;
|
| 54 |
+
var end = Math.min(to.ch != 0 || to.line == from.line ? to.line + 1 : to.line, self.lastLine() + 1);
|
| 55 |
+
var pad = options.padding == null ? " " : options.padding;
|
| 56 |
+
var blankLines = options.commentBlankLines || from.line == to.line;
|
| 57 |
+
|
| 58 |
+
self.operation(function() {
|
| 59 |
+
if (options.indent) {
|
| 60 |
+
var baseString = firstLine.slice(0, firstNonWS(firstLine));
|
| 61 |
+
for (var i = from.line; i < end; ++i) {
|
| 62 |
+
var line = self.getLine(i), cut = baseString.length;
|
| 63 |
+
if (!blankLines && !nonWS.test(line)) continue;
|
| 64 |
+
if (line.slice(0, cut) != baseString) cut = firstNonWS(line);
|
| 65 |
+
self.replaceRange(baseString + commentString + pad, Pos(i, 0), Pos(i, cut));
|
| 66 |
+
}
|
| 67 |
+
} else {
|
| 68 |
+
for (var i = from.line; i < end; ++i) {
|
| 69 |
+
if (blankLines || nonWS.test(self.getLine(i)))
|
| 70 |
+
self.replaceRange(commentString + pad, Pos(i, 0));
|
| 71 |
+
}
|
| 72 |
+
}
|
| 73 |
+
});
|
| 74 |
+
});
|
| 75 |
+
|
| 76 |
+
CodeMirror.defineExtension("blockComment", function(from, to, options) {
|
| 77 |
+
if (!options) options = noOptions;
|
| 78 |
+
var self = this, mode = self.getModeAt(from);
|
| 79 |
+
var startString = options.blockCommentStart || mode.blockCommentStart;
|
| 80 |
+
var endString = options.blockCommentEnd || mode.blockCommentEnd;
|
| 81 |
+
if (!startString || !endString) {
|
| 82 |
+
if ((options.lineComment || mode.lineComment) && options.fullLines != false)
|
| 83 |
+
self.lineComment(from, to, options);
|
| 84 |
+
return;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
var end = Math.min(to.line, self.lastLine());
|
| 88 |
+
if (end != from.line && to.ch == 0 && nonWS.test(self.getLine(end))) --end;
|
| 89 |
+
|
| 90 |
+
var pad = options.padding == null ? " " : options.padding;
|
| 91 |
+
if (from.line > end) return;
|
| 92 |
+
|
| 93 |
+
self.operation(function() {
|
| 94 |
+
if (options.fullLines != false) {
|
| 95 |
+
var lastLineHasText = nonWS.test(self.getLine(end));
|
| 96 |
+
self.replaceRange(pad + endString, Pos(end));
|
| 97 |
+
self.replaceRange(startString + pad, Pos(from.line, 0));
|
| 98 |
+
var lead = options.blockCommentLead || mode.blockCommentLead;
|
| 99 |
+
if (lead != null) for (var i = from.line + 1; i <= end; ++i)
|
| 100 |
+
if (i != end || lastLineHasText)
|
| 101 |
+
self.replaceRange(lead + pad, Pos(i, 0));
|
| 102 |
+
} else {
|
| 103 |
+
self.replaceRange(endString, to);
|
| 104 |
+
self.replaceRange(startString, from);
|
| 105 |
+
}
|
| 106 |
+
});
|
| 107 |
+
});
|
| 108 |
+
|
| 109 |
+
CodeMirror.defineExtension("uncomment", function(from, to, options) {
|
| 110 |
+
if (!options) options = noOptions;
|
| 111 |
+
var self = this, mode = self.getModeAt(from);
|
| 112 |
+
var end = Math.min(to.ch != 0 || to.line == from.line ? to.line : to.line - 1, self.lastLine()), start = Math.min(from.line, end);
|
| 113 |
+
|
| 114 |
+
// Try finding line comments
|
| 115 |
+
var lineString = options.lineComment || mode.lineComment, lines = [];
|
| 116 |
+
var pad = options.padding == null ? " " : options.padding, didSomething;
|
| 117 |
+
lineComment: {
|
| 118 |
+
if (!lineString) break lineComment;
|
| 119 |
+
for (var i = start; i <= end; ++i) {
|
| 120 |
+
var line = self.getLine(i);
|
| 121 |
+
var found = line.indexOf(lineString);
|
| 122 |
+
if (found > -1 && !/comment/.test(self.getTokenTypeAt(Pos(i, found + 1)))) found = -1;
|
| 123 |
+
if (found == -1 && (i != end || i == start) && nonWS.test(line)) break lineComment;
|
| 124 |
+
if (found > -1 && nonWS.test(line.slice(0, found))) break lineComment;
|
| 125 |
+
lines.push(line);
|
| 126 |
+
}
|
| 127 |
+
self.operation(function() {
|
| 128 |
+
for (var i = start; i <= end; ++i) {
|
| 129 |
+
var line = lines[i - start];
|
| 130 |
+
var pos = line.indexOf(lineString), endPos = pos + lineString.length;
|
| 131 |
+
if (pos < 0) continue;
|
| 132 |
+
if (line.slice(endPos, endPos + pad.length) == pad) endPos += pad.length;
|
| 133 |
+
didSomething = true;
|
| 134 |
+
self.replaceRange("", Pos(i, pos), Pos(i, endPos));
|
| 135 |
+
}
|
| 136 |
+
});
|
| 137 |
+
if (didSomething) return true;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
// Try block comments
|
| 141 |
+
var startString = options.blockCommentStart || mode.blockCommentStart;
|
| 142 |
+
var endString = options.blockCommentEnd || mode.blockCommentEnd;
|
| 143 |
+
if (!startString || !endString) return false;
|
| 144 |
+
var lead = options.blockCommentLead || mode.blockCommentLead;
|
| 145 |
+
var startLine = self.getLine(start), endLine = end == start ? startLine : self.getLine(end);
|
| 146 |
+
var open = startLine.indexOf(startString), close = endLine.lastIndexOf(endString);
|
| 147 |
+
if (close == -1 && start != end) {
|
| 148 |
+
endLine = self.getLine(--end);
|
| 149 |
+
close = endLine.lastIndexOf(endString);
|
| 150 |
+
}
|
| 151 |
+
if (open == -1 || close == -1 ||
|
| 152 |
+
!/comment/.test(self.getTokenTypeAt(Pos(start, open + 1))) ||
|
| 153 |
+
!/comment/.test(self.getTokenTypeAt(Pos(end, close + 1))))
|
| 154 |
+
return false;
|
| 155 |
+
|
| 156 |
+
// Avoid killing block comments completely outside the selection.
|
| 157 |
+
// Positions of the last startString before the start of the selection, and the first endString after it.
|
| 158 |
+
var lastStart = startLine.lastIndexOf(startString, from.ch);
|
| 159 |
+
var firstEnd = lastStart == -1 ? -1 : startLine.slice(0, from.ch).indexOf(endString, lastStart + startString.length);
|
| 160 |
+
if (lastStart != -1 && firstEnd != -1 && firstEnd + endString.length != from.ch) return false;
|
| 161 |
+
// Positions of the first endString after the end of the selection, and the last startString before it.
|
| 162 |
+
firstEnd = endLine.indexOf(endString, to.ch);
|
| 163 |
+
var almostLastStart = endLine.slice(to.ch).lastIndexOf(startString, firstEnd - to.ch);
|
| 164 |
+
lastStart = (firstEnd == -1 || almostLastStart == -1) ? -1 : to.ch + almostLastStart;
|
| 165 |
+
if (firstEnd != -1 && lastStart != -1 && lastStart != to.ch) return false;
|
| 166 |
+
|
| 167 |
+
self.operation(function() {
|
| 168 |
+
self.replaceRange("", Pos(end, close - (pad && endLine.slice(close - pad.length, close) == pad ? pad.length : 0)),
|
| 169 |
+
Pos(end, close + endString.length));
|
| 170 |
+
var openEnd = open + startString.length;
|
| 171 |
+
if (pad && startLine.slice(openEnd, openEnd + pad.length) == pad) openEnd += pad.length;
|
| 172 |
+
self.replaceRange("", Pos(start, open), Pos(start, openEnd));
|
| 173 |
+
if (lead) for (var i = start + 1; i <= end; ++i) {
|
| 174 |
+
var line = self.getLine(i), found = line.indexOf(lead);
|
| 175 |
+
if (found == -1 || nonWS.test(line.slice(0, found))) continue;
|
| 176 |
+
var foundEnd = found + lead.length;
|
| 177 |
+
if (pad && line.slice(foundEnd, foundEnd + pad.length) == pad) foundEnd += pad.length;
|
| 178 |
+
self.replaceRange("", Pos(i, found), Pos(i, foundEnd));
|
| 179 |
+
}
|
| 180 |
+
});
|
| 181 |
+
return true;
|
| 182 |
+
});
|
| 183 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/comment/continuecomment.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
var modes = ["clike", "css", "javascript"];
|
| 13 |
+
|
| 14 |
+
for (var i = 0; i < modes.length; ++i)
|
| 15 |
+
CodeMirror.extendMode(modes[i], {blockCommentContinue: " * "});
|
| 16 |
+
|
| 17 |
+
function continueComment(cm) {
|
| 18 |
+
if (cm.getOption("disableInput")) return CodeMirror.Pass;
|
| 19 |
+
var ranges = cm.listSelections(), mode, inserts = [];
|
| 20 |
+
for (var i = 0; i < ranges.length; i++) {
|
| 21 |
+
var pos = ranges[i].head, token = cm.getTokenAt(pos);
|
| 22 |
+
if (token.type != "comment") return CodeMirror.Pass;
|
| 23 |
+
var modeHere = CodeMirror.innerMode(cm.getMode(), token.state).mode;
|
| 24 |
+
if (!mode) mode = modeHere;
|
| 25 |
+
else if (mode != modeHere) return CodeMirror.Pass;
|
| 26 |
+
|
| 27 |
+
var insert = null;
|
| 28 |
+
if (mode.blockCommentStart && mode.blockCommentContinue) {
|
| 29 |
+
var end = token.string.indexOf(mode.blockCommentEnd);
|
| 30 |
+
var full = cm.getRange(CodeMirror.Pos(pos.line, 0), CodeMirror.Pos(pos.line, token.end)), found;
|
| 31 |
+
if (end != -1 && end == token.string.length - mode.blockCommentEnd.length && pos.ch >= end) {
|
| 32 |
+
// Comment ended, don't continue it
|
| 33 |
+
} else if (token.string.indexOf(mode.blockCommentStart) == 0) {
|
| 34 |
+
insert = full.slice(0, token.start);
|
| 35 |
+
if (!/^\s*$/.test(insert)) {
|
| 36 |
+
insert = "";
|
| 37 |
+
for (var j = 0; j < token.start; ++j) insert += " ";
|
| 38 |
+
}
|
| 39 |
+
} else if ((found = full.indexOf(mode.blockCommentContinue)) != -1 &&
|
| 40 |
+
found + mode.blockCommentContinue.length > token.start &&
|
| 41 |
+
/^\s*$/.test(full.slice(0, found))) {
|
| 42 |
+
insert = full.slice(0, found);
|
| 43 |
+
}
|
| 44 |
+
if (insert != null) insert += mode.blockCommentContinue;
|
| 45 |
+
}
|
| 46 |
+
if (insert == null && mode.lineComment && continueLineCommentEnabled(cm)) {
|
| 47 |
+
var line = cm.getLine(pos.line), found = line.indexOf(mode.lineComment);
|
| 48 |
+
if (found > -1) {
|
| 49 |
+
insert = line.slice(0, found);
|
| 50 |
+
if (/\S/.test(insert)) insert = null;
|
| 51 |
+
else insert += mode.lineComment + line.slice(found + mode.lineComment.length).match(/^\s*/)[0];
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
if (insert == null) return CodeMirror.Pass;
|
| 55 |
+
inserts[i] = "\n" + insert;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
cm.operation(function() {
|
| 59 |
+
for (var i = ranges.length - 1; i >= 0; i--)
|
| 60 |
+
cm.replaceRange(inserts[i], ranges[i].from(), ranges[i].to(), "+insert");
|
| 61 |
+
});
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
function continueLineCommentEnabled(cm) {
|
| 65 |
+
var opt = cm.getOption("continueComments");
|
| 66 |
+
if (opt && typeof opt == "object")
|
| 67 |
+
return opt.continueLineComment !== false;
|
| 68 |
+
return true;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
CodeMirror.defineOption("continueComments", null, function(cm, val, prev) {
|
| 72 |
+
if (prev && prev != CodeMirror.Init)
|
| 73 |
+
cm.removeKeyMap("continueComment");
|
| 74 |
+
if (val) {
|
| 75 |
+
var key = "Enter";
|
| 76 |
+
if (typeof val == "string")
|
| 77 |
+
key = val;
|
| 78 |
+
else if (typeof val == "object" && val.key)
|
| 79 |
+
key = val.key;
|
| 80 |
+
var map = {name: "continueComment"};
|
| 81 |
+
map[key] = continueComment;
|
| 82 |
+
cm.addKeyMap(map);
|
| 83 |
+
}
|
| 84 |
+
});
|
| 85 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/dialog/dialog.css
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.CodeMirror-dialog {
|
| 2 |
+
position: absolute;
|
| 3 |
+
left: 0; right: 0;
|
| 4 |
+
background: inherit;
|
| 5 |
+
z-index: 15;
|
| 6 |
+
padding: .1em .8em;
|
| 7 |
+
overflow: hidden;
|
| 8 |
+
color: inherit;
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
.CodeMirror-dialog-top {
|
| 12 |
+
border-bottom: 1px solid #eee;
|
| 13 |
+
top: 0;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
.CodeMirror-dialog-bottom {
|
| 17 |
+
border-top: 1px solid #eee;
|
| 18 |
+
bottom: 0;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.CodeMirror-dialog input {
|
| 22 |
+
border: none;
|
| 23 |
+
outline: none;
|
| 24 |
+
background: transparent;
|
| 25 |
+
width: 20em;
|
| 26 |
+
color: inherit;
|
| 27 |
+
font-family: monospace;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.CodeMirror-dialog button {
|
| 31 |
+
font-size: 70%;
|
| 32 |
+
}
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/dialog/dialog.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
// Open simple dialogs on top of an editor. Relies on dialog.css.
|
| 5 |
+
|
| 6 |
+
(function(mod) {
|
| 7 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 8 |
+
mod(require("../../lib/codemirror"));
|
| 9 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 10 |
+
define(["../../lib/codemirror"], mod);
|
| 11 |
+
else // Plain browser env
|
| 12 |
+
mod(CodeMirror);
|
| 13 |
+
})(function(CodeMirror) {
|
| 14 |
+
function dialogDiv(cm, template, bottom) {
|
| 15 |
+
var wrap = cm.getWrapperElement();
|
| 16 |
+
var dialog;
|
| 17 |
+
dialog = wrap.appendChild(document.createElement("div"));
|
| 18 |
+
if (bottom)
|
| 19 |
+
dialog.className = "CodeMirror-dialog CodeMirror-dialog-bottom";
|
| 20 |
+
else
|
| 21 |
+
dialog.className = "CodeMirror-dialog CodeMirror-dialog-top";
|
| 22 |
+
|
| 23 |
+
if (typeof template == "string") {
|
| 24 |
+
dialog.innerHTML = template;
|
| 25 |
+
} else { // Assuming it's a detached DOM element.
|
| 26 |
+
dialog.appendChild(template);
|
| 27 |
+
}
|
| 28 |
+
return dialog;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
function closeNotification(cm, newVal) {
|
| 32 |
+
if (cm.state.currentNotificationClose)
|
| 33 |
+
cm.state.currentNotificationClose();
|
| 34 |
+
cm.state.currentNotificationClose = newVal;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
CodeMirror.defineExtension("openDialog", function(template, callback, options) {
|
| 38 |
+
if (!options) options = {};
|
| 39 |
+
|
| 40 |
+
closeNotification(this, null);
|
| 41 |
+
|
| 42 |
+
var dialog = dialogDiv(this, template, options.bottom);
|
| 43 |
+
var closed = false, me = this;
|
| 44 |
+
function close(newVal) {
|
| 45 |
+
if (typeof newVal == 'string') {
|
| 46 |
+
inp.value = newVal;
|
| 47 |
+
} else {
|
| 48 |
+
if (closed) return;
|
| 49 |
+
closed = true;
|
| 50 |
+
dialog.parentNode.removeChild(dialog);
|
| 51 |
+
me.focus();
|
| 52 |
+
|
| 53 |
+
if (options.onClose) options.onClose(dialog);
|
| 54 |
+
}
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
var inp = dialog.getElementsByTagName("input")[0], button;
|
| 58 |
+
if (inp) {
|
| 59 |
+
if (options.value) {
|
| 60 |
+
inp.value = options.value;
|
| 61 |
+
if (options.selectValueOnOpen !== false) {
|
| 62 |
+
inp.select();
|
| 63 |
+
}
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
if (options.onInput)
|
| 67 |
+
CodeMirror.on(inp, "input", function(e) { options.onInput(e, inp.value, close);});
|
| 68 |
+
if (options.onKeyUp)
|
| 69 |
+
CodeMirror.on(inp, "keyup", function(e) {options.onKeyUp(e, inp.value, close);});
|
| 70 |
+
|
| 71 |
+
CodeMirror.on(inp, "keydown", function(e) {
|
| 72 |
+
if (options && options.onKeyDown && options.onKeyDown(e, inp.value, close)) { return; }
|
| 73 |
+
if (e.keyCode == 27 || (options.closeOnEnter !== false && e.keyCode == 13)) {
|
| 74 |
+
inp.blur();
|
| 75 |
+
CodeMirror.e_stop(e);
|
| 76 |
+
close();
|
| 77 |
+
}
|
| 78 |
+
if (e.keyCode == 13) callback(inp.value, e);
|
| 79 |
+
});
|
| 80 |
+
|
| 81 |
+
if (options.closeOnBlur !== false) CodeMirror.on(inp, "blur", close);
|
| 82 |
+
|
| 83 |
+
inp.focus();
|
| 84 |
+
} else if (button = dialog.getElementsByTagName("button")[0]) {
|
| 85 |
+
CodeMirror.on(button, "click", function() {
|
| 86 |
+
close();
|
| 87 |
+
me.focus();
|
| 88 |
+
});
|
| 89 |
+
|
| 90 |
+
if (options.closeOnBlur !== false) CodeMirror.on(button, "blur", close);
|
| 91 |
+
|
| 92 |
+
button.focus();
|
| 93 |
+
}
|
| 94 |
+
return close;
|
| 95 |
+
});
|
| 96 |
+
|
| 97 |
+
CodeMirror.defineExtension("openConfirm", function(template, callbacks, options) {
|
| 98 |
+
closeNotification(this, null);
|
| 99 |
+
var dialog = dialogDiv(this, template, options && options.bottom);
|
| 100 |
+
var buttons = dialog.getElementsByTagName("button");
|
| 101 |
+
var closed = false, me = this, blurring = 1;
|
| 102 |
+
function close() {
|
| 103 |
+
if (closed) return;
|
| 104 |
+
closed = true;
|
| 105 |
+
dialog.parentNode.removeChild(dialog);
|
| 106 |
+
me.focus();
|
| 107 |
+
}
|
| 108 |
+
buttons[0].focus();
|
| 109 |
+
for (var i = 0; i < buttons.length; ++i) {
|
| 110 |
+
var b = buttons[i];
|
| 111 |
+
(function(callback) {
|
| 112 |
+
CodeMirror.on(b, "click", function(e) {
|
| 113 |
+
CodeMirror.e_preventDefault(e);
|
| 114 |
+
close();
|
| 115 |
+
if (callback) callback(me);
|
| 116 |
+
});
|
| 117 |
+
})(callbacks[i]);
|
| 118 |
+
CodeMirror.on(b, "blur", function() {
|
| 119 |
+
--blurring;
|
| 120 |
+
setTimeout(function() { if (blurring <= 0) close(); }, 200);
|
| 121 |
+
});
|
| 122 |
+
CodeMirror.on(b, "focus", function() { ++blurring; });
|
| 123 |
+
}
|
| 124 |
+
});
|
| 125 |
+
|
| 126 |
+
/*
|
| 127 |
+
* openNotification
|
| 128 |
+
* Opens a notification, that can be closed with an optional timer
|
| 129 |
+
* (default 5000ms timer) and always closes on click.
|
| 130 |
+
*
|
| 131 |
+
* If a notification is opened while another is opened, it will close the
|
| 132 |
+
* currently opened one and open the new one immediately.
|
| 133 |
+
*/
|
| 134 |
+
CodeMirror.defineExtension("openNotification", function(template, options) {
|
| 135 |
+
closeNotification(this, close);
|
| 136 |
+
var dialog = dialogDiv(this, template, options && options.bottom);
|
| 137 |
+
var closed = false, doneTimer;
|
| 138 |
+
var duration = options && typeof options.duration !== "undefined" ? options.duration : 5000;
|
| 139 |
+
|
| 140 |
+
function close() {
|
| 141 |
+
if (closed) return;
|
| 142 |
+
closed = true;
|
| 143 |
+
clearTimeout(doneTimer);
|
| 144 |
+
dialog.parentNode.removeChild(dialog);
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
CodeMirror.on(dialog, 'click', function(e) {
|
| 148 |
+
CodeMirror.e_preventDefault(e);
|
| 149 |
+
close();
|
| 150 |
+
});
|
| 151 |
+
|
| 152 |
+
if (duration)
|
| 153 |
+
doneTimer = setTimeout(close, duration);
|
| 154 |
+
|
| 155 |
+
return close;
|
| 156 |
+
});
|
| 157 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/display/fullscreen.css
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.CodeMirror-fullscreen {
|
| 2 |
+
position: fixed;
|
| 3 |
+
top: 0; left: 0; right: 0; bottom: 0;
|
| 4 |
+
height: auto;
|
| 5 |
+
z-index: 9;
|
| 6 |
+
}
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/display/fullscreen.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
"use strict";
|
| 13 |
+
|
| 14 |
+
CodeMirror.defineOption("fullScreen", false, function(cm, val, old) {
|
| 15 |
+
if (old == CodeMirror.Init) old = false;
|
| 16 |
+
if (!old == !val) return;
|
| 17 |
+
if (val) setFullscreen(cm);
|
| 18 |
+
else setNormal(cm);
|
| 19 |
+
});
|
| 20 |
+
|
| 21 |
+
function setFullscreen(cm) {
|
| 22 |
+
var wrap = cm.getWrapperElement();
|
| 23 |
+
cm.state.fullScreenRestore = {scrollTop: window.pageYOffset, scrollLeft: window.pageXOffset,
|
| 24 |
+
width: wrap.style.width, height: wrap.style.height};
|
| 25 |
+
wrap.style.width = "";
|
| 26 |
+
wrap.style.height = "auto";
|
| 27 |
+
wrap.className += " CodeMirror-fullscreen";
|
| 28 |
+
document.documentElement.style.overflow = "hidden";
|
| 29 |
+
cm.refresh();
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
function setNormal(cm) {
|
| 33 |
+
var wrap = cm.getWrapperElement();
|
| 34 |
+
wrap.className = wrap.className.replace(/\s*CodeMirror-fullscreen\b/, "");
|
| 35 |
+
document.documentElement.style.overflow = "";
|
| 36 |
+
var info = cm.state.fullScreenRestore;
|
| 37 |
+
wrap.style.width = info.width; wrap.style.height = info.height;
|
| 38 |
+
window.scrollTo(info.scrollLeft, info.scrollTop);
|
| 39 |
+
cm.refresh();
|
| 40 |
+
}
|
| 41 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/display/panel.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
CodeMirror.defineExtension("addPanel", function(node, options) {
|
| 13 |
+
options = options || {};
|
| 14 |
+
|
| 15 |
+
if (!this.state.panels) initPanels(this);
|
| 16 |
+
|
| 17 |
+
var info = this.state.panels;
|
| 18 |
+
var wrapper = info.wrapper;
|
| 19 |
+
var cmWrapper = this.getWrapperElement();
|
| 20 |
+
|
| 21 |
+
if (options.after instanceof Panel && !options.after.cleared) {
|
| 22 |
+
wrapper.insertBefore(node, options.before.node.nextSibling);
|
| 23 |
+
} else if (options.before instanceof Panel && !options.before.cleared) {
|
| 24 |
+
wrapper.insertBefore(node, options.before.node);
|
| 25 |
+
} else if (options.replace instanceof Panel && !options.replace.cleared) {
|
| 26 |
+
wrapper.insertBefore(node, options.replace.node);
|
| 27 |
+
options.replace.clear();
|
| 28 |
+
} else if (options.position == "bottom") {
|
| 29 |
+
wrapper.appendChild(node);
|
| 30 |
+
} else if (options.position == "before-bottom") {
|
| 31 |
+
wrapper.insertBefore(node, cmWrapper.nextSibling);
|
| 32 |
+
} else if (options.position == "after-top") {
|
| 33 |
+
wrapper.insertBefore(node, cmWrapper);
|
| 34 |
+
} else {
|
| 35 |
+
wrapper.insertBefore(node, wrapper.firstChild);
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
var height = (options && options.height) || node.offsetHeight;
|
| 39 |
+
this._setSize(null, info.heightLeft -= height);
|
| 40 |
+
info.panels++;
|
| 41 |
+
return new Panel(this, node, options, height);
|
| 42 |
+
});
|
| 43 |
+
|
| 44 |
+
function Panel(cm, node, options, height) {
|
| 45 |
+
this.cm = cm;
|
| 46 |
+
this.node = node;
|
| 47 |
+
this.options = options;
|
| 48 |
+
this.height = height;
|
| 49 |
+
this.cleared = false;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
Panel.prototype.clear = function() {
|
| 53 |
+
if (this.cleared) return;
|
| 54 |
+
this.cleared = true;
|
| 55 |
+
var info = this.cm.state.panels;
|
| 56 |
+
this.cm._setSize(null, info.heightLeft += this.height);
|
| 57 |
+
info.wrapper.removeChild(this.node);
|
| 58 |
+
if (--info.panels == 0) removePanels(this.cm);
|
| 59 |
+
};
|
| 60 |
+
|
| 61 |
+
Panel.prototype.changed = function(height) {
|
| 62 |
+
var newHeight = height == null ? this.node.offsetHeight : height;
|
| 63 |
+
var info = this.cm.state.panels;
|
| 64 |
+
this.cm._setSize(null, info.height += (newHeight - this.height));
|
| 65 |
+
this.height = newHeight;
|
| 66 |
+
};
|
| 67 |
+
|
| 68 |
+
function initPanels(cm) {
|
| 69 |
+
var wrap = cm.getWrapperElement();
|
| 70 |
+
var style = window.getComputedStyle ? window.getComputedStyle(wrap) : wrap.currentStyle;
|
| 71 |
+
var height = parseInt(style.height);
|
| 72 |
+
var info = cm.state.panels = {
|
| 73 |
+
setHeight: wrap.style.height,
|
| 74 |
+
heightLeft: height,
|
| 75 |
+
panels: 0,
|
| 76 |
+
wrapper: document.createElement("div")
|
| 77 |
+
};
|
| 78 |
+
wrap.parentNode.insertBefore(info.wrapper, wrap);
|
| 79 |
+
var hasFocus = cm.hasFocus();
|
| 80 |
+
info.wrapper.appendChild(wrap);
|
| 81 |
+
if (hasFocus) cm.focus();
|
| 82 |
+
|
| 83 |
+
cm._setSize = cm.setSize;
|
| 84 |
+
if (height != null) cm.setSize = function(width, newHeight) {
|
| 85 |
+
if (newHeight == null) return this._setSize(width, newHeight);
|
| 86 |
+
info.setHeight = newHeight;
|
| 87 |
+
if (typeof newHeight != "number") {
|
| 88 |
+
var px = /^(\d+\.?\d*)px$/.exec(newHeight);
|
| 89 |
+
if (px) {
|
| 90 |
+
newHeight = Number(px[1]);
|
| 91 |
+
} else {
|
| 92 |
+
info.wrapper.style.height = newHeight;
|
| 93 |
+
newHeight = info.wrapper.offsetHeight;
|
| 94 |
+
info.wrapper.style.height = "";
|
| 95 |
+
}
|
| 96 |
+
}
|
| 97 |
+
cm._setSize(width, info.heightLeft += (newHeight - height));
|
| 98 |
+
height = newHeight;
|
| 99 |
+
};
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
function removePanels(cm) {
|
| 103 |
+
var info = cm.state.panels;
|
| 104 |
+
cm.state.panels = null;
|
| 105 |
+
|
| 106 |
+
var wrap = cm.getWrapperElement();
|
| 107 |
+
info.wrapper.parentNode.replaceChild(wrap, info.wrapper);
|
| 108 |
+
wrap.style.height = info.setHeight;
|
| 109 |
+
cm.setSize = cm._setSize;
|
| 110 |
+
cm.setSize();
|
| 111 |
+
}
|
| 112 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/display/placeholder.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
CodeMirror.defineOption("placeholder", "", function(cm, val, old) {
|
| 13 |
+
var prev = old && old != CodeMirror.Init;
|
| 14 |
+
if (val && !prev) {
|
| 15 |
+
cm.on("blur", onBlur);
|
| 16 |
+
cm.on("change", onChange);
|
| 17 |
+
onChange(cm);
|
| 18 |
+
} else if (!val && prev) {
|
| 19 |
+
cm.off("blur", onBlur);
|
| 20 |
+
cm.off("change", onChange);
|
| 21 |
+
clearPlaceholder(cm);
|
| 22 |
+
var wrapper = cm.getWrapperElement();
|
| 23 |
+
wrapper.className = wrapper.className.replace(" CodeMirror-empty", "");
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
if (val && !cm.hasFocus()) onBlur(cm);
|
| 27 |
+
});
|
| 28 |
+
|
| 29 |
+
function clearPlaceholder(cm) {
|
| 30 |
+
if (cm.state.placeholder) {
|
| 31 |
+
cm.state.placeholder.parentNode.removeChild(cm.state.placeholder);
|
| 32 |
+
cm.state.placeholder = null;
|
| 33 |
+
}
|
| 34 |
+
}
|
| 35 |
+
function setPlaceholder(cm) {
|
| 36 |
+
clearPlaceholder(cm);
|
| 37 |
+
var elt = cm.state.placeholder = document.createElement("pre");
|
| 38 |
+
elt.style.cssText = "height: 0; overflow: visible";
|
| 39 |
+
elt.className = "CodeMirror-placeholder";
|
| 40 |
+
elt.appendChild(document.createTextNode(cm.getOption("placeholder")));
|
| 41 |
+
cm.display.lineSpace.insertBefore(elt, cm.display.lineSpace.firstChild);
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
function onBlur(cm) {
|
| 45 |
+
if (isEmpty(cm)) setPlaceholder(cm);
|
| 46 |
+
}
|
| 47 |
+
function onChange(cm) {
|
| 48 |
+
var wrapper = cm.getWrapperElement(), empty = isEmpty(cm);
|
| 49 |
+
wrapper.className = wrapper.className.replace(" CodeMirror-empty", "") + (empty ? " CodeMirror-empty" : "");
|
| 50 |
+
|
| 51 |
+
if (empty) setPlaceholder(cm);
|
| 52 |
+
else clearPlaceholder(cm);
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
function isEmpty(cm) {
|
| 56 |
+
return (cm.lineCount() === 1) && (cm.getLine(0) === "");
|
| 57 |
+
}
|
| 58 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/display/rulers.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
"use strict";
|
| 13 |
+
|
| 14 |
+
CodeMirror.defineOption("rulers", false, function(cm, val, old) {
|
| 15 |
+
if (old && old != CodeMirror.Init) {
|
| 16 |
+
clearRulers(cm);
|
| 17 |
+
cm.off("refresh", refreshRulers);
|
| 18 |
+
}
|
| 19 |
+
if (val && val.length) {
|
| 20 |
+
setRulers(cm);
|
| 21 |
+
cm.on("refresh", refreshRulers);
|
| 22 |
+
}
|
| 23 |
+
});
|
| 24 |
+
|
| 25 |
+
function clearRulers(cm) {
|
| 26 |
+
for (var i = cm.display.lineSpace.childNodes.length - 1; i >= 0; i--) {
|
| 27 |
+
var node = cm.display.lineSpace.childNodes[i];
|
| 28 |
+
if (/(^|\s)CodeMirror-ruler($|\s)/.test(node.className))
|
| 29 |
+
node.parentNode.removeChild(node);
|
| 30 |
+
}
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
function setRulers(cm) {
|
| 34 |
+
var val = cm.getOption("rulers");
|
| 35 |
+
var cw = cm.defaultCharWidth();
|
| 36 |
+
var left = cm.charCoords(CodeMirror.Pos(cm.firstLine(), 0), "div").left;
|
| 37 |
+
var minH = cm.display.scroller.offsetHeight + 30;
|
| 38 |
+
for (var i = 0; i < val.length; i++) {
|
| 39 |
+
var elt = document.createElement("div");
|
| 40 |
+
elt.className = "CodeMirror-ruler";
|
| 41 |
+
var col, conf = val[i];
|
| 42 |
+
if (typeof conf == "number") {
|
| 43 |
+
col = conf;
|
| 44 |
+
} else {
|
| 45 |
+
col = conf.column;
|
| 46 |
+
if (conf.className) elt.className += " " + conf.className;
|
| 47 |
+
if (conf.color) elt.style.borderColor = conf.color;
|
| 48 |
+
if (conf.lineStyle) elt.style.borderLeftStyle = conf.lineStyle;
|
| 49 |
+
if (conf.width) elt.style.borderLeftWidth = conf.width;
|
| 50 |
+
}
|
| 51 |
+
elt.style.left = (left + col * cw) + "px";
|
| 52 |
+
elt.style.top = "-50px";
|
| 53 |
+
elt.style.bottom = "-20px";
|
| 54 |
+
elt.style.minHeight = minH + "px";
|
| 55 |
+
cm.display.lineSpace.insertBefore(elt, cm.display.cursorDiv);
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
|
| 59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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
var defaults = {
|
| 13 |
+
pairs: "()[]{}''\"\"",
|
| 14 |
+
triples: "",
|
| 15 |
+
explode: "[]{}"
|
| 16 |
+
};
|
| 17 |
+
|
| 18 |
+
var Pos = CodeMirror.Pos;
|
| 19 |
+
|
| 20 |
+
CodeMirror.defineOption("autoCloseBrackets", false, function(cm, val, old) {
|
| 21 |
+
if (old && old != CodeMirror.Init) {
|
| 22 |
+
cm.removeKeyMap(keyMap);
|
| 23 |
+
cm.state.closeBrackets = null;
|
| 24 |
+
}
|
| 25 |
+
if (val) {
|
| 26 |
+
cm.state.closeBrackets = val;
|
| 27 |
+
cm.addKeyMap(keyMap);
|
| 28 |
+
}
|
| 29 |
+
});
|
| 30 |
+
|
| 31 |
+
function getOption(conf, name) {
|
| 32 |
+
if (name == "pairs" && typeof conf == "string") return conf;
|
| 33 |
+
if (typeof conf == "object" && conf[name] != null) return conf[name];
|
| 34 |
+
return defaults[name];
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
var bind = defaults.pairs + "`";
|
| 38 |
+
var keyMap = {Backspace: handleBackspace, Enter: handleEnter};
|
| 39 |
+
for (var i = 0; i < bind.length; i++)
|
| 40 |
+
keyMap["'" + bind.charAt(i) + "'"] = handler(bind.charAt(i));
|
| 41 |
+
|
| 42 |
+
function handler(ch) {
|
| 43 |
+
return function(cm) { return handleChar(cm, ch); };
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
function getConfig(cm) {
|
| 47 |
+
var deflt = cm.state.closeBrackets;
|
| 48 |
+
if (!deflt) return null;
|
| 49 |
+
var mode = cm.getModeAt(cm.getCursor());
|
| 50 |
+
return mode.closeBrackets || deflt;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
function handleBackspace(cm) {
|
| 54 |
+
var conf = getConfig(cm);
|
| 55 |
+
if (!conf || cm.getOption("disableInput")) return CodeMirror.Pass;
|
| 56 |
+
|
| 57 |
+
var pairs = getOption(conf, "pairs");
|
| 58 |
+
var ranges = cm.listSelections();
|
| 59 |
+
for (var i = 0; i < ranges.length; i++) {
|
| 60 |
+
if (!ranges[i].empty()) return CodeMirror.Pass;
|
| 61 |
+
var around = charsAround(cm, ranges[i].head);
|
| 62 |
+
if (!around || pairs.indexOf(around) % 2 != 0) return CodeMirror.Pass;
|
| 63 |
+
}
|
| 64 |
+
for (var i = ranges.length - 1; i >= 0; i--) {
|
| 65 |
+
var cur = ranges[i].head;
|
| 66 |
+
cm.replaceRange("", Pos(cur.line, cur.ch - 1), Pos(cur.line, cur.ch + 1));
|
| 67 |
+
}
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
function handleEnter(cm) {
|
| 71 |
+
var conf = getConfig(cm);
|
| 72 |
+
var explode = conf && getOption(conf, "explode");
|
| 73 |
+
if (!explode || cm.getOption("disableInput")) return CodeMirror.Pass;
|
| 74 |
+
|
| 75 |
+
var ranges = cm.listSelections();
|
| 76 |
+
for (var i = 0; i < ranges.length; i++) {
|
| 77 |
+
if (!ranges[i].empty()) return CodeMirror.Pass;
|
| 78 |
+
var around = charsAround(cm, ranges[i].head);
|
| 79 |
+
if (!around || explode.indexOf(around) % 2 != 0) return CodeMirror.Pass;
|
| 80 |
+
}
|
| 81 |
+
cm.operation(function() {
|
| 82 |
+
cm.replaceSelection("\n\n", null);
|
| 83 |
+
cm.execCommand("goCharLeft");
|
| 84 |
+
ranges = cm.listSelections();
|
| 85 |
+
for (var i = 0; i < ranges.length; i++) {
|
| 86 |
+
var line = ranges[i].head.line;
|
| 87 |
+
cm.indentLine(line, null, true);
|
| 88 |
+
cm.indentLine(line + 1, null, true);
|
| 89 |
+
}
|
| 90 |
+
});
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
function handleChar(cm, ch) {
|
| 94 |
+
var conf = getConfig(cm);
|
| 95 |
+
if (!conf || cm.getOption("disableInput")) return CodeMirror.Pass;
|
| 96 |
+
|
| 97 |
+
var pairs = getOption(conf, "pairs");
|
| 98 |
+
var pos = pairs.indexOf(ch);
|
| 99 |
+
if (pos == -1) return CodeMirror.Pass;
|
| 100 |
+
var triples = getOption(conf, "triples");
|
| 101 |
+
|
| 102 |
+
var identical = pairs.charAt(pos + 1) == ch;
|
| 103 |
+
var ranges = cm.listSelections();
|
| 104 |
+
var opening = pos % 2 == 0;
|
| 105 |
+
|
| 106 |
+
var type, next;
|
| 107 |
+
for (var i = 0; i < ranges.length; i++) {
|
| 108 |
+
var range = ranges[i], cur = range.head, curType;
|
| 109 |
+
var next = cm.getRange(cur, Pos(cur.line, cur.ch + 1));
|
| 110 |
+
if (opening && !range.empty()) {
|
| 111 |
+
curType = "surround";
|
| 112 |
+
} else if ((identical || !opening) && next == ch) {
|
| 113 |
+
if (triples.indexOf(ch) >= 0 && cm.getRange(cur, Pos(cur.line, cur.ch + 3)) == ch + ch + ch)
|
| 114 |
+
curType = "skipThree";
|
| 115 |
+
else
|
| 116 |
+
curType = "skip";
|
| 117 |
+
} else if (identical && cur.ch > 1 && triples.indexOf(ch) >= 0 &&
|
| 118 |
+
cm.getRange(Pos(cur.line, cur.ch - 2), cur) == ch + ch &&
|
| 119 |
+
(cur.ch <= 2 || cm.getRange(Pos(cur.line, cur.ch - 3), Pos(cur.line, cur.ch - 2)) != ch)) {
|
| 120 |
+
curType = "addFour";
|
| 121 |
+
} else if (identical) {
|
| 122 |
+
if (!CodeMirror.isWordChar(next) && enteringString(cm, cur, ch)) curType = "both";
|
| 123 |
+
else return CodeMirror.Pass;
|
| 124 |
+
} else if (opening && (cm.getLine(cur.line).length == cur.ch ||
|
| 125 |
+
isClosingBracket(next, pairs) ||
|
| 126 |
+
/\s/.test(next))) {
|
| 127 |
+
curType = "both";
|
| 128 |
+
} else {
|
| 129 |
+
return CodeMirror.Pass;
|
| 130 |
+
}
|
| 131 |
+
if (!type) type = curType;
|
| 132 |
+
else if (type != curType) return CodeMirror.Pass;
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
var left = pos % 2 ? pairs.charAt(pos - 1) : ch;
|
| 136 |
+
var right = pos % 2 ? ch : pairs.charAt(pos + 1);
|
| 137 |
+
cm.operation(function() {
|
| 138 |
+
if (type == "skip") {
|
| 139 |
+
cm.execCommand("goCharRight");
|
| 140 |
+
} else if (type == "skipThree") {
|
| 141 |
+
for (var i = 0; i < 3; i++)
|
| 142 |
+
cm.execCommand("goCharRight");
|
| 143 |
+
} else if (type == "surround") {
|
| 144 |
+
var sels = cm.getSelections();
|
| 145 |
+
for (var i = 0; i < sels.length; i++)
|
| 146 |
+
sels[i] = left + sels[i] + right;
|
| 147 |
+
cm.replaceSelections(sels, "around");
|
| 148 |
+
} else if (type == "both") {
|
| 149 |
+
cm.replaceSelection(left + right, null);
|
| 150 |
+
cm.triggerElectric(left + right);
|
| 151 |
+
cm.execCommand("goCharLeft");
|
| 152 |
+
} else if (type == "addFour") {
|
| 153 |
+
cm.replaceSelection(left + left + left + left, "before");
|
| 154 |
+
cm.execCommand("goCharRight");
|
| 155 |
+
}
|
| 156 |
+
});
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
function isClosingBracket(ch, pairs) {
|
| 160 |
+
var pos = pairs.lastIndexOf(ch);
|
| 161 |
+
return pos > -1 && pos % 2 == 1;
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
function charsAround(cm, pos) {
|
| 165 |
+
var str = cm.getRange(Pos(pos.line, pos.ch - 1),
|
| 166 |
+
Pos(pos.line, pos.ch + 1));
|
| 167 |
+
return str.length == 2 ? str : null;
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
// Project the token type that will exists after the given char is
|
| 171 |
+
// typed, and use it to determine whether it would cause the start
|
| 172 |
+
// of a string token.
|
| 173 |
+
function enteringString(cm, pos, ch) {
|
| 174 |
+
var line = cm.getLine(pos.line);
|
| 175 |
+
var token = cm.getTokenAt(pos);
|
| 176 |
+
if (/\bstring2?\b/.test(token.type)) return false;
|
| 177 |
+
var stream = new CodeMirror.StringStream(line.slice(0, pos.ch) + ch + line.slice(pos.ch), 4);
|
| 178 |
+
stream.pos = stream.start = token.start;
|
| 179 |
+
for (;;) {
|
| 180 |
+
var type1 = cm.getMode().token(stream, token.state);
|
| 181 |
+
if (stream.pos >= pos.ch + 1) return /\bstring2?\b/.test(type1);
|
| 182 |
+
stream.start = stream.pos;
|
| 183 |
+
}
|
| 184 |
+
}
|
| 185 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/edit/closetag.js
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
/**
|
| 5 |
+
* Tag-closer extension for CodeMirror.
|
| 6 |
+
*
|
| 7 |
+
* This extension adds an "autoCloseTags" option that can be set to
|
| 8 |
+
* either true to get the default behavior, or an object to further
|
| 9 |
+
* configure its behavior.
|
| 10 |
+
*
|
| 11 |
+
* These are supported options:
|
| 12 |
+
*
|
| 13 |
+
* `whenClosing` (default true)
|
| 14 |
+
* Whether to autoclose when the '/' of a closing tag is typed.
|
| 15 |
+
* `whenOpening` (default true)
|
| 16 |
+
* Whether to autoclose the tag when the final '>' of an opening
|
| 17 |
+
* tag is typed.
|
| 18 |
+
* `dontCloseTags` (default is empty tags for HTML, none for XML)
|
| 19 |
+
* An array of tag names that should not be autoclosed.
|
| 20 |
+
* `indentTags` (default is block tags for HTML, none for XML)
|
| 21 |
+
* An array of tag names that should, when opened, cause a
|
| 22 |
+
* blank line to be added inside the tag, and the blank line and
|
| 23 |
+
* closing line to be indented.
|
| 24 |
+
*
|
| 25 |
+
* See demos/closetag.html for a usage example.
|
| 26 |
+
*/
|
| 27 |
+
|
| 28 |
+
(function(mod) {
|
| 29 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 30 |
+
mod(require("../../lib/codemirror"), require("../fold/xml-fold"));
|
| 31 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 32 |
+
define(["../../lib/codemirror", "../fold/xml-fold"], mod);
|
| 33 |
+
else // Plain browser env
|
| 34 |
+
mod(CodeMirror);
|
| 35 |
+
})(function(CodeMirror) {
|
| 36 |
+
CodeMirror.defineOption("autoCloseTags", false, function(cm, val, old) {
|
| 37 |
+
if (old != CodeMirror.Init && old)
|
| 38 |
+
cm.removeKeyMap("autoCloseTags");
|
| 39 |
+
if (!val) return;
|
| 40 |
+
var map = {name: "autoCloseTags"};
|
| 41 |
+
if (typeof val != "object" || val.whenClosing)
|
| 42 |
+
map["'/'"] = function(cm) { return autoCloseSlash(cm); };
|
| 43 |
+
if (typeof val != "object" || val.whenOpening)
|
| 44 |
+
map["'>'"] = function(cm) { return autoCloseGT(cm); };
|
| 45 |
+
cm.addKeyMap(map);
|
| 46 |
+
});
|
| 47 |
+
|
| 48 |
+
var htmlDontClose = ["area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param",
|
| 49 |
+
"source", "track", "wbr"];
|
| 50 |
+
var htmlIndent = ["applet", "blockquote", "body", "button", "div", "dl", "fieldset", "form", "frameset", "h1", "h2", "h3", "h4",
|
| 51 |
+
"h5", "h6", "head", "html", "iframe", "layer", "legend", "object", "ol", "p", "select", "table", "ul"];
|
| 52 |
+
|
| 53 |
+
function autoCloseGT(cm) {
|
| 54 |
+
if (cm.getOption("disableInput")) return CodeMirror.Pass;
|
| 55 |
+
var ranges = cm.listSelections(), replacements = [];
|
| 56 |
+
for (var i = 0; i < ranges.length; i++) {
|
| 57 |
+
if (!ranges[i].empty()) return CodeMirror.Pass;
|
| 58 |
+
var pos = ranges[i].head, tok = cm.getTokenAt(pos);
|
| 59 |
+
var inner = CodeMirror.innerMode(cm.getMode(), tok.state), state = inner.state;
|
| 60 |
+
if (inner.mode.name != "xml" || !state.tagName) return CodeMirror.Pass;
|
| 61 |
+
|
| 62 |
+
var opt = cm.getOption("autoCloseTags"), html = inner.mode.configuration == "html";
|
| 63 |
+
var dontCloseTags = (typeof opt == "object" && opt.dontCloseTags) || (html && htmlDontClose);
|
| 64 |
+
var indentTags = (typeof opt == "object" && opt.indentTags) || (html && htmlIndent);
|
| 65 |
+
|
| 66 |
+
var tagName = state.tagName;
|
| 67 |
+
if (tok.end > pos.ch) tagName = tagName.slice(0, tagName.length - tok.end + pos.ch);
|
| 68 |
+
var lowerTagName = tagName.toLowerCase();
|
| 69 |
+
// Don't process the '>' at the end of an end-tag or self-closing tag
|
| 70 |
+
if (!tagName ||
|
| 71 |
+
tok.type == "string" && (tok.end != pos.ch || !/[\"\']/.test(tok.string.charAt(tok.string.length - 1)) || tok.string.length == 1) ||
|
| 72 |
+
tok.type == "tag" && state.type == "closeTag" ||
|
| 73 |
+
tok.string.indexOf("/") == (tok.string.length - 1) || // match something like <someTagName />
|
| 74 |
+
dontCloseTags && indexOf(dontCloseTags, lowerTagName) > -1 ||
|
| 75 |
+
closingTagExists(cm, tagName, pos, state, true))
|
| 76 |
+
return CodeMirror.Pass;
|
| 77 |
+
|
| 78 |
+
var indent = indentTags && indexOf(indentTags, lowerTagName) > -1;
|
| 79 |
+
replacements[i] = {indent: indent,
|
| 80 |
+
text: ">" + (indent ? "\n\n" : "") + "</" + tagName + ">",
|
| 81 |
+
newPos: indent ? CodeMirror.Pos(pos.line + 1, 0) : CodeMirror.Pos(pos.line, pos.ch + 1)};
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
for (var i = ranges.length - 1; i >= 0; i--) {
|
| 85 |
+
var info = replacements[i];
|
| 86 |
+
cm.replaceRange(info.text, ranges[i].head, ranges[i].anchor, "+insert");
|
| 87 |
+
var sel = cm.listSelections().slice(0);
|
| 88 |
+
sel[i] = {head: info.newPos, anchor: info.newPos};
|
| 89 |
+
cm.setSelections(sel);
|
| 90 |
+
if (info.indent) {
|
| 91 |
+
cm.indentLine(info.newPos.line, null, true);
|
| 92 |
+
cm.indentLine(info.newPos.line + 1, null, true);
|
| 93 |
+
}
|
| 94 |
+
}
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
function autoCloseCurrent(cm, typingSlash) {
|
| 98 |
+
var ranges = cm.listSelections(), replacements = [];
|
| 99 |
+
var head = typingSlash ? "/" : "</";
|
| 100 |
+
for (var i = 0; i < ranges.length; i++) {
|
| 101 |
+
if (!ranges[i].empty()) return CodeMirror.Pass;
|
| 102 |
+
var pos = ranges[i].head, tok = cm.getTokenAt(pos);
|
| 103 |
+
var inner = CodeMirror.innerMode(cm.getMode(), tok.state), state = inner.state;
|
| 104 |
+
if (typingSlash && (tok.type == "string" || tok.string.charAt(0) != "<" ||
|
| 105 |
+
tok.start != pos.ch - 1))
|
| 106 |
+
return CodeMirror.Pass;
|
| 107 |
+
// Kludge to get around the fact that we are not in XML mode
|
| 108 |
+
// when completing in JS/CSS snippet in htmlmixed mode. Does not
|
| 109 |
+
// work for other XML embedded languages (there is no general
|
| 110 |
+
// way to go from a mixed mode to its current XML state).
|
| 111 |
+
if (inner.mode.name != "xml") {
|
| 112 |
+
if (cm.getMode().name == "htmlmixed" && inner.mode.name == "javascript")
|
| 113 |
+
replacements[i] = head + "script>";
|
| 114 |
+
else if (cm.getMode().name == "htmlmixed" && inner.mode.name == "css")
|
| 115 |
+
replacements[i] = head + "style>";
|
| 116 |
+
else
|
| 117 |
+
return CodeMirror.Pass;
|
| 118 |
+
} else {
|
| 119 |
+
if (!state.context || !state.context.tagName ||
|
| 120 |
+
closingTagExists(cm, state.context.tagName, pos, state))
|
| 121 |
+
return CodeMirror.Pass;
|
| 122 |
+
replacements[i] = head + state.context.tagName + ">";
|
| 123 |
+
}
|
| 124 |
+
}
|
| 125 |
+
cm.replaceSelections(replacements);
|
| 126 |
+
ranges = cm.listSelections();
|
| 127 |
+
for (var i = 0; i < ranges.length; i++)
|
| 128 |
+
if (i == ranges.length - 1 || ranges[i].head.line < ranges[i + 1].head.line)
|
| 129 |
+
cm.indentLine(ranges[i].head.line);
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
function autoCloseSlash(cm) {
|
| 133 |
+
if (cm.getOption("disableInput")) return CodeMirror.Pass;
|
| 134 |
+
return autoCloseCurrent(cm, true);
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
CodeMirror.commands.closeTag = function(cm) { return autoCloseCurrent(cm); };
|
| 138 |
+
|
| 139 |
+
function indexOf(collection, elt) {
|
| 140 |
+
if (collection.indexOf) return collection.indexOf(elt);
|
| 141 |
+
for (var i = 0, e = collection.length; i < e; ++i)
|
| 142 |
+
if (collection[i] == elt) return i;
|
| 143 |
+
return -1;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
// If xml-fold is loaded, we use its functionality to try and verify
|
| 147 |
+
// whether a given tag is actually unclosed.
|
| 148 |
+
function closingTagExists(cm, tagName, pos, state, newTag) {
|
| 149 |
+
if (!CodeMirror.scanForClosingTag) return false;
|
| 150 |
+
var end = Math.min(cm.lastLine() + 1, pos.line + 500);
|
| 151 |
+
var nextClose = CodeMirror.scanForClosingTag(cm, pos, null, end);
|
| 152 |
+
if (!nextClose || nextClose.tag != tagName) return false;
|
| 153 |
+
var cx = state.context;
|
| 154 |
+
// If the immediate wrapping context contains onCx instances of
|
| 155 |
+
// the same tag, a closing tag only exists if there are at least
|
| 156 |
+
// that many closing tags of that type following.
|
| 157 |
+
for (var onCx = newTag ? 1 : 0; cx && cx.tagName == tagName; cx = cx.prev) ++onCx;
|
| 158 |
+
pos = nextClose.to;
|
| 159 |
+
for (var i = 1; i < onCx; i++) {
|
| 160 |
+
var next = CodeMirror.scanForClosingTag(cm, pos, null, end);
|
| 161 |
+
if (!next || next.tag != tagName) return false;
|
| 162 |
+
pos = next.to;
|
| 163 |
+
}
|
| 164 |
+
return true;
|
| 165 |
+
}
|
| 166 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/edit/continuelist.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
"use strict";
|
| 13 |
+
|
| 14 |
+
var listRE = /^(\s*)(>[> ]*|[*+-]\s|(\d+)\.)(\s*)/,
|
| 15 |
+
emptyListRE = /^(\s*)(>[> ]*|[*+-]|(\d+)\.)(\s*)$/,
|
| 16 |
+
unorderedListRE = /[*+-]\s/;
|
| 17 |
+
|
| 18 |
+
CodeMirror.commands.newlineAndIndentContinueMarkdownList = function(cm) {
|
| 19 |
+
if (cm.getOption("disableInput")) return CodeMirror.Pass;
|
| 20 |
+
var ranges = cm.listSelections(), replacements = [];
|
| 21 |
+
for (var i = 0; i < ranges.length; i++) {
|
| 22 |
+
var pos = ranges[i].head;
|
| 23 |
+
var eolState = cm.getStateAfter(pos.line);
|
| 24 |
+
var inList = eolState.list !== false;
|
| 25 |
+
var inQuote = eolState.quote !== 0;
|
| 26 |
+
|
| 27 |
+
var line = cm.getLine(pos.line), match = listRE.exec(line);
|
| 28 |
+
if (!ranges[i].empty() || (!inList && !inQuote) || !match) {
|
| 29 |
+
cm.execCommand("newlineAndIndent");
|
| 30 |
+
return;
|
| 31 |
+
}
|
| 32 |
+
if (emptyListRE.test(line)) {
|
| 33 |
+
cm.replaceRange("", {
|
| 34 |
+
line: pos.line, ch: 0
|
| 35 |
+
}, {
|
| 36 |
+
line: pos.line, ch: pos.ch + 1
|
| 37 |
+
});
|
| 38 |
+
replacements[i] = "\n";
|
| 39 |
+
} else {
|
| 40 |
+
var indent = match[1], after = match[4];
|
| 41 |
+
var bullet = unorderedListRE.test(match[2]) || match[2].indexOf(">") >= 0
|
| 42 |
+
? match[2]
|
| 43 |
+
: (parseInt(match[3], 10) + 1) + ".";
|
| 44 |
+
|
| 45 |
+
replacements[i] = "\n" + indent + bullet + after;
|
| 46 |
+
}
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
cm.replaceSelections(replacements);
|
| 50 |
+
};
|
| 51 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/edit/matchbrackets.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
var ie_lt8 = /MSIE \d/.test(navigator.userAgent) &&
|
| 13 |
+
(document.documentMode == null || document.documentMode < 8);
|
| 14 |
+
|
| 15 |
+
var Pos = CodeMirror.Pos;
|
| 16 |
+
|
| 17 |
+
var matching = {"(": ")>", ")": "(<", "[": "]>", "]": "[<", "{": "}>", "}": "{<"};
|
| 18 |
+
|
| 19 |
+
function findMatchingBracket(cm, where, strict, config) {
|
| 20 |
+
var line = cm.getLineHandle(where.line), pos = where.ch - 1;
|
| 21 |
+
var match = (pos >= 0 && matching[line.text.charAt(pos)]) || matching[line.text.charAt(++pos)];
|
| 22 |
+
if (!match) return null;
|
| 23 |
+
var dir = match.charAt(1) == ">" ? 1 : -1;
|
| 24 |
+
if (strict && (dir > 0) != (pos == where.ch)) return null;
|
| 25 |
+
var style = cm.getTokenTypeAt(Pos(where.line, pos + 1));
|
| 26 |
+
|
| 27 |
+
var found = scanForBracket(cm, Pos(where.line, pos + (dir > 0 ? 1 : 0)), dir, style || null, config);
|
| 28 |
+
if (found == null) return null;
|
| 29 |
+
return {from: Pos(where.line, pos), to: found && found.pos,
|
| 30 |
+
match: found && found.ch == match.charAt(0), forward: dir > 0};
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
// bracketRegex is used to specify which type of bracket to scan
|
| 34 |
+
// should be a regexp, e.g. /[[\]]/
|
| 35 |
+
//
|
| 36 |
+
// Note: If "where" is on an open bracket, then this bracket is ignored.
|
| 37 |
+
//
|
| 38 |
+
// Returns false when no bracket was found, null when it reached
|
| 39 |
+
// maxScanLines and gave up
|
| 40 |
+
function scanForBracket(cm, where, dir, style, config) {
|
| 41 |
+
var maxScanLen = (config && config.maxScanLineLength) || 10000;
|
| 42 |
+
var maxScanLines = (config && config.maxScanLines) || 1000;
|
| 43 |
+
|
| 44 |
+
var stack = [];
|
| 45 |
+
var re = config && config.bracketRegex ? config.bracketRegex : /[(){}[\]]/;
|
| 46 |
+
var lineEnd = dir > 0 ? Math.min(where.line + maxScanLines, cm.lastLine() + 1)
|
| 47 |
+
: Math.max(cm.firstLine() - 1, where.line - maxScanLines);
|
| 48 |
+
for (var lineNo = where.line; lineNo != lineEnd; lineNo += dir) {
|
| 49 |
+
var line = cm.getLine(lineNo);
|
| 50 |
+
if (!line) continue;
|
| 51 |
+
var pos = dir > 0 ? 0 : line.length - 1, end = dir > 0 ? line.length : -1;
|
| 52 |
+
if (line.length > maxScanLen) continue;
|
| 53 |
+
if (lineNo == where.line) pos = where.ch - (dir < 0 ? 1 : 0);
|
| 54 |
+
for (; pos != end; pos += dir) {
|
| 55 |
+
var ch = line.charAt(pos);
|
| 56 |
+
if (re.test(ch) && (style === undefined || cm.getTokenTypeAt(Pos(lineNo, pos + 1)) == style)) {
|
| 57 |
+
var match = matching[ch];
|
| 58 |
+
if ((match.charAt(1) == ">") == (dir > 0)) stack.push(ch);
|
| 59 |
+
else if (!stack.length) return {pos: Pos(lineNo, pos), ch: ch};
|
| 60 |
+
else stack.pop();
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
+
}
|
| 64 |
+
return lineNo - dir == (dir > 0 ? cm.lastLine() : cm.firstLine()) ? false : null;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
function matchBrackets(cm, autoclear, config) {
|
| 68 |
+
// Disable brace matching in long lines, since it'll cause hugely slow updates
|
| 69 |
+
var maxHighlightLen = cm.state.matchBrackets.maxHighlightLineLength || 1000;
|
| 70 |
+
var marks = [], ranges = cm.listSelections();
|
| 71 |
+
for (var i = 0; i < ranges.length; i++) {
|
| 72 |
+
var match = ranges[i].empty() && findMatchingBracket(cm, ranges[i].head, false, config);
|
| 73 |
+
if (match && cm.getLine(match.from.line).length <= maxHighlightLen) {
|
| 74 |
+
var style = match.match ? "CodeMirror-matchingbracket" : "CodeMirror-nonmatchingbracket";
|
| 75 |
+
marks.push(cm.markText(match.from, Pos(match.from.line, match.from.ch + 1), {className: style}));
|
| 76 |
+
if (match.to && cm.getLine(match.to.line).length <= maxHighlightLen)
|
| 77 |
+
marks.push(cm.markText(match.to, Pos(match.to.line, match.to.ch + 1), {className: style}));
|
| 78 |
+
}
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
if (marks.length) {
|
| 82 |
+
// Kludge to work around the IE bug from issue #1193, where text
|
| 83 |
+
// input stops going to the textare whever this fires.
|
| 84 |
+
if (ie_lt8 && cm.state.focused) cm.focus();
|
| 85 |
+
|
| 86 |
+
var clear = function() {
|
| 87 |
+
cm.operation(function() {
|
| 88 |
+
for (var i = 0; i < marks.length; i++) marks[i].clear();
|
| 89 |
+
});
|
| 90 |
+
};
|
| 91 |
+
if (autoclear) setTimeout(clear, 800);
|
| 92 |
+
else return clear;
|
| 93 |
+
}
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
var currentlyHighlighted = null;
|
| 97 |
+
function doMatchBrackets(cm) {
|
| 98 |
+
cm.operation(function() {
|
| 99 |
+
if (currentlyHighlighted) {currentlyHighlighted(); currentlyHighlighted = null;}
|
| 100 |
+
currentlyHighlighted = matchBrackets(cm, false, cm.state.matchBrackets);
|
| 101 |
+
});
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
CodeMirror.defineOption("matchBrackets", false, function(cm, val, old) {
|
| 105 |
+
if (old && old != CodeMirror.Init)
|
| 106 |
+
cm.off("cursorActivity", doMatchBrackets);
|
| 107 |
+
if (val) {
|
| 108 |
+
cm.state.matchBrackets = typeof val == "object" ? val : {};
|
| 109 |
+
cm.on("cursorActivity", doMatchBrackets);
|
| 110 |
+
}
|
| 111 |
+
});
|
| 112 |
+
|
| 113 |
+
CodeMirror.defineExtension("matchBrackets", function() {matchBrackets(this, true);});
|
| 114 |
+
CodeMirror.defineExtension("findMatchingBracket", function(pos, strict, config){
|
| 115 |
+
return findMatchingBracket(this, pos, strict, config);
|
| 116 |
+
});
|
| 117 |
+
CodeMirror.defineExtension("scanForBracket", function(pos, dir, style, config){
|
| 118 |
+
return scanForBracket(this, pos, dir, style, config);
|
| 119 |
+
});
|
| 120 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/edit/matchtags.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"), require("../fold/xml-fold"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror", "../fold/xml-fold"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
"use strict";
|
| 13 |
+
|
| 14 |
+
CodeMirror.defineOption("matchTags", false, function(cm, val, old) {
|
| 15 |
+
if (old && old != CodeMirror.Init) {
|
| 16 |
+
cm.off("cursorActivity", doMatchTags);
|
| 17 |
+
cm.off("viewportChange", maybeUpdateMatch);
|
| 18 |
+
clear(cm);
|
| 19 |
+
}
|
| 20 |
+
if (val) {
|
| 21 |
+
cm.state.matchBothTags = typeof val == "object" && val.bothTags;
|
| 22 |
+
cm.on("cursorActivity", doMatchTags);
|
| 23 |
+
cm.on("viewportChange", maybeUpdateMatch);
|
| 24 |
+
doMatchTags(cm);
|
| 25 |
+
}
|
| 26 |
+
});
|
| 27 |
+
|
| 28 |
+
function clear(cm) {
|
| 29 |
+
if (cm.state.tagHit) cm.state.tagHit.clear();
|
| 30 |
+
if (cm.state.tagOther) cm.state.tagOther.clear();
|
| 31 |
+
cm.state.tagHit = cm.state.tagOther = null;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
function doMatchTags(cm) {
|
| 35 |
+
cm.state.failedTagMatch = false;
|
| 36 |
+
cm.operation(function() {
|
| 37 |
+
clear(cm);
|
| 38 |
+
if (cm.somethingSelected()) return;
|
| 39 |
+
var cur = cm.getCursor(), range = cm.getViewport();
|
| 40 |
+
range.from = Math.min(range.from, cur.line); range.to = Math.max(cur.line + 1, range.to);
|
| 41 |
+
var match = CodeMirror.findMatchingTag(cm, cur, range);
|
| 42 |
+
if (!match) return;
|
| 43 |
+
if (cm.state.matchBothTags) {
|
| 44 |
+
var hit = match.at == "open" ? match.open : match.close;
|
| 45 |
+
if (hit) cm.state.tagHit = cm.markText(hit.from, hit.to, {className: "CodeMirror-matchingtag"});
|
| 46 |
+
}
|
| 47 |
+
var other = match.at == "close" ? match.open : match.close;
|
| 48 |
+
if (other)
|
| 49 |
+
cm.state.tagOther = cm.markText(other.from, other.to, {className: "CodeMirror-matchingtag"});
|
| 50 |
+
else
|
| 51 |
+
cm.state.failedTagMatch = true;
|
| 52 |
+
});
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
function maybeUpdateMatch(cm) {
|
| 56 |
+
if (cm.state.failedTagMatch) doMatchTags(cm);
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
CodeMirror.commands.toMatchingTag = function(cm) {
|
| 60 |
+
var found = CodeMirror.findMatchingTag(cm, cm.getCursor());
|
| 61 |
+
if (found) {
|
| 62 |
+
var other = found.at == "close" ? found.open : found.close;
|
| 63 |
+
if (other) cm.extendSelection(other.to, other.from);
|
| 64 |
+
}
|
| 65 |
+
};
|
| 66 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/edit/trailingspace.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
CodeMirror.defineOption("showTrailingSpace", false, function(cm, val, prev) {
|
| 13 |
+
if (prev == CodeMirror.Init) prev = false;
|
| 14 |
+
if (prev && !val)
|
| 15 |
+
cm.removeOverlay("trailingspace");
|
| 16 |
+
else if (!prev && val)
|
| 17 |
+
cm.addOverlay({
|
| 18 |
+
token: function(stream) {
|
| 19 |
+
for (var l = stream.string.length, i = l; i && /\s/.test(stream.string.charAt(i - 1)); --i) {}
|
| 20 |
+
if (i > stream.pos) { stream.pos = i; return null; }
|
| 21 |
+
stream.pos = l;
|
| 22 |
+
return "trailingspace";
|
| 23 |
+
},
|
| 24 |
+
name: "trailingspace"
|
| 25 |
+
});
|
| 26 |
+
});
|
| 27 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/fold/brace-fold.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
"use strict";
|
| 13 |
+
|
| 14 |
+
CodeMirror.registerHelper("fold", "brace", function(cm, start) {
|
| 15 |
+
var line = start.line, lineText = cm.getLine(line);
|
| 16 |
+
var startCh, tokenType;
|
| 17 |
+
|
| 18 |
+
function findOpening(openCh) {
|
| 19 |
+
for (var at = start.ch, pass = 0;;) {
|
| 20 |
+
var found = at <= 0 ? -1 : lineText.lastIndexOf(openCh, at - 1);
|
| 21 |
+
if (found == -1) {
|
| 22 |
+
if (pass == 1) break;
|
| 23 |
+
pass = 1;
|
| 24 |
+
at = lineText.length;
|
| 25 |
+
continue;
|
| 26 |
+
}
|
| 27 |
+
if (pass == 1 && found < start.ch) break;
|
| 28 |
+
tokenType = cm.getTokenTypeAt(CodeMirror.Pos(line, found + 1));
|
| 29 |
+
if (!/^(comment|string)/.test(tokenType)) return found + 1;
|
| 30 |
+
at = found - 1;
|
| 31 |
+
}
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
var startToken = "{", endToken = "}", startCh = findOpening("{");
|
| 35 |
+
if (startCh == null) {
|
| 36 |
+
startToken = "[", endToken = "]";
|
| 37 |
+
startCh = findOpening("[");
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
if (startCh == null) return;
|
| 41 |
+
var count = 1, lastLine = cm.lastLine(), end, endCh;
|
| 42 |
+
outer: for (var i = line; i <= lastLine; ++i) {
|
| 43 |
+
var text = cm.getLine(i), pos = i == line ? startCh : 0;
|
| 44 |
+
for (;;) {
|
| 45 |
+
var nextOpen = text.indexOf(startToken, pos), nextClose = text.indexOf(endToken, pos);
|
| 46 |
+
if (nextOpen < 0) nextOpen = text.length;
|
| 47 |
+
if (nextClose < 0) nextClose = text.length;
|
| 48 |
+
pos = Math.min(nextOpen, nextClose);
|
| 49 |
+
if (pos == text.length) break;
|
| 50 |
+
if (cm.getTokenTypeAt(CodeMirror.Pos(i, pos + 1)) == tokenType) {
|
| 51 |
+
if (pos == nextOpen) ++count;
|
| 52 |
+
else if (!--count) { end = i; endCh = pos; break outer; }
|
| 53 |
+
}
|
| 54 |
+
++pos;
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
if (end == null || line == end && endCh == startCh) return;
|
| 58 |
+
return {from: CodeMirror.Pos(line, startCh),
|
| 59 |
+
to: CodeMirror.Pos(end, endCh)};
|
| 60 |
+
});
|
| 61 |
+
|
| 62 |
+
CodeMirror.registerHelper("fold", "import", function(cm, start) {
|
| 63 |
+
function hasImport(line) {
|
| 64 |
+
if (line < cm.firstLine() || line > cm.lastLine()) return null;
|
| 65 |
+
var start = cm.getTokenAt(CodeMirror.Pos(line, 1));
|
| 66 |
+
if (!/\S/.test(start.string)) start = cm.getTokenAt(CodeMirror.Pos(line, start.end + 1));
|
| 67 |
+
if (start.type != "keyword" || start.string != "import") return null;
|
| 68 |
+
// Now find closing semicolon, return its position
|
| 69 |
+
for (var i = line, e = Math.min(cm.lastLine(), line + 10); i <= e; ++i) {
|
| 70 |
+
var text = cm.getLine(i), semi = text.indexOf(";");
|
| 71 |
+
if (semi != -1) return {startCh: start.end, end: CodeMirror.Pos(i, semi)};
|
| 72 |
+
}
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
var start = start.line, has = hasImport(start), prev;
|
| 76 |
+
if (!has || hasImport(start - 1) || ((prev = hasImport(start - 2)) && prev.end.line == start - 1))
|
| 77 |
+
return null;
|
| 78 |
+
for (var end = has.end;;) {
|
| 79 |
+
var next = hasImport(end.line + 1);
|
| 80 |
+
if (next == null) break;
|
| 81 |
+
end = next.end;
|
| 82 |
+
}
|
| 83 |
+
return {from: cm.clipPos(CodeMirror.Pos(start, has.startCh + 1)), to: end};
|
| 84 |
+
});
|
| 85 |
+
|
| 86 |
+
CodeMirror.registerHelper("fold", "include", function(cm, start) {
|
| 87 |
+
function hasInclude(line) {
|
| 88 |
+
if (line < cm.firstLine() || line > cm.lastLine()) return null;
|
| 89 |
+
var start = cm.getTokenAt(CodeMirror.Pos(line, 1));
|
| 90 |
+
if (!/\S/.test(start.string)) start = cm.getTokenAt(CodeMirror.Pos(line, start.end + 1));
|
| 91 |
+
if (start.type == "meta" && start.string.slice(0, 8) == "#include") return start.start + 8;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
var start = start.line, has = hasInclude(start);
|
| 95 |
+
if (has == null || hasInclude(start - 1) != null) return null;
|
| 96 |
+
for (var end = start;;) {
|
| 97 |
+
var next = hasInclude(end + 1);
|
| 98 |
+
if (next == null) break;
|
| 99 |
+
++end;
|
| 100 |
+
}
|
| 101 |
+
return {from: CodeMirror.Pos(start, has + 1),
|
| 102 |
+
to: cm.clipPos(CodeMirror.Pos(end))};
|
| 103 |
+
});
|
| 104 |
+
|
| 105 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/fold/comment-fold.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
"use strict";
|
| 13 |
+
|
| 14 |
+
CodeMirror.registerGlobalHelper("fold", "comment", function(mode) {
|
| 15 |
+
return mode.blockCommentStart && mode.blockCommentEnd;
|
| 16 |
+
}, function(cm, start) {
|
| 17 |
+
var mode = cm.getModeAt(start), startToken = mode.blockCommentStart, endToken = mode.blockCommentEnd;
|
| 18 |
+
if (!startToken || !endToken) return;
|
| 19 |
+
var line = start.line, lineText = cm.getLine(line);
|
| 20 |
+
|
| 21 |
+
var startCh;
|
| 22 |
+
for (var at = start.ch, pass = 0;;) {
|
| 23 |
+
var found = at <= 0 ? -1 : lineText.lastIndexOf(startToken, at - 1);
|
| 24 |
+
if (found == -1) {
|
| 25 |
+
if (pass == 1) return;
|
| 26 |
+
pass = 1;
|
| 27 |
+
at = lineText.length;
|
| 28 |
+
continue;
|
| 29 |
+
}
|
| 30 |
+
if (pass == 1 && found < start.ch) return;
|
| 31 |
+
if (/comment/.test(cm.getTokenTypeAt(CodeMirror.Pos(line, found + 1)))) {
|
| 32 |
+
startCh = found + startToken.length;
|
| 33 |
+
break;
|
| 34 |
+
}
|
| 35 |
+
at = found - 1;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
var depth = 1, lastLine = cm.lastLine(), end, endCh;
|
| 39 |
+
outer: for (var i = line; i <= lastLine; ++i) {
|
| 40 |
+
var text = cm.getLine(i), pos = i == line ? startCh : 0;
|
| 41 |
+
for (;;) {
|
| 42 |
+
var nextOpen = text.indexOf(startToken, pos), nextClose = text.indexOf(endToken, pos);
|
| 43 |
+
if (nextOpen < 0) nextOpen = text.length;
|
| 44 |
+
if (nextClose < 0) nextClose = text.length;
|
| 45 |
+
pos = Math.min(nextOpen, nextClose);
|
| 46 |
+
if (pos == text.length) break;
|
| 47 |
+
if (pos == nextOpen) ++depth;
|
| 48 |
+
else if (!--depth) { end = i; endCh = pos; break outer; }
|
| 49 |
+
++pos;
|
| 50 |
+
}
|
| 51 |
+
}
|
| 52 |
+
if (end == null || line == end && endCh == startCh) return;
|
| 53 |
+
return {from: CodeMirror.Pos(line, startCh),
|
| 54 |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1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
"use strict";
|
| 13 |
+
|
| 14 |
+
function doFold(cm, pos, options, force) {
|
| 15 |
+
if (options && options.call) {
|
| 16 |
+
var finder = options;
|
| 17 |
+
options = null;
|
| 18 |
+
} else {
|
| 19 |
+
var finder = getOption(cm, options, "rangeFinder");
|
| 20 |
+
}
|
| 21 |
+
if (typeof pos == "number") pos = CodeMirror.Pos(pos, 0);
|
| 22 |
+
var minSize = getOption(cm, options, "minFoldSize");
|
| 23 |
+
|
| 24 |
+
function getRange(allowFolded) {
|
| 25 |
+
var range = finder(cm, pos);
|
| 26 |
+
if (!range || range.to.line - range.from.line < minSize) return null;
|
| 27 |
+
var marks = cm.findMarksAt(range.from);
|
| 28 |
+
for (var i = 0; i < marks.length; ++i) {
|
| 29 |
+
if (marks[i].__isFold && force !== "fold") {
|
| 30 |
+
if (!allowFolded) return null;
|
| 31 |
+
range.cleared = true;
|
| 32 |
+
marks[i].clear();
|
| 33 |
+
}
|
| 34 |
+
}
|
| 35 |
+
return range;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
var range = getRange(true);
|
| 39 |
+
if (getOption(cm, options, "scanUp")) while (!range && pos.line > cm.firstLine()) {
|
| 40 |
+
pos = CodeMirror.Pos(pos.line - 1, 0);
|
| 41 |
+
range = getRange(false);
|
| 42 |
+
}
|
| 43 |
+
if (!range || range.cleared || force === "unfold") return;
|
| 44 |
+
|
| 45 |
+
var myWidget = makeWidget(cm, options);
|
| 46 |
+
CodeMirror.on(myWidget, "mousedown", function(e) {
|
| 47 |
+
myRange.clear();
|
| 48 |
+
CodeMirror.e_preventDefault(e);
|
| 49 |
+
});
|
| 50 |
+
var myRange = cm.markText(range.from, range.to, {
|
| 51 |
+
replacedWith: myWidget,
|
| 52 |
+
clearOnEnter: true,
|
| 53 |
+
__isFold: true
|
| 54 |
+
});
|
| 55 |
+
myRange.on("clear", function(from, to) {
|
| 56 |
+
CodeMirror.signal(cm, "unfold", cm, from, to);
|
| 57 |
+
});
|
| 58 |
+
CodeMirror.signal(cm, "fold", cm, range.from, range.to);
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
function makeWidget(cm, options) {
|
| 62 |
+
var widget = getOption(cm, options, "widget");
|
| 63 |
+
if (typeof widget == "string") {
|
| 64 |
+
var text = document.createTextNode(widget);
|
| 65 |
+
widget = document.createElement("span");
|
| 66 |
+
widget.appendChild(text);
|
| 67 |
+
widget.className = "CodeMirror-foldmarker";
|
| 68 |
+
}
|
| 69 |
+
return widget;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
// Clumsy backwards-compatible interface
|
| 73 |
+
CodeMirror.newFoldFunction = function(rangeFinder, widget) {
|
| 74 |
+
return function(cm, pos) { doFold(cm, pos, {rangeFinder: rangeFinder, widget: widget}); };
|
| 75 |
+
};
|
| 76 |
+
|
| 77 |
+
// New-style interface
|
| 78 |
+
CodeMirror.defineExtension("foldCode", function(pos, options, force) {
|
| 79 |
+
doFold(this, pos, options, force);
|
| 80 |
+
});
|
| 81 |
+
|
| 82 |
+
CodeMirror.defineExtension("isFolded", function(pos) {
|
| 83 |
+
var marks = this.findMarksAt(pos);
|
| 84 |
+
for (var i = 0; i < marks.length; ++i)
|
| 85 |
+
if (marks[i].__isFold) return true;
|
| 86 |
+
});
|
| 87 |
+
|
| 88 |
+
CodeMirror.commands.toggleFold = function(cm) {
|
| 89 |
+
cm.foldCode(cm.getCursor());
|
| 90 |
+
};
|
| 91 |
+
CodeMirror.commands.fold = function(cm) {
|
| 92 |
+
cm.foldCode(cm.getCursor(), null, "fold");
|
| 93 |
+
};
|
| 94 |
+
CodeMirror.commands.unfold = function(cm) {
|
| 95 |
+
cm.foldCode(cm.getCursor(), null, "unfold");
|
| 96 |
+
};
|
| 97 |
+
CodeMirror.commands.foldAll = function(cm) {
|
| 98 |
+
cm.operation(function() {
|
| 99 |
+
for (var i = cm.firstLine(), e = cm.lastLine(); i <= e; i++)
|
| 100 |
+
cm.foldCode(CodeMirror.Pos(i, 0), null, "fold");
|
| 101 |
+
});
|
| 102 |
+
};
|
| 103 |
+
CodeMirror.commands.unfoldAll = function(cm) {
|
| 104 |
+
cm.operation(function() {
|
| 105 |
+
for (var i = cm.firstLine(), e = cm.lastLine(); i <= e; i++)
|
| 106 |
+
cm.foldCode(CodeMirror.Pos(i, 0), null, "unfold");
|
| 107 |
+
});
|
| 108 |
+
};
|
| 109 |
+
|
| 110 |
+
CodeMirror.registerHelper("fold", "combine", function() {
|
| 111 |
+
var funcs = Array.prototype.slice.call(arguments, 0);
|
| 112 |
+
return function(cm, start) {
|
| 113 |
+
for (var i = 0; i < funcs.length; ++i) {
|
| 114 |
+
var found = funcs[i](cm, start);
|
| 115 |
+
if (found) return found;
|
| 116 |
+
}
|
| 117 |
+
};
|
| 118 |
+
});
|
| 119 |
+
|
| 120 |
+
CodeMirror.registerHelper("fold", "auto", function(cm, start) {
|
| 121 |
+
var helpers = cm.getHelpers(start, "fold");
|
| 122 |
+
for (var i = 0; i < helpers.length; i++) {
|
| 123 |
+
var cur = helpers[i](cm, start);
|
| 124 |
+
if (cur) return cur;
|
| 125 |
+
}
|
| 126 |
+
});
|
| 127 |
+
|
| 128 |
+
var defaultOptions = {
|
| 129 |
+
rangeFinder: CodeMirror.fold.auto,
|
| 130 |
+
widget: "\u2194",
|
| 131 |
+
minFoldSize: 0,
|
| 132 |
+
scanUp: false
|
| 133 |
+
};
|
| 134 |
+
|
| 135 |
+
CodeMirror.defineOption("foldOptions", null);
|
| 136 |
+
|
| 137 |
+
function getOption(cm, options, name) {
|
| 138 |
+
if (options && options[name] !== undefined)
|
| 139 |
+
return options[name];
|
| 140 |
+
var editorOptions = cm.options.foldOptions;
|
| 141 |
+
if (editorOptions && editorOptions[name] !== undefined)
|
| 142 |
+
return editorOptions[name];
|
| 143 |
+
return defaultOptions[name];
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
CodeMirror.defineExtension("foldOption", function(options, name) {
|
| 147 |
+
return getOption(this, options, name);
|
| 148 |
+
});
|
| 149 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/fold/foldgutter.css
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.CodeMirror-foldmarker {
|
| 2 |
+
color: blue;
|
| 3 |
+
text-shadow: #b9f 1px 1px 2px, #b9f -1px -1px 2px, #b9f 1px -1px 2px, #b9f -1px 1px 2px;
|
| 4 |
+
font-family: arial;
|
| 5 |
+
line-height: .3;
|
| 6 |
+
cursor: pointer;
|
| 7 |
+
}
|
| 8 |
+
.CodeMirror-foldgutter {
|
| 9 |
+
width: .7em;
|
| 10 |
+
}
|
| 11 |
+
.CodeMirror-foldgutter-open,
|
| 12 |
+
.CodeMirror-foldgutter-folded {
|
| 13 |
+
cursor: pointer;
|
| 14 |
+
}
|
| 15 |
+
.CodeMirror-foldgutter-open:after {
|
| 16 |
+
content: "\25BE";
|
| 17 |
+
}
|
| 18 |
+
.CodeMirror-foldgutter-folded:after {
|
| 19 |
+
content: "\25B8";
|
| 20 |
+
}
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/fold/foldgutter.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"), require("./foldcode"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror", "./foldcode"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
"use strict";
|
| 13 |
+
|
| 14 |
+
CodeMirror.defineOption("foldGutter", false, function(cm, val, old) {
|
| 15 |
+
if (old && old != CodeMirror.Init) {
|
| 16 |
+
cm.clearGutter(cm.state.foldGutter.options.gutter);
|
| 17 |
+
cm.state.foldGutter = null;
|
| 18 |
+
cm.off("gutterClick", onGutterClick);
|
| 19 |
+
cm.off("change", onChange);
|
| 20 |
+
cm.off("viewportChange", onViewportChange);
|
| 21 |
+
cm.off("fold", onFold);
|
| 22 |
+
cm.off("unfold", onFold);
|
| 23 |
+
cm.off("swapDoc", updateInViewport);
|
| 24 |
+
}
|
| 25 |
+
if (val) {
|
| 26 |
+
cm.state.foldGutter = new State(parseOptions(val));
|
| 27 |
+
updateInViewport(cm);
|
| 28 |
+
cm.on("gutterClick", onGutterClick);
|
| 29 |
+
cm.on("change", onChange);
|
| 30 |
+
cm.on("viewportChange", onViewportChange);
|
| 31 |
+
cm.on("fold", onFold);
|
| 32 |
+
cm.on("unfold", onFold);
|
| 33 |
+
cm.on("swapDoc", updateInViewport);
|
| 34 |
+
}
|
| 35 |
+
});
|
| 36 |
+
|
| 37 |
+
var Pos = CodeMirror.Pos;
|
| 38 |
+
|
| 39 |
+
function State(options) {
|
| 40 |
+
this.options = options;
|
| 41 |
+
this.from = this.to = 0;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
function parseOptions(opts) {
|
| 45 |
+
if (opts === true) opts = {};
|
| 46 |
+
if (opts.gutter == null) opts.gutter = "CodeMirror-foldgutter";
|
| 47 |
+
if (opts.indicatorOpen == null) opts.indicatorOpen = "CodeMirror-foldgutter-open";
|
| 48 |
+
if (opts.indicatorFolded == null) opts.indicatorFolded = "CodeMirror-foldgutter-folded";
|
| 49 |
+
return opts;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
function isFolded(cm, line) {
|
| 53 |
+
var marks = cm.findMarksAt(Pos(line));
|
| 54 |
+
for (var i = 0; i < marks.length; ++i)
|
| 55 |
+
if (marks[i].__isFold && marks[i].find().from.line == line) return marks[i];
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
function marker(spec) {
|
| 59 |
+
if (typeof spec == "string") {
|
| 60 |
+
var elt = document.createElement("div");
|
| 61 |
+
elt.className = spec + " CodeMirror-guttermarker-subtle";
|
| 62 |
+
return elt;
|
| 63 |
+
} else {
|
| 64 |
+
return spec.cloneNode(true);
|
| 65 |
+
}
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
function updateFoldInfo(cm, from, to) {
|
| 69 |
+
var opts = cm.state.foldGutter.options, cur = from;
|
| 70 |
+
var minSize = cm.foldOption(opts, "minFoldSize");
|
| 71 |
+
var func = cm.foldOption(opts, "rangeFinder");
|
| 72 |
+
cm.eachLine(from, to, function(line) {
|
| 73 |
+
var mark = null;
|
| 74 |
+
if (isFolded(cm, cur)) {
|
| 75 |
+
mark = marker(opts.indicatorFolded);
|
| 76 |
+
} else {
|
| 77 |
+
var pos = Pos(cur, 0);
|
| 78 |
+
var range = func && func(cm, pos);
|
| 79 |
+
if (range && range.to.line - range.from.line >= minSize)
|
| 80 |
+
mark = marker(opts.indicatorOpen);
|
| 81 |
+
}
|
| 82 |
+
cm.setGutterMarker(line, opts.gutter, mark);
|
| 83 |
+
++cur;
|
| 84 |
+
});
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
function updateInViewport(cm) {
|
| 88 |
+
var vp = cm.getViewport(), state = cm.state.foldGutter;
|
| 89 |
+
if (!state) return;
|
| 90 |
+
cm.operation(function() {
|
| 91 |
+
updateFoldInfo(cm, vp.from, vp.to);
|
| 92 |
+
});
|
| 93 |
+
state.from = vp.from; state.to = vp.to;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
function onGutterClick(cm, line, gutter) {
|
| 97 |
+
var state = cm.state.foldGutter;
|
| 98 |
+
if (!state) return;
|
| 99 |
+
var opts = state.options;
|
| 100 |
+
if (gutter != opts.gutter) return;
|
| 101 |
+
var folded = isFolded(cm, line);
|
| 102 |
+
if (folded) folded.clear();
|
| 103 |
+
else cm.foldCode(Pos(line, 0), opts.rangeFinder);
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
function onChange(cm) {
|
| 107 |
+
var state = cm.state.foldGutter;
|
| 108 |
+
if (!state) return;
|
| 109 |
+
var opts = state.options;
|
| 110 |
+
state.from = state.to = 0;
|
| 111 |
+
clearTimeout(state.changeUpdate);
|
| 112 |
+
state.changeUpdate = setTimeout(function() { updateInViewport(cm); }, opts.foldOnChangeTimeSpan || 600);
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
function onViewportChange(cm) {
|
| 116 |
+
var state = cm.state.foldGutter;
|
| 117 |
+
if (!state) return;
|
| 118 |
+
var opts = state.options;
|
| 119 |
+
clearTimeout(state.changeUpdate);
|
| 120 |
+
state.changeUpdate = setTimeout(function() {
|
| 121 |
+
var vp = cm.getViewport();
|
| 122 |
+
if (state.from == state.to || vp.from - state.to > 20 || state.from - vp.to > 20) {
|
| 123 |
+
updateInViewport(cm);
|
| 124 |
+
} else {
|
| 125 |
+
cm.operation(function() {
|
| 126 |
+
if (vp.from < state.from) {
|
| 127 |
+
updateFoldInfo(cm, vp.from, state.from);
|
| 128 |
+
state.from = vp.from;
|
| 129 |
+
}
|
| 130 |
+
if (vp.to > state.to) {
|
| 131 |
+
updateFoldInfo(cm, state.to, vp.to);
|
| 132 |
+
state.to = vp.to;
|
| 133 |
+
}
|
| 134 |
+
});
|
| 135 |
+
}
|
| 136 |
+
}, opts.updateViewportTimeSpan || 400);
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
function onFold(cm, from) {
|
| 140 |
+
var state = cm.state.foldGutter;
|
| 141 |
+
if (!state) return;
|
| 142 |
+
var line = from.line;
|
| 143 |
+
if (line >= state.from && line < state.to)
|
| 144 |
+
updateFoldInfo(cm, line, line + 1);
|
| 145 |
+
}
|
| 146 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/fold/indent-fold.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
"use strict";
|
| 13 |
+
|
| 14 |
+
CodeMirror.registerHelper("fold", "indent", function(cm, start) {
|
| 15 |
+
var tabSize = cm.getOption("tabSize"), firstLine = cm.getLine(start.line);
|
| 16 |
+
if (!/\S/.test(firstLine)) return;
|
| 17 |
+
var getIndent = function(line) {
|
| 18 |
+
return CodeMirror.countColumn(line, null, tabSize);
|
| 19 |
+
};
|
| 20 |
+
var myIndent = getIndent(firstLine);
|
| 21 |
+
var lastLineInFold = null;
|
| 22 |
+
// Go through lines until we find a line that definitely doesn't belong in
|
| 23 |
+
// the block we're folding, or to the end.
|
| 24 |
+
for (var i = start.line + 1, end = cm.lastLine(); i <= end; ++i) {
|
| 25 |
+
var curLine = cm.getLine(i);
|
| 26 |
+
var curIndent = getIndent(curLine);
|
| 27 |
+
if (curIndent > myIndent) {
|
| 28 |
+
// Lines with a greater indent are considered part of the block.
|
| 29 |
+
lastLineInFold = i;
|
| 30 |
+
} else if (!/\S/.test(curLine)) {
|
| 31 |
+
// Empty lines might be breaks within the block we're trying to fold.
|
| 32 |
+
} else {
|
| 33 |
+
// A non-empty line at an indent equal to or less than ours marks the
|
| 34 |
+
// start of another block.
|
| 35 |
+
break;
|
| 36 |
+
}
|
| 37 |
+
}
|
| 38 |
+
if (lastLineInFold) return {
|
| 39 |
+
from: CodeMirror.Pos(start.line, firstLine.length),
|
| 40 |
+
to: CodeMirror.Pos(lastLineInFold, cm.getLine(lastLineInFold).length)
|
| 41 |
+
};
|
| 42 |
+
});
|
| 43 |
+
|
| 44 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/fold/markdown-fold.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
"use strict";
|
| 13 |
+
|
| 14 |
+
CodeMirror.registerHelper("fold", "markdown", function(cm, start) {
|
| 15 |
+
var maxDepth = 100;
|
| 16 |
+
|
| 17 |
+
function isHeader(lineNo) {
|
| 18 |
+
var tokentype = cm.getTokenTypeAt(CodeMirror.Pos(lineNo, 0));
|
| 19 |
+
return tokentype && /\bheader\b/.test(tokentype);
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
function headerLevel(lineNo, line, nextLine) {
|
| 23 |
+
var match = line && line.match(/^#+/);
|
| 24 |
+
if (match && isHeader(lineNo)) return match[0].length;
|
| 25 |
+
match = nextLine && nextLine.match(/^[=\-]+\s*$/);
|
| 26 |
+
if (match && isHeader(lineNo + 1)) return nextLine[0] == "=" ? 1 : 2;
|
| 27 |
+
return maxDepth;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
var firstLine = cm.getLine(start.line), nextLine = cm.getLine(start.line + 1);
|
| 31 |
+
var level = headerLevel(start.line, firstLine, nextLine);
|
| 32 |
+
if (level === maxDepth) return undefined;
|
| 33 |
+
|
| 34 |
+
var lastLineNo = cm.lastLine();
|
| 35 |
+
var end = start.line, nextNextLine = cm.getLine(end + 2);
|
| 36 |
+
while (end < lastLineNo) {
|
| 37 |
+
if (headerLevel(end + 1, nextLine, nextNextLine) <= level) break;
|
| 38 |
+
++end;
|
| 39 |
+
nextLine = nextNextLine;
|
| 40 |
+
nextNextLine = cm.getLine(end + 2);
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
return {
|
| 44 |
+
from: CodeMirror.Pos(start.line, firstLine.length),
|
| 45 |
+
to: CodeMirror.Pos(end, cm.getLine(end).length)
|
| 46 |
+
};
|
| 47 |
+
});
|
| 48 |
+
|
| 49 |
+
});
|
js/t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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
"use strict";
|
| 13 |
+
|
| 14 |
+
var Pos = CodeMirror.Pos;
|
| 15 |
+
function cmp(a, b) { return a.line - b.line || a.ch - b.ch; }
|
| 16 |
+
|
| 17 |
+
var nameStartChar = "A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD";
|
| 18 |
+
var nameChar = nameStartChar + "\-\:\.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040";
|
| 19 |
+
var xmlTagStart = new RegExp("<(/?)([" + nameStartChar + "][" + nameChar + "]*)", "g");
|
| 20 |
+
|
| 21 |
+
function Iter(cm, line, ch, range) {
|
| 22 |
+
this.line = line; this.ch = ch;
|
| 23 |
+
this.cm = cm; this.text = cm.getLine(line);
|
| 24 |
+
this.min = range ? range.from : cm.firstLine();
|
| 25 |
+
this.max = range ? range.to - 1 : cm.lastLine();
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
function tagAt(iter, ch) {
|
| 29 |
+
var type = iter.cm.getTokenTypeAt(Pos(iter.line, ch));
|
| 30 |
+
return type && /\btag\b/.test(type);
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
function nextLine(iter) {
|
| 34 |
+
if (iter.line >= iter.max) return;
|
| 35 |
+
iter.ch = 0;
|
| 36 |
+
iter.text = iter.cm.getLine(++iter.line);
|
| 37 |
+
return true;
|
| 38 |
+
}
|
| 39 |
+
function prevLine(iter) {
|
| 40 |
+
if (iter.line <= iter.min) return;
|
| 41 |
+
iter.text = iter.cm.getLine(--iter.line);
|
| 42 |
+
iter.ch = iter.text.length;
|
| 43 |
+
return true;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
function toTagEnd(iter) {
|
| 47 |
+
for (;;) {
|
| 48 |
+
var gt = iter.text.indexOf(">", iter.ch);
|
| 49 |
+
if (gt == -1) { if (nextLine(iter)) continue; else return; }
|
| 50 |
+
if (!tagAt(iter, gt + 1)) { iter.ch = gt + 1; continue; }
|
| 51 |
+
var lastSlash = iter.text.lastIndexOf("/", gt);
|
| 52 |
+
var selfClose = lastSlash > -1 && !/\S/.test(iter.text.slice(lastSlash + 1, gt));
|
| 53 |
+
iter.ch = gt + 1;
|
| 54 |
+
return selfClose ? "selfClose" : "regular";
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
function toTagStart(iter) {
|
| 58 |
+
for (;;) {
|
| 59 |
+
var lt = iter.ch ? iter.text.lastIndexOf("<", iter.ch - 1) : -1;
|
| 60 |
+
if (lt == -1) { if (prevLine(iter)) continue; else return; }
|
| 61 |
+
if (!tagAt(iter, lt + 1)) { iter.ch = lt; continue; }
|
| 62 |
+
xmlTagStart.lastIndex = lt;
|
| 63 |
+
iter.ch = lt;
|
| 64 |
+
var match = xmlTagStart.exec(iter.text);
|
| 65 |
+
if (match && match.index == lt) return match;
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
function toNextTag(iter) {
|
| 70 |
+
for (;;) {
|
| 71 |
+
xmlTagStart.lastIndex = iter.ch;
|
| 72 |
+
var found = xmlTagStart.exec(iter.text);
|
| 73 |
+
if (!found) { if (nextLine(iter)) continue; else return; }
|
| 74 |
+
if (!tagAt(iter, found.index + 1)) { iter.ch = found.index + 1; continue; }
|
| 75 |
+
iter.ch = found.index + found[0].length;
|
| 76 |
+
return found;
|
| 77 |
+
}
|
| 78 |
+
}
|
| 79 |
+
function toPrevTag(iter) {
|
| 80 |
+
for (;;) {
|
| 81 |
+
var gt = iter.ch ? iter.text.lastIndexOf(">", iter.ch - 1) : -1;
|
| 82 |
+
if (gt == -1) { if (prevLine(iter)) continue; else return; }
|
| 83 |
+
if (!tagAt(iter, gt + 1)) { iter.ch = gt; continue; }
|
| 84 |
+
var lastSlash = iter.text.lastIndexOf("/", gt);
|
| 85 |
+
var selfClose = lastSlash > -1 && !/\S/.test(iter.text.slice(lastSlash + 1, gt));
|
| 86 |
+
iter.ch = gt + 1;
|
| 87 |
+
return selfClose ? "selfClose" : "regular";
|
| 88 |
+
}
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
function findMatchingClose(iter, tag) {
|
| 92 |
+
var stack = [];
|
| 93 |
+
for (;;) {
|
| 94 |
+
var next = toNextTag(iter), end, startLine = iter.line, startCh = iter.ch - (next ? next[0].length : 0);
|
| 95 |
+
if (!next || !(end = toTagEnd(iter))) return;
|
| 96 |
+
if (end == "selfClose") continue;
|
| 97 |
+
if (next[1]) { // closing tag
|
| 98 |
+
for (var i = stack.length - 1; i >= 0; --i) if (stack[i] == next[2]) {
|
| 99 |
+
stack.length = i;
|
| 100 |
+
break;
|
| 101 |
+
}
|
| 102 |
+
if (i < 0 && (!tag || tag == next[2])) return {
|
| 103 |
+
tag: next[2],
|
| 104 |
+
from: Pos(startLine, startCh),
|
| 105 |
+
to: Pos(iter.line, iter.ch)
|
| 106 |
+
};
|
| 107 |
+
} else { // opening tag
|
| 108 |
+
stack.push(next[2]);
|
| 109 |
+
}
|
| 110 |
+
}
|
| 111 |
+
}
|
| 112 |
+
function findMatchingOpen(iter, tag) {
|
| 113 |
+
var stack = [];
|
| 114 |
+
for (;;) {
|
| 115 |
+
var prev = toPrevTag(iter);
|
| 116 |
+
if (!prev) return;
|
| 117 |
+
if (prev == "selfClose") { toTagStart(iter); continue; }
|
| 118 |
+
var endLine = iter.line, endCh = iter.ch;
|
| 119 |
+
var start = toTagStart(iter);
|
| 120 |
+
if (!start) return;
|
| 121 |
+
if (start[1]) { // closing tag
|
| 122 |
+
stack.push(start[2]);
|
| 123 |
+
} else { // opening tag
|
| 124 |
+
for (var i = stack.length - 1; i >= 0; --i) if (stack[i] == start[2]) {
|
| 125 |
+
stack.length = i;
|
| 126 |
+
break;
|
| 127 |
+
}
|
| 128 |
+
if (i < 0 && (!tag || tag == start[2])) return {
|
| 129 |
+
tag: start[2],
|
| 130 |
+
from: Pos(iter.line, iter.ch),
|
| 131 |
+
to: Pos(endLine, endCh)
|
| 132 |
+
};
|
| 133 |
+
}
|
| 134 |
+
}
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
CodeMirror.registerHelper("fold", "xml", function(cm, start) {
|
| 138 |
+
var iter = new Iter(cm, start.line, 0);
|
| 139 |
+
for (;;) {
|
| 140 |
+
var openTag = toNextTag(iter), end;
|
| 141 |
+
if (!openTag || iter.line != start.line || !(end = toTagEnd(iter))) return;
|
| 142 |
+
if (!openTag[1] && end != "selfClose") {
|
| 143 |
+
var start = Pos(iter.line, iter.ch);
|
| 144 |
+
var close = findMatchingClose(iter, openTag[2]);
|
| 145 |
+
return close && {from: start, to: close.from};
|
| 146 |
+
}
|
| 147 |
+
}
|
| 148 |
+
});
|
| 149 |
+
CodeMirror.findMatchingTag = function(cm, pos, range) {
|
| 150 |
+
var iter = new Iter(cm, pos.line, pos.ch, range);
|
| 151 |
+
if (iter.text.indexOf(">") == -1 && iter.text.indexOf("<") == -1) return;
|
| 152 |
+
var end = toTagEnd(iter), to = end && Pos(iter.line, iter.ch);
|
| 153 |
+
var start = end && toTagStart(iter);
|
| 154 |
+
if (!end || !start || cmp(iter, pos) > 0) return;
|
| 155 |
+
var here = {from: Pos(iter.line, iter.ch), to: to, tag: start[2]};
|
| 156 |
+
if (end == "selfClose") return {open: here, close: null, at: "open"};
|
| 157 |
+
|
| 158 |
+
if (start[1]) { // closing tag
|
| 159 |
+
return {open: findMatchingOpen(iter, start[2]), close: here, at: "close"};
|
| 160 |
+
} else { // opening tag
|
| 161 |
+
iter = new Iter(cm, to.line, to.ch, range);
|
| 162 |
+
return {open: here, close: findMatchingClose(iter, start[2]), at: "open"};
|
| 163 |
+
}
|
| 164 |
+
};
|
| 165 |
+
|
| 166 |
+
CodeMirror.findEnclosingTag = function(cm, pos, range) {
|
| 167 |
+
var iter = new Iter(cm, pos.line, pos.ch, range);
|
| 168 |
+
for (;;) {
|
| 169 |
+
var open = findMatchingOpen(iter);
|
| 170 |
+
if (!open) break;
|
| 171 |
+
var forward = new Iter(cm, pos.line, pos.ch, range);
|
| 172 |
+
var close = findMatchingClose(forward, open.tag);
|
| 173 |
+
if (close) return {open: open, close: close};
|
| 174 |
+
}
|
| 175 |
+
};
|
| 176 |
+
|
| 177 |
+
// Used by addon/edit/closetag.js
|
| 178 |
+
CodeMirror.scanForClosingTag = function(cm, pos, name, end) {
|
| 179 |
+
var iter = new Iter(cm, pos.line, pos.ch, end ? {from: 0, to: end} : null);
|
| 180 |
+
return findMatchingClose(iter, name);
|
| 181 |
+
};
|
| 182 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/hint/anyword-hint.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
"use strict";
|
| 13 |
+
|
| 14 |
+
var WORD = /[\w$]+/, RANGE = 500;
|
| 15 |
+
|
| 16 |
+
CodeMirror.registerHelper("hint", "anyword", function(editor, options) {
|
| 17 |
+
var word = options && options.word || WORD;
|
| 18 |
+
var range = options && options.range || RANGE;
|
| 19 |
+
var cur = editor.getCursor(), curLine = editor.getLine(cur.line);
|
| 20 |
+
var end = cur.ch, start = end;
|
| 21 |
+
while (start && word.test(curLine.charAt(start - 1))) --start;
|
| 22 |
+
var curWord = start != end && curLine.slice(start, end);
|
| 23 |
+
|
| 24 |
+
var list = [], seen = {};
|
| 25 |
+
var re = new RegExp(word.source, "g");
|
| 26 |
+
for (var dir = -1; dir <= 1; dir += 2) {
|
| 27 |
+
var line = cur.line, endLine = Math.min(Math.max(line + dir * range, editor.firstLine()), editor.lastLine()) + dir;
|
| 28 |
+
for (; line != endLine; line += dir) {
|
| 29 |
+
var text = editor.getLine(line), m;
|
| 30 |
+
while (m = re.exec(text)) {
|
| 31 |
+
if (line == cur.line && m[0] === curWord) continue;
|
| 32 |
+
if ((!curWord || m[0].lastIndexOf(curWord, 0) == 0) && !Object.prototype.hasOwnProperty.call(seen, m[0])) {
|
| 33 |
+
seen[m[0]] = true;
|
| 34 |
+
list.push(m[0]);
|
| 35 |
+
}
|
| 36 |
+
}
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
return {list: list, from: CodeMirror.Pos(cur.line, start), to: CodeMirror.Pos(cur.line, end)};
|
| 40 |
+
});
|
| 41 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/hint/css-hint.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"), require("../../mode/css/css"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror", "../../mode/css/css"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
"use strict";
|
| 13 |
+
|
| 14 |
+
var pseudoClasses = {link: 1, visited: 1, active: 1, hover: 1, focus: 1,
|
| 15 |
+
"first-letter": 1, "first-line": 1, "first-child": 1,
|
| 16 |
+
before: 1, after: 1, lang: 1};
|
| 17 |
+
|
| 18 |
+
CodeMirror.registerHelper("hint", "css", function(cm) {
|
| 19 |
+
var cur = cm.getCursor(), token = cm.getTokenAt(cur);
|
| 20 |
+
var inner = CodeMirror.innerMode(cm.getMode(), token.state);
|
| 21 |
+
if (inner.mode.name != "css") return;
|
| 22 |
+
|
| 23 |
+
if (token.type == "keyword" && "!important".indexOf(token.string) == 0)
|
| 24 |
+
return {list: ["!important"], from: CodeMirror.Pos(cur.line, token.start),
|
| 25 |
+
to: CodeMirror.Pos(cur.line, token.end)};
|
| 26 |
+
|
| 27 |
+
var start = token.start, end = cur.ch, word = token.string.slice(0, end - start);
|
| 28 |
+
if (/[^\w$_-]/.test(word)) {
|
| 29 |
+
word = ""; start = end = cur.ch;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
var spec = CodeMirror.resolveMode("text/css");
|
| 33 |
+
|
| 34 |
+
var result = [];
|
| 35 |
+
function add(keywords) {
|
| 36 |
+
for (var name in keywords)
|
| 37 |
+
if (!word || name.lastIndexOf(word, 0) == 0)
|
| 38 |
+
result.push(name);
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
var st = inner.state.state;
|
| 42 |
+
if (st == "pseudo" || token.type == "variable-3") {
|
| 43 |
+
add(pseudoClasses);
|
| 44 |
+
} else if (st == "block" || st == "maybeprop") {
|
| 45 |
+
add(spec.propertyKeywords);
|
| 46 |
+
} else if (st == "prop" || st == "parens" || st == "at" || st == "params") {
|
| 47 |
+
add(spec.valueKeywords);
|
| 48 |
+
add(spec.colorKeywords);
|
| 49 |
+
} else if (st == "media" || st == "media_parens") {
|
| 50 |
+
add(spec.mediaTypes);
|
| 51 |
+
add(spec.mediaFeatures);
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
if (result.length) return {
|
| 55 |
+
list: result,
|
| 56 |
+
from: CodeMirror.Pos(cur.line, start),
|
| 57 |
+
to: CodeMirror.Pos(cur.line, end)
|
| 58 |
+
};
|
| 59 |
+
});
|
| 60 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"), require("./xml-hint"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror", "./xml-hint"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
"use strict";
|
| 13 |
+
|
| 14 |
+
var langs = "ab aa af ak sq am ar an hy as av ae ay az bm ba eu be bn bh bi bs br bg my ca ch ce ny zh cv kw co cr hr cs da dv nl dz en eo et ee fo fj fi fr ff gl ka de el gn gu ht ha he hz hi ho hu ia id ie ga ig ik io is it iu ja jv kl kn kr ks kk km ki rw ky kv kg ko ku kj la lb lg li ln lo lt lu lv gv mk mg ms ml mt mi mr mh mn na nv nb nd ne ng nn no ii nr oc oj cu om or os pa pi fa pl ps pt qu rm rn ro ru sa sc sd se sm sg sr gd sn si sk sl so st es su sw ss sv ta te tg th ti bo tk tl tn to tr ts tt tw ty ug uk ur uz ve vi vo wa cy wo fy xh yi yo za zu".split(" ");
|
| 15 |
+
var targets = ["_blank", "_self", "_top", "_parent"];
|
| 16 |
+
var charsets = ["ascii", "utf-8", "utf-16", "latin1", "latin1"];
|
| 17 |
+
var methods = ["get", "post", "put", "delete"];
|
| 18 |
+
var encs = ["application/x-www-form-urlencoded", "multipart/form-data", "text/plain"];
|
| 19 |
+
var media = ["all", "screen", "print", "embossed", "braille", "handheld", "print", "projection", "screen", "tty", "tv", "speech",
|
| 20 |
+
"3d-glasses", "resolution [>][<][=] [X]", "device-aspect-ratio: X/Y", "orientation:portrait",
|
| 21 |
+
"orientation:landscape", "device-height: [X]", "device-width: [X]"];
|
| 22 |
+
var s = { attrs: {} }; // Simple tag, reused for a whole lot of tags
|
| 23 |
+
|
| 24 |
+
var data = {
|
| 25 |
+
a: {
|
| 26 |
+
attrs: {
|
| 27 |
+
href: null, ping: null, type: null,
|
| 28 |
+
media: media,
|
| 29 |
+
target: targets,
|
| 30 |
+
hreflang: langs
|
| 31 |
+
}
|
| 32 |
+
},
|
| 33 |
+
abbr: s,
|
| 34 |
+
acronym: s,
|
| 35 |
+
address: s,
|
| 36 |
+
applet: s,
|
| 37 |
+
area: {
|
| 38 |
+
attrs: {
|
| 39 |
+
alt: null, coords: null, href: null, target: null, ping: null,
|
| 40 |
+
media: media, hreflang: langs, type: null,
|
| 41 |
+
shape: ["default", "rect", "circle", "poly"]
|
| 42 |
+
}
|
| 43 |
+
},
|
| 44 |
+
article: s,
|
| 45 |
+
aside: s,
|
| 46 |
+
audio: {
|
| 47 |
+
attrs: {
|
| 48 |
+
src: null, mediagroup: null,
|
| 49 |
+
crossorigin: ["anonymous", "use-credentials"],
|
| 50 |
+
preload: ["none", "metadata", "auto"],
|
| 51 |
+
autoplay: ["", "autoplay"],
|
| 52 |
+
loop: ["", "loop"],
|
| 53 |
+
controls: ["", "controls"]
|
| 54 |
+
}
|
| 55 |
+
},
|
| 56 |
+
b: s,
|
| 57 |
+
base: { attrs: { href: null, target: targets } },
|
| 58 |
+
basefont: s,
|
| 59 |
+
bdi: s,
|
| 60 |
+
bdo: s,
|
| 61 |
+
big: s,
|
| 62 |
+
blockquote: { attrs: { cite: null } },
|
| 63 |
+
body: s,
|
| 64 |
+
br: s,
|
| 65 |
+
button: {
|
| 66 |
+
attrs: {
|
| 67 |
+
form: null, formaction: null, name: null, value: null,
|
| 68 |
+
autofocus: ["", "autofocus"],
|
| 69 |
+
disabled: ["", "autofocus"],
|
| 70 |
+
formenctype: encs,
|
| 71 |
+
formmethod: methods,
|
| 72 |
+
formnovalidate: ["", "novalidate"],
|
| 73 |
+
formtarget: targets,
|
| 74 |
+
type: ["submit", "reset", "button"]
|
| 75 |
+
}
|
| 76 |
+
},
|
| 77 |
+
canvas: { attrs: { width: null, height: null } },
|
| 78 |
+
caption: s,
|
| 79 |
+
center: s,
|
| 80 |
+
cite: s,
|
| 81 |
+
code: s,
|
| 82 |
+
col: { attrs: { span: null } },
|
| 83 |
+
colgroup: { attrs: { span: null } },
|
| 84 |
+
command: {
|
| 85 |
+
attrs: {
|
| 86 |
+
type: ["command", "checkbox", "radio"],
|
| 87 |
+
label: null, icon: null, radiogroup: null, command: null, title: null,
|
| 88 |
+
disabled: ["", "disabled"],
|
| 89 |
+
checked: ["", "checked"]
|
| 90 |
+
}
|
| 91 |
+
},
|
| 92 |
+
data: { attrs: { value: null } },
|
| 93 |
+
datagrid: { attrs: { disabled: ["", "disabled"], multiple: ["", "multiple"] } },
|
| 94 |
+
datalist: { attrs: { data: null } },
|
| 95 |
+
dd: s,
|
| 96 |
+
del: { attrs: { cite: null, datetime: null } },
|
| 97 |
+
details: { attrs: { open: ["", "open"] } },
|
| 98 |
+
dfn: s,
|
| 99 |
+
dir: s,
|
| 100 |
+
div: s,
|
| 101 |
+
dl: s,
|
| 102 |
+
dt: s,
|
| 103 |
+
em: s,
|
| 104 |
+
embed: { attrs: { src: null, type: null, width: null, height: null } },
|
| 105 |
+
eventsource: { attrs: { src: null } },
|
| 106 |
+
fieldset: { attrs: { disabled: ["", "disabled"], form: null, name: null } },
|
| 107 |
+
figcaption: s,
|
| 108 |
+
figure: s,
|
| 109 |
+
font: s,
|
| 110 |
+
footer: s,
|
| 111 |
+
form: {
|
| 112 |
+
attrs: {
|
| 113 |
+
action: null, name: null,
|
| 114 |
+
"accept-charset": charsets,
|
| 115 |
+
autocomplete: ["on", "off"],
|
| 116 |
+
enctype: encs,
|
| 117 |
+
method: methods,
|
| 118 |
+
novalidate: ["", "novalidate"],
|
| 119 |
+
target: targets
|
| 120 |
+
}
|
| 121 |
+
},
|
| 122 |
+
frame: s,
|
| 123 |
+
frameset: s,
|
| 124 |
+
h1: s, h2: s, h3: s, h4: s, h5: s, h6: s,
|
| 125 |
+
head: {
|
| 126 |
+
attrs: {},
|
| 127 |
+
children: ["title", "base", "link", "style", "meta", "script", "noscript", "command"]
|
| 128 |
+
},
|
| 129 |
+
header: s,
|
| 130 |
+
hgroup: s,
|
| 131 |
+
hr: s,
|
| 132 |
+
html: {
|
| 133 |
+
attrs: { manifest: null },
|
| 134 |
+
children: ["head", "body"]
|
| 135 |
+
},
|
| 136 |
+
i: s,
|
| 137 |
+
iframe: {
|
| 138 |
+
attrs: {
|
| 139 |
+
src: null, srcdoc: null, name: null, width: null, height: null,
|
| 140 |
+
sandbox: ["allow-top-navigation", "allow-same-origin", "allow-forms", "allow-scripts"],
|
| 141 |
+
seamless: ["", "seamless"]
|
| 142 |
+
}
|
| 143 |
+
},
|
| 144 |
+
img: {
|
| 145 |
+
attrs: {
|
| 146 |
+
alt: null, src: null, ismap: null, usemap: null, width: null, height: null,
|
| 147 |
+
crossorigin: ["anonymous", "use-credentials"]
|
| 148 |
+
}
|
| 149 |
+
},
|
| 150 |
+
input: {
|
| 151 |
+
attrs: {
|
| 152 |
+
alt: null, dirname: null, form: null, formaction: null,
|
| 153 |
+
height: null, list: null, max: null, maxlength: null, min: null,
|
| 154 |
+
name: null, pattern: null, placeholder: null, size: null, src: null,
|
| 155 |
+
step: null, value: null, width: null,
|
| 156 |
+
accept: ["audio/*", "video/*", "image/*"],
|
| 157 |
+
autocomplete: ["on", "off"],
|
| 158 |
+
autofocus: ["", "autofocus"],
|
| 159 |
+
checked: ["", "checked"],
|
| 160 |
+
disabled: ["", "disabled"],
|
| 161 |
+
formenctype: encs,
|
| 162 |
+
formmethod: methods,
|
| 163 |
+
formnovalidate: ["", "novalidate"],
|
| 164 |
+
formtarget: targets,
|
| 165 |
+
multiple: ["", "multiple"],
|
| 166 |
+
readonly: ["", "readonly"],
|
| 167 |
+
required: ["", "required"],
|
| 168 |
+
type: ["hidden", "text", "search", "tel", "url", "email", "password", "datetime", "date", "month",
|
| 169 |
+
"week", "time", "datetime-local", "number", "range", "color", "checkbox", "radio",
|
| 170 |
+
"file", "submit", "image", "reset", "button"]
|
| 171 |
+
}
|
| 172 |
+
},
|
| 173 |
+
ins: { attrs: { cite: null, datetime: null } },
|
| 174 |
+
kbd: s,
|
| 175 |
+
keygen: {
|
| 176 |
+
attrs: {
|
| 177 |
+
challenge: null, form: null, name: null,
|
| 178 |
+
autofocus: ["", "autofocus"],
|
| 179 |
+
disabled: ["", "disabled"],
|
| 180 |
+
keytype: ["RSA"]
|
| 181 |
+
}
|
| 182 |
+
},
|
| 183 |
+
label: { attrs: { "for": null, form: null } },
|
| 184 |
+
legend: s,
|
| 185 |
+
li: { attrs: { value: null } },
|
| 186 |
+
link: {
|
| 187 |
+
attrs: {
|
| 188 |
+
href: null, type: null,
|
| 189 |
+
hreflang: langs,
|
| 190 |
+
media: media,
|
| 191 |
+
sizes: ["all", "16x16", "16x16 32x32", "16x16 32x32 64x64"]
|
| 192 |
+
}
|
| 193 |
+
},
|
| 194 |
+
map: { attrs: { name: null } },
|
| 195 |
+
mark: s,
|
| 196 |
+
menu: { attrs: { label: null, type: ["list", "context", "toolbar"] } },
|
| 197 |
+
meta: {
|
| 198 |
+
attrs: {
|
| 199 |
+
content: null,
|
| 200 |
+
charset: charsets,
|
| 201 |
+
name: ["viewport", "application-name", "author", "description", "generator", "keywords"],
|
| 202 |
+
"http-equiv": ["content-language", "content-type", "default-style", "refresh"]
|
| 203 |
+
}
|
| 204 |
+
},
|
| 205 |
+
meter: { attrs: { value: null, min: null, low: null, high: null, max: null, optimum: null } },
|
| 206 |
+
nav: s,
|
| 207 |
+
noframes: s,
|
| 208 |
+
noscript: s,
|
| 209 |
+
object: {
|
| 210 |
+
attrs: {
|
| 211 |
+
data: null, type: null, name: null, usemap: null, form: null, width: null, height: null,
|
| 212 |
+
typemustmatch: ["", "typemustmatch"]
|
| 213 |
+
}
|
| 214 |
+
},
|
| 215 |
+
ol: { attrs: { reversed: ["", "reversed"], start: null, type: ["1", "a", "A", "i", "I"] } },
|
| 216 |
+
optgroup: { attrs: { disabled: ["", "disabled"], label: null } },
|
| 217 |
+
option: { attrs: { disabled: ["", "disabled"], label: null, selected: ["", "selected"], value: null } },
|
| 218 |
+
output: { attrs: { "for": null, form: null, name: null } },
|
| 219 |
+
p: s,
|
| 220 |
+
param: { attrs: { name: null, value: null } },
|
| 221 |
+
pre: s,
|
| 222 |
+
progress: { attrs: { value: null, max: null } },
|
| 223 |
+
q: { attrs: { cite: null } },
|
| 224 |
+
rp: s,
|
| 225 |
+
rt: s,
|
| 226 |
+
ruby: s,
|
| 227 |
+
s: s,
|
| 228 |
+
samp: s,
|
| 229 |
+
script: {
|
| 230 |
+
attrs: {
|
| 231 |
+
type: ["text/javascript"],
|
| 232 |
+
src: null,
|
| 233 |
+
async: ["", "async"],
|
| 234 |
+
defer: ["", "defer"],
|
| 235 |
+
charset: charsets
|
| 236 |
+
}
|
| 237 |
+
},
|
| 238 |
+
section: s,
|
| 239 |
+
select: {
|
| 240 |
+
attrs: {
|
| 241 |
+
form: null, name: null, size: null,
|
| 242 |
+
autofocus: ["", "autofocus"],
|
| 243 |
+
disabled: ["", "disabled"],
|
| 244 |
+
multiple: ["", "multiple"]
|
| 245 |
+
}
|
| 246 |
+
},
|
| 247 |
+
small: s,
|
| 248 |
+
source: { attrs: { src: null, type: null, media: null } },
|
| 249 |
+
span: s,
|
| 250 |
+
strike: s,
|
| 251 |
+
strong: s,
|
| 252 |
+
style: {
|
| 253 |
+
attrs: {
|
| 254 |
+
type: ["text/css"],
|
| 255 |
+
media: media,
|
| 256 |
+
scoped: null
|
| 257 |
+
}
|
| 258 |
+
},
|
| 259 |
+
sub: s,
|
| 260 |
+
summary: s,
|
| 261 |
+
sup: s,
|
| 262 |
+
table: s,
|
| 263 |
+
tbody: s,
|
| 264 |
+
td: { attrs: { colspan: null, rowspan: null, headers: null } },
|
| 265 |
+
textarea: {
|
| 266 |
+
attrs: {
|
| 267 |
+
dirname: null, form: null, maxlength: null, name: null, placeholder: null,
|
| 268 |
+
rows: null, cols: null,
|
| 269 |
+
autofocus: ["", "autofocus"],
|
| 270 |
+
disabled: ["", "disabled"],
|
| 271 |
+
readonly: ["", "readonly"],
|
| 272 |
+
required: ["", "required"],
|
| 273 |
+
wrap: ["soft", "hard"]
|
| 274 |
+
}
|
| 275 |
+
},
|
| 276 |
+
tfoot: s,
|
| 277 |
+
th: { attrs: { colspan: null, rowspan: null, headers: null, scope: ["row", "col", "rowgroup", "colgroup"] } },
|
| 278 |
+
thead: s,
|
| 279 |
+
time: { attrs: { datetime: null } },
|
| 280 |
+
title: s,
|
| 281 |
+
tr: s,
|
| 282 |
+
track: {
|
| 283 |
+
attrs: {
|
| 284 |
+
src: null, label: null, "default": null,
|
| 285 |
+
kind: ["subtitles", "captions", "descriptions", "chapters", "metadata"],
|
| 286 |
+
srclang: langs
|
| 287 |
+
}
|
| 288 |
+
},
|
| 289 |
+
tt: s,
|
| 290 |
+
u: s,
|
| 291 |
+
ul: s,
|
| 292 |
+
"var": s,
|
| 293 |
+
video: {
|
| 294 |
+
attrs: {
|
| 295 |
+
src: null, poster: null, width: null, height: null,
|
| 296 |
+
crossorigin: ["anonymous", "use-credentials"],
|
| 297 |
+
preload: ["auto", "metadata", "none"],
|
| 298 |
+
autoplay: ["", "autoplay"],
|
| 299 |
+
mediagroup: ["movie"],
|
| 300 |
+
muted: ["", "muted"],
|
| 301 |
+
controls: ["", "controls"]
|
| 302 |
+
}
|
| 303 |
+
},
|
| 304 |
+
wbr: s
|
| 305 |
+
};
|
| 306 |
+
|
| 307 |
+
var globalAttrs = {
|
| 308 |
+
accesskey: ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"],
|
| 309 |
+
"class": null,
|
| 310 |
+
contenteditable: ["true", "false"],
|
| 311 |
+
contextmenu: null,
|
| 312 |
+
dir: ["ltr", "rtl", "auto"],
|
| 313 |
+
draggable: ["true", "false", "auto"],
|
| 314 |
+
dropzone: ["copy", "move", "link", "string:", "file:"],
|
| 315 |
+
hidden: ["hidden"],
|
| 316 |
+
id: null,
|
| 317 |
+
inert: ["inert"],
|
| 318 |
+
itemid: null,
|
| 319 |
+
itemprop: null,
|
| 320 |
+
itemref: null,
|
| 321 |
+
itemscope: ["itemscope"],
|
| 322 |
+
itemtype: null,
|
| 323 |
+
lang: ["en", "es"],
|
| 324 |
+
spellcheck: ["true", "false"],
|
| 325 |
+
style: null,
|
| 326 |
+
tabindex: ["1", "2", "3", "4", "5", "6", "7", "8", "9"],
|
| 327 |
+
title: null,
|
| 328 |
+
translate: ["yes", "no"],
|
| 329 |
+
onclick: null,
|
| 330 |
+
rel: ["stylesheet", "alternate", "author", "bookmark", "help", "license", "next", "nofollow", "noreferrer", "prefetch", "prev", "search", "tag"]
|
| 331 |
+
};
|
| 332 |
+
function populate(obj) {
|
| 333 |
+
for (var attr in globalAttrs) if (globalAttrs.hasOwnProperty(attr))
|
| 334 |
+
obj.attrs[attr] = globalAttrs[attr];
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
populate(s);
|
| 338 |
+
for (var tag in data) if (data.hasOwnProperty(tag) && data[tag] != s)
|
| 339 |
+
populate(data[tag]);
|
| 340 |
+
|
| 341 |
+
CodeMirror.htmlSchema = data;
|
| 342 |
+
function htmlHint(cm, options) {
|
| 343 |
+
var local = {schemaInfo: data};
|
| 344 |
+
if (options) for (var opt in options) local[opt] = options[opt];
|
| 345 |
+
return CodeMirror.hint.xml(cm, local);
|
| 346 |
+
}
|
| 347 |
+
CodeMirror.registerHelper("hint", "html", htmlHint);
|
| 348 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/hint/javascript-hint.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
var Pos = CodeMirror.Pos;
|
| 13 |
+
|
| 14 |
+
function forEach(arr, f) {
|
| 15 |
+
for (var i = 0, e = arr.length; i < e; ++i) f(arr[i]);
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
function arrayContains(arr, item) {
|
| 19 |
+
if (!Array.prototype.indexOf) {
|
| 20 |
+
var i = arr.length;
|
| 21 |
+
while (i--) {
|
| 22 |
+
if (arr[i] === item) {
|
| 23 |
+
return true;
|
| 24 |
+
}
|
| 25 |
+
}
|
| 26 |
+
return false;
|
| 27 |
+
}
|
| 28 |
+
return arr.indexOf(item) != -1;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
function scriptHint(editor, keywords, getToken, options) {
|
| 32 |
+
// Find the token at the cursor
|
| 33 |
+
var cur = editor.getCursor(), token = getToken(editor, cur);
|
| 34 |
+
if (/\b(?:string|comment)\b/.test(token.type)) return;
|
| 35 |
+
token.state = CodeMirror.innerMode(editor.getMode(), token.state).state;
|
| 36 |
+
|
| 37 |
+
// If it's not a 'word-style' token, ignore the token.
|
| 38 |
+
if (!/^[\w$_]*$/.test(token.string)) {
|
| 39 |
+
token = {start: cur.ch, end: cur.ch, string: "", state: token.state,
|
| 40 |
+
type: token.string == "." ? "property" : null};
|
| 41 |
+
} else if (token.end > cur.ch) {
|
| 42 |
+
token.end = cur.ch;
|
| 43 |
+
token.string = token.string.slice(0, cur.ch - token.start);
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
var tprop = token;
|
| 47 |
+
// If it is a property, find out what it is a property of.
|
| 48 |
+
while (tprop.type == "property") {
|
| 49 |
+
tprop = getToken(editor, Pos(cur.line, tprop.start));
|
| 50 |
+
if (tprop.string != ".") return;
|
| 51 |
+
tprop = getToken(editor, Pos(cur.line, tprop.start));
|
| 52 |
+
if (!context) var context = [];
|
| 53 |
+
context.push(tprop);
|
| 54 |
+
}
|
| 55 |
+
return {list: getCompletions(token, context, keywords, options),
|
| 56 |
+
from: Pos(cur.line, token.start),
|
| 57 |
+
to: Pos(cur.line, token.end)};
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
function javascriptHint(editor, options) {
|
| 61 |
+
return scriptHint(editor, javascriptKeywords,
|
| 62 |
+
function (e, cur) {return e.getTokenAt(cur);},
|
| 63 |
+
options);
|
| 64 |
+
};
|
| 65 |
+
CodeMirror.registerHelper("hint", "javascript", javascriptHint);
|
| 66 |
+
|
| 67 |
+
function getCoffeeScriptToken(editor, cur) {
|
| 68 |
+
// This getToken, it is for coffeescript, imitates the behavior of
|
| 69 |
+
// getTokenAt method in javascript.js, that is, returning "property"
|
| 70 |
+
// type and treat "." as indepenent token.
|
| 71 |
+
var token = editor.getTokenAt(cur);
|
| 72 |
+
if (cur.ch == token.start + 1 && token.string.charAt(0) == '.') {
|
| 73 |
+
token.end = token.start;
|
| 74 |
+
token.string = '.';
|
| 75 |
+
token.type = "property";
|
| 76 |
+
}
|
| 77 |
+
else if (/^\.[\w$_]*$/.test(token.string)) {
|
| 78 |
+
token.type = "property";
|
| 79 |
+
token.start++;
|
| 80 |
+
token.string = token.string.replace(/\./, '');
|
| 81 |
+
}
|
| 82 |
+
return token;
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
function coffeescriptHint(editor, options) {
|
| 86 |
+
return scriptHint(editor, coffeescriptKeywords, getCoffeeScriptToken, options);
|
| 87 |
+
}
|
| 88 |
+
CodeMirror.registerHelper("hint", "coffeescript", coffeescriptHint);
|
| 89 |
+
|
| 90 |
+
var stringProps = ("charAt charCodeAt indexOf lastIndexOf substring substr slice trim trimLeft trimRight " +
|
| 91 |
+
"toUpperCase toLowerCase split concat match replace search").split(" ");
|
| 92 |
+
var arrayProps = ("length concat join splice push pop shift unshift slice reverse sort indexOf " +
|
| 93 |
+
"lastIndexOf every some filter forEach map reduce reduceRight ").split(" ");
|
| 94 |
+
var funcProps = "prototype apply call bind".split(" ");
|
| 95 |
+
var javascriptKeywords = ("break case catch continue debugger default delete do else false finally for function " +
|
| 96 |
+
"if in instanceof new null return switch throw true try typeof var void while with").split(" ");
|
| 97 |
+
var coffeescriptKeywords = ("and break catch class continue delete do else extends false finally for " +
|
| 98 |
+
"if in instanceof isnt new no not null of off on or return switch then throw true try typeof until void while with yes").split(" ");
|
| 99 |
+
|
| 100 |
+
function getCompletions(token, context, keywords, options) {
|
| 101 |
+
var found = [], start = token.string, global = options && options.globalScope || window;
|
| 102 |
+
function maybeAdd(str) {
|
| 103 |
+
if (str.lastIndexOf(start, 0) == 0 && !arrayContains(found, str)) found.push(str);
|
| 104 |
+
}
|
| 105 |
+
function gatherCompletions(obj) {
|
| 106 |
+
if (typeof obj == "string") forEach(stringProps, maybeAdd);
|
| 107 |
+
else if (obj instanceof Array) forEach(arrayProps, maybeAdd);
|
| 108 |
+
else if (obj instanceof Function) forEach(funcProps, maybeAdd);
|
| 109 |
+
for (var name in obj) maybeAdd(name);
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
if (context && context.length) {
|
| 113 |
+
// If this is a property, see if it belongs to some object we can
|
| 114 |
+
// find in the current environment.
|
| 115 |
+
var obj = context.pop(), base;
|
| 116 |
+
if (obj.type && obj.type.indexOf("variable") === 0) {
|
| 117 |
+
if (options && options.additionalContext)
|
| 118 |
+
base = options.additionalContext[obj.string];
|
| 119 |
+
if (!options || options.useGlobalScope !== false)
|
| 120 |
+
base = base || global[obj.string];
|
| 121 |
+
} else if (obj.type == "string") {
|
| 122 |
+
base = "";
|
| 123 |
+
} else if (obj.type == "atom") {
|
| 124 |
+
base = 1;
|
| 125 |
+
} else if (obj.type == "function") {
|
| 126 |
+
if (global.jQuery != null && (obj.string == '$' || obj.string == 'jQuery') &&
|
| 127 |
+
(typeof global.jQuery == 'function'))
|
| 128 |
+
base = global.jQuery();
|
| 129 |
+
else if (global._ != null && (obj.string == '_') && (typeof global._ == 'function'))
|
| 130 |
+
base = global._();
|
| 131 |
+
}
|
| 132 |
+
while (base != null && context.length)
|
| 133 |
+
base = base[context.pop().string];
|
| 134 |
+
if (base != null) gatherCompletions(base);
|
| 135 |
+
} else {
|
| 136 |
+
// If not, just look in the global object and any local scope
|
| 137 |
+
// (reading into JS mode internals to get at the local and global variables)
|
| 138 |
+
for (var v = token.state.localVars; v; v = v.next) maybeAdd(v.name);
|
| 139 |
+
for (var v = token.state.globalVars; v; v = v.next) maybeAdd(v.name);
|
| 140 |
+
if (!options || options.useGlobalScope !== false)
|
| 141 |
+
gatherCompletions(global);
|
| 142 |
+
forEach(keywords, maybeAdd);
|
| 143 |
+
}
|
| 144 |
+
return found;
|
| 145 |
+
}
|
| 146 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/hint/show-hint.css
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.CodeMirror-hints {
|
| 2 |
+
position: absolute;
|
| 3 |
+
z-index: 10;
|
| 4 |
+
overflow: hidden;
|
| 5 |
+
list-style: none;
|
| 6 |
+
|
| 7 |
+
margin: 0;
|
| 8 |
+
padding: 2px;
|
| 9 |
+
|
| 10 |
+
-webkit-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
|
| 11 |
+
-moz-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
|
| 12 |
+
box-shadow: 2px 3px 5px rgba(0,0,0,.2);
|
| 13 |
+
border-radius: 3px;
|
| 14 |
+
border: 1px solid silver;
|
| 15 |
+
|
| 16 |
+
background: white;
|
| 17 |
+
font-size: 90%;
|
| 18 |
+
font-family: monospace;
|
| 19 |
+
|
| 20 |
+
max-height: 20em;
|
| 21 |
+
overflow-y: auto;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
.CodeMirror-hint {
|
| 25 |
+
margin: 0;
|
| 26 |
+
padding: 0 4px;
|
| 27 |
+
border-radius: 2px;
|
| 28 |
+
max-width: 19em;
|
| 29 |
+
overflow: hidden;
|
| 30 |
+
white-space: pre;
|
| 31 |
+
color: black;
|
| 32 |
+
cursor: pointer;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
li.CodeMirror-hint-active {
|
| 36 |
+
background: #08f;
|
| 37 |
+
color: white;
|
| 38 |
+
}
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/hint/show-hint.js
ADDED
|
@@ -0,0 +1,383 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
"use strict";
|
| 13 |
+
|
| 14 |
+
var HINT_ELEMENT_CLASS = "CodeMirror-hint";
|
| 15 |
+
var ACTIVE_HINT_ELEMENT_CLASS = "CodeMirror-hint-active";
|
| 16 |
+
|
| 17 |
+
// This is the old interface, kept around for now to stay
|
| 18 |
+
// backwards-compatible.
|
| 19 |
+
CodeMirror.showHint = function(cm, getHints, options) {
|
| 20 |
+
if (!getHints) return cm.showHint(options);
|
| 21 |
+
if (options && options.async) getHints.async = true;
|
| 22 |
+
var newOpts = {hint: getHints};
|
| 23 |
+
if (options) for (var prop in options) newOpts[prop] = options[prop];
|
| 24 |
+
return cm.showHint(newOpts);
|
| 25 |
+
};
|
| 26 |
+
|
| 27 |
+
CodeMirror.defineExtension("showHint", function(options) {
|
| 28 |
+
// We want a single cursor position.
|
| 29 |
+
if (this.listSelections().length > 1 || this.somethingSelected()) return;
|
| 30 |
+
|
| 31 |
+
if (this.state.completionActive) this.state.completionActive.close();
|
| 32 |
+
var completion = this.state.completionActive = new Completion(this, options);
|
| 33 |
+
if (!completion.options.hint) return;
|
| 34 |
+
|
| 35 |
+
CodeMirror.signal(this, "startCompletion", this);
|
| 36 |
+
completion.update(true);
|
| 37 |
+
});
|
| 38 |
+
|
| 39 |
+
function Completion(cm, options) {
|
| 40 |
+
this.cm = cm;
|
| 41 |
+
this.options = this.buildOptions(options);
|
| 42 |
+
this.widget = null;
|
| 43 |
+
this.debounce = 0;
|
| 44 |
+
this.tick = 0;
|
| 45 |
+
this.startPos = this.cm.getCursor();
|
| 46 |
+
this.startLen = this.cm.getLine(this.startPos.line).length;
|
| 47 |
+
|
| 48 |
+
var self = this;
|
| 49 |
+
cm.on("cursorActivity", this.activityFunc = function() { self.cursorActivity(); });
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
var requestAnimationFrame = window.requestAnimationFrame || function(fn) {
|
| 53 |
+
return setTimeout(fn, 1000/60);
|
| 54 |
+
};
|
| 55 |
+
var cancelAnimationFrame = window.cancelAnimationFrame || clearTimeout;
|
| 56 |
+
|
| 57 |
+
Completion.prototype = {
|
| 58 |
+
close: function() {
|
| 59 |
+
if (!this.active()) return;
|
| 60 |
+
this.cm.state.completionActive = null;
|
| 61 |
+
this.tick = null;
|
| 62 |
+
this.cm.off("cursorActivity", this.activityFunc);
|
| 63 |
+
|
| 64 |
+
if (this.widget && this.data) CodeMirror.signal(this.data, "close");
|
| 65 |
+
if (this.widget) this.widget.close();
|
| 66 |
+
CodeMirror.signal(this.cm, "endCompletion", this.cm);
|
| 67 |
+
},
|
| 68 |
+
|
| 69 |
+
active: function() {
|
| 70 |
+
return this.cm.state.completionActive == this;
|
| 71 |
+
},
|
| 72 |
+
|
| 73 |
+
pick: function(data, i) {
|
| 74 |
+
var completion = data.list[i];
|
| 75 |
+
if (completion.hint) completion.hint(this.cm, data, completion);
|
| 76 |
+
else this.cm.replaceRange(getText(completion), completion.from || data.from,
|
| 77 |
+
completion.to || data.to, "complete");
|
| 78 |
+
CodeMirror.signal(data, "pick", completion);
|
| 79 |
+
this.close();
|
| 80 |
+
},
|
| 81 |
+
|
| 82 |
+
cursorActivity: function() {
|
| 83 |
+
if (this.debounce) {
|
| 84 |
+
cancelAnimationFrame(this.debounce);
|
| 85 |
+
this.debounce = 0;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
var pos = this.cm.getCursor(), line = this.cm.getLine(pos.line);
|
| 89 |
+
if (pos.line != this.startPos.line || line.length - pos.ch != this.startLen - this.startPos.ch ||
|
| 90 |
+
pos.ch < this.startPos.ch || this.cm.somethingSelected() ||
|
| 91 |
+
(pos.ch && this.options.closeCharacters.test(line.charAt(pos.ch - 1)))) {
|
| 92 |
+
this.close();
|
| 93 |
+
} else {
|
| 94 |
+
var self = this;
|
| 95 |
+
this.debounce = requestAnimationFrame(function() {self.update();});
|
| 96 |
+
if (this.widget) this.widget.disable();
|
| 97 |
+
}
|
| 98 |
+
},
|
| 99 |
+
|
| 100 |
+
update: function(first) {
|
| 101 |
+
if (this.tick == null) return;
|
| 102 |
+
if (this.data) CodeMirror.signal(this.data, "update");
|
| 103 |
+
if (!this.options.hint.async) {
|
| 104 |
+
this.finishUpdate(this.options.hint(this.cm, this.options), first);
|
| 105 |
+
} else {
|
| 106 |
+
var myTick = ++this.tick, self = this;
|
| 107 |
+
this.options.hint(this.cm, function(data) {
|
| 108 |
+
if (self.tick == myTick) self.finishUpdate(data, first);
|
| 109 |
+
}, this.options);
|
| 110 |
+
}
|
| 111 |
+
},
|
| 112 |
+
|
| 113 |
+
finishUpdate: function(data, first) {
|
| 114 |
+
this.data = data;
|
| 115 |
+
|
| 116 |
+
var picked = (this.widget && this.widget.picked) || (first && this.options.completeSingle);
|
| 117 |
+
if (this.widget) this.widget.close();
|
| 118 |
+
if (data && data.list.length) {
|
| 119 |
+
if (picked && data.list.length == 1) {
|
| 120 |
+
this.pick(data, 0);
|
| 121 |
+
} else {
|
| 122 |
+
this.widget = new Widget(this, data);
|
| 123 |
+
CodeMirror.signal(data, "shown");
|
| 124 |
+
}
|
| 125 |
+
}
|
| 126 |
+
},
|
| 127 |
+
|
| 128 |
+
buildOptions: function(options) {
|
| 129 |
+
var editor = this.cm.options.hintOptions;
|
| 130 |
+
var out = {};
|
| 131 |
+
for (var prop in defaultOptions) out[prop] = defaultOptions[prop];
|
| 132 |
+
if (editor) for (var prop in editor)
|
| 133 |
+
if (editor[prop] !== undefined) out[prop] = editor[prop];
|
| 134 |
+
if (options) for (var prop in options)
|
| 135 |
+
if (options[prop] !== undefined) out[prop] = options[prop];
|
| 136 |
+
return out;
|
| 137 |
+
}
|
| 138 |
+
};
|
| 139 |
+
|
| 140 |
+
function getText(completion) {
|
| 141 |
+
if (typeof completion == "string") return completion;
|
| 142 |
+
else return completion.text;
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
function buildKeyMap(completion, handle) {
|
| 146 |
+
var baseMap = {
|
| 147 |
+
Up: function() {handle.moveFocus(-1);},
|
| 148 |
+
Down: function() {handle.moveFocus(1);},
|
| 149 |
+
PageUp: function() {handle.moveFocus(-handle.menuSize() + 1, true);},
|
| 150 |
+
PageDown: function() {handle.moveFocus(handle.menuSize() - 1, true);},
|
| 151 |
+
Home: function() {handle.setFocus(0);},
|
| 152 |
+
End: function() {handle.setFocus(handle.length - 1);},
|
| 153 |
+
Enter: handle.pick,
|
| 154 |
+
Tab: handle.pick,
|
| 155 |
+
Esc: handle.close
|
| 156 |
+
};
|
| 157 |
+
var custom = completion.options.customKeys;
|
| 158 |
+
var ourMap = custom ? {} : baseMap;
|
| 159 |
+
function addBinding(key, val) {
|
| 160 |
+
var bound;
|
| 161 |
+
if (typeof val != "string")
|
| 162 |
+
bound = function(cm) { return val(cm, handle); };
|
| 163 |
+
// This mechanism is deprecated
|
| 164 |
+
else if (baseMap.hasOwnProperty(val))
|
| 165 |
+
bound = baseMap[val];
|
| 166 |
+
else
|
| 167 |
+
bound = val;
|
| 168 |
+
ourMap[key] = bound;
|
| 169 |
+
}
|
| 170 |
+
if (custom)
|
| 171 |
+
for (var key in custom) if (custom.hasOwnProperty(key))
|
| 172 |
+
addBinding(key, custom[key]);
|
| 173 |
+
var extra = completion.options.extraKeys;
|
| 174 |
+
if (extra)
|
| 175 |
+
for (var key in extra) if (extra.hasOwnProperty(key))
|
| 176 |
+
addBinding(key, extra[key]);
|
| 177 |
+
return ourMap;
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
function getHintElement(hintsElement, el) {
|
| 181 |
+
while (el && el != hintsElement) {
|
| 182 |
+
if (el.nodeName.toUpperCase() === "LI" && el.parentNode == hintsElement) return el;
|
| 183 |
+
el = el.parentNode;
|
| 184 |
+
}
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
function Widget(completion, data) {
|
| 188 |
+
this.completion = completion;
|
| 189 |
+
this.data = data;
|
| 190 |
+
this.picked = false;
|
| 191 |
+
var widget = this, cm = completion.cm;
|
| 192 |
+
|
| 193 |
+
var hints = this.hints = document.createElement("ul");
|
| 194 |
+
hints.className = "CodeMirror-hints";
|
| 195 |
+
this.selectedHint = data.selectedHint || 0;
|
| 196 |
+
|
| 197 |
+
var completions = data.list;
|
| 198 |
+
for (var i = 0; i < completions.length; ++i) {
|
| 199 |
+
var elt = hints.appendChild(document.createElement("li")), cur = completions[i];
|
| 200 |
+
var className = HINT_ELEMENT_CLASS + (i != this.selectedHint ? "" : " " + ACTIVE_HINT_ELEMENT_CLASS);
|
| 201 |
+
if (cur.className != null) className = cur.className + " " + className;
|
| 202 |
+
elt.className = className;
|
| 203 |
+
if (cur.render) cur.render(elt, data, cur);
|
| 204 |
+
else elt.appendChild(document.createTextNode(cur.displayText || getText(cur)));
|
| 205 |
+
elt.hintId = i;
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
var pos = cm.cursorCoords(completion.options.alignWithWord ? data.from : null);
|
| 209 |
+
var left = pos.left, top = pos.bottom, below = true;
|
| 210 |
+
hints.style.left = left + "px";
|
| 211 |
+
hints.style.top = top + "px";
|
| 212 |
+
// If we're at the edge of the screen, then we want the menu to appear on the left of the cursor.
|
| 213 |
+
var winW = window.innerWidth || Math.max(document.body.offsetWidth, document.documentElement.offsetWidth);
|
| 214 |
+
var winH = window.innerHeight || Math.max(document.body.offsetHeight, document.documentElement.offsetHeight);
|
| 215 |
+
(completion.options.container || document.body).appendChild(hints);
|
| 216 |
+
var box = hints.getBoundingClientRect(), overlapY = box.bottom - winH;
|
| 217 |
+
if (overlapY > 0) {
|
| 218 |
+
var height = box.bottom - box.top, curTop = pos.top - (pos.bottom - box.top);
|
| 219 |
+
if (curTop - height > 0) { // Fits above cursor
|
| 220 |
+
hints.style.top = (top = pos.top - height) + "px";
|
| 221 |
+
below = false;
|
| 222 |
+
} else if (height > winH) {
|
| 223 |
+
hints.style.height = (winH - 5) + "px";
|
| 224 |
+
hints.style.top = (top = pos.bottom - box.top) + "px";
|
| 225 |
+
var cursor = cm.getCursor();
|
| 226 |
+
if (data.from.ch != cursor.ch) {
|
| 227 |
+
pos = cm.cursorCoords(cursor);
|
| 228 |
+
hints.style.left = (left = pos.left) + "px";
|
| 229 |
+
box = hints.getBoundingClientRect();
|
| 230 |
+
}
|
| 231 |
+
}
|
| 232 |
+
}
|
| 233 |
+
var overlapX = box.right - winW;
|
| 234 |
+
if (overlapX > 0) {
|
| 235 |
+
if (box.right - box.left > winW) {
|
| 236 |
+
hints.style.width = (winW - 5) + "px";
|
| 237 |
+
overlapX -= (box.right - box.left) - winW;
|
| 238 |
+
}
|
| 239 |
+
hints.style.left = (left = pos.left - overlapX) + "px";
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
cm.addKeyMap(this.keyMap = buildKeyMap(completion, {
|
| 243 |
+
moveFocus: function(n, avoidWrap) { widget.changeActive(widget.selectedHint + n, avoidWrap); },
|
| 244 |
+
setFocus: function(n) { widget.changeActive(n); },
|
| 245 |
+
menuSize: function() { return widget.screenAmount(); },
|
| 246 |
+
length: completions.length,
|
| 247 |
+
close: function() { completion.close(); },
|
| 248 |
+
pick: function() { widget.pick(); },
|
| 249 |
+
data: data
|
| 250 |
+
}));
|
| 251 |
+
|
| 252 |
+
if (completion.options.closeOnUnfocus) {
|
| 253 |
+
var closingOnBlur;
|
| 254 |
+
cm.on("blur", this.onBlur = function() { closingOnBlur = setTimeout(function() { completion.close(); }, 100); });
|
| 255 |
+
cm.on("focus", this.onFocus = function() { clearTimeout(closingOnBlur); });
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
var startScroll = cm.getScrollInfo();
|
| 259 |
+
cm.on("scroll", this.onScroll = function() {
|
| 260 |
+
var curScroll = cm.getScrollInfo(), editor = cm.getWrapperElement().getBoundingClientRect();
|
| 261 |
+
var newTop = top + startScroll.top - curScroll.top;
|
| 262 |
+
var point = newTop - (window.pageYOffset || (document.documentElement || document.body).scrollTop);
|
| 263 |
+
if (!below) point += hints.offsetHeight;
|
| 264 |
+
if (point <= editor.top || point >= editor.bottom) return completion.close();
|
| 265 |
+
hints.style.top = newTop + "px";
|
| 266 |
+
hints.style.left = (left + startScroll.left - curScroll.left) + "px";
|
| 267 |
+
});
|
| 268 |
+
|
| 269 |
+
CodeMirror.on(hints, "dblclick", function(e) {
|
| 270 |
+
var t = getHintElement(hints, e.target || e.srcElement);
|
| 271 |
+
if (t && t.hintId != null) {widget.changeActive(t.hintId); widget.pick();}
|
| 272 |
+
});
|
| 273 |
+
|
| 274 |
+
CodeMirror.on(hints, "click", function(e) {
|
| 275 |
+
var t = getHintElement(hints, e.target || e.srcElement);
|
| 276 |
+
if (t && t.hintId != null) {
|
| 277 |
+
widget.changeActive(t.hintId);
|
| 278 |
+
if (completion.options.completeOnSingleClick) widget.pick();
|
| 279 |
+
}
|
| 280 |
+
});
|
| 281 |
+
|
| 282 |
+
CodeMirror.on(hints, "mousedown", function() {
|
| 283 |
+
setTimeout(function(){cm.focus();}, 20);
|
| 284 |
+
});
|
| 285 |
+
|
| 286 |
+
CodeMirror.signal(data, "select", completions[0], hints.firstChild);
|
| 287 |
+
return true;
|
| 288 |
+
}
|
| 289 |
+
|
| 290 |
+
Widget.prototype = {
|
| 291 |
+
close: function() {
|
| 292 |
+
if (this.completion.widget != this) return;
|
| 293 |
+
this.completion.widget = null;
|
| 294 |
+
this.hints.parentNode.removeChild(this.hints);
|
| 295 |
+
this.completion.cm.removeKeyMap(this.keyMap);
|
| 296 |
+
|
| 297 |
+
var cm = this.completion.cm;
|
| 298 |
+
if (this.completion.options.closeOnUnfocus) {
|
| 299 |
+
cm.off("blur", this.onBlur);
|
| 300 |
+
cm.off("focus", this.onFocus);
|
| 301 |
+
}
|
| 302 |
+
cm.off("scroll", this.onScroll);
|
| 303 |
+
},
|
| 304 |
+
|
| 305 |
+
disable: function() {
|
| 306 |
+
this.completion.cm.removeKeyMap(this.keyMap);
|
| 307 |
+
var widget = this;
|
| 308 |
+
this.keyMap = {Enter: function() { widget.picked = true; }};
|
| 309 |
+
this.completion.cm.addKeyMap(this.keyMap);
|
| 310 |
+
},
|
| 311 |
+
|
| 312 |
+
pick: function() {
|
| 313 |
+
this.completion.pick(this.data, this.selectedHint);
|
| 314 |
+
},
|
| 315 |
+
|
| 316 |
+
changeActive: function(i, avoidWrap) {
|
| 317 |
+
if (i >= this.data.list.length)
|
| 318 |
+
i = avoidWrap ? this.data.list.length - 1 : 0;
|
| 319 |
+
else if (i < 0)
|
| 320 |
+
i = avoidWrap ? 0 : this.data.list.length - 1;
|
| 321 |
+
if (this.selectedHint == i) return;
|
| 322 |
+
var node = this.hints.childNodes[this.selectedHint];
|
| 323 |
+
node.className = node.className.replace(" " + ACTIVE_HINT_ELEMENT_CLASS, "");
|
| 324 |
+
node = this.hints.childNodes[this.selectedHint = i];
|
| 325 |
+
node.className += " " + ACTIVE_HINT_ELEMENT_CLASS;
|
| 326 |
+
if (node.offsetTop < this.hints.scrollTop)
|
| 327 |
+
this.hints.scrollTop = node.offsetTop - 3;
|
| 328 |
+
else if (node.offsetTop + node.offsetHeight > this.hints.scrollTop + this.hints.clientHeight)
|
| 329 |
+
this.hints.scrollTop = node.offsetTop + node.offsetHeight - this.hints.clientHeight + 3;
|
| 330 |
+
CodeMirror.signal(this.data, "select", this.data.list[this.selectedHint], node);
|
| 331 |
+
},
|
| 332 |
+
|
| 333 |
+
screenAmount: function() {
|
| 334 |
+
return Math.floor(this.hints.clientHeight / this.hints.firstChild.offsetHeight) || 1;
|
| 335 |
+
}
|
| 336 |
+
};
|
| 337 |
+
|
| 338 |
+
CodeMirror.registerHelper("hint", "auto", function(cm, options) {
|
| 339 |
+
var helpers = cm.getHelpers(cm.getCursor(), "hint"), words;
|
| 340 |
+
if (helpers.length) {
|
| 341 |
+
for (var i = 0; i < helpers.length; i++) {
|
| 342 |
+
var cur = helpers[i](cm, options);
|
| 343 |
+
if (cur && cur.list.length) return cur;
|
| 344 |
+
}
|
| 345 |
+
} else if (words = cm.getHelper(cm.getCursor(), "hintWords")) {
|
| 346 |
+
if (words) return CodeMirror.hint.fromList(cm, {words: words});
|
| 347 |
+
} else if (CodeMirror.hint.anyword) {
|
| 348 |
+
return CodeMirror.hint.anyword(cm, options);
|
| 349 |
+
}
|
| 350 |
+
});
|
| 351 |
+
|
| 352 |
+
CodeMirror.registerHelper("hint", "fromList", function(cm, options) {
|
| 353 |
+
var cur = cm.getCursor(), token = cm.getTokenAt(cur);
|
| 354 |
+
var found = [];
|
| 355 |
+
for (var i = 0; i < options.words.length; i++) {
|
| 356 |
+
var word = options.words[i];
|
| 357 |
+
if (word.slice(0, token.string.length) == token.string)
|
| 358 |
+
found.push(word);
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
if (found.length) return {
|
| 362 |
+
list: found,
|
| 363 |
+
from: CodeMirror.Pos(cur.line, token.start),
|
| 364 |
+
to: CodeMirror.Pos(cur.line, token.end)
|
| 365 |
+
};
|
| 366 |
+
});
|
| 367 |
+
|
| 368 |
+
CodeMirror.commands.autocomplete = CodeMirror.showHint;
|
| 369 |
+
|
| 370 |
+
var defaultOptions = {
|
| 371 |
+
hint: CodeMirror.hint.auto,
|
| 372 |
+
completeSingle: true,
|
| 373 |
+
alignWithWord: true,
|
| 374 |
+
closeCharacters: /[\s()\[\]{};:>,]/,
|
| 375 |
+
closeOnUnfocus: true,
|
| 376 |
+
completeOnSingleClick: false,
|
| 377 |
+
container: null,
|
| 378 |
+
customKeys: null,
|
| 379 |
+
extraKeys: null
|
| 380 |
+
};
|
| 381 |
+
|
| 382 |
+
CodeMirror.defineOption("hintOptions", null);
|
| 383 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/hint/sql-hint.js
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"), require("../../mode/sql/sql"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror", "../../mode/sql/sql"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
"use strict";
|
| 13 |
+
|
| 14 |
+
var tables;
|
| 15 |
+
var defaultTable;
|
| 16 |
+
var keywords;
|
| 17 |
+
var CONS = {
|
| 18 |
+
QUERY_DIV: ";",
|
| 19 |
+
ALIAS_KEYWORD: "AS"
|
| 20 |
+
};
|
| 21 |
+
var Pos = CodeMirror.Pos;
|
| 22 |
+
|
| 23 |
+
function getKeywords(editor) {
|
| 24 |
+
var mode = editor.doc.modeOption;
|
| 25 |
+
if (mode === "sql") mode = "text/x-sql";
|
| 26 |
+
return CodeMirror.resolveMode(mode).keywords;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
function getText(item) {
|
| 30 |
+
return typeof item == "string" ? item : item.text;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
function getItem(list, item) {
|
| 34 |
+
if (!list.slice) return list[item];
|
| 35 |
+
for (var i = list.length - 1; i >= 0; i--) if (getText(list[i]) == item)
|
| 36 |
+
return list[i];
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
function shallowClone(object) {
|
| 40 |
+
var result = {};
|
| 41 |
+
for (var key in object) if (object.hasOwnProperty(key))
|
| 42 |
+
result[key] = object[key];
|
| 43 |
+
return result;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
function match(string, word) {
|
| 47 |
+
var len = string.length;
|
| 48 |
+
var sub = getText(word).substr(0, len);
|
| 49 |
+
return string.toUpperCase() === sub.toUpperCase();
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
function addMatches(result, search, wordlist, formatter) {
|
| 53 |
+
for (var word in wordlist) {
|
| 54 |
+
if (!wordlist.hasOwnProperty(word)) continue;
|
| 55 |
+
if (wordlist.slice) word = wordlist[word];
|
| 56 |
+
|
| 57 |
+
if (match(search, word)) result.push(formatter(word));
|
| 58 |
+
}
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
function cleanName(name) {
|
| 62 |
+
// Get rid name from backticks(`) and preceding dot(.)
|
| 63 |
+
if (name.charAt(0) == ".") {
|
| 64 |
+
name = name.substr(1);
|
| 65 |
+
}
|
| 66 |
+
return name.replace(/`/g, "");
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
function insertBackticks(name) {
|
| 70 |
+
var nameParts = getText(name).split(".");
|
| 71 |
+
for (var i = 0; i < nameParts.length; i++)
|
| 72 |
+
nameParts[i] = "`" + nameParts[i] + "`";
|
| 73 |
+
var escaped = nameParts.join(".");
|
| 74 |
+
if (typeof name == "string") return escaped;
|
| 75 |
+
name = shallowClone(name);
|
| 76 |
+
name.text = escaped;
|
| 77 |
+
return name;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
function nameCompletion(cur, token, result, editor) {
|
| 81 |
+
// Try to complete table, colunm names and return start position of completion
|
| 82 |
+
var useBacktick = false;
|
| 83 |
+
var nameParts = [];
|
| 84 |
+
var start = token.start;
|
| 85 |
+
var cont = true;
|
| 86 |
+
while (cont) {
|
| 87 |
+
cont = (token.string.charAt(0) == ".");
|
| 88 |
+
useBacktick = useBacktick || (token.string.charAt(0) == "`");
|
| 89 |
+
|
| 90 |
+
start = token.start;
|
| 91 |
+
nameParts.unshift(cleanName(token.string));
|
| 92 |
+
|
| 93 |
+
token = editor.getTokenAt(Pos(cur.line, token.start));
|
| 94 |
+
if (token.string == ".") {
|
| 95 |
+
cont = true;
|
| 96 |
+
token = editor.getTokenAt(Pos(cur.line, token.start));
|
| 97 |
+
}
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
// Try to complete table names
|
| 101 |
+
var string = nameParts.join(".");
|
| 102 |
+
addMatches(result, string, tables, function(w) {
|
| 103 |
+
return useBacktick ? insertBackticks(w) : w;
|
| 104 |
+
});
|
| 105 |
+
|
| 106 |
+
// Try to complete columns from defaultTable
|
| 107 |
+
addMatches(result, string, defaultTable, function(w) {
|
| 108 |
+
return useBacktick ? insertBackticks(w) : w;
|
| 109 |
+
});
|
| 110 |
+
|
| 111 |
+
// Try to complete columns
|
| 112 |
+
string = nameParts.pop();
|
| 113 |
+
var table = nameParts.join(".");
|
| 114 |
+
|
| 115 |
+
var alias = false;
|
| 116 |
+
var aliasTable = table;
|
| 117 |
+
// Check if table is available. If not, find table by Alias
|
| 118 |
+
if (!getItem(tables, table)) {
|
| 119 |
+
var oldTable = table;
|
| 120 |
+
table = findTableByAlias(table, editor);
|
| 121 |
+
if (table !== oldTable) alias = true;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
var columns = getItem(tables, table);
|
| 125 |
+
if (columns && columns.columns)
|
| 126 |
+
columns = columns.columns;
|
| 127 |
+
|
| 128 |
+
if (columns) {
|
| 129 |
+
addMatches(result, string, columns, function(w) {
|
| 130 |
+
var tableInsert = table;
|
| 131 |
+
if (alias == true) tableInsert = aliasTable;
|
| 132 |
+
if (typeof w == "string") {
|
| 133 |
+
w = tableInsert + "." + w;
|
| 134 |
+
} else {
|
| 135 |
+
w = shallowClone(w);
|
| 136 |
+
w.text = tableInsert + "." + w.text;
|
| 137 |
+
}
|
| 138 |
+
return useBacktick ? insertBackticks(w) : w;
|
| 139 |
+
});
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
return start;
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
function eachWord(lineText, f) {
|
| 146 |
+
if (!lineText) return;
|
| 147 |
+
var excepted = /[,;]/g;
|
| 148 |
+
var words = lineText.split(" ");
|
| 149 |
+
for (var i = 0; i < words.length; i++) {
|
| 150 |
+
f(words[i]?words[i].replace(excepted, '') : '');
|
| 151 |
+
}
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
function convertCurToNumber(cur) {
|
| 155 |
+
// max characters of a line is 999,999.
|
| 156 |
+
return cur.line + cur.ch / Math.pow(10, 6);
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
function convertNumberToCur(num) {
|
| 160 |
+
return Pos(Math.floor(num), +num.toString().split('.').pop());
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
function findTableByAlias(alias, editor) {
|
| 164 |
+
var doc = editor.doc;
|
| 165 |
+
var fullQuery = doc.getValue();
|
| 166 |
+
var aliasUpperCase = alias.toUpperCase();
|
| 167 |
+
var previousWord = "";
|
| 168 |
+
var table = "";
|
| 169 |
+
var separator = [];
|
| 170 |
+
var validRange = {
|
| 171 |
+
start: Pos(0, 0),
|
| 172 |
+
end: Pos(editor.lastLine(), editor.getLineHandle(editor.lastLine()).length)
|
| 173 |
+
};
|
| 174 |
+
|
| 175 |
+
//add separator
|
| 176 |
+
var indexOfSeparator = fullQuery.indexOf(CONS.QUERY_DIV);
|
| 177 |
+
while(indexOfSeparator != -1) {
|
| 178 |
+
separator.push(doc.posFromIndex(indexOfSeparator));
|
| 179 |
+
indexOfSeparator = fullQuery.indexOf(CONS.QUERY_DIV, indexOfSeparator+1);
|
| 180 |
+
}
|
| 181 |
+
separator.unshift(Pos(0, 0));
|
| 182 |
+
separator.push(Pos(editor.lastLine(), editor.getLineHandle(editor.lastLine()).text.length));
|
| 183 |
+
|
| 184 |
+
//find valid range
|
| 185 |
+
var prevItem = 0;
|
| 186 |
+
var current = convertCurToNumber(editor.getCursor());
|
| 187 |
+
for (var i=0; i< separator.length; i++) {
|
| 188 |
+
var _v = convertCurToNumber(separator[i]);
|
| 189 |
+
if (current > prevItem && current <= _v) {
|
| 190 |
+
validRange = { start: convertNumberToCur(prevItem), end: convertNumberToCur(_v) };
|
| 191 |
+
break;
|
| 192 |
+
}
|
| 193 |
+
prevItem = _v;
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
var query = doc.getRange(validRange.start, validRange.end, false);
|
| 197 |
+
|
| 198 |
+
for (var i = 0; i < query.length; i++) {
|
| 199 |
+
var lineText = query[i];
|
| 200 |
+
eachWord(lineText, function(word) {
|
| 201 |
+
var wordUpperCase = word.toUpperCase();
|
| 202 |
+
if (wordUpperCase === aliasUpperCase && getItem(tables, previousWord))
|
| 203 |
+
table = previousWord;
|
| 204 |
+
if (wordUpperCase !== CONS.ALIAS_KEYWORD)
|
| 205 |
+
previousWord = word;
|
| 206 |
+
});
|
| 207 |
+
if (table) break;
|
| 208 |
+
}
|
| 209 |
+
return table;
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
CodeMirror.registerHelper("hint", "sql", function(editor, options) {
|
| 213 |
+
tables = (options && options.tables) || {};
|
| 214 |
+
var defaultTableName = options && options.defaultTable;
|
| 215 |
+
var disableKeywords = options && options.disableKeywords;
|
| 216 |
+
defaultTable = defaultTableName && getItem(tables, defaultTableName);
|
| 217 |
+
keywords = keywords || getKeywords(editor);
|
| 218 |
+
|
| 219 |
+
if (defaultTableName && !defaultTable)
|
| 220 |
+
defaultTable = findTableByAlias(defaultTableName, editor);
|
| 221 |
+
|
| 222 |
+
defaultTable = defaultTable || [];
|
| 223 |
+
|
| 224 |
+
if (defaultTable.columns)
|
| 225 |
+
defaultTable = defaultTable.columns;
|
| 226 |
+
|
| 227 |
+
var cur = editor.getCursor();
|
| 228 |
+
var result = [];
|
| 229 |
+
var token = editor.getTokenAt(cur), start, end, search;
|
| 230 |
+
if (token.end > cur.ch) {
|
| 231 |
+
token.end = cur.ch;
|
| 232 |
+
token.string = token.string.slice(0, cur.ch - token.start);
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
if (token.string.match(/^[.`\w@]\w*$/)) {
|
| 236 |
+
search = token.string;
|
| 237 |
+
start = token.start;
|
| 238 |
+
end = token.end;
|
| 239 |
+
} else {
|
| 240 |
+
start = end = cur.ch;
|
| 241 |
+
search = "";
|
| 242 |
+
}
|
| 243 |
+
if (search.charAt(0) == "." || search.charAt(0) == "`") {
|
| 244 |
+
start = nameCompletion(cur, token, result, editor);
|
| 245 |
+
} else {
|
| 246 |
+
addMatches(result, search, tables, function(w) {return w;});
|
| 247 |
+
addMatches(result, search, defaultTable, function(w) {return w;});
|
| 248 |
+
if (!disableKeywords)
|
| 249 |
+
addMatches(result, search, keywords, function(w) {return w.toUpperCase();});
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
return {list: result, from: Pos(cur.line, start), to: Pos(cur.line, end)};
|
| 253 |
+
});
|
| 254 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/hint/xml-hint.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
"use strict";
|
| 13 |
+
|
| 14 |
+
var Pos = CodeMirror.Pos;
|
| 15 |
+
|
| 16 |
+
function getHints(cm, options) {
|
| 17 |
+
var tags = options && options.schemaInfo;
|
| 18 |
+
var quote = (options && options.quoteChar) || '"';
|
| 19 |
+
if (!tags) return;
|
| 20 |
+
var cur = cm.getCursor(), token = cm.getTokenAt(cur);
|
| 21 |
+
if (token.end > cur.ch) {
|
| 22 |
+
token.end = cur.ch;
|
| 23 |
+
token.string = token.string.slice(0, cur.ch - token.start);
|
| 24 |
+
}
|
| 25 |
+
var inner = CodeMirror.innerMode(cm.getMode(), token.state);
|
| 26 |
+
if (inner.mode.name != "xml") return;
|
| 27 |
+
var result = [], replaceToken = false, prefix;
|
| 28 |
+
var tag = /\btag\b/.test(token.type) && !/>$/.test(token.string);
|
| 29 |
+
var tagName = tag && /^\w/.test(token.string), tagStart;
|
| 30 |
+
|
| 31 |
+
if (tagName) {
|
| 32 |
+
var before = cm.getLine(cur.line).slice(Math.max(0, token.start - 2), token.start);
|
| 33 |
+
var tagType = /<\/$/.test(before) ? "close" : /<$/.test(before) ? "open" : null;
|
| 34 |
+
if (tagType) tagStart = token.start - (tagType == "close" ? 2 : 1);
|
| 35 |
+
} else if (tag && token.string == "<") {
|
| 36 |
+
tagType = "open";
|
| 37 |
+
} else if (tag && token.string == "</") {
|
| 38 |
+
tagType = "close";
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
if (!tag && !inner.state.tagName || tagType) {
|
| 42 |
+
if (tagName)
|
| 43 |
+
prefix = token.string;
|
| 44 |
+
replaceToken = tagType;
|
| 45 |
+
var cx = inner.state.context, curTag = cx && tags[cx.tagName];
|
| 46 |
+
var childList = cx ? curTag && curTag.children : tags["!top"];
|
| 47 |
+
if (childList && tagType != "close") {
|
| 48 |
+
for (var i = 0; i < childList.length; ++i) if (!prefix || childList[i].lastIndexOf(prefix, 0) == 0)
|
| 49 |
+
result.push("<" + childList[i]);
|
| 50 |
+
} else if (tagType != "close") {
|
| 51 |
+
for (var name in tags)
|
| 52 |
+
if (tags.hasOwnProperty(name) && name != "!top" && name != "!attrs" && (!prefix || name.lastIndexOf(prefix, 0) == 0))
|
| 53 |
+
result.push("<" + name);
|
| 54 |
+
}
|
| 55 |
+
if (cx && (!prefix || tagType == "close" && cx.tagName.lastIndexOf(prefix, 0) == 0))
|
| 56 |
+
result.push("</" + cx.tagName + ">");
|
| 57 |
+
} else {
|
| 58 |
+
// Attribute completion
|
| 59 |
+
var curTag = tags[inner.state.tagName], attrs = curTag && curTag.attrs;
|
| 60 |
+
var globalAttrs = tags["!attrs"];
|
| 61 |
+
if (!attrs && !globalAttrs) return;
|
| 62 |
+
if (!attrs) {
|
| 63 |
+
attrs = globalAttrs;
|
| 64 |
+
} else if (globalAttrs) { // Combine tag-local and global attributes
|
| 65 |
+
var set = {};
|
| 66 |
+
for (var nm in globalAttrs) if (globalAttrs.hasOwnProperty(nm)) set[nm] = globalAttrs[nm];
|
| 67 |
+
for (var nm in attrs) if (attrs.hasOwnProperty(nm)) set[nm] = attrs[nm];
|
| 68 |
+
attrs = set;
|
| 69 |
+
}
|
| 70 |
+
if (token.type == "string" || token.string == "=") { // A value
|
| 71 |
+
var before = cm.getRange(Pos(cur.line, Math.max(0, cur.ch - 60)),
|
| 72 |
+
Pos(cur.line, token.type == "string" ? token.start : token.end));
|
| 73 |
+
var atName = before.match(/([^\s\u00a0=<>\"\']+)=$/), atValues;
|
| 74 |
+
if (!atName || !attrs.hasOwnProperty(atName[1]) || !(atValues = attrs[atName[1]])) return;
|
| 75 |
+
if (typeof atValues == 'function') atValues = atValues.call(this, cm); // Functions can be used to supply values for autocomplete widget
|
| 76 |
+
if (token.type == "string") {
|
| 77 |
+
prefix = token.string;
|
| 78 |
+
var n = 0;
|
| 79 |
+
if (/['"]/.test(token.string.charAt(0))) {
|
| 80 |
+
quote = token.string.charAt(0);
|
| 81 |
+
prefix = token.string.slice(1);
|
| 82 |
+
n++;
|
| 83 |
+
}
|
| 84 |
+
var len = token.string.length;
|
| 85 |
+
if (/['"]/.test(token.string.charAt(len - 1))) {
|
| 86 |
+
quote = token.string.charAt(len - 1);
|
| 87 |
+
prefix = token.string.substr(n, len - 2);
|
| 88 |
+
}
|
| 89 |
+
replaceToken = true;
|
| 90 |
+
}
|
| 91 |
+
for (var i = 0; i < atValues.length; ++i) if (!prefix || atValues[i].lastIndexOf(prefix, 0) == 0)
|
| 92 |
+
result.push(quote + atValues[i] + quote);
|
| 93 |
+
} else { // An attribute name
|
| 94 |
+
if (token.type == "attribute") {
|
| 95 |
+
prefix = token.string;
|
| 96 |
+
replaceToken = true;
|
| 97 |
+
}
|
| 98 |
+
for (var attr in attrs) if (attrs.hasOwnProperty(attr) && (!prefix || attr.lastIndexOf(prefix, 0) == 0))
|
| 99 |
+
result.push(attr);
|
| 100 |
+
}
|
| 101 |
+
}
|
| 102 |
+
return {
|
| 103 |
+
list: result,
|
| 104 |
+
from: replaceToken ? Pos(cur.line, tagStart == null ? token.start : tagStart) : cur,
|
| 105 |
+
to: replaceToken ? Pos(cur.line, token.end) : cur
|
| 106 |
+
};
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
CodeMirror.registerHelper("hint", "xml", getHints);
|
| 110 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/lint/coffeescript-lint.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
// Depends on coffeelint.js from http://www.coffeelint.org/js/coffeelint.js
|
| 5 |
+
|
| 6 |
+
// declare global: coffeelint
|
| 7 |
+
|
| 8 |
+
(function(mod) {
|
| 9 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 10 |
+
mod(require("../../lib/codemirror"));
|
| 11 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 12 |
+
define(["../../lib/codemirror"], mod);
|
| 13 |
+
else // Plain browser env
|
| 14 |
+
mod(CodeMirror);
|
| 15 |
+
})(function(CodeMirror) {
|
| 16 |
+
"use strict";
|
| 17 |
+
|
| 18 |
+
CodeMirror.registerHelper("lint", "coffeescript", function(text) {
|
| 19 |
+
var found = [];
|
| 20 |
+
var parseError = function(err) {
|
| 21 |
+
var loc = err.lineNumber;
|
| 22 |
+
found.push({from: CodeMirror.Pos(loc-1, 0),
|
| 23 |
+
to: CodeMirror.Pos(loc, 0),
|
| 24 |
+
severity: err.level,
|
| 25 |
+
message: err.message});
|
| 26 |
+
};
|
| 27 |
+
try {
|
| 28 |
+
var res = coffeelint.lint(text);
|
| 29 |
+
for(var i = 0; i < res.length; i++) {
|
| 30 |
+
parseError(res[i]);
|
| 31 |
+
}
|
| 32 |
+
} catch(e) {
|
| 33 |
+
found.push({from: CodeMirror.Pos(e.location.first_line, 0),
|
| 34 |
+
to: CodeMirror.Pos(e.location.last_line, e.location.last_column),
|
| 35 |
+
severity: 'error',
|
| 36 |
+
message: e.message});
|
| 37 |
+
}
|
| 38 |
+
return found;
|
| 39 |
+
});
|
| 40 |
+
|
| 41 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/lint/css-lint.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
// Depends on csslint.js from https://github.com/stubbornella/csslint
|
| 5 |
+
|
| 6 |
+
// declare global: CSSLint
|
| 7 |
+
|
| 8 |
+
(function(mod) {
|
| 9 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 10 |
+
mod(require("../../lib/codemirror"));
|
| 11 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 12 |
+
define(["../../lib/codemirror"], mod);
|
| 13 |
+
else // Plain browser env
|
| 14 |
+
mod(CodeMirror);
|
| 15 |
+
})(function(CodeMirror) {
|
| 16 |
+
"use strict";
|
| 17 |
+
|
| 18 |
+
CodeMirror.registerHelper("lint", "css", function(text) {
|
| 19 |
+
var found = [];
|
| 20 |
+
if (!window.CSSLint) return found;
|
| 21 |
+
var results = CSSLint.verify(text), messages = results.messages, message = null;
|
| 22 |
+
for ( var i = 0; i < messages.length; i++) {
|
| 23 |
+
message = messages[i];
|
| 24 |
+
var startLine = message.line -1, endLine = message.line -1, startCol = message.col -1, endCol = message.col;
|
| 25 |
+
found.push({
|
| 26 |
+
from: CodeMirror.Pos(startLine, startCol),
|
| 27 |
+
to: CodeMirror.Pos(endLine, endCol),
|
| 28 |
+
message: message.message,
|
| 29 |
+
severity : message.type
|
| 30 |
+
});
|
| 31 |
+
}
|
| 32 |
+
return found;
|
| 33 |
+
});
|
| 34 |
+
|
| 35 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/lint/javascript-lint.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
"use strict";
|
| 13 |
+
// declare global: JSHINT
|
| 14 |
+
|
| 15 |
+
var bogus = [ "Dangerous comment" ];
|
| 16 |
+
|
| 17 |
+
var warnings = [ [ "Expected '{'",
|
| 18 |
+
"Statement body should be inside '{ }' braces." ] ];
|
| 19 |
+
|
| 20 |
+
var errors = [ "Missing semicolon", "Extra comma", "Missing property name",
|
| 21 |
+
"Unmatched ", " and instead saw", " is not defined",
|
| 22 |
+
"Unclosed string", "Stopping, unable to continue" ];
|
| 23 |
+
|
| 24 |
+
function validator(text, options) {
|
| 25 |
+
if (!window.JSHINT) return [];
|
| 26 |
+
JSHINT(text, options, options.globals);
|
| 27 |
+
var errors = JSHINT.data().errors, result = [];
|
| 28 |
+
if (errors) parseErrors(errors, result);
|
| 29 |
+
return result;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
CodeMirror.registerHelper("lint", "javascript", validator);
|
| 33 |
+
|
| 34 |
+
function cleanup(error) {
|
| 35 |
+
// All problems are warnings by default
|
| 36 |
+
fixWith(error, warnings, "warning", true);
|
| 37 |
+
fixWith(error, errors, "error");
|
| 38 |
+
|
| 39 |
+
return isBogus(error) ? null : error;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
function fixWith(error, fixes, severity, force) {
|
| 43 |
+
var description, fix, find, replace, found;
|
| 44 |
+
|
| 45 |
+
description = error.description;
|
| 46 |
+
|
| 47 |
+
for ( var i = 0; i < fixes.length; i++) {
|
| 48 |
+
fix = fixes[i];
|
| 49 |
+
find = (typeof fix === "string" ? fix : fix[0]);
|
| 50 |
+
replace = (typeof fix === "string" ? null : fix[1]);
|
| 51 |
+
found = description.indexOf(find) !== -1;
|
| 52 |
+
|
| 53 |
+
if (force || found) {
|
| 54 |
+
error.severity = severity;
|
| 55 |
+
}
|
| 56 |
+
if (found && replace) {
|
| 57 |
+
error.description = replace;
|
| 58 |
+
}
|
| 59 |
+
}
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
function isBogus(error) {
|
| 63 |
+
var description = error.description;
|
| 64 |
+
for ( var i = 0; i < bogus.length; i++) {
|
| 65 |
+
if (description.indexOf(bogus[i]) !== -1) {
|
| 66 |
+
return true;
|
| 67 |
+
}
|
| 68 |
+
}
|
| 69 |
+
return false;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
function parseErrors(errors, output) {
|
| 73 |
+
for ( var i = 0; i < errors.length; i++) {
|
| 74 |
+
var error = errors[i];
|
| 75 |
+
if (error) {
|
| 76 |
+
var linetabpositions, index;
|
| 77 |
+
|
| 78 |
+
linetabpositions = [];
|
| 79 |
+
|
| 80 |
+
// This next block is to fix a problem in jshint. Jshint
|
| 81 |
+
// replaces
|
| 82 |
+
// all tabs with spaces then performs some checks. The error
|
| 83 |
+
// positions (character/space) are then reported incorrectly,
|
| 84 |
+
// not taking the replacement step into account. Here we look
|
| 85 |
+
// at the evidence line and try to adjust the character position
|
| 86 |
+
// to the correct value.
|
| 87 |
+
if (error.evidence) {
|
| 88 |
+
// Tab positions are computed once per line and cached
|
| 89 |
+
var tabpositions = linetabpositions[error.line];
|
| 90 |
+
if (!tabpositions) {
|
| 91 |
+
var evidence = error.evidence;
|
| 92 |
+
tabpositions = [];
|
| 93 |
+
// ugggh phantomjs does not like this
|
| 94 |
+
// forEachChar(evidence, function(item, index) {
|
| 95 |
+
Array.prototype.forEach.call(evidence, function(item,
|
| 96 |
+
index) {
|
| 97 |
+
if (item === '\t') {
|
| 98 |
+
// First col is 1 (not 0) to match error
|
| 99 |
+
// positions
|
| 100 |
+
tabpositions.push(index + 1);
|
| 101 |
+
}
|
| 102 |
+
});
|
| 103 |
+
linetabpositions[error.line] = tabpositions;
|
| 104 |
+
}
|
| 105 |
+
if (tabpositions.length > 0) {
|
| 106 |
+
var pos = error.character;
|
| 107 |
+
tabpositions.forEach(function(tabposition) {
|
| 108 |
+
if (pos > tabposition) pos -= 1;
|
| 109 |
+
});
|
| 110 |
+
error.character = pos;
|
| 111 |
+
}
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
var start = error.character - 1, end = start + 1;
|
| 115 |
+
if (error.evidence) {
|
| 116 |
+
index = error.evidence.substring(start).search(/.\b/);
|
| 117 |
+
if (index > -1) {
|
| 118 |
+
end += index;
|
| 119 |
+
}
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
// Convert to format expected by validation service
|
| 123 |
+
error.description = error.reason;// + "(jshint)";
|
| 124 |
+
error.start = error.character;
|
| 125 |
+
error.end = end;
|
| 126 |
+
error = cleanup(error);
|
| 127 |
+
|
| 128 |
+
if (error)
|
| 129 |
+
output.push({message: error.description,
|
| 130 |
+
severity: error.severity,
|
| 131 |
+
from: CodeMirror.Pos(error.line - 1, start),
|
| 132 |
+
to: CodeMirror.Pos(error.line - 1, end)});
|
| 133 |
+
}
|
| 134 |
+
}
|
| 135 |
+
}
|
| 136 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/lint/json-lint.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
// Depends on jsonlint.js from https://github.com/zaach/jsonlint
|
| 5 |
+
|
| 6 |
+
// declare global: jsonlint
|
| 7 |
+
|
| 8 |
+
(function(mod) {
|
| 9 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 10 |
+
mod(require("../../lib/codemirror"));
|
| 11 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 12 |
+
define(["../../lib/codemirror"], mod);
|
| 13 |
+
else // Plain browser env
|
| 14 |
+
mod(CodeMirror);
|
| 15 |
+
})(function(CodeMirror) {
|
| 16 |
+
"use strict";
|
| 17 |
+
|
| 18 |
+
CodeMirror.registerHelper("lint", "json", function(text) {
|
| 19 |
+
var found = [];
|
| 20 |
+
jsonlint.parseError = function(str, hash) {
|
| 21 |
+
var loc = hash.loc;
|
| 22 |
+
found.push({from: CodeMirror.Pos(loc.first_line - 1, loc.first_column),
|
| 23 |
+
to: CodeMirror.Pos(loc.last_line - 1, loc.last_column),
|
| 24 |
+
message: str});
|
| 25 |
+
};
|
| 26 |
+
try { jsonlint.parse(text); }
|
| 27 |
+
catch(e) {}
|
| 28 |
+
return found;
|
| 29 |
+
});
|
| 30 |
+
|
| 31 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/lint/lint.css
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* The lint marker gutter */
|
| 2 |
+
.CodeMirror-lint-markers {
|
| 3 |
+
width: 16px;
|
| 4 |
+
}
|
| 5 |
+
|
| 6 |
+
.CodeMirror-lint-tooltip {
|
| 7 |
+
background-color: infobackground;
|
| 8 |
+
border: 1px solid black;
|
| 9 |
+
border-radius: 4px 4px 4px 4px;
|
| 10 |
+
color: infotext;
|
| 11 |
+
font-family: monospace;
|
| 12 |
+
font-size: 10pt;
|
| 13 |
+
overflow: hidden;
|
| 14 |
+
padding: 2px 5px;
|
| 15 |
+
position: fixed;
|
| 16 |
+
white-space: pre;
|
| 17 |
+
white-space: pre-wrap;
|
| 18 |
+
z-index: 100;
|
| 19 |
+
max-width: 600px;
|
| 20 |
+
opacity: 0;
|
| 21 |
+
transition: opacity .4s;
|
| 22 |
+
-moz-transition: opacity .4s;
|
| 23 |
+
-webkit-transition: opacity .4s;
|
| 24 |
+
-o-transition: opacity .4s;
|
| 25 |
+
-ms-transition: opacity .4s;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
.CodeMirror-lint-mark-error, .CodeMirror-lint-mark-warning {
|
| 29 |
+
background-position: left bottom;
|
| 30 |
+
background-repeat: repeat-x;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
.CodeMirror-lint-mark-error {
|
| 34 |
+
background-image:
|
| 35 |
+
url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAADCAYAAAC09K7GAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sJDw4cOCW1/KIAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAHElEQVQI12NggIL/DAz/GdA5/xkY/qPKMDAwAADLZwf5rvm+LQAAAABJRU5ErkJggg==")
|
| 36 |
+
;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
.CodeMirror-lint-mark-warning {
|
| 40 |
+
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAADCAYAAAC09K7GAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sJFhQXEbhTg7YAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAMklEQVQI12NkgIIvJ3QXMjAwdDN+OaEbysDA4MPAwNDNwMCwiOHLCd1zX07o6kBVGQEAKBANtobskNMAAAAASUVORK5CYII=");
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.CodeMirror-lint-marker-error, .CodeMirror-lint-marker-warning {
|
| 44 |
+
background-position: center center;
|
| 45 |
+
background-repeat: no-repeat;
|
| 46 |
+
cursor: pointer;
|
| 47 |
+
display: inline-block;
|
| 48 |
+
height: 16px;
|
| 49 |
+
width: 16px;
|
| 50 |
+
vertical-align: middle;
|
| 51 |
+
position: relative;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
.CodeMirror-lint-message-error, .CodeMirror-lint-message-warning {
|
| 55 |
+
padding-left: 18px;
|
| 56 |
+
background-position: top left;
|
| 57 |
+
background-repeat: no-repeat;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
.CodeMirror-lint-marker-error, .CodeMirror-lint-message-error {
|
| 61 |
+
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAHlBMVEW7AAC7AACxAAC7AAC7AAAAAAC4AAC5AAD///+7AAAUdclpAAAABnRSTlMXnORSiwCK0ZKSAAAATUlEQVR42mWPOQ7AQAgDuQLx/z8csYRmPRIFIwRGnosRrpamvkKi0FTIiMASR3hhKW+hAN6/tIWhu9PDWiTGNEkTtIOucA5Oyr9ckPgAWm0GPBog6v4AAAAASUVORK5CYII=");
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
.CodeMirror-lint-marker-warning, .CodeMirror-lint-message-warning {
|
| 65 |
+
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAANlBMVEX/uwDvrwD/uwD/uwD/uwD/uwD/uwD/uwD/uwD6twD/uwAAAADurwD2tQD7uAD+ugAAAAD/uwDhmeTRAAAADHRSTlMJ8mN1EYcbmiixgACm7WbuAAAAVklEQVR42n3PUQqAIBBFUU1LLc3u/jdbOJoW1P08DA9Gba8+YWJ6gNJoNYIBzAA2chBth5kLmG9YUoG0NHAUwFXwO9LuBQL1giCQb8gC9Oro2vp5rncCIY8L8uEx5ZkAAAAASUVORK5CYII=");
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
.CodeMirror-lint-marker-multiple {
|
| 69 |
+
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAcAAAAHCAMAAADzjKfhAAAACVBMVEUAAAAAAAC/v7914kyHAAAAAXRSTlMAQObYZgAAACNJREFUeNo1ioEJAAAIwmz/H90iFFSGJgFMe3gaLZ0od+9/AQZ0ADosbYraAAAAAElFTkSuQmCC");
|
| 70 |
+
background-repeat: no-repeat;
|
| 71 |
+
background-position: right bottom;
|
| 72 |
+
width: 100%; height: 100%;
|
| 73 |
+
}
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/lint/lint.js
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
"use strict";
|
| 13 |
+
var GUTTER_ID = "CodeMirror-lint-markers";
|
| 14 |
+
|
| 15 |
+
function showTooltip(e, content) {
|
| 16 |
+
var tt = document.createElement("div");
|
| 17 |
+
tt.className = "CodeMirror-lint-tooltip";
|
| 18 |
+
tt.appendChild(content.cloneNode(true));
|
| 19 |
+
document.body.appendChild(tt);
|
| 20 |
+
|
| 21 |
+
function position(e) {
|
| 22 |
+
if (!tt.parentNode) return CodeMirror.off(document, "mousemove", position);
|
| 23 |
+
tt.style.top = Math.max(0, e.clientY - tt.offsetHeight - 5) + "px";
|
| 24 |
+
tt.style.left = (e.clientX + 5) + "px";
|
| 25 |
+
}
|
| 26 |
+
CodeMirror.on(document, "mousemove", position);
|
| 27 |
+
position(e);
|
| 28 |
+
if (tt.style.opacity != null) tt.style.opacity = 1;
|
| 29 |
+
return tt;
|
| 30 |
+
}
|
| 31 |
+
function rm(elt) {
|
| 32 |
+
if (elt.parentNode) elt.parentNode.removeChild(elt);
|
| 33 |
+
}
|
| 34 |
+
function hideTooltip(tt) {
|
| 35 |
+
if (!tt.parentNode) return;
|
| 36 |
+
if (tt.style.opacity == null) rm(tt);
|
| 37 |
+
tt.style.opacity = 0;
|
| 38 |
+
setTimeout(function() { rm(tt); }, 600);
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
function showTooltipFor(e, content, node) {
|
| 42 |
+
var tooltip = showTooltip(e, content);
|
| 43 |
+
function hide() {
|
| 44 |
+
CodeMirror.off(node, "mouseout", hide);
|
| 45 |
+
if (tooltip) { hideTooltip(tooltip); tooltip = null; }
|
| 46 |
+
}
|
| 47 |
+
var poll = setInterval(function() {
|
| 48 |
+
if (tooltip) for (var n = node;; n = n.parentNode) {
|
| 49 |
+
if (n && n.nodeType == 11) n = n.host;
|
| 50 |
+
if (n == document.body) return;
|
| 51 |
+
if (!n) { hide(); break; }
|
| 52 |
+
}
|
| 53 |
+
if (!tooltip) return clearInterval(poll);
|
| 54 |
+
}, 400);
|
| 55 |
+
CodeMirror.on(node, "mouseout", hide);
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
function LintState(cm, options, hasGutter) {
|
| 59 |
+
this.marked = [];
|
| 60 |
+
this.options = options;
|
| 61 |
+
this.timeout = null;
|
| 62 |
+
this.hasGutter = hasGutter;
|
| 63 |
+
this.onMouseOver = function(e) { onMouseOver(cm, e); };
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
function parseOptions(_cm, options) {
|
| 67 |
+
if (options instanceof Function) return {getAnnotations: options};
|
| 68 |
+
if (!options || options === true) options = {};
|
| 69 |
+
return options;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
function clearMarks(cm) {
|
| 73 |
+
var state = cm.state.lint;
|
| 74 |
+
if (state.hasGutter) cm.clearGutter(GUTTER_ID);
|
| 75 |
+
for (var i = 0; i < state.marked.length; ++i)
|
| 76 |
+
state.marked[i].clear();
|
| 77 |
+
state.marked.length = 0;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
function makeMarker(labels, severity, multiple, tooltips) {
|
| 81 |
+
var marker = document.createElement("div"), inner = marker;
|
| 82 |
+
marker.className = "CodeMirror-lint-marker-" + severity;
|
| 83 |
+
if (multiple) {
|
| 84 |
+
inner = marker.appendChild(document.createElement("div"));
|
| 85 |
+
inner.className = "CodeMirror-lint-marker-multiple";
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
if (tooltips != false) CodeMirror.on(inner, "mouseover", function(e) {
|
| 89 |
+
showTooltipFor(e, labels, inner);
|
| 90 |
+
});
|
| 91 |
+
|
| 92 |
+
return marker;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
function getMaxSeverity(a, b) {
|
| 96 |
+
if (a == "error") return a;
|
| 97 |
+
else return b;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
function groupByLine(annotations) {
|
| 101 |
+
var lines = [];
|
| 102 |
+
for (var i = 0; i < annotations.length; ++i) {
|
| 103 |
+
var ann = annotations[i], line = ann.from.line;
|
| 104 |
+
(lines[line] || (lines[line] = [])).push(ann);
|
| 105 |
+
}
|
| 106 |
+
return lines;
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
function annotationTooltip(ann) {
|
| 110 |
+
var severity = ann.severity;
|
| 111 |
+
if (!severity) severity = "error";
|
| 112 |
+
var tip = document.createElement("div");
|
| 113 |
+
tip.className = "CodeMirror-lint-message-" + severity;
|
| 114 |
+
tip.appendChild(document.createTextNode(ann.message));
|
| 115 |
+
return tip;
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
function startLinting(cm) {
|
| 119 |
+
var state = cm.state.lint, options = state.options;
|
| 120 |
+
var passOptions = options.options || options; // Support deprecated passing of `options` property in options
|
| 121 |
+
var getAnnotations = options.getAnnotations || cm.getHelper(CodeMirror.Pos(0, 0), "lint");
|
| 122 |
+
if (!getAnnotations) return;
|
| 123 |
+
if (options.async || getAnnotations.async)
|
| 124 |
+
getAnnotations(cm.getValue(), updateLinting, passOptions, cm);
|
| 125 |
+
else
|
| 126 |
+
updateLinting(cm, getAnnotations(cm.getValue(), passOptions, cm));
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
function updateLinting(cm, annotationsNotSorted) {
|
| 130 |
+
clearMarks(cm);
|
| 131 |
+
var state = cm.state.lint, options = state.options;
|
| 132 |
+
|
| 133 |
+
var annotations = groupByLine(annotationsNotSorted);
|
| 134 |
+
|
| 135 |
+
for (var line = 0; line < annotations.length; ++line) {
|
| 136 |
+
var anns = annotations[line];
|
| 137 |
+
if (!anns) continue;
|
| 138 |
+
|
| 139 |
+
var maxSeverity = null;
|
| 140 |
+
var tipLabel = state.hasGutter && document.createDocumentFragment();
|
| 141 |
+
|
| 142 |
+
for (var i = 0; i < anns.length; ++i) {
|
| 143 |
+
var ann = anns[i];
|
| 144 |
+
var severity = ann.severity;
|
| 145 |
+
if (!severity) severity = "error";
|
| 146 |
+
maxSeverity = getMaxSeverity(maxSeverity, severity);
|
| 147 |
+
|
| 148 |
+
if (options.formatAnnotation) ann = options.formatAnnotation(ann);
|
| 149 |
+
if (state.hasGutter) tipLabel.appendChild(annotationTooltip(ann));
|
| 150 |
+
|
| 151 |
+
if (ann.to) state.marked.push(cm.markText(ann.from, ann.to, {
|
| 152 |
+
className: "CodeMirror-lint-mark-" + severity,
|
| 153 |
+
__annotation: ann
|
| 154 |
+
}));
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
if (state.hasGutter)
|
| 158 |
+
cm.setGutterMarker(line, GUTTER_ID, makeMarker(tipLabel, maxSeverity, anns.length > 1,
|
| 159 |
+
state.options.tooltips));
|
| 160 |
+
}
|
| 161 |
+
if (options.onUpdateLinting) options.onUpdateLinting(annotationsNotSorted, annotations, cm);
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
function onChange(cm) {
|
| 165 |
+
var state = cm.state.lint;
|
| 166 |
+
if (!state) return;
|
| 167 |
+
clearTimeout(state.timeout);
|
| 168 |
+
state.timeout = setTimeout(function(){startLinting(cm);}, state.options.delay || 500);
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
function popupSpanTooltip(ann, e) {
|
| 172 |
+
var target = e.target || e.srcElement;
|
| 173 |
+
showTooltipFor(e, annotationTooltip(ann), target);
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
function onMouseOver(cm, e) {
|
| 177 |
+
var target = e.target || e.srcElement;
|
| 178 |
+
if (!/\bCodeMirror-lint-mark-/.test(target.className)) return;
|
| 179 |
+
var box = target.getBoundingClientRect(), x = (box.left + box.right) / 2, y = (box.top + box.bottom) / 2;
|
| 180 |
+
var spans = cm.findMarksAt(cm.coordsChar({left: x, top: y}, "client"));
|
| 181 |
+
for (var i = 0; i < spans.length; ++i) {
|
| 182 |
+
var ann = spans[i].__annotation;
|
| 183 |
+
if (ann) return popupSpanTooltip(ann, e);
|
| 184 |
+
}
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
CodeMirror.defineOption("lint", false, function(cm, val, old) {
|
| 188 |
+
if (old && old != CodeMirror.Init) {
|
| 189 |
+
clearMarks(cm);
|
| 190 |
+
cm.off("change", onChange);
|
| 191 |
+
CodeMirror.off(cm.getWrapperElement(), "mouseover", cm.state.lint.onMouseOver);
|
| 192 |
+
clearTimeout(cm.state.lint.timeout);
|
| 193 |
+
delete cm.state.lint;
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
if (val) {
|
| 197 |
+
var gutters = cm.getOption("gutters"), hasLintGutter = false;
|
| 198 |
+
for (var i = 0; i < gutters.length; ++i) if (gutters[i] == GUTTER_ID) hasLintGutter = true;
|
| 199 |
+
var state = cm.state.lint = new LintState(cm, parseOptions(cm, val), hasLintGutter);
|
| 200 |
+
cm.on("change", onChange);
|
| 201 |
+
if (state.options.tooltips != false)
|
| 202 |
+
CodeMirror.on(cm.getWrapperElement(), "mouseover", state.onMouseOver);
|
| 203 |
+
|
| 204 |
+
startLinting(cm);
|
| 205 |
+
}
|
| 206 |
+
});
|
| 207 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/lint/yaml-lint.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
"use strict";
|
| 13 |
+
|
| 14 |
+
// Depends on js-yaml.js from https://github.com/nodeca/js-yaml
|
| 15 |
+
|
| 16 |
+
// declare global: jsyaml
|
| 17 |
+
|
| 18 |
+
CodeMirror.registerHelper("lint", "yaml", function(text) {
|
| 19 |
+
var found = [];
|
| 20 |
+
try { jsyaml.load(text); }
|
| 21 |
+
catch(e) {
|
| 22 |
+
var loc = e.mark;
|
| 23 |
+
found.push({ from: CodeMirror.Pos(loc.line, loc.column), to: CodeMirror.Pos(loc.line, loc.column), message: e.message });
|
| 24 |
+
}
|
| 25 |
+
return found;
|
| 26 |
+
});
|
| 27 |
+
|
| 28 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/merge/merge.css
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.CodeMirror-merge {
|
| 2 |
+
position: relative;
|
| 3 |
+
border: 1px solid #ddd;
|
| 4 |
+
white-space: pre;
|
| 5 |
+
}
|
| 6 |
+
|
| 7 |
+
.CodeMirror-merge, .CodeMirror-merge .CodeMirror {
|
| 8 |
+
height: 350px;
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
.CodeMirror-merge-2pane .CodeMirror-merge-pane { width: 47%; }
|
| 12 |
+
.CodeMirror-merge-2pane .CodeMirror-merge-gap { width: 6%; }
|
| 13 |
+
.CodeMirror-merge-3pane .CodeMirror-merge-pane { width: 31%; }
|
| 14 |
+
.CodeMirror-merge-3pane .CodeMirror-merge-gap { width: 3.5%; }
|
| 15 |
+
|
| 16 |
+
.CodeMirror-merge-pane {
|
| 17 |
+
display: inline-block;
|
| 18 |
+
white-space: normal;
|
| 19 |
+
vertical-align: top;
|
| 20 |
+
}
|
| 21 |
+
.CodeMirror-merge-pane-rightmost {
|
| 22 |
+
position: absolute;
|
| 23 |
+
right: 0px;
|
| 24 |
+
z-index: 1;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
.CodeMirror-merge-gap {
|
| 28 |
+
z-index: 2;
|
| 29 |
+
display: inline-block;
|
| 30 |
+
height: 100%;
|
| 31 |
+
-moz-box-sizing: border-box;
|
| 32 |
+
box-sizing: border-box;
|
| 33 |
+
overflow: hidden;
|
| 34 |
+
border-left: 1px solid #ddd;
|
| 35 |
+
border-right: 1px solid #ddd;
|
| 36 |
+
position: relative;
|
| 37 |
+
background: #f8f8f8;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
.CodeMirror-merge-scrolllock-wrap {
|
| 41 |
+
position: absolute;
|
| 42 |
+
bottom: 0; left: 50%;
|
| 43 |
+
}
|
| 44 |
+
.CodeMirror-merge-scrolllock {
|
| 45 |
+
position: relative;
|
| 46 |
+
left: -50%;
|
| 47 |
+
cursor: pointer;
|
| 48 |
+
color: #555;
|
| 49 |
+
line-height: 1;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
.CodeMirror-merge-copybuttons-left, .CodeMirror-merge-copybuttons-right {
|
| 53 |
+
position: absolute;
|
| 54 |
+
left: 0; top: 0;
|
| 55 |
+
right: 0; bottom: 0;
|
| 56 |
+
line-height: 1;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
.CodeMirror-merge-copy {
|
| 60 |
+
position: absolute;
|
| 61 |
+
cursor: pointer;
|
| 62 |
+
color: #44c;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
.CodeMirror-merge-copy-reverse {
|
| 66 |
+
position: absolute;
|
| 67 |
+
cursor: pointer;
|
| 68 |
+
color: #44c;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
.CodeMirror-merge-copybuttons-left .CodeMirror-merge-copy { left: 2px; }
|
| 72 |
+
.CodeMirror-merge-copybuttons-right .CodeMirror-merge-copy { right: 2px; }
|
| 73 |
+
|
| 74 |
+
.CodeMirror-merge-r-inserted, .CodeMirror-merge-l-inserted {
|
| 75 |
+
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAACCAYAAACddGYaAAAAGUlEQVQI12MwuCXy3+CWyH8GBgYGJgYkAABZbAQ9ELXurwAAAABJRU5ErkJggg==);
|
| 76 |
+
background-position: bottom left;
|
| 77 |
+
background-repeat: repeat-x;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
.CodeMirror-merge-r-deleted, .CodeMirror-merge-l-deleted {
|
| 81 |
+
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAACCAYAAACddGYaAAAAGUlEQVQI12M4Kyb2/6yY2H8GBgYGJgYkAABURgPz6Ks7wQAAAABJRU5ErkJggg==);
|
| 82 |
+
background-position: bottom left;
|
| 83 |
+
background-repeat: repeat-x;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
.CodeMirror-merge-r-chunk { background: #ffffe0; }
|
| 87 |
+
.CodeMirror-merge-r-chunk-start { border-top: 1px solid #ee8; }
|
| 88 |
+
.CodeMirror-merge-r-chunk-end { border-bottom: 1px solid #ee8; }
|
| 89 |
+
.CodeMirror-merge-r-connect { fill: #ffffe0; stroke: #ee8; stroke-width: 1px; }
|
| 90 |
+
|
| 91 |
+
.CodeMirror-merge-l-chunk { background: #eef; }
|
| 92 |
+
.CodeMirror-merge-l-chunk-start { border-top: 1px solid #88e; }
|
| 93 |
+
.CodeMirror-merge-l-chunk-end { border-bottom: 1px solid #88e; }
|
| 94 |
+
.CodeMirror-merge-l-connect { fill: #eef; stroke: #88e; stroke-width: 1px; }
|
| 95 |
+
|
| 96 |
+
.CodeMirror-merge-l-chunk.CodeMirror-merge-r-chunk { background: #dfd; }
|
| 97 |
+
.CodeMirror-merge-l-chunk-start.CodeMirror-merge-r-chunk-start { border-top: 1px solid #4e4; }
|
| 98 |
+
.CodeMirror-merge-l-chunk-end.CodeMirror-merge-r-chunk-end { border-bottom: 1px solid #4e4; }
|
| 99 |
+
|
| 100 |
+
.CodeMirror-merge-collapsed-widget:before {
|
| 101 |
+
content: "(...)";
|
| 102 |
+
}
|
| 103 |
+
.CodeMirror-merge-collapsed-widget {
|
| 104 |
+
cursor: pointer;
|
| 105 |
+
color: #88b;
|
| 106 |
+
background: #eef;
|
| 107 |
+
border: 1px solid #ddf;
|
| 108 |
+
font-size: 90%;
|
| 109 |
+
padding: 0 3px;
|
| 110 |
+
border-radius: 4px;
|
| 111 |
+
}
|
| 112 |
+
.CodeMirror-merge-collapsed-line .CodeMirror-gutter-elt { display: none; }
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/merge/merge.js
ADDED
|
@@ -0,0 +1,775 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
// declare global: diff_match_patch, DIFF_INSERT, DIFF_DELETE, DIFF_EQUAL
|
| 5 |
+
|
| 6 |
+
(function(mod) {
|
| 7 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 8 |
+
mod(require("../../lib/codemirror"), require("diff_match_patch"));
|
| 9 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 10 |
+
define(["../../lib/codemirror", "diff_match_patch"], mod);
|
| 11 |
+
else // Plain browser env
|
| 12 |
+
mod(CodeMirror, diff_match_patch);
|
| 13 |
+
})(function(CodeMirror, diff_match_patch) {
|
| 14 |
+
"use strict";
|
| 15 |
+
var Pos = CodeMirror.Pos;
|
| 16 |
+
var svgNS = "http://www.w3.org/2000/svg";
|
| 17 |
+
|
| 18 |
+
function DiffView(mv, type) {
|
| 19 |
+
this.mv = mv;
|
| 20 |
+
this.type = type;
|
| 21 |
+
this.classes = type == "left"
|
| 22 |
+
? {chunk: "CodeMirror-merge-l-chunk",
|
| 23 |
+
start: "CodeMirror-merge-l-chunk-start",
|
| 24 |
+
end: "CodeMirror-merge-l-chunk-end",
|
| 25 |
+
insert: "CodeMirror-merge-l-inserted",
|
| 26 |
+
del: "CodeMirror-merge-l-deleted",
|
| 27 |
+
connect: "CodeMirror-merge-l-connect"}
|
| 28 |
+
: {chunk: "CodeMirror-merge-r-chunk",
|
| 29 |
+
start: "CodeMirror-merge-r-chunk-start",
|
| 30 |
+
end: "CodeMirror-merge-r-chunk-end",
|
| 31 |
+
insert: "CodeMirror-merge-r-inserted",
|
| 32 |
+
del: "CodeMirror-merge-r-deleted",
|
| 33 |
+
connect: "CodeMirror-merge-r-connect"};
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
DiffView.prototype = {
|
| 37 |
+
constructor: DiffView,
|
| 38 |
+
init: function(pane, orig, options) {
|
| 39 |
+
this.edit = this.mv.edit;
|
| 40 |
+
(this.edit.state.diffViews || (this.edit.state.diffViews = [])).push(this);
|
| 41 |
+
this.orig = CodeMirror(pane, copyObj({value: orig, readOnly: !this.mv.options.allowEditingOriginals}, copyObj(options)));
|
| 42 |
+
this.orig.state.diffViews = [this];
|
| 43 |
+
|
| 44 |
+
this.diff = getDiff(asString(orig), asString(options.value));
|
| 45 |
+
this.chunks = getChunks(this.diff);
|
| 46 |
+
this.diffOutOfDate = this.dealigned = false;
|
| 47 |
+
|
| 48 |
+
this.showDifferences = options.showDifferences !== false;
|
| 49 |
+
this.forceUpdate = registerUpdate(this);
|
| 50 |
+
setScrollLock(this, true, false);
|
| 51 |
+
registerScroll(this);
|
| 52 |
+
},
|
| 53 |
+
setShowDifferences: function(val) {
|
| 54 |
+
val = val !== false;
|
| 55 |
+
if (val != this.showDifferences) {
|
| 56 |
+
this.showDifferences = val;
|
| 57 |
+
this.forceUpdate("full");
|
| 58 |
+
}
|
| 59 |
+
}
|
| 60 |
+
};
|
| 61 |
+
|
| 62 |
+
function ensureDiff(dv) {
|
| 63 |
+
if (dv.diffOutOfDate) {
|
| 64 |
+
dv.diff = getDiff(dv.orig.getValue(), dv.edit.getValue());
|
| 65 |
+
dv.chunks = getChunks(dv.diff);
|
| 66 |
+
dv.diffOutOfDate = false;
|
| 67 |
+
CodeMirror.signal(dv.edit, "updateDiff", dv.diff);
|
| 68 |
+
}
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
var updating = false;
|
| 72 |
+
function registerUpdate(dv) {
|
| 73 |
+
var edit = {from: 0, to: 0, marked: []};
|
| 74 |
+
var orig = {from: 0, to: 0, marked: []};
|
| 75 |
+
var debounceChange, updatingFast = false;
|
| 76 |
+
function update(mode) {
|
| 77 |
+
updating = true;
|
| 78 |
+
updatingFast = false;
|
| 79 |
+
if (mode == "full") {
|
| 80 |
+
if (dv.svg) clear(dv.svg);
|
| 81 |
+
if (dv.copyButtons) clear(dv.copyButtons);
|
| 82 |
+
clearMarks(dv.edit, edit.marked, dv.classes);
|
| 83 |
+
clearMarks(dv.orig, orig.marked, dv.classes);
|
| 84 |
+
edit.from = edit.to = orig.from = orig.to = 0;
|
| 85 |
+
}
|
| 86 |
+
ensureDiff(dv);
|
| 87 |
+
if (dv.showDifferences) {
|
| 88 |
+
updateMarks(dv.edit, dv.diff, edit, DIFF_INSERT, dv.classes);
|
| 89 |
+
updateMarks(dv.orig, dv.diff, orig, DIFF_DELETE, dv.classes);
|
| 90 |
+
}
|
| 91 |
+
makeConnections(dv);
|
| 92 |
+
|
| 93 |
+
if (dv.mv.options.connect == "align")
|
| 94 |
+
alignChunks(dv);
|
| 95 |
+
updating = false;
|
| 96 |
+
}
|
| 97 |
+
function setDealign(fast) {
|
| 98 |
+
if (updating) return;
|
| 99 |
+
dv.dealigned = true;
|
| 100 |
+
set(fast);
|
| 101 |
+
}
|
| 102 |
+
function set(fast) {
|
| 103 |
+
if (updating || updatingFast) return;
|
| 104 |
+
clearTimeout(debounceChange);
|
| 105 |
+
if (fast === true) updatingFast = true;
|
| 106 |
+
debounceChange = setTimeout(update, fast === true ? 20 : 250);
|
| 107 |
+
}
|
| 108 |
+
function change(_cm, change) {
|
| 109 |
+
if (!dv.diffOutOfDate) {
|
| 110 |
+
dv.diffOutOfDate = true;
|
| 111 |
+
edit.from = edit.to = orig.from = orig.to = 0;
|
| 112 |
+
}
|
| 113 |
+
// Update faster when a line was added/removed
|
| 114 |
+
setDealign(change.text.length - 1 != change.to.line - change.from.line);
|
| 115 |
+
}
|
| 116 |
+
dv.edit.on("change", change);
|
| 117 |
+
dv.orig.on("change", change);
|
| 118 |
+
dv.edit.on("markerAdded", setDealign);
|
| 119 |
+
dv.edit.on("markerCleared", setDealign);
|
| 120 |
+
dv.orig.on("markerAdded", setDealign);
|
| 121 |
+
dv.orig.on("markerCleared", setDealign);
|
| 122 |
+
dv.edit.on("viewportChange", function() { set(false); });
|
| 123 |
+
dv.orig.on("viewportChange", function() { set(false); });
|
| 124 |
+
update();
|
| 125 |
+
return update;
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
function registerScroll(dv) {
|
| 129 |
+
dv.edit.on("scroll", function() {
|
| 130 |
+
syncScroll(dv, DIFF_INSERT) && makeConnections(dv);
|
| 131 |
+
});
|
| 132 |
+
dv.orig.on("scroll", function() {
|
| 133 |
+
syncScroll(dv, DIFF_DELETE) && makeConnections(dv);
|
| 134 |
+
});
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
function syncScroll(dv, type) {
|
| 138 |
+
// Change handler will do a refresh after a timeout when diff is out of date
|
| 139 |
+
if (dv.diffOutOfDate) return false;
|
| 140 |
+
if (!dv.lockScroll) return true;
|
| 141 |
+
var editor, other, now = +new Date;
|
| 142 |
+
if (type == DIFF_INSERT) { editor = dv.edit; other = dv.orig; }
|
| 143 |
+
else { editor = dv.orig; other = dv.edit; }
|
| 144 |
+
// Don't take action if the position of this editor was recently set
|
| 145 |
+
// (to prevent feedback loops)
|
| 146 |
+
if (editor.state.scrollSetBy == dv && (editor.state.scrollSetAt || 0) + 50 > now) return false;
|
| 147 |
+
|
| 148 |
+
var sInfo = editor.getScrollInfo();
|
| 149 |
+
if (dv.mv.options.connect == "align") {
|
| 150 |
+
targetPos = sInfo.top;
|
| 151 |
+
} else {
|
| 152 |
+
var halfScreen = .5 * sInfo.clientHeight, midY = sInfo.top + halfScreen;
|
| 153 |
+
var mid = editor.lineAtHeight(midY, "local");
|
| 154 |
+
var around = chunkBoundariesAround(dv.chunks, mid, type == DIFF_INSERT);
|
| 155 |
+
var off = getOffsets(editor, type == DIFF_INSERT ? around.edit : around.orig);
|
| 156 |
+
var offOther = getOffsets(other, type == DIFF_INSERT ? around.orig : around.edit);
|
| 157 |
+
var ratio = (midY - off.top) / (off.bot - off.top);
|
| 158 |
+
var targetPos = (offOther.top - halfScreen) + ratio * (offOther.bot - offOther.top);
|
| 159 |
+
|
| 160 |
+
var botDist, mix;
|
| 161 |
+
// Some careful tweaking to make sure no space is left out of view
|
| 162 |
+
// when scrolling to top or bottom.
|
| 163 |
+
if (targetPos > sInfo.top && (mix = sInfo.top / halfScreen) < 1) {
|
| 164 |
+
targetPos = targetPos * mix + sInfo.top * (1 - mix);
|
| 165 |
+
} else if ((botDist = sInfo.height - sInfo.clientHeight - sInfo.top) < halfScreen) {
|
| 166 |
+
var otherInfo = other.getScrollInfo();
|
| 167 |
+
var botDistOther = otherInfo.height - otherInfo.clientHeight - targetPos;
|
| 168 |
+
if (botDistOther > botDist && (mix = botDist / halfScreen) < 1)
|
| 169 |
+
targetPos = targetPos * mix + (otherInfo.height - otherInfo.clientHeight - botDist) * (1 - mix);
|
| 170 |
+
}
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
other.scrollTo(sInfo.left, targetPos);
|
| 174 |
+
other.state.scrollSetAt = now;
|
| 175 |
+
other.state.scrollSetBy = dv;
|
| 176 |
+
return true;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
function getOffsets(editor, around) {
|
| 180 |
+
var bot = around.after;
|
| 181 |
+
if (bot == null) bot = editor.lastLine() + 1;
|
| 182 |
+
return {top: editor.heightAtLine(around.before || 0, "local"),
|
| 183 |
+
bot: editor.heightAtLine(bot, "local")};
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
function setScrollLock(dv, val, action) {
|
| 187 |
+
dv.lockScroll = val;
|
| 188 |
+
if (val && action != false) syncScroll(dv, DIFF_INSERT) && makeConnections(dv);
|
| 189 |
+
dv.lockButton.innerHTML = val ? "\u21db\u21da" : "\u21db \u21da";
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
// Updating the marks for editor content
|
| 193 |
+
|
| 194 |
+
function clearMarks(editor, arr, classes) {
|
| 195 |
+
for (var i = 0; i < arr.length; ++i) {
|
| 196 |
+
var mark = arr[i];
|
| 197 |
+
if (mark instanceof CodeMirror.TextMarker) {
|
| 198 |
+
mark.clear();
|
| 199 |
+
} else if (mark.parent) {
|
| 200 |
+
editor.removeLineClass(mark, "background", classes.chunk);
|
| 201 |
+
editor.removeLineClass(mark, "background", classes.start);
|
| 202 |
+
editor.removeLineClass(mark, "background", classes.end);
|
| 203 |
+
}
|
| 204 |
+
}
|
| 205 |
+
arr.length = 0;
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
// FIXME maybe add a margin around viewport to prevent too many updates
|
| 209 |
+
function updateMarks(editor, diff, state, type, classes) {
|
| 210 |
+
var vp = editor.getViewport();
|
| 211 |
+
editor.operation(function() {
|
| 212 |
+
if (state.from == state.to || vp.from - state.to > 20 || state.from - vp.to > 20) {
|
| 213 |
+
clearMarks(editor, state.marked, classes);
|
| 214 |
+
markChanges(editor, diff, type, state.marked, vp.from, vp.to, classes);
|
| 215 |
+
state.from = vp.from; state.to = vp.to;
|
| 216 |
+
} else {
|
| 217 |
+
if (vp.from < state.from) {
|
| 218 |
+
markChanges(editor, diff, type, state.marked, vp.from, state.from, classes);
|
| 219 |
+
state.from = vp.from;
|
| 220 |
+
}
|
| 221 |
+
if (vp.to > state.to) {
|
| 222 |
+
markChanges(editor, diff, type, state.marked, state.to, vp.to, classes);
|
| 223 |
+
state.to = vp.to;
|
| 224 |
+
}
|
| 225 |
+
}
|
| 226 |
+
});
|
| 227 |
+
}
|
| 228 |
+
|
| 229 |
+
function markChanges(editor, diff, type, marks, from, to, classes) {
|
| 230 |
+
var pos = Pos(0, 0);
|
| 231 |
+
var top = Pos(from, 0), bot = editor.clipPos(Pos(to - 1));
|
| 232 |
+
var cls = type == DIFF_DELETE ? classes.del : classes.insert;
|
| 233 |
+
function markChunk(start, end) {
|
| 234 |
+
var bfrom = Math.max(from, start), bto = Math.min(to, end);
|
| 235 |
+
for (var i = bfrom; i < bto; ++i) {
|
| 236 |
+
var line = editor.addLineClass(i, "background", classes.chunk);
|
| 237 |
+
if (i == start) editor.addLineClass(line, "background", classes.start);
|
| 238 |
+
if (i == end - 1) editor.addLineClass(line, "background", classes.end);
|
| 239 |
+
marks.push(line);
|
| 240 |
+
}
|
| 241 |
+
// When the chunk is empty, make sure a horizontal line shows up
|
| 242 |
+
if (start == end && bfrom == end && bto == end) {
|
| 243 |
+
if (bfrom)
|
| 244 |
+
marks.push(editor.addLineClass(bfrom - 1, "background", classes.end));
|
| 245 |
+
else
|
| 246 |
+
marks.push(editor.addLineClass(bfrom, "background", classes.start));
|
| 247 |
+
}
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
var chunkStart = 0;
|
| 251 |
+
for (var i = 0; i < diff.length; ++i) {
|
| 252 |
+
var part = diff[i], tp = part[0], str = part[1];
|
| 253 |
+
if (tp == DIFF_EQUAL) {
|
| 254 |
+
var cleanFrom = pos.line + (startOfLineClean(diff, i) ? 0 : 1);
|
| 255 |
+
moveOver(pos, str);
|
| 256 |
+
var cleanTo = pos.line + (endOfLineClean(diff, i) ? 1 : 0);
|
| 257 |
+
if (cleanTo > cleanFrom) {
|
| 258 |
+
if (i) markChunk(chunkStart, cleanFrom);
|
| 259 |
+
chunkStart = cleanTo;
|
| 260 |
+
}
|
| 261 |
+
} else {
|
| 262 |
+
if (tp == type) {
|
| 263 |
+
var end = moveOver(pos, str, true);
|
| 264 |
+
var a = posMax(top, pos), b = posMin(bot, end);
|
| 265 |
+
if (!posEq(a, b))
|
| 266 |
+
marks.push(editor.markText(a, b, {className: cls}));
|
| 267 |
+
pos = end;
|
| 268 |
+
}
|
| 269 |
+
}
|
| 270 |
+
}
|
| 271 |
+
if (chunkStart <= pos.line) markChunk(chunkStart, pos.line + 1);
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
// Updating the gap between editor and original
|
| 275 |
+
|
| 276 |
+
function makeConnections(dv) {
|
| 277 |
+
if (!dv.showDifferences) return;
|
| 278 |
+
|
| 279 |
+
if (dv.svg) {
|
| 280 |
+
clear(dv.svg);
|
| 281 |
+
var w = dv.gap.offsetWidth;
|
| 282 |
+
attrs(dv.svg, "width", w, "height", dv.gap.offsetHeight);
|
| 283 |
+
}
|
| 284 |
+
if (dv.copyButtons) clear(dv.copyButtons);
|
| 285 |
+
|
| 286 |
+
var vpEdit = dv.edit.getViewport(), vpOrig = dv.orig.getViewport();
|
| 287 |
+
var sTopEdit = dv.edit.getScrollInfo().top, sTopOrig = dv.orig.getScrollInfo().top;
|
| 288 |
+
for (var i = 0; i < dv.chunks.length; i++) {
|
| 289 |
+
var ch = dv.chunks[i];
|
| 290 |
+
if (ch.editFrom <= vpEdit.to && ch.editTo >= vpEdit.from &&
|
| 291 |
+
ch.origFrom <= vpOrig.to && ch.origTo >= vpOrig.from)
|
| 292 |
+
drawConnectorsForChunk(dv, ch, sTopOrig, sTopEdit, w);
|
| 293 |
+
}
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
function getMatchingOrigLine(editLine, chunks) {
|
| 297 |
+
var editStart = 0, origStart = 0;
|
| 298 |
+
for (var i = 0; i < chunks.length; i++) {
|
| 299 |
+
var chunk = chunks[i];
|
| 300 |
+
if (chunk.editTo > editLine && chunk.editFrom <= editLine) return null;
|
| 301 |
+
if (chunk.editFrom > editLine) break;
|
| 302 |
+
editStart = chunk.editTo;
|
| 303 |
+
origStart = chunk.origTo;
|
| 304 |
+
}
|
| 305 |
+
return origStart + (editLine - editStart);
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
function findAlignedLines(dv, other) {
|
| 309 |
+
var linesToAlign = [];
|
| 310 |
+
for (var i = 0; i < dv.chunks.length; i++) {
|
| 311 |
+
var chunk = dv.chunks[i];
|
| 312 |
+
linesToAlign.push([chunk.origTo, chunk.editTo, other ? getMatchingOrigLine(chunk.editTo, other.chunks) : null]);
|
| 313 |
+
}
|
| 314 |
+
if (other) {
|
| 315 |
+
for (var i = 0; i < other.chunks.length; i++) {
|
| 316 |
+
var chunk = other.chunks[i];
|
| 317 |
+
for (var j = 0; j < linesToAlign.length; j++) {
|
| 318 |
+
var align = linesToAlign[j];
|
| 319 |
+
if (align[1] == chunk.editTo) {
|
| 320 |
+
j = -1;
|
| 321 |
+
break;
|
| 322 |
+
} else if (align[1] > chunk.editTo) {
|
| 323 |
+
break;
|
| 324 |
+
}
|
| 325 |
+
}
|
| 326 |
+
if (j > -1)
|
| 327 |
+
linesToAlign.splice(j - 1, 0, [getMatchingOrigLine(chunk.editTo, dv.chunks), chunk.editTo, chunk.origTo]);
|
| 328 |
+
}
|
| 329 |
+
}
|
| 330 |
+
return linesToAlign;
|
| 331 |
+
}
|
| 332 |
+
|
| 333 |
+
function alignChunks(dv, force) {
|
| 334 |
+
if (!dv.dealigned && !force) return;
|
| 335 |
+
if (!dv.orig.curOp) return dv.orig.operation(function() {
|
| 336 |
+
alignChunks(dv, force);
|
| 337 |
+
});
|
| 338 |
+
|
| 339 |
+
dv.dealigned = false;
|
| 340 |
+
var other = dv.mv.left == dv ? dv.mv.right : dv.mv.left;
|
| 341 |
+
if (other) {
|
| 342 |
+
ensureDiff(other);
|
| 343 |
+
other.dealigned = false;
|
| 344 |
+
}
|
| 345 |
+
var linesToAlign = findAlignedLines(dv, other);
|
| 346 |
+
|
| 347 |
+
// Clear old aligners
|
| 348 |
+
var aligners = dv.mv.aligners;
|
| 349 |
+
for (var i = 0; i < aligners.length; i++)
|
| 350 |
+
aligners[i].clear();
|
| 351 |
+
aligners.length = 0;
|
| 352 |
+
|
| 353 |
+
var cm = [dv.orig, dv.edit], scroll = [];
|
| 354 |
+
if (other) cm.push(other.orig);
|
| 355 |
+
for (var i = 0; i < cm.length; i++)
|
| 356 |
+
scroll.push(cm[i].getScrollInfo().top);
|
| 357 |
+
|
| 358 |
+
for (var ln = 0; ln < linesToAlign.length; ln++)
|
| 359 |
+
alignLines(cm, linesToAlign[ln], aligners);
|
| 360 |
+
|
| 361 |
+
for (var i = 0; i < cm.length; i++)
|
| 362 |
+
cm[i].scrollTo(null, scroll[i]);
|
| 363 |
+
}
|
| 364 |
+
|
| 365 |
+
function alignLines(cm, lines, aligners) {
|
| 366 |
+
var maxOffset = 0, offset = [];
|
| 367 |
+
for (var i = 0; i < cm.length; i++) if (lines[i] != null) {
|
| 368 |
+
var off = cm[i].heightAtLine(lines[i], "local");
|
| 369 |
+
offset[i] = off;
|
| 370 |
+
maxOffset = Math.max(maxOffset, off);
|
| 371 |
+
}
|
| 372 |
+
for (var i = 0; i < cm.length; i++) if (lines[i] != null) {
|
| 373 |
+
var diff = maxOffset - offset[i];
|
| 374 |
+
if (diff > 1)
|
| 375 |
+
aligners.push(padAbove(cm[i], lines[i], diff));
|
| 376 |
+
}
|
| 377 |
+
}
|
| 378 |
+
|
| 379 |
+
function padAbove(cm, line, size) {
|
| 380 |
+
var above = true;
|
| 381 |
+
if (line > cm.lastLine()) {
|
| 382 |
+
line--;
|
| 383 |
+
above = false;
|
| 384 |
+
}
|
| 385 |
+
var elt = document.createElement("div");
|
| 386 |
+
elt.className = "CodeMirror-merge-spacer";
|
| 387 |
+
elt.style.height = size + "px"; elt.style.minWidth = "1px";
|
| 388 |
+
return cm.addLineWidget(line, elt, {height: size, above: above});
|
| 389 |
+
}
|
| 390 |
+
|
| 391 |
+
function drawConnectorsForChunk(dv, chunk, sTopOrig, sTopEdit, w) {
|
| 392 |
+
var flip = dv.type == "left";
|
| 393 |
+
var top = dv.orig.heightAtLine(chunk.origFrom, "local") - sTopOrig;
|
| 394 |
+
if (dv.svg) {
|
| 395 |
+
var topLpx = top;
|
| 396 |
+
var topRpx = dv.edit.heightAtLine(chunk.editFrom, "local") - sTopEdit;
|
| 397 |
+
if (flip) { var tmp = topLpx; topLpx = topRpx; topRpx = tmp; }
|
| 398 |
+
var botLpx = dv.orig.heightAtLine(chunk.origTo, "local") - sTopOrig;
|
| 399 |
+
var botRpx = dv.edit.heightAtLine(chunk.editTo, "local") - sTopEdit;
|
| 400 |
+
if (flip) { var tmp = botLpx; botLpx = botRpx; botRpx = tmp; }
|
| 401 |
+
var curveTop = " C " + w/2 + " " + topRpx + " " + w/2 + " " + topLpx + " " + (w + 2) + " " + topLpx;
|
| 402 |
+
var curveBot = " C " + w/2 + " " + botLpx + " " + w/2 + " " + botRpx + " -1 " + botRpx;
|
| 403 |
+
attrs(dv.svg.appendChild(document.createElementNS(svgNS, "path")),
|
| 404 |
+
"d", "M -1 " + topRpx + curveTop + " L " + (w + 2) + " " + botLpx + curveBot + " z",
|
| 405 |
+
"class", dv.classes.connect);
|
| 406 |
+
}
|
| 407 |
+
if (dv.copyButtons) {
|
| 408 |
+
var copy = dv.copyButtons.appendChild(elt("div", dv.type == "left" ? "\u21dd" : "\u21dc",
|
| 409 |
+
"CodeMirror-merge-copy"));
|
| 410 |
+
var editOriginals = dv.mv.options.allowEditingOriginals;
|
| 411 |
+
copy.title = editOriginals ? "Push to left" : "Revert chunk";
|
| 412 |
+
copy.chunk = chunk;
|
| 413 |
+
copy.style.top = top + "px";
|
| 414 |
+
|
| 415 |
+
if (editOriginals) {
|
| 416 |
+
var topReverse = dv.orig.heightAtLine(chunk.editFrom, "local") - sTopEdit;
|
| 417 |
+
var copyReverse = dv.copyButtons.appendChild(elt("div", dv.type == "right" ? "\u21dd" : "\u21dc",
|
| 418 |
+
"CodeMirror-merge-copy-reverse"));
|
| 419 |
+
copyReverse.title = "Push to right";
|
| 420 |
+
copyReverse.chunk = {editFrom: chunk.origFrom, editTo: chunk.origTo,
|
| 421 |
+
origFrom: chunk.editFrom, origTo: chunk.editTo};
|
| 422 |
+
copyReverse.style.top = topReverse + "px";
|
| 423 |
+
dv.type == "right" ? copyReverse.style.left = "2px" : copyReverse.style.right = "2px";
|
| 424 |
+
}
|
| 425 |
+
}
|
| 426 |
+
}
|
| 427 |
+
|
| 428 |
+
function copyChunk(dv, to, from, chunk) {
|
| 429 |
+
if (dv.diffOutOfDate) return;
|
| 430 |
+
to.replaceRange(from.getRange(Pos(chunk.origFrom, 0), Pos(chunk.origTo, 0)),
|
| 431 |
+
Pos(chunk.editFrom, 0), Pos(chunk.editTo, 0));
|
| 432 |
+
}
|
| 433 |
+
|
| 434 |
+
// Merge view, containing 0, 1, or 2 diff views.
|
| 435 |
+
|
| 436 |
+
var MergeView = CodeMirror.MergeView = function(node, options) {
|
| 437 |
+
if (!(this instanceof MergeView)) return new MergeView(node, options);
|
| 438 |
+
|
| 439 |
+
this.options = options;
|
| 440 |
+
var origLeft = options.origLeft, origRight = options.origRight == null ? options.orig : options.origRight;
|
| 441 |
+
|
| 442 |
+
var hasLeft = origLeft != null, hasRight = origRight != null;
|
| 443 |
+
var panes = 1 + (hasLeft ? 1 : 0) + (hasRight ? 1 : 0);
|
| 444 |
+
var wrap = [], left = this.left = null, right = this.right = null;
|
| 445 |
+
var self = this;
|
| 446 |
+
|
| 447 |
+
if (hasLeft) {
|
| 448 |
+
left = this.left = new DiffView(this, "left");
|
| 449 |
+
var leftPane = elt("div", null, "CodeMirror-merge-pane");
|
| 450 |
+
wrap.push(leftPane);
|
| 451 |
+
wrap.push(buildGap(left));
|
| 452 |
+
}
|
| 453 |
+
|
| 454 |
+
var editPane = elt("div", null, "CodeMirror-merge-pane");
|
| 455 |
+
wrap.push(editPane);
|
| 456 |
+
|
| 457 |
+
if (hasRight) {
|
| 458 |
+
right = this.right = new DiffView(this, "right");
|
| 459 |
+
wrap.push(buildGap(right));
|
| 460 |
+
var rightPane = elt("div", null, "CodeMirror-merge-pane");
|
| 461 |
+
wrap.push(rightPane);
|
| 462 |
+
}
|
| 463 |
+
|
| 464 |
+
(hasRight ? rightPane : editPane).className += " CodeMirror-merge-pane-rightmost";
|
| 465 |
+
|
| 466 |
+
wrap.push(elt("div", null, null, "height: 0; clear: both;"));
|
| 467 |
+
|
| 468 |
+
var wrapElt = this.wrap = node.appendChild(elt("div", wrap, "CodeMirror-merge CodeMirror-merge-" + panes + "pane"));
|
| 469 |
+
this.edit = CodeMirror(editPane, copyObj(options));
|
| 470 |
+
|
| 471 |
+
if (left) left.init(leftPane, origLeft, options);
|
| 472 |
+
if (right) right.init(rightPane, origRight, options);
|
| 473 |
+
|
| 474 |
+
if (options.collapseIdentical) {
|
| 475 |
+
updating = true;
|
| 476 |
+
this.editor().operation(function() {
|
| 477 |
+
collapseIdenticalStretches(self, options.collapseIdentical);
|
| 478 |
+
});
|
| 479 |
+
updating = false;
|
| 480 |
+
}
|
| 481 |
+
if (options.connect == "align") {
|
| 482 |
+
this.aligners = [];
|
| 483 |
+
alignChunks(this.left || this.right, true);
|
| 484 |
+
}
|
| 485 |
+
|
| 486 |
+
var onResize = function() {
|
| 487 |
+
if (left) makeConnections(left);
|
| 488 |
+
if (right) makeConnections(right);
|
| 489 |
+
};
|
| 490 |
+
CodeMirror.on(window, "resize", onResize);
|
| 491 |
+
var resizeInterval = setInterval(function() {
|
| 492 |
+
for (var p = wrapElt.parentNode; p && p != document.body; p = p.parentNode) {}
|
| 493 |
+
if (!p) { clearInterval(resizeInterval); CodeMirror.off(window, "resize", onResize); }
|
| 494 |
+
}, 5000);
|
| 495 |
+
};
|
| 496 |
+
|
| 497 |
+
function buildGap(dv) {
|
| 498 |
+
var lock = dv.lockButton = elt("div", null, "CodeMirror-merge-scrolllock");
|
| 499 |
+
lock.title = "Toggle locked scrolling";
|
| 500 |
+
var lockWrap = elt("div", [lock], "CodeMirror-merge-scrolllock-wrap");
|
| 501 |
+
CodeMirror.on(lock, "click", function() { setScrollLock(dv, !dv.lockScroll); });
|
| 502 |
+
var gapElts = [lockWrap];
|
| 503 |
+
if (dv.mv.options.revertButtons !== false) {
|
| 504 |
+
dv.copyButtons = elt("div", null, "CodeMirror-merge-copybuttons-" + dv.type);
|
| 505 |
+
CodeMirror.on(dv.copyButtons, "click", function(e) {
|
| 506 |
+
var node = e.target || e.srcElement;
|
| 507 |
+
if (!node.chunk) return;
|
| 508 |
+
if (node.className == "CodeMirror-merge-copy-reverse") {
|
| 509 |
+
copyChunk(dv, dv.orig, dv.edit, node.chunk);
|
| 510 |
+
return;
|
| 511 |
+
}
|
| 512 |
+
copyChunk(dv, dv.edit, dv.orig, node.chunk);
|
| 513 |
+
});
|
| 514 |
+
gapElts.unshift(dv.copyButtons);
|
| 515 |
+
}
|
| 516 |
+
if (dv.mv.options.connect != "align") {
|
| 517 |
+
var svg = document.createElementNS && document.createElementNS(svgNS, "svg");
|
| 518 |
+
if (svg && !svg.createSVGRect) svg = null;
|
| 519 |
+
dv.svg = svg;
|
| 520 |
+
if (svg) gapElts.push(svg);
|
| 521 |
+
}
|
| 522 |
+
|
| 523 |
+
return dv.gap = elt("div", gapElts, "CodeMirror-merge-gap");
|
| 524 |
+
}
|
| 525 |
+
|
| 526 |
+
MergeView.prototype = {
|
| 527 |
+
constuctor: MergeView,
|
| 528 |
+
editor: function() { return this.edit; },
|
| 529 |
+
rightOriginal: function() { return this.right && this.right.orig; },
|
| 530 |
+
leftOriginal: function() { return this.left && this.left.orig; },
|
| 531 |
+
setShowDifferences: function(val) {
|
| 532 |
+
if (this.right) this.right.setShowDifferences(val);
|
| 533 |
+
if (this.left) this.left.setShowDifferences(val);
|
| 534 |
+
},
|
| 535 |
+
rightChunks: function() {
|
| 536 |
+
if (this.right) { ensureDiff(this.right); return this.right.chunks; }
|
| 537 |
+
},
|
| 538 |
+
leftChunks: function() {
|
| 539 |
+
if (this.left) { ensureDiff(this.left); return this.left.chunks; }
|
| 540 |
+
}
|
| 541 |
+
};
|
| 542 |
+
|
| 543 |
+
function asString(obj) {
|
| 544 |
+
if (typeof obj == "string") return obj;
|
| 545 |
+
else return obj.getValue();
|
| 546 |
+
}
|
| 547 |
+
|
| 548 |
+
// Operations on diffs
|
| 549 |
+
|
| 550 |
+
var dmp = new diff_match_patch();
|
| 551 |
+
function getDiff(a, b) {
|
| 552 |
+
var diff = dmp.diff_main(a, b);
|
| 553 |
+
dmp.diff_cleanupSemantic(diff);
|
| 554 |
+
// The library sometimes leaves in empty parts, which confuse the algorithm
|
| 555 |
+
for (var i = 0; i < diff.length; ++i) {
|
| 556 |
+
var part = diff[i];
|
| 557 |
+
if (!part[1]) {
|
| 558 |
+
diff.splice(i--, 1);
|
| 559 |
+
} else if (i && diff[i - 1][0] == part[0]) {
|
| 560 |
+
diff.splice(i--, 1);
|
| 561 |
+
diff[i][1] += part[1];
|
| 562 |
+
}
|
| 563 |
+
}
|
| 564 |
+
return diff;
|
| 565 |
+
}
|
| 566 |
+
|
| 567 |
+
function getChunks(diff) {
|
| 568 |
+
var chunks = [];
|
| 569 |
+
var startEdit = 0, startOrig = 0;
|
| 570 |
+
var edit = Pos(0, 0), orig = Pos(0, 0);
|
| 571 |
+
for (var i = 0; i < diff.length; ++i) {
|
| 572 |
+
var part = diff[i], tp = part[0];
|
| 573 |
+
if (tp == DIFF_EQUAL) {
|
| 574 |
+
var startOff = startOfLineClean(diff, i) ? 0 : 1;
|
| 575 |
+
var cleanFromEdit = edit.line + startOff, cleanFromOrig = orig.line + startOff;
|
| 576 |
+
moveOver(edit, part[1], null, orig);
|
| 577 |
+
var endOff = endOfLineClean(diff, i) ? 1 : 0;
|
| 578 |
+
var cleanToEdit = edit.line + endOff, cleanToOrig = orig.line + endOff;
|
| 579 |
+
if (cleanToEdit > cleanFromEdit) {
|
| 580 |
+
if (i) chunks.push({origFrom: startOrig, origTo: cleanFromOrig,
|
| 581 |
+
editFrom: startEdit, editTo: cleanFromEdit});
|
| 582 |
+
startEdit = cleanToEdit; startOrig = cleanToOrig;
|
| 583 |
+
}
|
| 584 |
+
} else {
|
| 585 |
+
moveOver(tp == DIFF_INSERT ? edit : orig, part[1]);
|
| 586 |
+
}
|
| 587 |
+
}
|
| 588 |
+
if (startEdit <= edit.line || startOrig <= orig.line)
|
| 589 |
+
chunks.push({origFrom: startOrig, origTo: orig.line + 1,
|
| 590 |
+
editFrom: startEdit, editTo: edit.line + 1});
|
| 591 |
+
return chunks;
|
| 592 |
+
}
|
| 593 |
+
|
| 594 |
+
function endOfLineClean(diff, i) {
|
| 595 |
+
if (i == diff.length - 1) return true;
|
| 596 |
+
var next = diff[i + 1][1];
|
| 597 |
+
if (next.length == 1 || next.charCodeAt(0) != 10) return false;
|
| 598 |
+
if (i == diff.length - 2) return true;
|
| 599 |
+
next = diff[i + 2][1];
|
| 600 |
+
return next.length > 1 && next.charCodeAt(0) == 10;
|
| 601 |
+
}
|
| 602 |
+
|
| 603 |
+
function startOfLineClean(diff, i) {
|
| 604 |
+
if (i == 0) return true;
|
| 605 |
+
var last = diff[i - 1][1];
|
| 606 |
+
if (last.charCodeAt(last.length - 1) != 10) return false;
|
| 607 |
+
if (i == 1) return true;
|
| 608 |
+
last = diff[i - 2][1];
|
| 609 |
+
return last.charCodeAt(last.length - 1) == 10;
|
| 610 |
+
}
|
| 611 |
+
|
| 612 |
+
function chunkBoundariesAround(chunks, n, nInEdit) {
|
| 613 |
+
var beforeE, afterE, beforeO, afterO;
|
| 614 |
+
for (var i = 0; i < chunks.length; i++) {
|
| 615 |
+
var chunk = chunks[i];
|
| 616 |
+
var fromLocal = nInEdit ? chunk.editFrom : chunk.origFrom;
|
| 617 |
+
var toLocal = nInEdit ? chunk.editTo : chunk.origTo;
|
| 618 |
+
if (afterE == null) {
|
| 619 |
+
if (fromLocal > n) { afterE = chunk.editFrom; afterO = chunk.origFrom; }
|
| 620 |
+
else if (toLocal > n) { afterE = chunk.editTo; afterO = chunk.origTo; }
|
| 621 |
+
}
|
| 622 |
+
if (toLocal <= n) { beforeE = chunk.editTo; beforeO = chunk.origTo; }
|
| 623 |
+
else if (fromLocal <= n) { beforeE = chunk.editFrom; beforeO = chunk.origFrom; }
|
| 624 |
+
}
|
| 625 |
+
return {edit: {before: beforeE, after: afterE}, orig: {before: beforeO, after: afterO}};
|
| 626 |
+
}
|
| 627 |
+
|
| 628 |
+
function collapseSingle(cm, from, to) {
|
| 629 |
+
cm.addLineClass(from, "wrap", "CodeMirror-merge-collapsed-line");
|
| 630 |
+
var widget = document.createElement("span");
|
| 631 |
+
widget.className = "CodeMirror-merge-collapsed-widget";
|
| 632 |
+
widget.title = "Identical text collapsed. Click to expand.";
|
| 633 |
+
var mark = cm.markText(Pos(from, 0), Pos(to - 1), {
|
| 634 |
+
inclusiveLeft: true,
|
| 635 |
+
inclusiveRight: true,
|
| 636 |
+
replacedWith: widget,
|
| 637 |
+
clearOnEnter: true
|
| 638 |
+
});
|
| 639 |
+
function clear() {
|
| 640 |
+
mark.clear();
|
| 641 |
+
cm.removeLineClass(from, "wrap", "CodeMirror-merge-collapsed-line");
|
| 642 |
+
}
|
| 643 |
+
widget.addEventListener("click", clear);
|
| 644 |
+
return {mark: mark, clear: clear};
|
| 645 |
+
}
|
| 646 |
+
|
| 647 |
+
function collapseStretch(size, editors) {
|
| 648 |
+
var marks = [];
|
| 649 |
+
function clear() {
|
| 650 |
+
for (var i = 0; i < marks.length; i++) marks[i].clear();
|
| 651 |
+
}
|
| 652 |
+
for (var i = 0; i < editors.length; i++) {
|
| 653 |
+
var editor = editors[i];
|
| 654 |
+
var mark = collapseSingle(editor.cm, editor.line, editor.line + size);
|
| 655 |
+
marks.push(mark);
|
| 656 |
+
mark.mark.on("clear", clear);
|
| 657 |
+
}
|
| 658 |
+
return marks[0].mark;
|
| 659 |
+
}
|
| 660 |
+
|
| 661 |
+
function unclearNearChunks(dv, margin, off, clear) {
|
| 662 |
+
for (var i = 0; i < dv.chunks.length; i++) {
|
| 663 |
+
var chunk = dv.chunks[i];
|
| 664 |
+
for (var l = chunk.editFrom - margin; l < chunk.editTo + margin; l++) {
|
| 665 |
+
var pos = l + off;
|
| 666 |
+
if (pos >= 0 && pos < clear.length) clear[pos] = false;
|
| 667 |
+
}
|
| 668 |
+
}
|
| 669 |
+
}
|
| 670 |
+
|
| 671 |
+
function collapseIdenticalStretches(mv, margin) {
|
| 672 |
+
if (typeof margin != "number") margin = 2;
|
| 673 |
+
var clear = [], edit = mv.editor(), off = edit.firstLine();
|
| 674 |
+
for (var l = off, e = edit.lastLine(); l <= e; l++) clear.push(true);
|
| 675 |
+
if (mv.left) unclearNearChunks(mv.left, margin, off, clear);
|
| 676 |
+
if (mv.right) unclearNearChunks(mv.right, margin, off, clear);
|
| 677 |
+
|
| 678 |
+
for (var i = 0; i < clear.length; i++) {
|
| 679 |
+
if (clear[i]) {
|
| 680 |
+
var line = i + off;
|
| 681 |
+
for (var size = 1; i < clear.length - 1 && clear[i + 1]; i++, size++) {}
|
| 682 |
+
if (size > margin) {
|
| 683 |
+
var editors = [{line: line, cm: edit}];
|
| 684 |
+
if (mv.left) editors.push({line: getMatchingOrigLine(line, mv.left.chunks), cm: mv.left.orig});
|
| 685 |
+
if (mv.right) editors.push({line: getMatchingOrigLine(line, mv.right.chunks), cm: mv.right.orig});
|
| 686 |
+
var mark = collapseStretch(size, editors);
|
| 687 |
+
if (mv.options.onCollapse) mv.options.onCollapse(mv, line, size, mark);
|
| 688 |
+
}
|
| 689 |
+
}
|
| 690 |
+
}
|
| 691 |
+
}
|
| 692 |
+
|
| 693 |
+
// General utilities
|
| 694 |
+
|
| 695 |
+
function elt(tag, content, className, style) {
|
| 696 |
+
var e = document.createElement(tag);
|
| 697 |
+
if (className) e.className = className;
|
| 698 |
+
if (style) e.style.cssText = style;
|
| 699 |
+
if (typeof content == "string") e.appendChild(document.createTextNode(content));
|
| 700 |
+
else if (content) for (var i = 0; i < content.length; ++i) e.appendChild(content[i]);
|
| 701 |
+
return e;
|
| 702 |
+
}
|
| 703 |
+
|
| 704 |
+
function clear(node) {
|
| 705 |
+
for (var count = node.childNodes.length; count > 0; --count)
|
| 706 |
+
node.removeChild(node.firstChild);
|
| 707 |
+
}
|
| 708 |
+
|
| 709 |
+
function attrs(elt) {
|
| 710 |
+
for (var i = 1; i < arguments.length; i += 2)
|
| 711 |
+
elt.setAttribute(arguments[i], arguments[i+1]);
|
| 712 |
+
}
|
| 713 |
+
|
| 714 |
+
function copyObj(obj, target) {
|
| 715 |
+
if (!target) target = {};
|
| 716 |
+
for (var prop in obj) if (obj.hasOwnProperty(prop)) target[prop] = obj[prop];
|
| 717 |
+
return target;
|
| 718 |
+
}
|
| 719 |
+
|
| 720 |
+
function moveOver(pos, str, copy, other) {
|
| 721 |
+
var out = copy ? Pos(pos.line, pos.ch) : pos, at = 0;
|
| 722 |
+
for (;;) {
|
| 723 |
+
var nl = str.indexOf("\n", at);
|
| 724 |
+
if (nl == -1) break;
|
| 725 |
+
++out.line;
|
| 726 |
+
if (other) ++other.line;
|
| 727 |
+
at = nl + 1;
|
| 728 |
+
}
|
| 729 |
+
out.ch = (at ? 0 : out.ch) + (str.length - at);
|
| 730 |
+
if (other) other.ch = (at ? 0 : other.ch) + (str.length - at);
|
| 731 |
+
return out;
|
| 732 |
+
}
|
| 733 |
+
|
| 734 |
+
function posMin(a, b) { return (a.line - b.line || a.ch - b.ch) < 0 ? a : b; }
|
| 735 |
+
function posMax(a, b) { return (a.line - b.line || a.ch - b.ch) > 0 ? a : b; }
|
| 736 |
+
function posEq(a, b) { return a.line == b.line && a.ch == b.ch; }
|
| 737 |
+
|
| 738 |
+
function findPrevDiff(chunks, start, isOrig) {
|
| 739 |
+
for (var i = chunks.length - 1; i >= 0; i--) {
|
| 740 |
+
var chunk = chunks[i];
|
| 741 |
+
var to = (isOrig ? chunk.origTo : chunk.editTo) - 1;
|
| 742 |
+
if (to < start) return to;
|
| 743 |
+
}
|
| 744 |
+
}
|
| 745 |
+
|
| 746 |
+
function findNextDiff(chunks, start, isOrig) {
|
| 747 |
+
for (var i = 0; i < chunks.length; i++) {
|
| 748 |
+
var chunk = chunks[i];
|
| 749 |
+
var from = (isOrig ? chunk.origFrom : chunk.editFrom);
|
| 750 |
+
if (from > start) return from;
|
| 751 |
+
}
|
| 752 |
+
}
|
| 753 |
+
|
| 754 |
+
function goNearbyDiff(cm, dir) {
|
| 755 |
+
var found = null, views = cm.state.diffViews, line = cm.getCursor().line;
|
| 756 |
+
if (views) for (var i = 0; i < views.length; i++) {
|
| 757 |
+
var dv = views[i], isOrig = cm == dv.orig;
|
| 758 |
+
ensureDiff(dv);
|
| 759 |
+
var pos = dir < 0 ? findPrevDiff(dv.chunks, line, isOrig) : findNextDiff(dv.chunks, line, isOrig);
|
| 760 |
+
if (pos != null && (found == null || (dir < 0 ? pos > found : pos < found)))
|
| 761 |
+
found = pos;
|
| 762 |
+
}
|
| 763 |
+
if (found != null)
|
| 764 |
+
cm.setCursor(found, 0);
|
| 765 |
+
else
|
| 766 |
+
return CodeMirror.Pass;
|
| 767 |
+
}
|
| 768 |
+
|
| 769 |
+
CodeMirror.commands.goNextDiff = function(cm) {
|
| 770 |
+
return goNearbyDiff(cm, 1);
|
| 771 |
+
};
|
| 772 |
+
CodeMirror.commands.goPrevDiff = function(cm) {
|
| 773 |
+
return goNearbyDiff(cm, -1);
|
| 774 |
+
};
|
| 775 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/mode/loadmode.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"), "cjs");
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror"], function(CM) { mod(CM, "amd"); });
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror, "plain");
|
| 11 |
+
})(function(CodeMirror, env) {
|
| 12 |
+
if (!CodeMirror.modeURL) CodeMirror.modeURL = "../mode/%N/%N.js";
|
| 13 |
+
|
| 14 |
+
var loading = {};
|
| 15 |
+
function splitCallback(cont, n) {
|
| 16 |
+
var countDown = n;
|
| 17 |
+
return function() { if (--countDown == 0) cont(); };
|
| 18 |
+
}
|
| 19 |
+
function ensureDeps(mode, cont) {
|
| 20 |
+
var deps = CodeMirror.modes[mode].dependencies;
|
| 21 |
+
if (!deps) return cont();
|
| 22 |
+
var missing = [];
|
| 23 |
+
for (var i = 0; i < deps.length; ++i) {
|
| 24 |
+
if (!CodeMirror.modes.hasOwnProperty(deps[i]))
|
| 25 |
+
missing.push(deps[i]);
|
| 26 |
+
}
|
| 27 |
+
if (!missing.length) return cont();
|
| 28 |
+
var split = splitCallback(cont, missing.length);
|
| 29 |
+
for (var i = 0; i < missing.length; ++i)
|
| 30 |
+
CodeMirror.requireMode(missing[i], split);
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
CodeMirror.requireMode = function(mode, cont) {
|
| 34 |
+
if (typeof mode != "string") mode = mode.name;
|
| 35 |
+
if (CodeMirror.modes.hasOwnProperty(mode)) return ensureDeps(mode, cont);
|
| 36 |
+
if (loading.hasOwnProperty(mode)) return loading[mode].push(cont);
|
| 37 |
+
|
| 38 |
+
var file = CodeMirror.modeURL.replace(/%N/g, mode);
|
| 39 |
+
if (env == "plain") {
|
| 40 |
+
var script = document.createElement("script");
|
| 41 |
+
script.src = file;
|
| 42 |
+
var others = document.getElementsByTagName("script")[0];
|
| 43 |
+
var list = loading[mode] = [cont];
|
| 44 |
+
CodeMirror.on(script, "load", function() {
|
| 45 |
+
ensureDeps(mode, function() {
|
| 46 |
+
for (var i = 0; i < list.length; ++i) list[i]();
|
| 47 |
+
});
|
| 48 |
+
});
|
| 49 |
+
others.parentNode.insertBefore(script, others);
|
| 50 |
+
} else if (env == "cjs") {
|
| 51 |
+
require(file);
|
| 52 |
+
cont();
|
| 53 |
+
} else if (env == "amd") {
|
| 54 |
+
requirejs([file], cont);
|
| 55 |
+
}
|
| 56 |
+
};
|
| 57 |
+
|
| 58 |
+
CodeMirror.autoLoadMode = function(instance, mode) {
|
| 59 |
+
if (!CodeMirror.modes.hasOwnProperty(mode))
|
| 60 |
+
CodeMirror.requireMode(mode, function() {
|
| 61 |
+
instance.setOption("mode", instance.getOption("mode"));
|
| 62 |
+
});
|
| 63 |
+
};
|
| 64 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/mode/multiplex.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
"use strict";
|
| 13 |
+
|
| 14 |
+
CodeMirror.multiplexingMode = function(outer /*, others */) {
|
| 15 |
+
// Others should be {open, close, mode [, delimStyle] [, innerStyle]} objects
|
| 16 |
+
var others = Array.prototype.slice.call(arguments, 1);
|
| 17 |
+
|
| 18 |
+
function indexOf(string, pattern, from, returnEnd) {
|
| 19 |
+
if (typeof pattern == "string") {
|
| 20 |
+
var found = string.indexOf(pattern, from);
|
| 21 |
+
return returnEnd && found > -1 ? found + pattern.length : found;
|
| 22 |
+
}
|
| 23 |
+
var m = pattern.exec(from ? string.slice(from) : string);
|
| 24 |
+
return m ? m.index + from + (returnEnd ? m[0].length : 0) : -1;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
return {
|
| 28 |
+
startState: function() {
|
| 29 |
+
return {
|
| 30 |
+
outer: CodeMirror.startState(outer),
|
| 31 |
+
innerActive: null,
|
| 32 |
+
inner: null
|
| 33 |
+
};
|
| 34 |
+
},
|
| 35 |
+
|
| 36 |
+
copyState: function(state) {
|
| 37 |
+
return {
|
| 38 |
+
outer: CodeMirror.copyState(outer, state.outer),
|
| 39 |
+
innerActive: state.innerActive,
|
| 40 |
+
inner: state.innerActive && CodeMirror.copyState(state.innerActive.mode, state.inner)
|
| 41 |
+
};
|
| 42 |
+
},
|
| 43 |
+
|
| 44 |
+
token: function(stream, state) {
|
| 45 |
+
if (!state.innerActive) {
|
| 46 |
+
var cutOff = Infinity, oldContent = stream.string;
|
| 47 |
+
for (var i = 0; i < others.length; ++i) {
|
| 48 |
+
var other = others[i];
|
| 49 |
+
var found = indexOf(oldContent, other.open, stream.pos);
|
| 50 |
+
if (found == stream.pos) {
|
| 51 |
+
if (!other.parseDelimiters) stream.match(other.open);
|
| 52 |
+
state.innerActive = other;
|
| 53 |
+
state.inner = CodeMirror.startState(other.mode, outer.indent ? outer.indent(state.outer, "") : 0);
|
| 54 |
+
return other.delimStyle;
|
| 55 |
+
} else if (found != -1 && found < cutOff) {
|
| 56 |
+
cutOff = found;
|
| 57 |
+
}
|
| 58 |
+
}
|
| 59 |
+
if (cutOff != Infinity) stream.string = oldContent.slice(0, cutOff);
|
| 60 |
+
var outerToken = outer.token(stream, state.outer);
|
| 61 |
+
if (cutOff != Infinity) stream.string = oldContent;
|
| 62 |
+
return outerToken;
|
| 63 |
+
} else {
|
| 64 |
+
var curInner = state.innerActive, oldContent = stream.string;
|
| 65 |
+
if (!curInner.close && stream.sol()) {
|
| 66 |
+
state.innerActive = state.inner = null;
|
| 67 |
+
return this.token(stream, state);
|
| 68 |
+
}
|
| 69 |
+
var found = curInner.close ? indexOf(oldContent, curInner.close, stream.pos, curInner.parseDelimiters) : -1;
|
| 70 |
+
if (found == stream.pos && !curInner.parseDelimiters) {
|
| 71 |
+
stream.match(curInner.close);
|
| 72 |
+
state.innerActive = state.inner = null;
|
| 73 |
+
return curInner.delimStyle;
|
| 74 |
+
}
|
| 75 |
+
if (found > -1) stream.string = oldContent.slice(0, found);
|
| 76 |
+
var innerToken = curInner.mode.token(stream, state.inner);
|
| 77 |
+
if (found > -1) stream.string = oldContent;
|
| 78 |
+
|
| 79 |
+
if (found == stream.pos && curInner.parseDelimiters)
|
| 80 |
+
state.innerActive = state.inner = null;
|
| 81 |
+
|
| 82 |
+
if (curInner.innerStyle) {
|
| 83 |
+
if (innerToken) innerToken = innerToken + ' ' + curInner.innerStyle;
|
| 84 |
+
else innerToken = curInner.innerStyle;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
return innerToken;
|
| 88 |
+
}
|
| 89 |
+
},
|
| 90 |
+
|
| 91 |
+
indent: function(state, textAfter) {
|
| 92 |
+
var mode = state.innerActive ? state.innerActive.mode : outer;
|
| 93 |
+
if (!mode.indent) return CodeMirror.Pass;
|
| 94 |
+
return mode.indent(state.innerActive ? state.inner : state.outer, textAfter);
|
| 95 |
+
},
|
| 96 |
+
|
| 97 |
+
blankLine: function(state) {
|
| 98 |
+
var mode = state.innerActive ? state.innerActive.mode : outer;
|
| 99 |
+
if (mode.blankLine) {
|
| 100 |
+
mode.blankLine(state.innerActive ? state.inner : state.outer);
|
| 101 |
+
}
|
| 102 |
+
if (!state.innerActive) {
|
| 103 |
+
for (var i = 0; i < others.length; ++i) {
|
| 104 |
+
var other = others[i];
|
| 105 |
+
if (other.open === "\n") {
|
| 106 |
+
state.innerActive = other;
|
| 107 |
+
state.inner = CodeMirror.startState(other.mode, mode.indent ? mode.indent(state.outer, "") : 0);
|
| 108 |
+
}
|
| 109 |
+
}
|
| 110 |
+
} else if (state.innerActive.close === "\n") {
|
| 111 |
+
state.innerActive = state.inner = null;
|
| 112 |
+
}
|
| 113 |
+
},
|
| 114 |
+
|
| 115 |
+
electricChars: outer.electricChars,
|
| 116 |
+
|
| 117 |
+
innerMode: function(state) {
|
| 118 |
+
return state.inner ? {state: state.inner, mode: state.innerActive.mode} : {state: state.outer, mode: outer};
|
| 119 |
+
}
|
| 120 |
+
};
|
| 121 |
+
};
|
| 122 |
+
|
| 123 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/mode/multiplex_test.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function() {
|
| 5 |
+
CodeMirror.defineMode("markdown_with_stex", function(){
|
| 6 |
+
var inner = CodeMirror.getMode({}, "stex");
|
| 7 |
+
var outer = CodeMirror.getMode({}, "markdown");
|
| 8 |
+
|
| 9 |
+
var innerOptions = {
|
| 10 |
+
open: '$',
|
| 11 |
+
close: '$',
|
| 12 |
+
mode: inner,
|
| 13 |
+
delimStyle: 'delim',
|
| 14 |
+
innerStyle: 'inner'
|
| 15 |
+
};
|
| 16 |
+
|
| 17 |
+
return CodeMirror.multiplexingMode(outer, innerOptions);
|
| 18 |
+
});
|
| 19 |
+
|
| 20 |
+
var mode = CodeMirror.getMode({}, "markdown_with_stex");
|
| 21 |
+
|
| 22 |
+
function MT(name) {
|
| 23 |
+
test.mode(
|
| 24 |
+
name,
|
| 25 |
+
mode,
|
| 26 |
+
Array.prototype.slice.call(arguments, 1),
|
| 27 |
+
'multiplexing');
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
MT(
|
| 31 |
+
"stexInsideMarkdown",
|
| 32 |
+
"[strong **Equation:**] [delim $][inner&tag \\pi][delim $]");
|
| 33 |
+
})();
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/mode/overlay.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
// Utility function that allows modes to be combined. The mode given
|
| 5 |
+
// as the base argument takes care of most of the normal mode
|
| 6 |
+
// functionality, but a second (typically simple) mode is used, which
|
| 7 |
+
// can override the style of text. Both modes get to parse all of the
|
| 8 |
+
// text, but when both assign a non-null style to a piece of code, the
|
| 9 |
+
// overlay wins, unless the combine argument was true and not overridden,
|
| 10 |
+
// or state.overlay.combineTokens was true, in which case the styles are
|
| 11 |
+
// combined.
|
| 12 |
+
|
| 13 |
+
(function(mod) {
|
| 14 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 15 |
+
mod(require("../../lib/codemirror"));
|
| 16 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 17 |
+
define(["../../lib/codemirror"], mod);
|
| 18 |
+
else // Plain browser env
|
| 19 |
+
mod(CodeMirror);
|
| 20 |
+
})(function(CodeMirror) {
|
| 21 |
+
"use strict";
|
| 22 |
+
|
| 23 |
+
CodeMirror.overlayMode = function(base, overlay, combine) {
|
| 24 |
+
return {
|
| 25 |
+
startState: function() {
|
| 26 |
+
return {
|
| 27 |
+
base: CodeMirror.startState(base),
|
| 28 |
+
overlay: CodeMirror.startState(overlay),
|
| 29 |
+
basePos: 0, baseCur: null,
|
| 30 |
+
overlayPos: 0, overlayCur: null,
|
| 31 |
+
streamSeen: null
|
| 32 |
+
};
|
| 33 |
+
},
|
| 34 |
+
copyState: function(state) {
|
| 35 |
+
return {
|
| 36 |
+
base: CodeMirror.copyState(base, state.base),
|
| 37 |
+
overlay: CodeMirror.copyState(overlay, state.overlay),
|
| 38 |
+
basePos: state.basePos, baseCur: null,
|
| 39 |
+
overlayPos: state.overlayPos, overlayCur: null
|
| 40 |
+
};
|
| 41 |
+
},
|
| 42 |
+
|
| 43 |
+
token: function(stream, state) {
|
| 44 |
+
if (stream != state.streamSeen ||
|
| 45 |
+
Math.min(state.basePos, state.overlayPos) < stream.start) {
|
| 46 |
+
state.streamSeen = stream;
|
| 47 |
+
state.basePos = state.overlayPos = stream.start;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
if (stream.start == state.basePos) {
|
| 51 |
+
state.baseCur = base.token(stream, state.base);
|
| 52 |
+
state.basePos = stream.pos;
|
| 53 |
+
}
|
| 54 |
+
if (stream.start == state.overlayPos) {
|
| 55 |
+
stream.pos = stream.start;
|
| 56 |
+
state.overlayCur = overlay.token(stream, state.overlay);
|
| 57 |
+
state.overlayPos = stream.pos;
|
| 58 |
+
}
|
| 59 |
+
stream.pos = Math.min(state.basePos, state.overlayPos);
|
| 60 |
+
|
| 61 |
+
// state.overlay.combineTokens always takes precedence over combine,
|
| 62 |
+
// unless set to null
|
| 63 |
+
if (state.overlayCur == null) return state.baseCur;
|
| 64 |
+
else if (state.baseCur != null &&
|
| 65 |
+
state.overlay.combineTokens ||
|
| 66 |
+
combine && state.overlay.combineTokens == null)
|
| 67 |
+
return state.baseCur + " " + state.overlayCur;
|
| 68 |
+
else return state.overlayCur;
|
| 69 |
+
},
|
| 70 |
+
|
| 71 |
+
indent: base.indent && function(state, textAfter) {
|
| 72 |
+
return base.indent(state.base, textAfter);
|
| 73 |
+
},
|
| 74 |
+
electricChars: base.electricChars,
|
| 75 |
+
|
| 76 |
+
innerMode: function(state) { return {state: state.base, mode: base}; },
|
| 77 |
+
|
| 78 |
+
blankLine: function(state) {
|
| 79 |
+
if (base.blankLine) base.blankLine(state.base);
|
| 80 |
+
if (overlay.blankLine) overlay.blankLine(state.overlay);
|
| 81 |
+
}
|
| 82 |
+
};
|
| 83 |
+
};
|
| 84 |
+
|
| 85 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/mode/simple.js
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
"use strict";
|
| 13 |
+
|
| 14 |
+
CodeMirror.defineSimpleMode = function(name, states) {
|
| 15 |
+
CodeMirror.defineMode(name, function(config) {
|
| 16 |
+
return CodeMirror.simpleMode(config, states);
|
| 17 |
+
});
|
| 18 |
+
};
|
| 19 |
+
|
| 20 |
+
CodeMirror.simpleMode = function(config, states) {
|
| 21 |
+
ensureState(states, "start");
|
| 22 |
+
var states_ = {}, meta = states.meta || {}, hasIndentation = false;
|
| 23 |
+
for (var state in states) if (state != meta && states.hasOwnProperty(state)) {
|
| 24 |
+
var list = states_[state] = [], orig = states[state];
|
| 25 |
+
for (var i = 0; i < orig.length; i++) {
|
| 26 |
+
var data = orig[i];
|
| 27 |
+
list.push(new Rule(data, states));
|
| 28 |
+
if (data.indent || data.dedent) hasIndentation = true;
|
| 29 |
+
}
|
| 30 |
+
}
|
| 31 |
+
var mode = {
|
| 32 |
+
startState: function() {
|
| 33 |
+
return {state: "start", pending: null,
|
| 34 |
+
local: null, localState: null,
|
| 35 |
+
indent: hasIndentation ? [] : null};
|
| 36 |
+
},
|
| 37 |
+
copyState: function(state) {
|
| 38 |
+
var s = {state: state.state, pending: state.pending,
|
| 39 |
+
local: state.local, localState: null,
|
| 40 |
+
indent: state.indent && state.indent.slice(0)};
|
| 41 |
+
if (state.localState)
|
| 42 |
+
s.localState = CodeMirror.copyState(state.local.mode, state.localState);
|
| 43 |
+
if (state.stack)
|
| 44 |
+
s.stack = state.stack.slice(0);
|
| 45 |
+
for (var pers = state.persistentStates; pers; pers = pers.next)
|
| 46 |
+
s.persistentStates = {mode: pers.mode,
|
| 47 |
+
spec: pers.spec,
|
| 48 |
+
state: pers.state == state.localState ? s.localState : CodeMirror.copyState(pers.mode, pers.state),
|
| 49 |
+
next: s.persistentStates};
|
| 50 |
+
return s;
|
| 51 |
+
},
|
| 52 |
+
token: tokenFunction(states_, config),
|
| 53 |
+
innerMode: function(state) { return state.local && {mode: state.local.mode, state: state.localState}; },
|
| 54 |
+
indent: indentFunction(states_, meta)
|
| 55 |
+
};
|
| 56 |
+
if (meta) for (var prop in meta) if (meta.hasOwnProperty(prop))
|
| 57 |
+
mode[prop] = meta[prop];
|
| 58 |
+
return mode;
|
| 59 |
+
};
|
| 60 |
+
|
| 61 |
+
function ensureState(states, name) {
|
| 62 |
+
if (!states.hasOwnProperty(name))
|
| 63 |
+
throw new Error("Undefined state " + name + "in simple mode");
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
function toRegex(val, caret) {
|
| 67 |
+
if (!val) return /(?:)/;
|
| 68 |
+
var flags = "";
|
| 69 |
+
if (val instanceof RegExp) {
|
| 70 |
+
if (val.ignoreCase) flags = "i";
|
| 71 |
+
val = val.source;
|
| 72 |
+
} else {
|
| 73 |
+
val = String(val);
|
| 74 |
+
}
|
| 75 |
+
return new RegExp((caret === false ? "" : "^") + "(?:" + val + ")", flags);
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
function asToken(val) {
|
| 79 |
+
if (!val) return null;
|
| 80 |
+
if (typeof val == "string") return val.replace(/\./g, " ");
|
| 81 |
+
var result = [];
|
| 82 |
+
for (var i = 0; i < val.length; i++)
|
| 83 |
+
result.push(val[i] && val[i].replace(/\./g, " "));
|
| 84 |
+
return result;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
function Rule(data, states) {
|
| 88 |
+
if (data.next || data.push) ensureState(states, data.next || data.push);
|
| 89 |
+
this.regex = toRegex(data.regex);
|
| 90 |
+
this.token = asToken(data.token);
|
| 91 |
+
this.data = data;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
function tokenFunction(states, config) {
|
| 95 |
+
return function(stream, state) {
|
| 96 |
+
if (state.pending) {
|
| 97 |
+
var pend = state.pending.shift();
|
| 98 |
+
if (state.pending.length == 0) state.pending = null;
|
| 99 |
+
stream.pos += pend.text.length;
|
| 100 |
+
return pend.token;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
if (state.local) {
|
| 104 |
+
if (state.local.end && stream.match(state.local.end)) {
|
| 105 |
+
var tok = state.local.endToken || null;
|
| 106 |
+
state.local = state.localState = null;
|
| 107 |
+
return tok;
|
| 108 |
+
} else {
|
| 109 |
+
var tok = state.local.mode.token(stream, state.localState), m;
|
| 110 |
+
if (state.local.endScan && (m = state.local.endScan.exec(stream.current())))
|
| 111 |
+
stream.pos = stream.start + m.index;
|
| 112 |
+
return tok;
|
| 113 |
+
}
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
var curState = states[state.state];
|
| 117 |
+
for (var i = 0; i < curState.length; i++) {
|
| 118 |
+
var rule = curState[i];
|
| 119 |
+
var matches = (!rule.data.sol || stream.sol()) && stream.match(rule.regex);
|
| 120 |
+
if (matches) {
|
| 121 |
+
if (rule.data.next) {
|
| 122 |
+
state.state = rule.data.next;
|
| 123 |
+
} else if (rule.data.push) {
|
| 124 |
+
(state.stack || (state.stack = [])).push(state.state);
|
| 125 |
+
state.state = rule.data.push;
|
| 126 |
+
} else if (rule.data.pop && state.stack && state.stack.length) {
|
| 127 |
+
state.state = state.stack.pop();
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
if (rule.data.mode)
|
| 131 |
+
enterLocalMode(config, state, rule.data.mode, rule.token);
|
| 132 |
+
if (rule.data.indent)
|
| 133 |
+
state.indent.push(stream.indentation() + config.indentUnit);
|
| 134 |
+
if (rule.data.dedent)
|
| 135 |
+
state.indent.pop();
|
| 136 |
+
if (matches.length > 2) {
|
| 137 |
+
state.pending = [];
|
| 138 |
+
for (var j = 2; j < matches.length; j++)
|
| 139 |
+
if (matches[j])
|
| 140 |
+
state.pending.push({text: matches[j], token: rule.token[j - 1]});
|
| 141 |
+
stream.backUp(matches[0].length - (matches[1] ? matches[1].length : 0));
|
| 142 |
+
return rule.token[0];
|
| 143 |
+
} else if (rule.token && rule.token.join) {
|
| 144 |
+
return rule.token[0];
|
| 145 |
+
} else {
|
| 146 |
+
return rule.token;
|
| 147 |
+
}
|
| 148 |
+
}
|
| 149 |
+
}
|
| 150 |
+
stream.next();
|
| 151 |
+
return null;
|
| 152 |
+
};
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
function cmp(a, b) {
|
| 156 |
+
if (a === b) return true;
|
| 157 |
+
if (!a || typeof a != "object" || !b || typeof b != "object") return false;
|
| 158 |
+
var props = 0;
|
| 159 |
+
for (var prop in a) if (a.hasOwnProperty(prop)) {
|
| 160 |
+
if (!b.hasOwnProperty(prop) || !cmp(a[prop], b[prop])) return false;
|
| 161 |
+
props++;
|
| 162 |
+
}
|
| 163 |
+
for (var prop in b) if (b.hasOwnProperty(prop)) props--;
|
| 164 |
+
return props == 0;
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
function enterLocalMode(config, state, spec, token) {
|
| 168 |
+
var pers;
|
| 169 |
+
if (spec.persistent) for (var p = state.persistentStates; p && !pers; p = p.next)
|
| 170 |
+
if (spec.spec ? cmp(spec.spec, p.spec) : spec.mode == p.mode) pers = p;
|
| 171 |
+
var mode = pers ? pers.mode : spec.mode || CodeMirror.getMode(config, spec.spec);
|
| 172 |
+
var lState = pers ? pers.state : CodeMirror.startState(mode);
|
| 173 |
+
if (spec.persistent && !pers)
|
| 174 |
+
state.persistentStates = {mode: mode, spec: spec.spec, state: lState, next: state.persistentStates};
|
| 175 |
+
|
| 176 |
+
state.localState = lState;
|
| 177 |
+
state.local = {mode: mode,
|
| 178 |
+
end: spec.end && toRegex(spec.end),
|
| 179 |
+
endScan: spec.end && spec.forceEnd !== false && toRegex(spec.end, false),
|
| 180 |
+
endToken: token && token.join ? token[token.length - 1] : token};
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
function indexOf(val, arr) {
|
| 184 |
+
for (var i = 0; i < arr.length; i++) if (arr[i] === val) return true;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
function indentFunction(states, meta) {
|
| 188 |
+
return function(state, textAfter, line) {
|
| 189 |
+
if (state.local && state.local.mode.indent)
|
| 190 |
+
return state.local.mode.indent(state.localState, textAfter, line);
|
| 191 |
+
if (state.indent == null || state.local || meta.dontIndentStates && indexOf(state.state, meta.dontIndentStates) > -1)
|
| 192 |
+
return CodeMirror.Pass;
|
| 193 |
+
|
| 194 |
+
var pos = state.indent.length - 1, rules = states[state.state];
|
| 195 |
+
scan: for (;;) {
|
| 196 |
+
for (var i = 0; i < rules.length; i++) {
|
| 197 |
+
var rule = rules[i];
|
| 198 |
+
if (rule.data.dedent && rule.data.dedentIfLineStart !== false) {
|
| 199 |
+
var m = rule.regex.exec(textAfter);
|
| 200 |
+
if (m && m[0]) {
|
| 201 |
+
pos--;
|
| 202 |
+
if (rule.next || rule.push) rules = states[rule.next || rule.push];
|
| 203 |
+
textAfter = textAfter.slice(m[0].length);
|
| 204 |
+
continue scan;
|
| 205 |
+
}
|
| 206 |
+
}
|
| 207 |
+
}
|
| 208 |
+
break;
|
| 209 |
+
}
|
| 210 |
+
return pos < 0 ? 0 : state.indent[pos];
|
| 211 |
+
};
|
| 212 |
+
}
|
| 213 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/runmode/colorize.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"), require("./runmode"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror", "./runmode"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
"use strict";
|
| 13 |
+
|
| 14 |
+
var isBlock = /^(p|li|div|h\\d|pre|blockquote|td)$/;
|
| 15 |
+
|
| 16 |
+
function textContent(node, out) {
|
| 17 |
+
if (node.nodeType == 3) return out.push(node.nodeValue);
|
| 18 |
+
for (var ch = node.firstChild; ch; ch = ch.nextSibling) {
|
| 19 |
+
textContent(ch, out);
|
| 20 |
+
if (isBlock.test(node.nodeType)) out.push("\n");
|
| 21 |
+
}
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
CodeMirror.colorize = function(collection, defaultMode) {
|
| 25 |
+
if (!collection) collection = document.body.getElementsByTagName("pre");
|
| 26 |
+
|
| 27 |
+
for (var i = 0; i < collection.length; ++i) {
|
| 28 |
+
var node = collection[i];
|
| 29 |
+
var mode = node.getAttribute("data-lang") || defaultMode;
|
| 30 |
+
if (!mode) continue;
|
| 31 |
+
|
| 32 |
+
var text = [];
|
| 33 |
+
textContent(node, text);
|
| 34 |
+
node.innerHTML = "";
|
| 35 |
+
CodeMirror.runMode(text.join(""), mode, node);
|
| 36 |
+
|
| 37 |
+
node.className += " cm-s-default";
|
| 38 |
+
}
|
| 39 |
+
};
|
| 40 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/runmode/runmode-standalone.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
window.CodeMirror = {};
|
| 5 |
+
|
| 6 |
+
(function() {
|
| 7 |
+
"use strict";
|
| 8 |
+
|
| 9 |
+
function splitLines(string){ return string.split(/\r?\n|\r/); };
|
| 10 |
+
|
| 11 |
+
function StringStream(string) {
|
| 12 |
+
this.pos = this.start = 0;
|
| 13 |
+
this.string = string;
|
| 14 |
+
this.lineStart = 0;
|
| 15 |
+
}
|
| 16 |
+
StringStream.prototype = {
|
| 17 |
+
eol: function() {return this.pos >= this.string.length;},
|
| 18 |
+
sol: function() {return this.pos == 0;},
|
| 19 |
+
peek: function() {return this.string.charAt(this.pos) || null;},
|
| 20 |
+
next: function() {
|
| 21 |
+
if (this.pos < this.string.length)
|
| 22 |
+
return this.string.charAt(this.pos++);
|
| 23 |
+
},
|
| 24 |
+
eat: function(match) {
|
| 25 |
+
var ch = this.string.charAt(this.pos);
|
| 26 |
+
if (typeof match == "string") var ok = ch == match;
|
| 27 |
+
else var ok = ch && (match.test ? match.test(ch) : match(ch));
|
| 28 |
+
if (ok) {++this.pos; return ch;}
|
| 29 |
+
},
|
| 30 |
+
eatWhile: function(match) {
|
| 31 |
+
var start = this.pos;
|
| 32 |
+
while (this.eat(match)){}
|
| 33 |
+
return this.pos > start;
|
| 34 |
+
},
|
| 35 |
+
eatSpace: function() {
|
| 36 |
+
var start = this.pos;
|
| 37 |
+
while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) ++this.pos;
|
| 38 |
+
return this.pos > start;
|
| 39 |
+
},
|
| 40 |
+
skipToEnd: function() {this.pos = this.string.length;},
|
| 41 |
+
skipTo: function(ch) {
|
| 42 |
+
var found = this.string.indexOf(ch, this.pos);
|
| 43 |
+
if (found > -1) {this.pos = found; return true;}
|
| 44 |
+
},
|
| 45 |
+
backUp: function(n) {this.pos -= n;},
|
| 46 |
+
column: function() {return this.start - this.lineStart;},
|
| 47 |
+
indentation: function() {return 0;},
|
| 48 |
+
match: function(pattern, consume, caseInsensitive) {
|
| 49 |
+
if (typeof pattern == "string") {
|
| 50 |
+
var cased = function(str) {return caseInsensitive ? str.toLowerCase() : str;};
|
| 51 |
+
var substr = this.string.substr(this.pos, pattern.length);
|
| 52 |
+
if (cased(substr) == cased(pattern)) {
|
| 53 |
+
if (consume !== false) this.pos += pattern.length;
|
| 54 |
+
return true;
|
| 55 |
+
}
|
| 56 |
+
} else {
|
| 57 |
+
var match = this.string.slice(this.pos).match(pattern);
|
| 58 |
+
if (match && match.index > 0) return null;
|
| 59 |
+
if (match && consume !== false) this.pos += match[0].length;
|
| 60 |
+
return match;
|
| 61 |
+
}
|
| 62 |
+
},
|
| 63 |
+
current: function(){return this.string.slice(this.start, this.pos);},
|
| 64 |
+
hideFirstChars: function(n, inner) {
|
| 65 |
+
this.lineStart += n;
|
| 66 |
+
try { return inner(); }
|
| 67 |
+
finally { this.lineStart -= n; }
|
| 68 |
+
}
|
| 69 |
+
};
|
| 70 |
+
CodeMirror.StringStream = StringStream;
|
| 71 |
+
|
| 72 |
+
CodeMirror.startState = function (mode, a1, a2) {
|
| 73 |
+
return mode.startState ? mode.startState(a1, a2) : true;
|
| 74 |
+
};
|
| 75 |
+
|
| 76 |
+
var modes = CodeMirror.modes = {}, mimeModes = CodeMirror.mimeModes = {};
|
| 77 |
+
CodeMirror.defineMode = function (name, mode) {
|
| 78 |
+
if (arguments.length > 2)
|
| 79 |
+
mode.dependencies = Array.prototype.slice.call(arguments, 2);
|
| 80 |
+
modes[name] = mode;
|
| 81 |
+
};
|
| 82 |
+
CodeMirror.defineMIME = function (mime, spec) { mimeModes[mime] = spec; };
|
| 83 |
+
CodeMirror.resolveMode = function(spec) {
|
| 84 |
+
if (typeof spec == "string" && mimeModes.hasOwnProperty(spec)) {
|
| 85 |
+
spec = mimeModes[spec];
|
| 86 |
+
} else if (spec && typeof spec.name == "string" && mimeModes.hasOwnProperty(spec.name)) {
|
| 87 |
+
spec = mimeModes[spec.name];
|
| 88 |
+
}
|
| 89 |
+
if (typeof spec == "string") return {name: spec};
|
| 90 |
+
else return spec || {name: "null"};
|
| 91 |
+
};
|
| 92 |
+
CodeMirror.getMode = function (options, spec) {
|
| 93 |
+
spec = CodeMirror.resolveMode(spec);
|
| 94 |
+
var mfactory = modes[spec.name];
|
| 95 |
+
if (!mfactory) throw new Error("Unknown mode: " + spec);
|
| 96 |
+
return mfactory(options, spec);
|
| 97 |
+
};
|
| 98 |
+
CodeMirror.registerHelper = CodeMirror.registerGlobalHelper = Math.min;
|
| 99 |
+
CodeMirror.defineMode("null", function() {
|
| 100 |
+
return {token: function(stream) {stream.skipToEnd();}};
|
| 101 |
+
});
|
| 102 |
+
CodeMirror.defineMIME("text/plain", "null");
|
| 103 |
+
|
| 104 |
+
CodeMirror.runMode = function (string, modespec, callback, options) {
|
| 105 |
+
var mode = CodeMirror.getMode({ indentUnit: 2 }, modespec);
|
| 106 |
+
|
| 107 |
+
if (callback.nodeType == 1) {
|
| 108 |
+
var tabSize = (options && options.tabSize) || 4;
|
| 109 |
+
var node = callback, col = 0;
|
| 110 |
+
node.innerHTML = "";
|
| 111 |
+
callback = function (text, style) {
|
| 112 |
+
if (text == "\n") {
|
| 113 |
+
node.appendChild(document.createElement("br"));
|
| 114 |
+
col = 0;
|
| 115 |
+
return;
|
| 116 |
+
}
|
| 117 |
+
var content = "";
|
| 118 |
+
// replace tabs
|
| 119 |
+
for (var pos = 0; ;) {
|
| 120 |
+
var idx = text.indexOf("\t", pos);
|
| 121 |
+
if (idx == -1) {
|
| 122 |
+
content += text.slice(pos);
|
| 123 |
+
col += text.length - pos;
|
| 124 |
+
break;
|
| 125 |
+
} else {
|
| 126 |
+
col += idx - pos;
|
| 127 |
+
content += text.slice(pos, idx);
|
| 128 |
+
var size = tabSize - col % tabSize;
|
| 129 |
+
col += size;
|
| 130 |
+
for (var i = 0; i < size; ++i) content += " ";
|
| 131 |
+
pos = idx + 1;
|
| 132 |
+
}
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
if (style) {
|
| 136 |
+
var sp = node.appendChild(document.createElement("span"));
|
| 137 |
+
sp.className = "cm-" + style.replace(/ +/g, " cm-");
|
| 138 |
+
sp.appendChild(document.createTextNode(content));
|
| 139 |
+
} else {
|
| 140 |
+
node.appendChild(document.createTextNode(content));
|
| 141 |
+
}
|
| 142 |
+
};
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
var lines = splitLines(string), state = (options && options.state) || CodeMirror.startState(mode);
|
| 146 |
+
for (var i = 0, e = lines.length; i < e; ++i) {
|
| 147 |
+
if (i) callback("\n");
|
| 148 |
+
var stream = new CodeMirror.StringStream(lines[i]);
|
| 149 |
+
if (!stream.string && mode.blankLine) mode.blankLine(state);
|
| 150 |
+
while (!stream.eol()) {
|
| 151 |
+
var style = mode.token(stream, state);
|
| 152 |
+
callback(stream.current(), style, i, stream.start, state);
|
| 153 |
+
stream.start = stream.pos;
|
| 154 |
+
}
|
| 155 |
+
}
|
| 156 |
+
};
|
| 157 |
+
})();
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/runmode/runmode.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
"use strict";
|
| 13 |
+
|
| 14 |
+
CodeMirror.runMode = function(string, modespec, callback, options) {
|
| 15 |
+
var mode = CodeMirror.getMode(CodeMirror.defaults, modespec);
|
| 16 |
+
var ie = /MSIE \d/.test(navigator.userAgent);
|
| 17 |
+
var ie_lt9 = ie && (document.documentMode == null || document.documentMode < 9);
|
| 18 |
+
|
| 19 |
+
if (callback.nodeType == 1) {
|
| 20 |
+
var tabSize = (options && options.tabSize) || CodeMirror.defaults.tabSize;
|
| 21 |
+
var node = callback, col = 0;
|
| 22 |
+
node.innerHTML = "";
|
| 23 |
+
callback = function(text, style) {
|
| 24 |
+
if (text == "\n") {
|
| 25 |
+
// Emitting LF or CRLF on IE8 or earlier results in an incorrect display.
|
| 26 |
+
// Emitting a carriage return makes everything ok.
|
| 27 |
+
node.appendChild(document.createTextNode(ie_lt9 ? '\r' : text));
|
| 28 |
+
col = 0;
|
| 29 |
+
return;
|
| 30 |
+
}
|
| 31 |
+
var content = "";
|
| 32 |
+
// replace tabs
|
| 33 |
+
for (var pos = 0;;) {
|
| 34 |
+
var idx = text.indexOf("\t", pos);
|
| 35 |
+
if (idx == -1) {
|
| 36 |
+
content += text.slice(pos);
|
| 37 |
+
col += text.length - pos;
|
| 38 |
+
break;
|
| 39 |
+
} else {
|
| 40 |
+
col += idx - pos;
|
| 41 |
+
content += text.slice(pos, idx);
|
| 42 |
+
var size = tabSize - col % tabSize;
|
| 43 |
+
col += size;
|
| 44 |
+
for (var i = 0; i < size; ++i) content += " ";
|
| 45 |
+
pos = idx + 1;
|
| 46 |
+
}
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
if (style) {
|
| 50 |
+
var sp = node.appendChild(document.createElement("span"));
|
| 51 |
+
sp.className = "cm-" + style.replace(/ +/g, " cm-");
|
| 52 |
+
sp.appendChild(document.createTextNode(content));
|
| 53 |
+
} else {
|
| 54 |
+
node.appendChild(document.createTextNode(content));
|
| 55 |
+
}
|
| 56 |
+
};
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
var lines = CodeMirror.splitLines(string), state = (options && options.state) || CodeMirror.startState(mode);
|
| 60 |
+
for (var i = 0, e = lines.length; i < e; ++i) {
|
| 61 |
+
if (i) callback("\n");
|
| 62 |
+
var stream = new CodeMirror.StringStream(lines[i]);
|
| 63 |
+
if (!stream.string && mode.blankLine) mode.blankLine(state);
|
| 64 |
+
while (!stream.eol()) {
|
| 65 |
+
var style = mode.token(stream, state);
|
| 66 |
+
callback(stream.current(), style, i, stream.start, state);
|
| 67 |
+
stream.start = stream.pos;
|
| 68 |
+
}
|
| 69 |
+
}
|
| 70 |
+
};
|
| 71 |
+
|
| 72 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/runmode/runmode.node.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
/* Just enough of CodeMirror to run runMode under node.js */
|
| 5 |
+
|
| 6 |
+
// declare global: StringStream
|
| 7 |
+
|
| 8 |
+
function splitLines(string){ return string.split(/\r?\n|\r/); };
|
| 9 |
+
|
| 10 |
+
function StringStream(string) {
|
| 11 |
+
this.pos = this.start = 0;
|
| 12 |
+
this.string = string;
|
| 13 |
+
this.lineStart = 0;
|
| 14 |
+
}
|
| 15 |
+
StringStream.prototype = {
|
| 16 |
+
eol: function() {return this.pos >= this.string.length;},
|
| 17 |
+
sol: function() {return this.pos == 0;},
|
| 18 |
+
peek: function() {return this.string.charAt(this.pos) || null;},
|
| 19 |
+
next: function() {
|
| 20 |
+
if (this.pos < this.string.length)
|
| 21 |
+
return this.string.charAt(this.pos++);
|
| 22 |
+
},
|
| 23 |
+
eat: function(match) {
|
| 24 |
+
var ch = this.string.charAt(this.pos);
|
| 25 |
+
if (typeof match == "string") var ok = ch == match;
|
| 26 |
+
else var ok = ch && (match.test ? match.test(ch) : match(ch));
|
| 27 |
+
if (ok) {++this.pos; return ch;}
|
| 28 |
+
},
|
| 29 |
+
eatWhile: function(match) {
|
| 30 |
+
var start = this.pos;
|
| 31 |
+
while (this.eat(match)){}
|
| 32 |
+
return this.pos > start;
|
| 33 |
+
},
|
| 34 |
+
eatSpace: function() {
|
| 35 |
+
var start = this.pos;
|
| 36 |
+
while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) ++this.pos;
|
| 37 |
+
return this.pos > start;
|
| 38 |
+
},
|
| 39 |
+
skipToEnd: function() {this.pos = this.string.length;},
|
| 40 |
+
skipTo: function(ch) {
|
| 41 |
+
var found = this.string.indexOf(ch, this.pos);
|
| 42 |
+
if (found > -1) {this.pos = found; return true;}
|
| 43 |
+
},
|
| 44 |
+
backUp: function(n) {this.pos -= n;},
|
| 45 |
+
column: function() {return this.start - this.lineStart;},
|
| 46 |
+
indentation: function() {return 0;},
|
| 47 |
+
match: function(pattern, consume, caseInsensitive) {
|
| 48 |
+
if (typeof pattern == "string") {
|
| 49 |
+
var cased = function(str) {return caseInsensitive ? str.toLowerCase() : str;};
|
| 50 |
+
var substr = this.string.substr(this.pos, pattern.length);
|
| 51 |
+
if (cased(substr) == cased(pattern)) {
|
| 52 |
+
if (consume !== false) this.pos += pattern.length;
|
| 53 |
+
return true;
|
| 54 |
+
}
|
| 55 |
+
} else {
|
| 56 |
+
var match = this.string.slice(this.pos).match(pattern);
|
| 57 |
+
if (match && match.index > 0) return null;
|
| 58 |
+
if (match && consume !== false) this.pos += match[0].length;
|
| 59 |
+
return match;
|
| 60 |
+
}
|
| 61 |
+
},
|
| 62 |
+
current: function(){return this.string.slice(this.start, this.pos);},
|
| 63 |
+
hideFirstChars: function(n, inner) {
|
| 64 |
+
this.lineStart += n;
|
| 65 |
+
try { return inner(); }
|
| 66 |
+
finally { this.lineStart -= n; }
|
| 67 |
+
}
|
| 68 |
+
};
|
| 69 |
+
exports.StringStream = StringStream;
|
| 70 |
+
|
| 71 |
+
exports.startState = function(mode, a1, a2) {
|
| 72 |
+
return mode.startState ? mode.startState(a1, a2) : true;
|
| 73 |
+
};
|
| 74 |
+
|
| 75 |
+
var modes = exports.modes = {}, mimeModes = exports.mimeModes = {};
|
| 76 |
+
exports.defineMode = function(name, mode) {
|
| 77 |
+
if (arguments.length > 2)
|
| 78 |
+
mode.dependencies = Array.prototype.slice.call(arguments, 2);
|
| 79 |
+
modes[name] = mode;
|
| 80 |
+
};
|
| 81 |
+
exports.defineMIME = function(mime, spec) { mimeModes[mime] = spec; };
|
| 82 |
+
|
| 83 |
+
exports.defineMode("null", function() {
|
| 84 |
+
return {token: function(stream) {stream.skipToEnd();}};
|
| 85 |
+
});
|
| 86 |
+
exports.defineMIME("text/plain", "null");
|
| 87 |
+
|
| 88 |
+
exports.resolveMode = function(spec) {
|
| 89 |
+
if (typeof spec == "string" && mimeModes.hasOwnProperty(spec)) {
|
| 90 |
+
spec = mimeModes[spec];
|
| 91 |
+
} else if (spec && typeof spec.name == "string" && mimeModes.hasOwnProperty(spec.name)) {
|
| 92 |
+
spec = mimeModes[spec.name];
|
| 93 |
+
}
|
| 94 |
+
if (typeof spec == "string") return {name: spec};
|
| 95 |
+
else return spec || {name: "null"};
|
| 96 |
+
};
|
| 97 |
+
exports.getMode = function(options, spec) {
|
| 98 |
+
spec = exports.resolveMode(spec);
|
| 99 |
+
var mfactory = modes[spec.name];
|
| 100 |
+
if (!mfactory) throw new Error("Unknown mode: " + spec);
|
| 101 |
+
return mfactory(options, spec);
|
| 102 |
+
};
|
| 103 |
+
exports.registerHelper = exports.registerGlobalHelper = Math.min;
|
| 104 |
+
|
| 105 |
+
exports.runMode = function(string, modespec, callback, options) {
|
| 106 |
+
var mode = exports.getMode({indentUnit: 2}, modespec);
|
| 107 |
+
var lines = splitLines(string), state = (options && options.state) || exports.startState(mode);
|
| 108 |
+
for (var i = 0, e = lines.length; i < e; ++i) {
|
| 109 |
+
if (i) callback("\n");
|
| 110 |
+
var stream = new exports.StringStream(lines[i]);
|
| 111 |
+
if (!stream.string && mode.blankLine) mode.blankLine(state);
|
| 112 |
+
while (!stream.eol()) {
|
| 113 |
+
var style = mode.token(stream, state);
|
| 114 |
+
callback(stream.current(), style, i, stream.start, state);
|
| 115 |
+
stream.start = stream.pos;
|
| 116 |
+
}
|
| 117 |
+
}
|
| 118 |
+
};
|
| 119 |
+
|
| 120 |
+
require.cache[require.resolve("../../lib/codemirror")] = require.cache[require.resolve("./runmode.node")];
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/scroll/annotatescrollbar.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
"use strict";
|
| 13 |
+
|
| 14 |
+
CodeMirror.defineExtension("annotateScrollbar", function(options) {
|
| 15 |
+
if (typeof options == "string") options = {className: options};
|
| 16 |
+
return new Annotation(this, options);
|
| 17 |
+
});
|
| 18 |
+
|
| 19 |
+
CodeMirror.defineOption("scrollButtonHeight", 0);
|
| 20 |
+
|
| 21 |
+
function Annotation(cm, options) {
|
| 22 |
+
this.cm = cm;
|
| 23 |
+
this.options = options;
|
| 24 |
+
this.buttonHeight = options.scrollButtonHeight || cm.getOption("scrollButtonHeight");
|
| 25 |
+
this.annotations = [];
|
| 26 |
+
this.doRedraw = this.doUpdate = null;
|
| 27 |
+
this.div = cm.getWrapperElement().appendChild(document.createElement("div"));
|
| 28 |
+
this.div.style.cssText = "position: absolute; right: 0; top: 0; z-index: 7; pointer-events: none";
|
| 29 |
+
this.computeScale();
|
| 30 |
+
|
| 31 |
+
function scheduleRedraw(delay) {
|
| 32 |
+
clearTimeout(self.doRedraw);
|
| 33 |
+
self.doRedraw = setTimeout(function() { self.redraw(); }, delay);
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
var self = this;
|
| 37 |
+
cm.on("refresh", this.resizeHandler = function() {
|
| 38 |
+
clearTimeout(self.doUpdate);
|
| 39 |
+
self.doUpdate = setTimeout(function() {
|
| 40 |
+
if (self.computeScale()) scheduleRedraw(20);
|
| 41 |
+
}, 100);
|
| 42 |
+
});
|
| 43 |
+
cm.on("markerAdded", this.resizeHandler);
|
| 44 |
+
cm.on("markerCleared", this.resizeHandler);
|
| 45 |
+
if (options.listenForChanges !== false)
|
| 46 |
+
cm.on("change", this.changeHandler = function() {
|
| 47 |
+
scheduleRedraw(250);
|
| 48 |
+
});
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
Annotation.prototype.computeScale = function() {
|
| 52 |
+
var cm = this.cm;
|
| 53 |
+
var hScale = (cm.getWrapperElement().clientHeight - cm.display.barHeight - this.buttonHeight * 2) /
|
| 54 |
+
cm.heightAtLine(cm.lastLine() + 1, "local");
|
| 55 |
+
if (hScale != this.hScale) {
|
| 56 |
+
this.hScale = hScale;
|
| 57 |
+
return true;
|
| 58 |
+
}
|
| 59 |
+
};
|
| 60 |
+
|
| 61 |
+
Annotation.prototype.update = function(annotations) {
|
| 62 |
+
this.annotations = annotations;
|
| 63 |
+
this.redraw();
|
| 64 |
+
};
|
| 65 |
+
|
| 66 |
+
Annotation.prototype.redraw = function(compute) {
|
| 67 |
+
if (compute !== false) this.computeScale();
|
| 68 |
+
var cm = this.cm, hScale = this.hScale;
|
| 69 |
+
|
| 70 |
+
var frag = document.createDocumentFragment(), anns = this.annotations;
|
| 71 |
+
|
| 72 |
+
var wrapping = cm.getOption("lineWrapping");
|
| 73 |
+
var singleLineH = wrapping && cm.defaultTextHeight() * 1.5;
|
| 74 |
+
var curLine = null, curLineObj = null;
|
| 75 |
+
function getY(pos, top) {
|
| 76 |
+
if (curLine != pos.line) {
|
| 77 |
+
curLine = pos.line;
|
| 78 |
+
curLineObj = cm.getLineHandle(curLine);
|
| 79 |
+
}
|
| 80 |
+
if (wrapping && curLineObj.height > singleLineH)
|
| 81 |
+
return cm.charCoords(pos, "local")[top ? "top" : "bottom"];
|
| 82 |
+
var topY = cm.heightAtLine(curLineObj, "local");
|
| 83 |
+
return topY + (top ? 0 : curLineObj.height);
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
if (cm.display.barWidth) for (var i = 0, nextTop; i < anns.length; i++) {
|
| 87 |
+
var ann = anns[i];
|
| 88 |
+
var top = nextTop || getY(ann.from, true) * hScale;
|
| 89 |
+
var bottom = getY(ann.to, false) * hScale;
|
| 90 |
+
while (i < anns.length - 1) {
|
| 91 |
+
nextTop = getY(anns[i + 1].from, true) * hScale;
|
| 92 |
+
if (nextTop > bottom + .9) break;
|
| 93 |
+
ann = anns[++i];
|
| 94 |
+
bottom = getY(ann.to, false) * hScale;
|
| 95 |
+
}
|
| 96 |
+
if (bottom == top) continue;
|
| 97 |
+
var height = Math.max(bottom - top, 3);
|
| 98 |
+
|
| 99 |
+
var elt = frag.appendChild(document.createElement("div"));
|
| 100 |
+
elt.style.cssText = "position: absolute; right: 0px; width: " + Math.max(cm.display.barWidth - 1, 2) + "px; top: "
|
| 101 |
+
+ (top + this.buttonHeight) + "px; height: " + height + "px";
|
| 102 |
+
elt.className = this.options.className;
|
| 103 |
+
}
|
| 104 |
+
this.div.textContent = "";
|
| 105 |
+
this.div.appendChild(frag);
|
| 106 |
+
};
|
| 107 |
+
|
| 108 |
+
Annotation.prototype.clear = function() {
|
| 109 |
+
this.cm.off("refresh", this.resizeHandler);
|
| 110 |
+
this.cm.off("markerAdded", this.resizeHandler);
|
| 111 |
+
this.cm.off("markerCleared", this.resizeHandler);
|
| 112 |
+
if (this.changeHandler) this.cm.off("change", this.changeHandler);
|
| 113 |
+
this.div.parentNode.removeChild(this.div);
|
| 114 |
+
};
|
| 115 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/scroll/scrollpastend.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
"use strict";
|
| 13 |
+
|
| 14 |
+
CodeMirror.defineOption("scrollPastEnd", false, function(cm, val, old) {
|
| 15 |
+
if (old && old != CodeMirror.Init) {
|
| 16 |
+
cm.off("change", onChange);
|
| 17 |
+
cm.off("refresh", updateBottomMargin);
|
| 18 |
+
cm.display.lineSpace.parentNode.style.paddingBottom = "";
|
| 19 |
+
cm.state.scrollPastEndPadding = null;
|
| 20 |
+
}
|
| 21 |
+
if (val) {
|
| 22 |
+
cm.on("change", onChange);
|
| 23 |
+
cm.on("refresh", updateBottomMargin);
|
| 24 |
+
updateBottomMargin(cm);
|
| 25 |
+
}
|
| 26 |
+
});
|
| 27 |
+
|
| 28 |
+
function onChange(cm, change) {
|
| 29 |
+
if (CodeMirror.changeEnd(change).line == cm.lastLine())
|
| 30 |
+
updateBottomMargin(cm);
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
function updateBottomMargin(cm) {
|
| 34 |
+
var padding = "";
|
| 35 |
+
if (cm.lineCount() > 1) {
|
| 36 |
+
var totalH = cm.display.scroller.clientHeight - 30,
|
| 37 |
+
lastLineH = cm.getLineHandle(cm.lastLine()).height;
|
| 38 |
+
padding = (totalH - lastLineH) + "px";
|
| 39 |
+
}
|
| 40 |
+
if (cm.state.scrollPastEndPadding != padding) {
|
| 41 |
+
cm.state.scrollPastEndPadding = padding;
|
| 42 |
+
cm.display.lineSpace.parentNode.style.paddingBottom = padding;
|
| 43 |
+
cm.setSize();
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/scroll/simplescrollbars.css
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.CodeMirror-simplescroll-horizontal div, .CodeMirror-simplescroll-vertical div {
|
| 2 |
+
position: absolute;
|
| 3 |
+
background: #ccc;
|
| 4 |
+
-moz-box-sizing: border-box;
|
| 5 |
+
box-sizing: border-box;
|
| 6 |
+
border: 1px solid #bbb;
|
| 7 |
+
border-radius: 2px;
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
.CodeMirror-simplescroll-horizontal, .CodeMirror-simplescroll-vertical {
|
| 11 |
+
position: absolute;
|
| 12 |
+
z-index: 6;
|
| 13 |
+
background: #eee;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
.CodeMirror-simplescroll-horizontal {
|
| 17 |
+
bottom: 0; left: 0;
|
| 18 |
+
height: 8px;
|
| 19 |
+
}
|
| 20 |
+
.CodeMirror-simplescroll-horizontal div {
|
| 21 |
+
bottom: 0;
|
| 22 |
+
height: 100%;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
.CodeMirror-simplescroll-vertical {
|
| 26 |
+
right: 0; top: 0;
|
| 27 |
+
width: 8px;
|
| 28 |
+
}
|
| 29 |
+
.CodeMirror-simplescroll-vertical div {
|
| 30 |
+
right: 0;
|
| 31 |
+
width: 100%;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
.CodeMirror-overlayscroll .CodeMirror-scrollbar-filler, .CodeMirror-overlayscroll .CodeMirror-gutter-filler {
|
| 36 |
+
display: none;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
.CodeMirror-overlayscroll-horizontal div, .CodeMirror-overlayscroll-vertical div {
|
| 40 |
+
position: absolute;
|
| 41 |
+
background: #bcd;
|
| 42 |
+
border-radius: 3px;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
.CodeMirror-overlayscroll-horizontal, .CodeMirror-overlayscroll-vertical {
|
| 46 |
+
position: absolute;
|
| 47 |
+
z-index: 6;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
.CodeMirror-overlayscroll-horizontal {
|
| 51 |
+
bottom: 0; left: 0;
|
| 52 |
+
height: 6px;
|
| 53 |
+
}
|
| 54 |
+
.CodeMirror-overlayscroll-horizontal div {
|
| 55 |
+
bottom: 0;
|
| 56 |
+
height: 100%;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
.CodeMirror-overlayscroll-vertical {
|
| 60 |
+
right: 0; top: 0;
|
| 61 |
+
width: 6px;
|
| 62 |
+
}
|
| 63 |
+
.CodeMirror-overlayscroll-vertical div {
|
| 64 |
+
right: 0;
|
| 65 |
+
width: 100%;
|
| 66 |
+
}
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/scroll/simplescrollbars.js
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
"use strict";
|
| 13 |
+
|
| 14 |
+
function Bar(cls, orientation, scroll) {
|
| 15 |
+
this.orientation = orientation;
|
| 16 |
+
this.scroll = scroll;
|
| 17 |
+
this.screen = this.total = this.size = 1;
|
| 18 |
+
this.pos = 0;
|
| 19 |
+
|
| 20 |
+
this.node = document.createElement("div");
|
| 21 |
+
this.node.className = cls + "-" + orientation;
|
| 22 |
+
this.inner = this.node.appendChild(document.createElement("div"));
|
| 23 |
+
|
| 24 |
+
var self = this;
|
| 25 |
+
CodeMirror.on(this.inner, "mousedown", function(e) {
|
| 26 |
+
if (e.which != 1) return;
|
| 27 |
+
CodeMirror.e_preventDefault(e);
|
| 28 |
+
var axis = self.orientation == "horizontal" ? "pageX" : "pageY";
|
| 29 |
+
var start = e[axis], startpos = self.pos;
|
| 30 |
+
function done() {
|
| 31 |
+
CodeMirror.off(document, "mousemove", move);
|
| 32 |
+
CodeMirror.off(document, "mouseup", done);
|
| 33 |
+
}
|
| 34 |
+
function move(e) {
|
| 35 |
+
if (e.which != 1) return done();
|
| 36 |
+
self.moveTo(startpos + (e[axis] - start) * (self.total / self.size));
|
| 37 |
+
}
|
| 38 |
+
CodeMirror.on(document, "mousemove", move);
|
| 39 |
+
CodeMirror.on(document, "mouseup", done);
|
| 40 |
+
});
|
| 41 |
+
|
| 42 |
+
CodeMirror.on(this.node, "click", function(e) {
|
| 43 |
+
CodeMirror.e_preventDefault(e);
|
| 44 |
+
var innerBox = self.inner.getBoundingClientRect(), where;
|
| 45 |
+
if (self.orientation == "horizontal")
|
| 46 |
+
where = e.clientX < innerBox.left ? -1 : e.clientX > innerBox.right ? 1 : 0;
|
| 47 |
+
else
|
| 48 |
+
where = e.clientY < innerBox.top ? -1 : e.clientY > innerBox.bottom ? 1 : 0;
|
| 49 |
+
self.moveTo(self.pos + where * self.screen);
|
| 50 |
+
});
|
| 51 |
+
|
| 52 |
+
function onWheel(e) {
|
| 53 |
+
var moved = CodeMirror.wheelEventPixels(e)[self.orientation == "horizontal" ? "x" : "y"];
|
| 54 |
+
var oldPos = self.pos;
|
| 55 |
+
self.moveTo(self.pos + moved);
|
| 56 |
+
if (self.pos != oldPos) CodeMirror.e_preventDefault(e);
|
| 57 |
+
}
|
| 58 |
+
CodeMirror.on(this.node, "mousewheel", onWheel);
|
| 59 |
+
CodeMirror.on(this.node, "DOMMouseScroll", onWheel);
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
Bar.prototype.moveTo = function(pos, update) {
|
| 63 |
+
if (pos < 0) pos = 0;
|
| 64 |
+
if (pos > this.total - this.screen) pos = this.total - this.screen;
|
| 65 |
+
if (pos == this.pos) return;
|
| 66 |
+
this.pos = pos;
|
| 67 |
+
this.inner.style[this.orientation == "horizontal" ? "left" : "top"] =
|
| 68 |
+
(pos * (this.size / this.total)) + "px";
|
| 69 |
+
if (update !== false) this.scroll(pos, this.orientation);
|
| 70 |
+
};
|
| 71 |
+
|
| 72 |
+
var minButtonSize = 10;
|
| 73 |
+
|
| 74 |
+
Bar.prototype.update = function(scrollSize, clientSize, barSize) {
|
| 75 |
+
this.screen = clientSize;
|
| 76 |
+
this.total = scrollSize;
|
| 77 |
+
this.size = barSize;
|
| 78 |
+
|
| 79 |
+
var buttonSize = this.screen * (this.size / this.total);
|
| 80 |
+
if (buttonSize < minButtonSize) {
|
| 81 |
+
this.size -= minButtonSize - buttonSize;
|
| 82 |
+
buttonSize = minButtonSize;
|
| 83 |
+
}
|
| 84 |
+
this.inner.style[this.orientation == "horizontal" ? "width" : "height"] =
|
| 85 |
+
buttonSize + "px";
|
| 86 |
+
this.inner.style[this.orientation == "horizontal" ? "left" : "top"] =
|
| 87 |
+
this.pos * (this.size / this.total) + "px";
|
| 88 |
+
};
|
| 89 |
+
|
| 90 |
+
function SimpleScrollbars(cls, place, scroll) {
|
| 91 |
+
this.addClass = cls;
|
| 92 |
+
this.horiz = new Bar(cls, "horizontal", scroll);
|
| 93 |
+
place(this.horiz.node);
|
| 94 |
+
this.vert = new Bar(cls, "vertical", scroll);
|
| 95 |
+
place(this.vert.node);
|
| 96 |
+
this.width = null;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
SimpleScrollbars.prototype.update = function(measure) {
|
| 100 |
+
if (this.width == null) {
|
| 101 |
+
var style = window.getComputedStyle ? window.getComputedStyle(this.horiz.node) : this.horiz.node.currentStyle;
|
| 102 |
+
if (style) this.width = parseInt(style.height);
|
| 103 |
+
}
|
| 104 |
+
var width = this.width || 0;
|
| 105 |
+
|
| 106 |
+
var needsH = measure.scrollWidth > measure.clientWidth + 1;
|
| 107 |
+
var needsV = measure.scrollHeight > measure.clientHeight + 1;
|
| 108 |
+
this.vert.node.style.display = needsV ? "block" : "none";
|
| 109 |
+
this.horiz.node.style.display = needsH ? "block" : "none";
|
| 110 |
+
|
| 111 |
+
if (needsV) {
|
| 112 |
+
this.vert.update(measure.scrollHeight, measure.clientHeight,
|
| 113 |
+
measure.viewHeight - (needsH ? width : 0));
|
| 114 |
+
this.vert.node.style.display = "block";
|
| 115 |
+
this.vert.node.style.bottom = needsH ? width + "px" : "0";
|
| 116 |
+
}
|
| 117 |
+
if (needsH) {
|
| 118 |
+
this.horiz.update(measure.scrollWidth, measure.clientWidth,
|
| 119 |
+
measure.viewWidth - (needsV ? width : 0) - measure.barLeft);
|
| 120 |
+
this.horiz.node.style.right = needsV ? width + "px" : "0";
|
| 121 |
+
this.horiz.node.style.left = measure.barLeft + "px";
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
return {right: needsV ? width : 0, bottom: needsH ? width : 0};
|
| 125 |
+
};
|
| 126 |
+
|
| 127 |
+
SimpleScrollbars.prototype.setScrollTop = function(pos) {
|
| 128 |
+
this.vert.moveTo(pos, false);
|
| 129 |
+
};
|
| 130 |
+
|
| 131 |
+
SimpleScrollbars.prototype.setScrollLeft = function(pos) {
|
| 132 |
+
this.horiz.moveTo(pos, false);
|
| 133 |
+
};
|
| 134 |
+
|
| 135 |
+
SimpleScrollbars.prototype.clear = function() {
|
| 136 |
+
var parent = this.horiz.node.parentNode;
|
| 137 |
+
parent.removeChild(this.horiz.node);
|
| 138 |
+
parent.removeChild(this.vert.node);
|
| 139 |
+
};
|
| 140 |
+
|
| 141 |
+
CodeMirror.scrollbarModel.simple = function(place, scroll) {
|
| 142 |
+
return new SimpleScrollbars("CodeMirror-simplescroll", place, scroll);
|
| 143 |
+
};
|
| 144 |
+
CodeMirror.scrollbarModel.overlay = function(place, scroll) {
|
| 145 |
+
return new SimpleScrollbars("CodeMirror-overlayscroll", place, scroll);
|
| 146 |
+
};
|
| 147 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/search/match-highlighter.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
// Highlighting text that matches the selection
|
| 5 |
+
//
|
| 6 |
+
// Defines an option highlightSelectionMatches, which, when enabled,
|
| 7 |
+
// will style strings that match the selection throughout the
|
| 8 |
+
// document.
|
| 9 |
+
//
|
| 10 |
+
// The option can be set to true to simply enable it, or to a
|
| 11 |
+
// {minChars, style, wordsOnly, showToken, delay} object to explicitly
|
| 12 |
+
// configure it. minChars is the minimum amount of characters that should be
|
| 13 |
+
// selected for the behavior to occur, and style is the token style to
|
| 14 |
+
// apply to the matches. This will be prefixed by "cm-" to create an
|
| 15 |
+
// actual CSS class name. If wordsOnly is enabled, the matches will be
|
| 16 |
+
// highlighted only if the selected text is a word. showToken, when enabled,
|
| 17 |
+
// will cause the current token to be highlighted when nothing is selected.
|
| 18 |
+
// delay is used to specify how much time to wait, in milliseconds, before
|
| 19 |
+
// highlighting the matches.
|
| 20 |
+
|
| 21 |
+
(function(mod) {
|
| 22 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 23 |
+
mod(require("../../lib/codemirror"));
|
| 24 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 25 |
+
define(["../../lib/codemirror"], mod);
|
| 26 |
+
else // Plain browser env
|
| 27 |
+
mod(CodeMirror);
|
| 28 |
+
})(function(CodeMirror) {
|
| 29 |
+
"use strict";
|
| 30 |
+
|
| 31 |
+
var DEFAULT_MIN_CHARS = 2;
|
| 32 |
+
var DEFAULT_TOKEN_STYLE = "matchhighlight";
|
| 33 |
+
var DEFAULT_DELAY = 100;
|
| 34 |
+
var DEFAULT_WORDS_ONLY = false;
|
| 35 |
+
|
| 36 |
+
function State(options) {
|
| 37 |
+
if (typeof options == "object") {
|
| 38 |
+
this.minChars = options.minChars;
|
| 39 |
+
this.style = options.style;
|
| 40 |
+
this.showToken = options.showToken;
|
| 41 |
+
this.delay = options.delay;
|
| 42 |
+
this.wordsOnly = options.wordsOnly;
|
| 43 |
+
}
|
| 44 |
+
if (this.style == null) this.style = DEFAULT_TOKEN_STYLE;
|
| 45 |
+
if (this.minChars == null) this.minChars = DEFAULT_MIN_CHARS;
|
| 46 |
+
if (this.delay == null) this.delay = DEFAULT_DELAY;
|
| 47 |
+
if (this.wordsOnly == null) this.wordsOnly = DEFAULT_WORDS_ONLY;
|
| 48 |
+
this.overlay = this.timeout = null;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
CodeMirror.defineOption("highlightSelectionMatches", false, function(cm, val, old) {
|
| 52 |
+
if (old && old != CodeMirror.Init) {
|
| 53 |
+
var over = cm.state.matchHighlighter.overlay;
|
| 54 |
+
if (over) cm.removeOverlay(over);
|
| 55 |
+
clearTimeout(cm.state.matchHighlighter.timeout);
|
| 56 |
+
cm.state.matchHighlighter = null;
|
| 57 |
+
cm.off("cursorActivity", cursorActivity);
|
| 58 |
+
}
|
| 59 |
+
if (val) {
|
| 60 |
+
cm.state.matchHighlighter = new State(val);
|
| 61 |
+
highlightMatches(cm);
|
| 62 |
+
cm.on("cursorActivity", cursorActivity);
|
| 63 |
+
}
|
| 64 |
+
});
|
| 65 |
+
|
| 66 |
+
function cursorActivity(cm) {
|
| 67 |
+
var state = cm.state.matchHighlighter;
|
| 68 |
+
clearTimeout(state.timeout);
|
| 69 |
+
state.timeout = setTimeout(function() {highlightMatches(cm);}, state.delay);
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
function highlightMatches(cm) {
|
| 73 |
+
cm.operation(function() {
|
| 74 |
+
var state = cm.state.matchHighlighter;
|
| 75 |
+
if (state.overlay) {
|
| 76 |
+
cm.removeOverlay(state.overlay);
|
| 77 |
+
state.overlay = null;
|
| 78 |
+
}
|
| 79 |
+
if (!cm.somethingSelected() && state.showToken) {
|
| 80 |
+
var re = state.showToken === true ? /[\w$]/ : state.showToken;
|
| 81 |
+
var cur = cm.getCursor(), line = cm.getLine(cur.line), start = cur.ch, end = start;
|
| 82 |
+
while (start && re.test(line.charAt(start - 1))) --start;
|
| 83 |
+
while (end < line.length && re.test(line.charAt(end))) ++end;
|
| 84 |
+
if (start < end)
|
| 85 |
+
cm.addOverlay(state.overlay = makeOverlay(line.slice(start, end), re, state.style));
|
| 86 |
+
return;
|
| 87 |
+
}
|
| 88 |
+
var from = cm.getCursor("from"), to = cm.getCursor("to");
|
| 89 |
+
if (from.line != to.line) return;
|
| 90 |
+
if (state.wordsOnly && !isWord(cm, from, to)) return;
|
| 91 |
+
var selection = cm.getRange(from, to).replace(/^\s+|\s+$/g, "");
|
| 92 |
+
if (selection.length >= state.minChars)
|
| 93 |
+
cm.addOverlay(state.overlay = makeOverlay(selection, false, state.style));
|
| 94 |
+
});
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
function isWord(cm, from, to) {
|
| 98 |
+
var str = cm.getRange(from, to);
|
| 99 |
+
if (str.match(/^\w+$/) !== null) {
|
| 100 |
+
if (from.ch > 0) {
|
| 101 |
+
var pos = {line: from.line, ch: from.ch - 1};
|
| 102 |
+
var chr = cm.getRange(pos, from);
|
| 103 |
+
if (chr.match(/\W/) === null) return false;
|
| 104 |
+
}
|
| 105 |
+
if (to.ch < cm.getLine(from.line).length) {
|
| 106 |
+
var pos = {line: to.line, ch: to.ch + 1};
|
| 107 |
+
var chr = cm.getRange(to, pos);
|
| 108 |
+
if (chr.match(/\W/) === null) return false;
|
| 109 |
+
}
|
| 110 |
+
return true;
|
| 111 |
+
} else return false;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
function boundariesAround(stream, re) {
|
| 115 |
+
return (!stream.start || !re.test(stream.string.charAt(stream.start - 1))) &&
|
| 116 |
+
(stream.pos == stream.string.length || !re.test(stream.string.charAt(stream.pos)));
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
function makeOverlay(query, hasBoundary, style) {
|
| 120 |
+
return {token: function(stream) {
|
| 121 |
+
if (stream.match(query) &&
|
| 122 |
+
(!hasBoundary || boundariesAround(stream, hasBoundary)))
|
| 123 |
+
return style;
|
| 124 |
+
stream.next();
|
| 125 |
+
stream.skipTo(query.charAt(0)) || stream.skipToEnd();
|
| 126 |
+
}};
|
| 127 |
+
}
|
| 128 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/search/matchesonscrollbar.css
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.CodeMirror-search-match {
|
| 2 |
+
background: gold;
|
| 3 |
+
border-top: 1px solid orange;
|
| 4 |
+
border-bottom: 1px solid orange;
|
| 5 |
+
-moz-box-sizing: border-box;
|
| 6 |
+
box-sizing: border-box;
|
| 7 |
+
opacity: .5;
|
| 8 |
+
}
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/search/matchesonscrollbar.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"), require("./searchcursor"), require("../scroll/annotatescrollbar"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror", "./searchcursor", "../scroll/annotatescrollbar"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
"use strict";
|
| 13 |
+
|
| 14 |
+
CodeMirror.defineExtension("showMatchesOnScrollbar", function(query, caseFold, options) {
|
| 15 |
+
if (typeof options == "string") options = {className: options};
|
| 16 |
+
if (!options) options = {};
|
| 17 |
+
return new SearchAnnotation(this, query, caseFold, options);
|
| 18 |
+
});
|
| 19 |
+
|
| 20 |
+
function SearchAnnotation(cm, query, caseFold, options) {
|
| 21 |
+
this.cm = cm;
|
| 22 |
+
this.options = options;
|
| 23 |
+
var annotateOptions = {listenForChanges: false};
|
| 24 |
+
for (var prop in options) annotateOptions[prop] = options[prop];
|
| 25 |
+
if (!annotateOptions.className) annotateOptions.className = "CodeMirror-search-match";
|
| 26 |
+
this.annotation = cm.annotateScrollbar(annotateOptions);
|
| 27 |
+
this.query = query;
|
| 28 |
+
this.caseFold = caseFold;
|
| 29 |
+
this.gap = {from: cm.firstLine(), to: cm.lastLine() + 1};
|
| 30 |
+
this.matches = [];
|
| 31 |
+
this.update = null;
|
| 32 |
+
|
| 33 |
+
this.findMatches();
|
| 34 |
+
this.annotation.update(this.matches);
|
| 35 |
+
|
| 36 |
+
var self = this;
|
| 37 |
+
cm.on("change", this.changeHandler = function(_cm, change) { self.onChange(change); });
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
var MAX_MATCHES = 1000;
|
| 41 |
+
|
| 42 |
+
SearchAnnotation.prototype.findMatches = function() {
|
| 43 |
+
if (!this.gap) return;
|
| 44 |
+
for (var i = 0; i < this.matches.length; i++) {
|
| 45 |
+
var match = this.matches[i];
|
| 46 |
+
if (match.from.line >= this.gap.to) break;
|
| 47 |
+
if (match.to.line >= this.gap.from) this.matches.splice(i--, 1);
|
| 48 |
+
}
|
| 49 |
+
var cursor = this.cm.getSearchCursor(this.query, CodeMirror.Pos(this.gap.from, 0), this.caseFold);
|
| 50 |
+
var maxMatches = this.options && this.options.maxMatches || MAX_MATCHES;
|
| 51 |
+
while (cursor.findNext()) {
|
| 52 |
+
var match = {from: cursor.from(), to: cursor.to()};
|
| 53 |
+
if (match.from.line >= this.gap.to) break;
|
| 54 |
+
this.matches.splice(i++, 0, match);
|
| 55 |
+
if (this.matches.length > maxMatches) break;
|
| 56 |
+
}
|
| 57 |
+
this.gap = null;
|
| 58 |
+
};
|
| 59 |
+
|
| 60 |
+
function offsetLine(line, changeStart, sizeChange) {
|
| 61 |
+
if (line <= changeStart) return line;
|
| 62 |
+
return Math.max(changeStart, line + sizeChange);
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
SearchAnnotation.prototype.onChange = function(change) {
|
| 66 |
+
var startLine = change.from.line;
|
| 67 |
+
var endLine = CodeMirror.changeEnd(change).line;
|
| 68 |
+
var sizeChange = endLine - change.to.line;
|
| 69 |
+
if (this.gap) {
|
| 70 |
+
this.gap.from = Math.min(offsetLine(this.gap.from, startLine, sizeChange), change.from.line);
|
| 71 |
+
this.gap.to = Math.max(offsetLine(this.gap.to, startLine, sizeChange), change.from.line);
|
| 72 |
+
} else {
|
| 73 |
+
this.gap = {from: change.from.line, to: endLine + 1};
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
if (sizeChange) for (var i = 0; i < this.matches.length; i++) {
|
| 77 |
+
var match = this.matches[i];
|
| 78 |
+
var newFrom = offsetLine(match.from.line, startLine, sizeChange);
|
| 79 |
+
if (newFrom != match.from.line) match.from = CodeMirror.Pos(newFrom, match.from.ch);
|
| 80 |
+
var newTo = offsetLine(match.to.line, startLine, sizeChange);
|
| 81 |
+
if (newTo != match.to.line) match.to = CodeMirror.Pos(newTo, match.to.ch);
|
| 82 |
+
}
|
| 83 |
+
clearTimeout(this.update);
|
| 84 |
+
var self = this;
|
| 85 |
+
this.update = setTimeout(function() { self.updateAfterChange(); }, 250);
|
| 86 |
+
};
|
| 87 |
+
|
| 88 |
+
SearchAnnotation.prototype.updateAfterChange = function() {
|
| 89 |
+
this.findMatches();
|
| 90 |
+
this.annotation.update(this.matches);
|
| 91 |
+
};
|
| 92 |
+
|
| 93 |
+
SearchAnnotation.prototype.clear = function() {
|
| 94 |
+
this.cm.off("change", this.changeHandler);
|
| 95 |
+
this.annotation.clear();
|
| 96 |
+
};
|
| 97 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/search/search.js
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
// Define search commands. Depends on dialog.js or another
|
| 5 |
+
// implementation of the openDialog method.
|
| 6 |
+
|
| 7 |
+
// Replace works a little oddly -- it will do the replace on the next
|
| 8 |
+
// Ctrl-G (or whatever is bound to findNext) press. You prevent a
|
| 9 |
+
// replace by making sure the match is no longer selected when hitting
|
| 10 |
+
// Ctrl-G.
|
| 11 |
+
|
| 12 |
+
(function(mod) {
|
| 13 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 14 |
+
mod(require("../../lib/codemirror"), require("./searchcursor"), require("../dialog/dialog"));
|
| 15 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 16 |
+
define(["../../lib/codemirror", "./searchcursor", "../dialog/dialog"], mod);
|
| 17 |
+
else // Plain browser env
|
| 18 |
+
mod(CodeMirror);
|
| 19 |
+
})(function(CodeMirror) {
|
| 20 |
+
"use strict";
|
| 21 |
+
function searchOverlay(query, caseInsensitive) {
|
| 22 |
+
if (typeof query == "string")
|
| 23 |
+
query = new RegExp(query.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"), caseInsensitive ? "gi" : "g");
|
| 24 |
+
else if (!query.global)
|
| 25 |
+
query = new RegExp(query.source, query.ignoreCase ? "gi" : "g");
|
| 26 |
+
|
| 27 |
+
return {token: function(stream) {
|
| 28 |
+
query.lastIndex = stream.pos;
|
| 29 |
+
var match = query.exec(stream.string);
|
| 30 |
+
if (match && match.index == stream.pos) {
|
| 31 |
+
stream.pos += match[0].length;
|
| 32 |
+
return "searching";
|
| 33 |
+
} else if (match) {
|
| 34 |
+
stream.pos = match.index;
|
| 35 |
+
} else {
|
| 36 |
+
stream.skipToEnd();
|
| 37 |
+
}
|
| 38 |
+
}};
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
function SearchState() {
|
| 42 |
+
this.posFrom = this.posTo = this.lastQuery = this.query = null;
|
| 43 |
+
this.overlay = null;
|
| 44 |
+
}
|
| 45 |
+
function getSearchState(cm) {
|
| 46 |
+
return cm.state.search || (cm.state.search = new SearchState());
|
| 47 |
+
}
|
| 48 |
+
function queryCaseInsensitive(query) {
|
| 49 |
+
return typeof query == "string" && query == query.toLowerCase();
|
| 50 |
+
}
|
| 51 |
+
function getSearchCursor(cm, query, pos) {
|
| 52 |
+
// Heuristic: if the query string is all lowercase, do a case insensitive search.
|
| 53 |
+
return cm.getSearchCursor(query, pos, queryCaseInsensitive(query));
|
| 54 |
+
}
|
| 55 |
+
function dialog(cm, text, shortText, deflt, f) {
|
| 56 |
+
if (cm.openDialog) cm.openDialog(text, f, {value: deflt, selectValueOnOpen: true});
|
| 57 |
+
else f(prompt(shortText, deflt));
|
| 58 |
+
}
|
| 59 |
+
function confirmDialog(cm, text, shortText, fs) {
|
| 60 |
+
if (cm.openConfirm) cm.openConfirm(text, fs);
|
| 61 |
+
else if (confirm(shortText)) fs[0]();
|
| 62 |
+
}
|
| 63 |
+
function parseQuery(query) {
|
| 64 |
+
var isRE = query.match(/^\/(.*)\/([a-z]*)$/);
|
| 65 |
+
if (isRE) {
|
| 66 |
+
try { query = new RegExp(isRE[1], isRE[2].indexOf("i") == -1 ? "" : "i"); }
|
| 67 |
+
catch(e) {} // Not a regular expression after all, do a string search
|
| 68 |
+
}
|
| 69 |
+
if (typeof query == "string" ? query == "" : query.test(""))
|
| 70 |
+
query = /x^/;
|
| 71 |
+
return query;
|
| 72 |
+
}
|
| 73 |
+
var queryDialog =
|
| 74 |
+
'Search: <input type="text" style="width: 10em" class="CodeMirror-search-field"/> <span style="color: #888" class="CodeMirror-search-hint">(Use /re/ syntax for regexp search)</span>';
|
| 75 |
+
function doSearch(cm, rev) {
|
| 76 |
+
var state = getSearchState(cm);
|
| 77 |
+
if (state.query) return findNext(cm, rev);
|
| 78 |
+
var q = cm.getSelection() || state.lastQuery;
|
| 79 |
+
dialog(cm, queryDialog, "Search for:", q, function(query) {
|
| 80 |
+
cm.operation(function() {
|
| 81 |
+
if (!query || state.query) return;
|
| 82 |
+
state.query = parseQuery(query);
|
| 83 |
+
cm.removeOverlay(state.overlay, queryCaseInsensitive(state.query));
|
| 84 |
+
state.overlay = searchOverlay(state.query, queryCaseInsensitive(state.query));
|
| 85 |
+
cm.addOverlay(state.overlay);
|
| 86 |
+
if (cm.showMatchesOnScrollbar) {
|
| 87 |
+
if (state.annotate) { state.annotate.clear(); state.annotate = null; }
|
| 88 |
+
state.annotate = cm.showMatchesOnScrollbar(state.query, queryCaseInsensitive(state.query));
|
| 89 |
+
}
|
| 90 |
+
state.posFrom = state.posTo = cm.getCursor();
|
| 91 |
+
findNext(cm, rev);
|
| 92 |
+
});
|
| 93 |
+
});
|
| 94 |
+
}
|
| 95 |
+
function findNext(cm, rev) {cm.operation(function() {
|
| 96 |
+
var state = getSearchState(cm);
|
| 97 |
+
var cursor = getSearchCursor(cm, state.query, rev ? state.posFrom : state.posTo);
|
| 98 |
+
if (!cursor.find(rev)) {
|
| 99 |
+
cursor = getSearchCursor(cm, state.query, rev ? CodeMirror.Pos(cm.lastLine()) : CodeMirror.Pos(cm.firstLine(), 0));
|
| 100 |
+
if (!cursor.find(rev)) return;
|
| 101 |
+
}
|
| 102 |
+
cm.setSelection(cursor.from(), cursor.to());
|
| 103 |
+
cm.scrollIntoView({from: cursor.from(), to: cursor.to()});
|
| 104 |
+
state.posFrom = cursor.from(); state.posTo = cursor.to();
|
| 105 |
+
});}
|
| 106 |
+
function clearSearch(cm) {cm.operation(function() {
|
| 107 |
+
var state = getSearchState(cm);
|
| 108 |
+
state.lastQuery = state.query;
|
| 109 |
+
if (!state.query) return;
|
| 110 |
+
state.query = null;
|
| 111 |
+
cm.removeOverlay(state.overlay);
|
| 112 |
+
if (state.annotate) { state.annotate.clear(); state.annotate = null; }
|
| 113 |
+
});}
|
| 114 |
+
|
| 115 |
+
var replaceQueryDialog =
|
| 116 |
+
'Replace: <input type="text" style="width: 10em" class="CodeMirror-search-field"/> <span style="color: #888" class="CodeMirror-search-hint">(Use /re/ syntax for regexp search)</span>';
|
| 117 |
+
var replacementQueryDialog = 'With: <input type="text" style="width: 10em" class="CodeMirror-search-field"/>';
|
| 118 |
+
var doReplaceConfirm = "Replace? <button>Yes</button> <button>No</button> <button>Stop</button>";
|
| 119 |
+
function replace(cm, all) {
|
| 120 |
+
if (cm.getOption("readOnly")) return;
|
| 121 |
+
var query = cm.getSelection() || getSearchState(cm).lastQuery;
|
| 122 |
+
dialog(cm, replaceQueryDialog, "Replace:", query, function(query) {
|
| 123 |
+
if (!query) return;
|
| 124 |
+
query = parseQuery(query);
|
| 125 |
+
dialog(cm, replacementQueryDialog, "Replace with:", "", function(text) {
|
| 126 |
+
if (all) {
|
| 127 |
+
cm.operation(function() {
|
| 128 |
+
for (var cursor = getSearchCursor(cm, query); cursor.findNext();) {
|
| 129 |
+
if (typeof query != "string") {
|
| 130 |
+
var match = cm.getRange(cursor.from(), cursor.to()).match(query);
|
| 131 |
+
cursor.replace(text.replace(/\$(\d)/g, function(_, i) {return match[i];}));
|
| 132 |
+
} else cursor.replace(text);
|
| 133 |
+
}
|
| 134 |
+
});
|
| 135 |
+
} else {
|
| 136 |
+
clearSearch(cm);
|
| 137 |
+
var cursor = getSearchCursor(cm, query, cm.getCursor());
|
| 138 |
+
var advance = function() {
|
| 139 |
+
var start = cursor.from(), match;
|
| 140 |
+
if (!(match = cursor.findNext())) {
|
| 141 |
+
cursor = getSearchCursor(cm, query);
|
| 142 |
+
if (!(match = cursor.findNext()) ||
|
| 143 |
+
(start && cursor.from().line == start.line && cursor.from().ch == start.ch)) return;
|
| 144 |
+
}
|
| 145 |
+
cm.setSelection(cursor.from(), cursor.to());
|
| 146 |
+
cm.scrollIntoView({from: cursor.from(), to: cursor.to()});
|
| 147 |
+
confirmDialog(cm, doReplaceConfirm, "Replace?",
|
| 148 |
+
[function() {doReplace(match);}, advance]);
|
| 149 |
+
};
|
| 150 |
+
var doReplace = function(match) {
|
| 151 |
+
cursor.replace(typeof query == "string" ? text :
|
| 152 |
+
text.replace(/\$(\d)/g, function(_, i) {return match[i];}));
|
| 153 |
+
advance();
|
| 154 |
+
};
|
| 155 |
+
advance();
|
| 156 |
+
}
|
| 157 |
+
});
|
| 158 |
+
});
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
CodeMirror.commands.find = function(cm) {clearSearch(cm); doSearch(cm);};
|
| 162 |
+
CodeMirror.commands.findNext = doSearch;
|
| 163 |
+
CodeMirror.commands.findPrev = function(cm) {doSearch(cm, true);};
|
| 164 |
+
CodeMirror.commands.clearSearch = clearSearch;
|
| 165 |
+
CodeMirror.commands.replace = replace;
|
| 166 |
+
CodeMirror.commands.replaceAll = function(cm) {replace(cm, true);};
|
| 167 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/search/searchcursor.js
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
"use strict";
|
| 13 |
+
var Pos = CodeMirror.Pos;
|
| 14 |
+
|
| 15 |
+
function SearchCursor(doc, query, pos, caseFold) {
|
| 16 |
+
this.atOccurrence = false; this.doc = doc;
|
| 17 |
+
if (caseFold == null && typeof query == "string") caseFold = false;
|
| 18 |
+
|
| 19 |
+
pos = pos ? doc.clipPos(pos) : Pos(0, 0);
|
| 20 |
+
this.pos = {from: pos, to: pos};
|
| 21 |
+
|
| 22 |
+
// The matches method is filled in based on the type of query.
|
| 23 |
+
// It takes a position and a direction, and returns an object
|
| 24 |
+
// describing the next occurrence of the query, or null if no
|
| 25 |
+
// more matches were found.
|
| 26 |
+
if (typeof query != "string") { // Regexp match
|
| 27 |
+
if (!query.global) query = new RegExp(query.source, query.ignoreCase ? "ig" : "g");
|
| 28 |
+
this.matches = function(reverse, pos) {
|
| 29 |
+
if (reverse) {
|
| 30 |
+
query.lastIndex = 0;
|
| 31 |
+
var line = doc.getLine(pos.line).slice(0, pos.ch), cutOff = 0, match, start;
|
| 32 |
+
for (;;) {
|
| 33 |
+
query.lastIndex = cutOff;
|
| 34 |
+
var newMatch = query.exec(line);
|
| 35 |
+
if (!newMatch) break;
|
| 36 |
+
match = newMatch;
|
| 37 |
+
start = match.index;
|
| 38 |
+
cutOff = match.index + (match[0].length || 1);
|
| 39 |
+
if (cutOff == line.length) break;
|
| 40 |
+
}
|
| 41 |
+
var matchLen = (match && match[0].length) || 0;
|
| 42 |
+
if (!matchLen) {
|
| 43 |
+
if (start == 0 && line.length == 0) {match = undefined;}
|
| 44 |
+
else if (start != doc.getLine(pos.line).length) {
|
| 45 |
+
matchLen++;
|
| 46 |
+
}
|
| 47 |
+
}
|
| 48 |
+
} else {
|
| 49 |
+
query.lastIndex = pos.ch;
|
| 50 |
+
var line = doc.getLine(pos.line), match = query.exec(line);
|
| 51 |
+
var matchLen = (match && match[0].length) || 0;
|
| 52 |
+
var start = match && match.index;
|
| 53 |
+
if (start + matchLen != line.length && !matchLen) matchLen = 1;
|
| 54 |
+
}
|
| 55 |
+
if (match && matchLen)
|
| 56 |
+
return {from: Pos(pos.line, start),
|
| 57 |
+
to: Pos(pos.line, start + matchLen),
|
| 58 |
+
match: match};
|
| 59 |
+
};
|
| 60 |
+
} else { // String query
|
| 61 |
+
var origQuery = query;
|
| 62 |
+
if (caseFold) query = query.toLowerCase();
|
| 63 |
+
var fold = caseFold ? function(str){return str.toLowerCase();} : function(str){return str;};
|
| 64 |
+
var target = query.split("\n");
|
| 65 |
+
// Different methods for single-line and multi-line queries
|
| 66 |
+
if (target.length == 1) {
|
| 67 |
+
if (!query.length) {
|
| 68 |
+
// Empty string would match anything and never progress, so
|
| 69 |
+
// we define it to match nothing instead.
|
| 70 |
+
this.matches = function() {};
|
| 71 |
+
} else {
|
| 72 |
+
this.matches = function(reverse, pos) {
|
| 73 |
+
if (reverse) {
|
| 74 |
+
var orig = doc.getLine(pos.line).slice(0, pos.ch), line = fold(orig);
|
| 75 |
+
var match = line.lastIndexOf(query);
|
| 76 |
+
if (match > -1) {
|
| 77 |
+
match = adjustPos(orig, line, match);
|
| 78 |
+
return {from: Pos(pos.line, match), to: Pos(pos.line, match + origQuery.length)};
|
| 79 |
+
}
|
| 80 |
+
} else {
|
| 81 |
+
var orig = doc.getLine(pos.line).slice(pos.ch), line = fold(orig);
|
| 82 |
+
var match = line.indexOf(query);
|
| 83 |
+
if (match > -1) {
|
| 84 |
+
match = adjustPos(orig, line, match) + pos.ch;
|
| 85 |
+
return {from: Pos(pos.line, match), to: Pos(pos.line, match + origQuery.length)};
|
| 86 |
+
}
|
| 87 |
+
}
|
| 88 |
+
};
|
| 89 |
+
}
|
| 90 |
+
} else {
|
| 91 |
+
var origTarget = origQuery.split("\n");
|
| 92 |
+
this.matches = function(reverse, pos) {
|
| 93 |
+
var last = target.length - 1;
|
| 94 |
+
if (reverse) {
|
| 95 |
+
if (pos.line - (target.length - 1) < doc.firstLine()) return;
|
| 96 |
+
if (fold(doc.getLine(pos.line).slice(0, origTarget[last].length)) != target[target.length - 1]) return;
|
| 97 |
+
var to = Pos(pos.line, origTarget[last].length);
|
| 98 |
+
for (var ln = pos.line - 1, i = last - 1; i >= 1; --i, --ln)
|
| 99 |
+
if (target[i] != fold(doc.getLine(ln))) return;
|
| 100 |
+
var line = doc.getLine(ln), cut = line.length - origTarget[0].length;
|
| 101 |
+
if (fold(line.slice(cut)) != target[0]) return;
|
| 102 |
+
return {from: Pos(ln, cut), to: to};
|
| 103 |
+
} else {
|
| 104 |
+
if (pos.line + (target.length - 1) > doc.lastLine()) return;
|
| 105 |
+
var line = doc.getLine(pos.line), cut = line.length - origTarget[0].length;
|
| 106 |
+
if (fold(line.slice(cut)) != target[0]) return;
|
| 107 |
+
var from = Pos(pos.line, cut);
|
| 108 |
+
for (var ln = pos.line + 1, i = 1; i < last; ++i, ++ln)
|
| 109 |
+
if (target[i] != fold(doc.getLine(ln))) return;
|
| 110 |
+
if (fold(doc.getLine(ln).slice(0, origTarget[last].length)) != target[last]) return;
|
| 111 |
+
return {from: from, to: Pos(ln, origTarget[last].length)};
|
| 112 |
+
}
|
| 113 |
+
};
|
| 114 |
+
}
|
| 115 |
+
}
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
SearchCursor.prototype = {
|
| 119 |
+
findNext: function() {return this.find(false);},
|
| 120 |
+
findPrevious: function() {return this.find(true);},
|
| 121 |
+
|
| 122 |
+
find: function(reverse) {
|
| 123 |
+
var self = this, pos = this.doc.clipPos(reverse ? this.pos.from : this.pos.to);
|
| 124 |
+
function savePosAndFail(line) {
|
| 125 |
+
var pos = Pos(line, 0);
|
| 126 |
+
self.pos = {from: pos, to: pos};
|
| 127 |
+
self.atOccurrence = false;
|
| 128 |
+
return false;
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
for (;;) {
|
| 132 |
+
if (this.pos = this.matches(reverse, pos)) {
|
| 133 |
+
this.atOccurrence = true;
|
| 134 |
+
return this.pos.match || true;
|
| 135 |
+
}
|
| 136 |
+
if (reverse) {
|
| 137 |
+
if (!pos.line) return savePosAndFail(0);
|
| 138 |
+
pos = Pos(pos.line-1, this.doc.getLine(pos.line-1).length);
|
| 139 |
+
}
|
| 140 |
+
else {
|
| 141 |
+
var maxLine = this.doc.lineCount();
|
| 142 |
+
if (pos.line == maxLine - 1) return savePosAndFail(maxLine);
|
| 143 |
+
pos = Pos(pos.line + 1, 0);
|
| 144 |
+
}
|
| 145 |
+
}
|
| 146 |
+
},
|
| 147 |
+
|
| 148 |
+
from: function() {if (this.atOccurrence) return this.pos.from;},
|
| 149 |
+
to: function() {if (this.atOccurrence) return this.pos.to;},
|
| 150 |
+
|
| 151 |
+
replace: function(newText, origin) {
|
| 152 |
+
if (!this.atOccurrence) return;
|
| 153 |
+
var lines = CodeMirror.splitLines(newText);
|
| 154 |
+
this.doc.replaceRange(lines, this.pos.from, this.pos.to, origin);
|
| 155 |
+
this.pos.to = Pos(this.pos.from.line + lines.length - 1,
|
| 156 |
+
lines[lines.length - 1].length + (lines.length == 1 ? this.pos.from.ch : 0));
|
| 157 |
+
}
|
| 158 |
+
};
|
| 159 |
+
|
| 160 |
+
// Maps a position in a case-folded line back to a position in the original line
|
| 161 |
+
// (compensating for codepoints increasing in number during folding)
|
| 162 |
+
function adjustPos(orig, folded, pos) {
|
| 163 |
+
if (orig.length == folded.length) return pos;
|
| 164 |
+
for (var pos1 = Math.min(pos, orig.length);;) {
|
| 165 |
+
var len1 = orig.slice(0, pos1).toLowerCase().length;
|
| 166 |
+
if (len1 < pos) ++pos1;
|
| 167 |
+
else if (len1 > pos) --pos1;
|
| 168 |
+
else return pos1;
|
| 169 |
+
}
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
CodeMirror.defineExtension("getSearchCursor", function(query, pos, caseFold) {
|
| 173 |
+
return new SearchCursor(this.doc, query, pos, caseFold);
|
| 174 |
+
});
|
| 175 |
+
CodeMirror.defineDocExtension("getSearchCursor", function(query, pos, caseFold) {
|
| 176 |
+
return new SearchCursor(this, query, pos, caseFold);
|
| 177 |
+
});
|
| 178 |
+
|
| 179 |
+
CodeMirror.defineExtension("selectMatches", function(query, caseFold) {
|
| 180 |
+
var ranges = [];
|
| 181 |
+
var cur = this.getSearchCursor(query, this.getCursor("from"), caseFold);
|
| 182 |
+
while (cur.findNext()) {
|
| 183 |
+
if (CodeMirror.cmpPos(cur.to(), this.getCursor("to")) > 0) break;
|
| 184 |
+
ranges.push({anchor: cur.from(), head: cur.to()});
|
| 185 |
+
}
|
| 186 |
+
if (ranges.length)
|
| 187 |
+
this.setSelections(ranges, 0);
|
| 188 |
+
});
|
| 189 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/selection/active-line.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
// Because sometimes you need to style the cursor's line.
|
| 5 |
+
//
|
| 6 |
+
// Adds an option 'styleActiveLine' which, when enabled, gives the
|
| 7 |
+
// active line's wrapping <div> the CSS class "CodeMirror-activeline",
|
| 8 |
+
// and gives its background <div> the class "CodeMirror-activeline-background".
|
| 9 |
+
|
| 10 |
+
(function(mod) {
|
| 11 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 12 |
+
mod(require("../../lib/codemirror"));
|
| 13 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 14 |
+
define(["../../lib/codemirror"], mod);
|
| 15 |
+
else // Plain browser env
|
| 16 |
+
mod(CodeMirror);
|
| 17 |
+
})(function(CodeMirror) {
|
| 18 |
+
"use strict";
|
| 19 |
+
var WRAP_CLASS = "CodeMirror-activeline";
|
| 20 |
+
var BACK_CLASS = "CodeMirror-activeline-background";
|
| 21 |
+
|
| 22 |
+
CodeMirror.defineOption("styleActiveLine", false, function(cm, val, old) {
|
| 23 |
+
var prev = old && old != CodeMirror.Init;
|
| 24 |
+
if (val && !prev) {
|
| 25 |
+
cm.state.activeLines = [];
|
| 26 |
+
updateActiveLines(cm, cm.listSelections());
|
| 27 |
+
cm.on("beforeSelectionChange", selectionChange);
|
| 28 |
+
} else if (!val && prev) {
|
| 29 |
+
cm.off("beforeSelectionChange", selectionChange);
|
| 30 |
+
clearActiveLines(cm);
|
| 31 |
+
delete cm.state.activeLines;
|
| 32 |
+
}
|
| 33 |
+
});
|
| 34 |
+
|
| 35 |
+
function clearActiveLines(cm) {
|
| 36 |
+
for (var i = 0; i < cm.state.activeLines.length; i++) {
|
| 37 |
+
cm.removeLineClass(cm.state.activeLines[i], "wrap", WRAP_CLASS);
|
| 38 |
+
cm.removeLineClass(cm.state.activeLines[i], "background", BACK_CLASS);
|
| 39 |
+
}
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
function sameArray(a, b) {
|
| 43 |
+
if (a.length != b.length) return false;
|
| 44 |
+
for (var i = 0; i < a.length; i++)
|
| 45 |
+
if (a[i] != b[i]) return false;
|
| 46 |
+
return true;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
function updateActiveLines(cm, ranges) {
|
| 50 |
+
var active = [];
|
| 51 |
+
for (var i = 0; i < ranges.length; i++) {
|
| 52 |
+
var range = ranges[i];
|
| 53 |
+
if (!range.empty()) continue;
|
| 54 |
+
var line = cm.getLineHandleVisualStart(range.head.line);
|
| 55 |
+
if (active[active.length - 1] != line) active.push(line);
|
| 56 |
+
}
|
| 57 |
+
if (sameArray(cm.state.activeLines, active)) return;
|
| 58 |
+
cm.operation(function() {
|
| 59 |
+
clearActiveLines(cm);
|
| 60 |
+
for (var i = 0; i < active.length; i++) {
|
| 61 |
+
cm.addLineClass(active[i], "wrap", WRAP_CLASS);
|
| 62 |
+
cm.addLineClass(active[i], "background", BACK_CLASS);
|
| 63 |
+
}
|
| 64 |
+
cm.state.activeLines = active;
|
| 65 |
+
});
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
function selectionChange(cm, sel) {
|
| 69 |
+
updateActiveLines(cm, sel.ranges);
|
| 70 |
+
}
|
| 71 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/selection/mark-selection.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
// Because sometimes you need to mark the selected *text*.
|
| 5 |
+
//
|
| 6 |
+
// Adds an option 'styleSelectedText' which, when enabled, gives
|
| 7 |
+
// selected text the CSS class given as option value, or
|
| 8 |
+
// "CodeMirror-selectedtext" when the value is not a string.
|
| 9 |
+
|
| 10 |
+
(function(mod) {
|
| 11 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 12 |
+
mod(require("../../lib/codemirror"));
|
| 13 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 14 |
+
define(["../../lib/codemirror"], mod);
|
| 15 |
+
else // Plain browser env
|
| 16 |
+
mod(CodeMirror);
|
| 17 |
+
})(function(CodeMirror) {
|
| 18 |
+
"use strict";
|
| 19 |
+
|
| 20 |
+
CodeMirror.defineOption("styleSelectedText", false, function(cm, val, old) {
|
| 21 |
+
var prev = old && old != CodeMirror.Init;
|
| 22 |
+
if (val && !prev) {
|
| 23 |
+
cm.state.markedSelection = [];
|
| 24 |
+
cm.state.markedSelectionStyle = typeof val == "string" ? val : "CodeMirror-selectedtext";
|
| 25 |
+
reset(cm);
|
| 26 |
+
cm.on("cursorActivity", onCursorActivity);
|
| 27 |
+
cm.on("change", onChange);
|
| 28 |
+
} else if (!val && prev) {
|
| 29 |
+
cm.off("cursorActivity", onCursorActivity);
|
| 30 |
+
cm.off("change", onChange);
|
| 31 |
+
clear(cm);
|
| 32 |
+
cm.state.markedSelection = cm.state.markedSelectionStyle = null;
|
| 33 |
+
}
|
| 34 |
+
});
|
| 35 |
+
|
| 36 |
+
function onCursorActivity(cm) {
|
| 37 |
+
cm.operation(function() { update(cm); });
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
function onChange(cm) {
|
| 41 |
+
if (cm.state.markedSelection.length)
|
| 42 |
+
cm.operation(function() { clear(cm); });
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
var CHUNK_SIZE = 8;
|
| 46 |
+
var Pos = CodeMirror.Pos;
|
| 47 |
+
var cmp = CodeMirror.cmpPos;
|
| 48 |
+
|
| 49 |
+
function coverRange(cm, from, to, addAt) {
|
| 50 |
+
if (cmp(from, to) == 0) return;
|
| 51 |
+
var array = cm.state.markedSelection;
|
| 52 |
+
var cls = cm.state.markedSelectionStyle;
|
| 53 |
+
for (var line = from.line;;) {
|
| 54 |
+
var start = line == from.line ? from : Pos(line, 0);
|
| 55 |
+
var endLine = line + CHUNK_SIZE, atEnd = endLine >= to.line;
|
| 56 |
+
var end = atEnd ? to : Pos(endLine, 0);
|
| 57 |
+
var mark = cm.markText(start, end, {className: cls});
|
| 58 |
+
if (addAt == null) array.push(mark);
|
| 59 |
+
else array.splice(addAt++, 0, mark);
|
| 60 |
+
if (atEnd) break;
|
| 61 |
+
line = endLine;
|
| 62 |
+
}
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
function clear(cm) {
|
| 66 |
+
var array = cm.state.markedSelection;
|
| 67 |
+
for (var i = 0; i < array.length; ++i) array[i].clear();
|
| 68 |
+
array.length = 0;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
function reset(cm) {
|
| 72 |
+
clear(cm);
|
| 73 |
+
var ranges = cm.listSelections();
|
| 74 |
+
for (var i = 0; i < ranges.length; i++)
|
| 75 |
+
coverRange(cm, ranges[i].from(), ranges[i].to());
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
function update(cm) {
|
| 79 |
+
if (!cm.somethingSelected()) return clear(cm);
|
| 80 |
+
if (cm.listSelections().length > 1) return reset(cm);
|
| 81 |
+
|
| 82 |
+
var from = cm.getCursor("start"), to = cm.getCursor("end");
|
| 83 |
+
|
| 84 |
+
var array = cm.state.markedSelection;
|
| 85 |
+
if (!array.length) return coverRange(cm, from, to);
|
| 86 |
+
|
| 87 |
+
var coverStart = array[0].find(), coverEnd = array[array.length - 1].find();
|
| 88 |
+
if (!coverStart || !coverEnd || to.line - from.line < CHUNK_SIZE ||
|
| 89 |
+
cmp(from, coverEnd.to) >= 0 || cmp(to, coverStart.from) <= 0)
|
| 90 |
+
return reset(cm);
|
| 91 |
+
|
| 92 |
+
while (cmp(from, coverStart.from) > 0) {
|
| 93 |
+
array.shift().clear();
|
| 94 |
+
coverStart = array[0].find();
|
| 95 |
+
}
|
| 96 |
+
if (cmp(from, coverStart.from) < 0) {
|
| 97 |
+
if (coverStart.to.line - from.line < CHUNK_SIZE) {
|
| 98 |
+
array.shift().clear();
|
| 99 |
+
coverRange(cm, from, coverStart.to, 0);
|
| 100 |
+
} else {
|
| 101 |
+
coverRange(cm, from, coverStart.from, 0);
|
| 102 |
+
}
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
while (cmp(to, coverEnd.to) < 0) {
|
| 106 |
+
array.pop().clear();
|
| 107 |
+
coverEnd = array[array.length - 1].find();
|
| 108 |
+
}
|
| 109 |
+
if (cmp(to, coverEnd.to) > 0) {
|
| 110 |
+
if (to.line - coverEnd.from.line < CHUNK_SIZE) {
|
| 111 |
+
array.pop().clear();
|
| 112 |
+
coverRange(cm, coverEnd.from, to);
|
| 113 |
+
} else {
|
| 114 |
+
coverRange(cm, coverEnd.to, to);
|
| 115 |
+
}
|
| 116 |
+
}
|
| 117 |
+
}
|
| 118 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/selection/selection-pointer.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
"use strict";
|
| 13 |
+
|
| 14 |
+
CodeMirror.defineOption("selectionPointer", false, function(cm, val) {
|
| 15 |
+
var data = cm.state.selectionPointer;
|
| 16 |
+
if (data) {
|
| 17 |
+
CodeMirror.off(cm.getWrapperElement(), "mousemove", data.mousemove);
|
| 18 |
+
CodeMirror.off(cm.getWrapperElement(), "mouseout", data.mouseout);
|
| 19 |
+
CodeMirror.off(window, "scroll", data.windowScroll);
|
| 20 |
+
cm.off("cursorActivity", reset);
|
| 21 |
+
cm.off("scroll", reset);
|
| 22 |
+
cm.state.selectionPointer = null;
|
| 23 |
+
cm.display.lineDiv.style.cursor = "";
|
| 24 |
+
}
|
| 25 |
+
if (val) {
|
| 26 |
+
data = cm.state.selectionPointer = {
|
| 27 |
+
value: typeof val == "string" ? val : "default",
|
| 28 |
+
mousemove: function(event) { mousemove(cm, event); },
|
| 29 |
+
mouseout: function(event) { mouseout(cm, event); },
|
| 30 |
+
windowScroll: function() { reset(cm); },
|
| 31 |
+
rects: null,
|
| 32 |
+
mouseX: null, mouseY: null,
|
| 33 |
+
willUpdate: false
|
| 34 |
+
};
|
| 35 |
+
CodeMirror.on(cm.getWrapperElement(), "mousemove", data.mousemove);
|
| 36 |
+
CodeMirror.on(cm.getWrapperElement(), "mouseout", data.mouseout);
|
| 37 |
+
CodeMirror.on(window, "scroll", data.windowScroll);
|
| 38 |
+
cm.on("cursorActivity", reset);
|
| 39 |
+
cm.on("scroll", reset);
|
| 40 |
+
}
|
| 41 |
+
});
|
| 42 |
+
|
| 43 |
+
function mousemove(cm, event) {
|
| 44 |
+
var data = cm.state.selectionPointer;
|
| 45 |
+
if (event.buttons == null ? event.which : event.buttons) {
|
| 46 |
+
data.mouseX = data.mouseY = null;
|
| 47 |
+
} else {
|
| 48 |
+
data.mouseX = event.clientX;
|
| 49 |
+
data.mouseY = event.clientY;
|
| 50 |
+
}
|
| 51 |
+
scheduleUpdate(cm);
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
function mouseout(cm, event) {
|
| 55 |
+
if (!cm.getWrapperElement().contains(event.relatedTarget)) {
|
| 56 |
+
var data = cm.state.selectionPointer;
|
| 57 |
+
data.mouseX = data.mouseY = null;
|
| 58 |
+
scheduleUpdate(cm);
|
| 59 |
+
}
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
function reset(cm) {
|
| 63 |
+
cm.state.selectionPointer.rects = null;
|
| 64 |
+
scheduleUpdate(cm);
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
function scheduleUpdate(cm) {
|
| 68 |
+
if (!cm.state.selectionPointer.willUpdate) {
|
| 69 |
+
cm.state.selectionPointer.willUpdate = true;
|
| 70 |
+
setTimeout(function() {
|
| 71 |
+
update(cm);
|
| 72 |
+
cm.state.selectionPointer.willUpdate = false;
|
| 73 |
+
}, 50);
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
function update(cm) {
|
| 78 |
+
var data = cm.state.selectionPointer;
|
| 79 |
+
if (!data) return;
|
| 80 |
+
if (data.rects == null && data.mouseX != null) {
|
| 81 |
+
data.rects = [];
|
| 82 |
+
if (cm.somethingSelected()) {
|
| 83 |
+
for (var sel = cm.display.selectionDiv.firstChild; sel; sel = sel.nextSibling)
|
| 84 |
+
data.rects.push(sel.getBoundingClientRect());
|
| 85 |
+
}
|
| 86 |
+
}
|
| 87 |
+
var inside = false;
|
| 88 |
+
if (data.mouseX != null) for (var i = 0; i < data.rects.length; i++) {
|
| 89 |
+
var rect = data.rects[i];
|
| 90 |
+
if (rect.left <= data.mouseX && rect.right >= data.mouseX &&
|
| 91 |
+
rect.top <= data.mouseY && rect.bottom >= data.mouseY)
|
| 92 |
+
inside = true;
|
| 93 |
+
}
|
| 94 |
+
var cursor = inside ? data.value : "";
|
| 95 |
+
if (cm.display.lineDiv.style.cursor != cursor)
|
| 96 |
+
cm.display.lineDiv.style.cursor = cursor;
|
| 97 |
+
}
|
| 98 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/tern/tern.css
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.CodeMirror-Tern-completion {
|
| 2 |
+
padding-left: 22px;
|
| 3 |
+
position: relative;
|
| 4 |
+
}
|
| 5 |
+
.CodeMirror-Tern-completion:before {
|
| 6 |
+
position: absolute;
|
| 7 |
+
left: 2px;
|
| 8 |
+
bottom: 2px;
|
| 9 |
+
border-radius: 50%;
|
| 10 |
+
font-size: 12px;
|
| 11 |
+
font-weight: bold;
|
| 12 |
+
height: 15px;
|
| 13 |
+
width: 15px;
|
| 14 |
+
line-height: 16px;
|
| 15 |
+
text-align: center;
|
| 16 |
+
color: white;
|
| 17 |
+
-moz-box-sizing: border-box;
|
| 18 |
+
box-sizing: border-box;
|
| 19 |
+
}
|
| 20 |
+
.CodeMirror-Tern-completion-unknown:before {
|
| 21 |
+
content: "?";
|
| 22 |
+
background: #4bb;
|
| 23 |
+
}
|
| 24 |
+
.CodeMirror-Tern-completion-object:before {
|
| 25 |
+
content: "O";
|
| 26 |
+
background: #77c;
|
| 27 |
+
}
|
| 28 |
+
.CodeMirror-Tern-completion-fn:before {
|
| 29 |
+
content: "F";
|
| 30 |
+
background: #7c7;
|
| 31 |
+
}
|
| 32 |
+
.CodeMirror-Tern-completion-array:before {
|
| 33 |
+
content: "A";
|
| 34 |
+
background: #c66;
|
| 35 |
+
}
|
| 36 |
+
.CodeMirror-Tern-completion-number:before {
|
| 37 |
+
content: "1";
|
| 38 |
+
background: #999;
|
| 39 |
+
}
|
| 40 |
+
.CodeMirror-Tern-completion-string:before {
|
| 41 |
+
content: "S";
|
| 42 |
+
background: #999;
|
| 43 |
+
}
|
| 44 |
+
.CodeMirror-Tern-completion-bool:before {
|
| 45 |
+
content: "B";
|
| 46 |
+
background: #999;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
.CodeMirror-Tern-completion-guess {
|
| 50 |
+
color: #999;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.CodeMirror-Tern-tooltip {
|
| 54 |
+
border: 1px solid silver;
|
| 55 |
+
border-radius: 3px;
|
| 56 |
+
color: #444;
|
| 57 |
+
padding: 2px 5px;
|
| 58 |
+
font-size: 90%;
|
| 59 |
+
font-family: monospace;
|
| 60 |
+
background-color: white;
|
| 61 |
+
white-space: pre-wrap;
|
| 62 |
+
|
| 63 |
+
max-width: 40em;
|
| 64 |
+
position: absolute;
|
| 65 |
+
z-index: 10;
|
| 66 |
+
-webkit-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
|
| 67 |
+
-moz-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
|
| 68 |
+
box-shadow: 2px 3px 5px rgba(0,0,0,.2);
|
| 69 |
+
|
| 70 |
+
transition: opacity 1s;
|
| 71 |
+
-moz-transition: opacity 1s;
|
| 72 |
+
-webkit-transition: opacity 1s;
|
| 73 |
+
-o-transition: opacity 1s;
|
| 74 |
+
-ms-transition: opacity 1s;
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
.CodeMirror-Tern-hint-doc {
|
| 78 |
+
max-width: 25em;
|
| 79 |
+
margin-top: -3px;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
.CodeMirror-Tern-fname { color: black; }
|
| 83 |
+
.CodeMirror-Tern-farg { color: #70a; }
|
| 84 |
+
.CodeMirror-Tern-farg-current { text-decoration: underline; }
|
| 85 |
+
.CodeMirror-Tern-type { color: #07c; }
|
| 86 |
+
.CodeMirror-Tern-fhint-guess { opacity: .7; }
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/tern/tern.js
ADDED
|
@@ -0,0 +1,697 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
// Glue code between CodeMirror and Tern.
|
| 5 |
+
//
|
| 6 |
+
// Create a CodeMirror.TernServer to wrap an actual Tern server,
|
| 7 |
+
// register open documents (CodeMirror.Doc instances) with it, and
|
| 8 |
+
// call its methods to activate the assisting functions that Tern
|
| 9 |
+
// provides.
|
| 10 |
+
//
|
| 11 |
+
// Options supported (all optional):
|
| 12 |
+
// * defs: An array of JSON definition data structures.
|
| 13 |
+
// * plugins: An object mapping plugin names to configuration
|
| 14 |
+
// options.
|
| 15 |
+
// * getFile: A function(name, c) that can be used to access files in
|
| 16 |
+
// the project that haven't been loaded yet. Simply do c(null) to
|
| 17 |
+
// indicate that a file is not available.
|
| 18 |
+
// * fileFilter: A function(value, docName, doc) that will be applied
|
| 19 |
+
// to documents before passing them on to Tern.
|
| 20 |
+
// * switchToDoc: A function(name, doc) that should, when providing a
|
| 21 |
+
// multi-file view, switch the view or focus to the named file.
|
| 22 |
+
// * showError: A function(editor, message) that can be used to
|
| 23 |
+
// override the way errors are displayed.
|
| 24 |
+
// * completionTip: Customize the content in tooltips for completions.
|
| 25 |
+
// Is passed a single argument—the completion's data as returned by
|
| 26 |
+
// Tern—and may return a string, DOM node, or null to indicate that
|
| 27 |
+
// no tip should be shown. By default the docstring is shown.
|
| 28 |
+
// * typeTip: Like completionTip, but for the tooltips shown for type
|
| 29 |
+
// queries.
|
| 30 |
+
// * responseFilter: A function(doc, query, request, error, data) that
|
| 31 |
+
// will be applied to the Tern responses before treating them
|
| 32 |
+
//
|
| 33 |
+
//
|
| 34 |
+
// It is possible to run the Tern server in a web worker by specifying
|
| 35 |
+
// these additional options:
|
| 36 |
+
// * useWorker: Set to true to enable web worker mode. You'll probably
|
| 37 |
+
// want to feature detect the actual value you use here, for example
|
| 38 |
+
// !!window.Worker.
|
| 39 |
+
// * workerScript: The main script of the worker. Point this to
|
| 40 |
+
// wherever you are hosting worker.js from this directory.
|
| 41 |
+
// * workerDeps: An array of paths pointing (relative to workerScript)
|
| 42 |
+
// to the Acorn and Tern libraries and any Tern plugins you want to
|
| 43 |
+
// load. Or, if you minified those into a single script and included
|
| 44 |
+
// them in the workerScript, simply leave this undefined.
|
| 45 |
+
|
| 46 |
+
(function(mod) {
|
| 47 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 48 |
+
mod(require("../../lib/codemirror"));
|
| 49 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 50 |
+
define(["../../lib/codemirror"], mod);
|
| 51 |
+
else // Plain browser env
|
| 52 |
+
mod(CodeMirror);
|
| 53 |
+
})(function(CodeMirror) {
|
| 54 |
+
"use strict";
|
| 55 |
+
// declare global: tern
|
| 56 |
+
|
| 57 |
+
CodeMirror.TernServer = function(options) {
|
| 58 |
+
var self = this;
|
| 59 |
+
this.options = options || {};
|
| 60 |
+
var plugins = this.options.plugins || (this.options.plugins = {});
|
| 61 |
+
if (!plugins.doc_comment) plugins.doc_comment = true;
|
| 62 |
+
if (this.options.useWorker) {
|
| 63 |
+
this.server = new WorkerServer(this);
|
| 64 |
+
} else {
|
| 65 |
+
this.server = new tern.Server({
|
| 66 |
+
getFile: function(name, c) { return getFile(self, name, c); },
|
| 67 |
+
async: true,
|
| 68 |
+
defs: this.options.defs || [],
|
| 69 |
+
plugins: plugins
|
| 70 |
+
});
|
| 71 |
+
}
|
| 72 |
+
this.docs = Object.create(null);
|
| 73 |
+
this.trackChange = function(doc, change) { trackChange(self, doc, change); };
|
| 74 |
+
|
| 75 |
+
this.cachedArgHints = null;
|
| 76 |
+
this.activeArgHints = null;
|
| 77 |
+
this.jumpStack = [];
|
| 78 |
+
|
| 79 |
+
this.getHint = function(cm, c) { return hint(self, cm, c); };
|
| 80 |
+
this.getHint.async = true;
|
| 81 |
+
};
|
| 82 |
+
|
| 83 |
+
CodeMirror.TernServer.prototype = {
|
| 84 |
+
addDoc: function(name, doc) {
|
| 85 |
+
var data = {doc: doc, name: name, changed: null};
|
| 86 |
+
this.server.addFile(name, docValue(this, data));
|
| 87 |
+
CodeMirror.on(doc, "change", this.trackChange);
|
| 88 |
+
return this.docs[name] = data;
|
| 89 |
+
},
|
| 90 |
+
|
| 91 |
+
delDoc: function(id) {
|
| 92 |
+
var found = resolveDoc(this, id);
|
| 93 |
+
if (!found) return;
|
| 94 |
+
CodeMirror.off(found.doc, "change", this.trackChange);
|
| 95 |
+
delete this.docs[found.name];
|
| 96 |
+
this.server.delFile(found.name);
|
| 97 |
+
},
|
| 98 |
+
|
| 99 |
+
hideDoc: function(id) {
|
| 100 |
+
closeArgHints(this);
|
| 101 |
+
var found = resolveDoc(this, id);
|
| 102 |
+
if (found && found.changed) sendDoc(this, found);
|
| 103 |
+
},
|
| 104 |
+
|
| 105 |
+
complete: function(cm) {
|
| 106 |
+
cm.showHint({hint: this.getHint});
|
| 107 |
+
},
|
| 108 |
+
|
| 109 |
+
showType: function(cm, pos, c) { showContextInfo(this, cm, pos, "type", c); },
|
| 110 |
+
|
| 111 |
+
showDocs: function(cm, pos, c) { showContextInfo(this, cm, pos, "documentation", c); },
|
| 112 |
+
|
| 113 |
+
updateArgHints: function(cm) { updateArgHints(this, cm); },
|
| 114 |
+
|
| 115 |
+
jumpToDef: function(cm) { jumpToDef(this, cm); },
|
| 116 |
+
|
| 117 |
+
jumpBack: function(cm) { jumpBack(this, cm); },
|
| 118 |
+
|
| 119 |
+
rename: function(cm) { rename(this, cm); },
|
| 120 |
+
|
| 121 |
+
selectName: function(cm) { selectName(this, cm); },
|
| 122 |
+
|
| 123 |
+
request: function (cm, query, c, pos) {
|
| 124 |
+
var self = this;
|
| 125 |
+
var doc = findDoc(this, cm.getDoc());
|
| 126 |
+
var request = buildRequest(this, doc, query, pos);
|
| 127 |
+
|
| 128 |
+
this.server.request(request, function (error, data) {
|
| 129 |
+
if (!error && self.options.responseFilter)
|
| 130 |
+
data = self.options.responseFilter(doc, query, request, error, data);
|
| 131 |
+
c(error, data);
|
| 132 |
+
});
|
| 133 |
+
},
|
| 134 |
+
|
| 135 |
+
destroy: function () {
|
| 136 |
+
if (this.worker) {
|
| 137 |
+
this.worker.terminate();
|
| 138 |
+
this.worker = null;
|
| 139 |
+
}
|
| 140 |
+
}
|
| 141 |
+
};
|
| 142 |
+
|
| 143 |
+
var Pos = CodeMirror.Pos;
|
| 144 |
+
var cls = "CodeMirror-Tern-";
|
| 145 |
+
var bigDoc = 250;
|
| 146 |
+
|
| 147 |
+
function getFile(ts, name, c) {
|
| 148 |
+
var buf = ts.docs[name];
|
| 149 |
+
if (buf)
|
| 150 |
+
c(docValue(ts, buf));
|
| 151 |
+
else if (ts.options.getFile)
|
| 152 |
+
ts.options.getFile(name, c);
|
| 153 |
+
else
|
| 154 |
+
c(null);
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
function findDoc(ts, doc, name) {
|
| 158 |
+
for (var n in ts.docs) {
|
| 159 |
+
var cur = ts.docs[n];
|
| 160 |
+
if (cur.doc == doc) return cur;
|
| 161 |
+
}
|
| 162 |
+
if (!name) for (var i = 0;; ++i) {
|
| 163 |
+
n = "[doc" + (i || "") + "]";
|
| 164 |
+
if (!ts.docs[n]) { name = n; break; }
|
| 165 |
+
}
|
| 166 |
+
return ts.addDoc(name, doc);
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
function resolveDoc(ts, id) {
|
| 170 |
+
if (typeof id == "string") return ts.docs[id];
|
| 171 |
+
if (id instanceof CodeMirror) id = id.getDoc();
|
| 172 |
+
if (id instanceof CodeMirror.Doc) return findDoc(ts, id);
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
function trackChange(ts, doc, change) {
|
| 176 |
+
var data = findDoc(ts, doc);
|
| 177 |
+
|
| 178 |
+
var argHints = ts.cachedArgHints;
|
| 179 |
+
if (argHints && argHints.doc == doc && cmpPos(argHints.start, change.to) <= 0)
|
| 180 |
+
ts.cachedArgHints = null;
|
| 181 |
+
|
| 182 |
+
var changed = data.changed;
|
| 183 |
+
if (changed == null)
|
| 184 |
+
data.changed = changed = {from: change.from.line, to: change.from.line};
|
| 185 |
+
var end = change.from.line + (change.text.length - 1);
|
| 186 |
+
if (change.from.line < changed.to) changed.to = changed.to - (change.to.line - end);
|
| 187 |
+
if (end >= changed.to) changed.to = end + 1;
|
| 188 |
+
if (changed.from > change.from.line) changed.from = change.from.line;
|
| 189 |
+
|
| 190 |
+
if (doc.lineCount() > bigDoc && change.to - changed.from > 100) setTimeout(function() {
|
| 191 |
+
if (data.changed && data.changed.to - data.changed.from > 100) sendDoc(ts, data);
|
| 192 |
+
}, 200);
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
function sendDoc(ts, doc) {
|
| 196 |
+
ts.server.request({files: [{type: "full", name: doc.name, text: docValue(ts, doc)}]}, function(error) {
|
| 197 |
+
if (error) window.console.error(error);
|
| 198 |
+
else doc.changed = null;
|
| 199 |
+
});
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
// Completion
|
| 203 |
+
|
| 204 |
+
function hint(ts, cm, c) {
|
| 205 |
+
ts.request(cm, {type: "completions", types: true, docs: true, urls: true}, function(error, data) {
|
| 206 |
+
if (error) return showError(ts, cm, error);
|
| 207 |
+
var completions = [], after = "";
|
| 208 |
+
var from = data.start, to = data.end;
|
| 209 |
+
if (cm.getRange(Pos(from.line, from.ch - 2), from) == "[\"" &&
|
| 210 |
+
cm.getRange(to, Pos(to.line, to.ch + 2)) != "\"]")
|
| 211 |
+
after = "\"]";
|
| 212 |
+
|
| 213 |
+
for (var i = 0; i < data.completions.length; ++i) {
|
| 214 |
+
var completion = data.completions[i], className = typeToIcon(completion.type);
|
| 215 |
+
if (data.guess) className += " " + cls + "guess";
|
| 216 |
+
completions.push({text: completion.name + after,
|
| 217 |
+
displayText: completion.name,
|
| 218 |
+
className: className,
|
| 219 |
+
data: completion});
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
var obj = {from: from, to: to, list: completions};
|
| 223 |
+
var tooltip = null;
|
| 224 |
+
CodeMirror.on(obj, "close", function() { remove(tooltip); });
|
| 225 |
+
CodeMirror.on(obj, "update", function() { remove(tooltip); });
|
| 226 |
+
CodeMirror.on(obj, "select", function(cur, node) {
|
| 227 |
+
remove(tooltip);
|
| 228 |
+
var content = ts.options.completionTip ? ts.options.completionTip(cur.data) : cur.data.doc;
|
| 229 |
+
if (content) {
|
| 230 |
+
tooltip = makeTooltip(node.parentNode.getBoundingClientRect().right + window.pageXOffset,
|
| 231 |
+
node.getBoundingClientRect().top + window.pageYOffset, content);
|
| 232 |
+
tooltip.className += " " + cls + "hint-doc";
|
| 233 |
+
}
|
| 234 |
+
});
|
| 235 |
+
c(obj);
|
| 236 |
+
});
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
function typeToIcon(type) {
|
| 240 |
+
var suffix;
|
| 241 |
+
if (type == "?") suffix = "unknown";
|
| 242 |
+
else if (type == "number" || type == "string" || type == "bool") suffix = type;
|
| 243 |
+
else if (/^fn\(/.test(type)) suffix = "fn";
|
| 244 |
+
else if (/^\[/.test(type)) suffix = "array";
|
| 245 |
+
else suffix = "object";
|
| 246 |
+
return cls + "completion " + cls + "completion-" + suffix;
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
// Type queries
|
| 250 |
+
|
| 251 |
+
function showContextInfo(ts, cm, pos, queryName, c) {
|
| 252 |
+
ts.request(cm, queryName, function(error, data) {
|
| 253 |
+
if (error) return showError(ts, cm, error);
|
| 254 |
+
if (ts.options.typeTip) {
|
| 255 |
+
var tip = ts.options.typeTip(data);
|
| 256 |
+
} else {
|
| 257 |
+
var tip = elt("span", null, elt("strong", null, data.type || "not found"));
|
| 258 |
+
if (data.doc)
|
| 259 |
+
tip.appendChild(document.createTextNode(" — " + data.doc));
|
| 260 |
+
if (data.url) {
|
| 261 |
+
tip.appendChild(document.createTextNode(" "));
|
| 262 |
+
var child = tip.appendChild(elt("a", null, "[docs]"));
|
| 263 |
+
child.href = data.url;
|
| 264 |
+
child.target = "_blank";
|
| 265 |
+
}
|
| 266 |
+
}
|
| 267 |
+
tempTooltip(cm, tip);
|
| 268 |
+
if (c) c();
|
| 269 |
+
}, pos);
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
// Maintaining argument hints
|
| 273 |
+
|
| 274 |
+
function updateArgHints(ts, cm) {
|
| 275 |
+
closeArgHints(ts);
|
| 276 |
+
|
| 277 |
+
if (cm.somethingSelected()) return;
|
| 278 |
+
var state = cm.getTokenAt(cm.getCursor()).state;
|
| 279 |
+
var inner = CodeMirror.innerMode(cm.getMode(), state);
|
| 280 |
+
if (inner.mode.name != "javascript") return;
|
| 281 |
+
var lex = inner.state.lexical;
|
| 282 |
+
if (lex.info != "call") return;
|
| 283 |
+
|
| 284 |
+
var ch, argPos = lex.pos || 0, tabSize = cm.getOption("tabSize");
|
| 285 |
+
for (var line = cm.getCursor().line, e = Math.max(0, line - 9), found = false; line >= e; --line) {
|
| 286 |
+
var str = cm.getLine(line), extra = 0;
|
| 287 |
+
for (var pos = 0;;) {
|
| 288 |
+
var tab = str.indexOf("\t", pos);
|
| 289 |
+
if (tab == -1) break;
|
| 290 |
+
extra += tabSize - (tab + extra) % tabSize - 1;
|
| 291 |
+
pos = tab + 1;
|
| 292 |
+
}
|
| 293 |
+
ch = lex.column - extra;
|
| 294 |
+
if (str.charAt(ch) == "(") {found = true; break;}
|
| 295 |
+
}
|
| 296 |
+
if (!found) return;
|
| 297 |
+
|
| 298 |
+
var start = Pos(line, ch);
|
| 299 |
+
var cache = ts.cachedArgHints;
|
| 300 |
+
if (cache && cache.doc == cm.getDoc() && cmpPos(start, cache.start) == 0)
|
| 301 |
+
return showArgHints(ts, cm, argPos);
|
| 302 |
+
|
| 303 |
+
ts.request(cm, {type: "type", preferFunction: true, end: start}, function(error, data) {
|
| 304 |
+
if (error || !data.type || !(/^fn\(/).test(data.type)) return;
|
| 305 |
+
ts.cachedArgHints = {
|
| 306 |
+
start: pos,
|
| 307 |
+
type: parseFnType(data.type),
|
| 308 |
+
name: data.exprName || data.name || "fn",
|
| 309 |
+
guess: data.guess,
|
| 310 |
+
doc: cm.getDoc()
|
| 311 |
+
};
|
| 312 |
+
showArgHints(ts, cm, argPos);
|
| 313 |
+
});
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
function showArgHints(ts, cm, pos) {
|
| 317 |
+
closeArgHints(ts);
|
| 318 |
+
|
| 319 |
+
var cache = ts.cachedArgHints, tp = cache.type;
|
| 320 |
+
var tip = elt("span", cache.guess ? cls + "fhint-guess" : null,
|
| 321 |
+
elt("span", cls + "fname", cache.name), "(");
|
| 322 |
+
for (var i = 0; i < tp.args.length; ++i) {
|
| 323 |
+
if (i) tip.appendChild(document.createTextNode(", "));
|
| 324 |
+
var arg = tp.args[i];
|
| 325 |
+
tip.appendChild(elt("span", cls + "farg" + (i == pos ? " " + cls + "farg-current" : ""), arg.name || "?"));
|
| 326 |
+
if (arg.type != "?") {
|
| 327 |
+
tip.appendChild(document.createTextNode(":\u00a0"));
|
| 328 |
+
tip.appendChild(elt("span", cls + "type", arg.type));
|
| 329 |
+
}
|
| 330 |
+
}
|
| 331 |
+
tip.appendChild(document.createTextNode(tp.rettype ? ") ->\u00a0" : ")"));
|
| 332 |
+
if (tp.rettype) tip.appendChild(elt("span", cls + "type", tp.rettype));
|
| 333 |
+
var place = cm.cursorCoords(null, "page");
|
| 334 |
+
ts.activeArgHints = makeTooltip(place.right + 1, place.bottom, tip);
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
function parseFnType(text) {
|
| 338 |
+
var args = [], pos = 3;
|
| 339 |
+
|
| 340 |
+
function skipMatching(upto) {
|
| 341 |
+
var depth = 0, start = pos;
|
| 342 |
+
for (;;) {
|
| 343 |
+
var next = text.charAt(pos);
|
| 344 |
+
if (upto.test(next) && !depth) return text.slice(start, pos);
|
| 345 |
+
if (/[{\[\(]/.test(next)) ++depth;
|
| 346 |
+
else if (/[}\]\)]/.test(next)) --depth;
|
| 347 |
+
++pos;
|
| 348 |
+
}
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
// Parse arguments
|
| 352 |
+
if (text.charAt(pos) != ")") for (;;) {
|
| 353 |
+
var name = text.slice(pos).match(/^([^, \(\[\{]+): /);
|
| 354 |
+
if (name) {
|
| 355 |
+
pos += name[0].length;
|
| 356 |
+
name = name[1];
|
| 357 |
+
}
|
| 358 |
+
args.push({name: name, type: skipMatching(/[\),]/)});
|
| 359 |
+
if (text.charAt(pos) == ")") break;
|
| 360 |
+
pos += 2;
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
var rettype = text.slice(pos).match(/^\) -> (.*)$/);
|
| 364 |
+
|
| 365 |
+
return {args: args, rettype: rettype && rettype[1]};
|
| 366 |
+
}
|
| 367 |
+
|
| 368 |
+
// Moving to the definition of something
|
| 369 |
+
|
| 370 |
+
function jumpToDef(ts, cm) {
|
| 371 |
+
function inner(varName) {
|
| 372 |
+
var req = {type: "definition", variable: varName || null};
|
| 373 |
+
var doc = findDoc(ts, cm.getDoc());
|
| 374 |
+
ts.server.request(buildRequest(ts, doc, req), function(error, data) {
|
| 375 |
+
if (error) return showError(ts, cm, error);
|
| 376 |
+
if (!data.file && data.url) { window.open(data.url); return; }
|
| 377 |
+
|
| 378 |
+
if (data.file) {
|
| 379 |
+
var localDoc = ts.docs[data.file], found;
|
| 380 |
+
if (localDoc && (found = findContext(localDoc.doc, data))) {
|
| 381 |
+
ts.jumpStack.push({file: doc.name,
|
| 382 |
+
start: cm.getCursor("from"),
|
| 383 |
+
end: cm.getCursor("to")});
|
| 384 |
+
moveTo(ts, doc, localDoc, found.start, found.end);
|
| 385 |
+
return;
|
| 386 |
+
}
|
| 387 |
+
}
|
| 388 |
+
showError(ts, cm, "Could not find a definition.");
|
| 389 |
+
});
|
| 390 |
+
}
|
| 391 |
+
|
| 392 |
+
if (!atInterestingExpression(cm))
|
| 393 |
+
dialog(cm, "Jump to variable", function(name) { if (name) inner(name); });
|
| 394 |
+
else
|
| 395 |
+
inner();
|
| 396 |
+
}
|
| 397 |
+
|
| 398 |
+
function jumpBack(ts, cm) {
|
| 399 |
+
var pos = ts.jumpStack.pop(), doc = pos && ts.docs[pos.file];
|
| 400 |
+
if (!doc) return;
|
| 401 |
+
moveTo(ts, findDoc(ts, cm.getDoc()), doc, pos.start, pos.end);
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
function moveTo(ts, curDoc, doc, start, end) {
|
| 405 |
+
doc.doc.setSelection(start, end);
|
| 406 |
+
if (curDoc != doc && ts.options.switchToDoc) {
|
| 407 |
+
closeArgHints(ts);
|
| 408 |
+
ts.options.switchToDoc(doc.name, doc.doc);
|
| 409 |
+
}
|
| 410 |
+
}
|
| 411 |
+
|
| 412 |
+
// The {line,ch} representation of positions makes this rather awkward.
|
| 413 |
+
function findContext(doc, data) {
|
| 414 |
+
var before = data.context.slice(0, data.contextOffset).split("\n");
|
| 415 |
+
var startLine = data.start.line - (before.length - 1);
|
| 416 |
+
var start = Pos(startLine, (before.length == 1 ? data.start.ch : doc.getLine(startLine).length) - before[0].length);
|
| 417 |
+
|
| 418 |
+
var text = doc.getLine(startLine).slice(start.ch);
|
| 419 |
+
for (var cur = startLine + 1; cur < doc.lineCount() && text.length < data.context.length; ++cur)
|
| 420 |
+
text += "\n" + doc.getLine(cur);
|
| 421 |
+
if (text.slice(0, data.context.length) == data.context) return data;
|
| 422 |
+
|
| 423 |
+
var cursor = doc.getSearchCursor(data.context, 0, false);
|
| 424 |
+
var nearest, nearestDist = Infinity;
|
| 425 |
+
while (cursor.findNext()) {
|
| 426 |
+
var from = cursor.from(), dist = Math.abs(from.line - start.line) * 10000;
|
| 427 |
+
if (!dist) dist = Math.abs(from.ch - start.ch);
|
| 428 |
+
if (dist < nearestDist) { nearest = from; nearestDist = dist; }
|
| 429 |
+
}
|
| 430 |
+
if (!nearest) return null;
|
| 431 |
+
|
| 432 |
+
if (before.length == 1)
|
| 433 |
+
nearest.ch += before[0].length;
|
| 434 |
+
else
|
| 435 |
+
nearest = Pos(nearest.line + (before.length - 1), before[before.length - 1].length);
|
| 436 |
+
if (data.start.line == data.end.line)
|
| 437 |
+
var end = Pos(nearest.line, nearest.ch + (data.end.ch - data.start.ch));
|
| 438 |
+
else
|
| 439 |
+
var end = Pos(nearest.line + (data.end.line - data.start.line), data.end.ch);
|
| 440 |
+
return {start: nearest, end: end};
|
| 441 |
+
}
|
| 442 |
+
|
| 443 |
+
function atInterestingExpression(cm) {
|
| 444 |
+
var pos = cm.getCursor("end"), tok = cm.getTokenAt(pos);
|
| 445 |
+
if (tok.start < pos.ch && (tok.type == "comment" || tok.type == "string")) return false;
|
| 446 |
+
return /[\w)\]]/.test(cm.getLine(pos.line).slice(Math.max(pos.ch - 1, 0), pos.ch + 1));
|
| 447 |
+
}
|
| 448 |
+
|
| 449 |
+
// Variable renaming
|
| 450 |
+
|
| 451 |
+
function rename(ts, cm) {
|
| 452 |
+
var token = cm.getTokenAt(cm.getCursor());
|
| 453 |
+
if (!/\w/.test(token.string)) return showError(ts, cm, "Not at a variable");
|
| 454 |
+
dialog(cm, "New name for " + token.string, function(newName) {
|
| 455 |
+
ts.request(cm, {type: "rename", newName: newName, fullDocs: true}, function(error, data) {
|
| 456 |
+
if (error) return showError(ts, cm, error);
|
| 457 |
+
applyChanges(ts, data.changes);
|
| 458 |
+
});
|
| 459 |
+
});
|
| 460 |
+
}
|
| 461 |
+
|
| 462 |
+
function selectName(ts, cm) {
|
| 463 |
+
var name = findDoc(ts, cm.doc).name;
|
| 464 |
+
ts.request(cm, {type: "refs"}, function(error, data) {
|
| 465 |
+
if (error) return showError(ts, cm, error);
|
| 466 |
+
var ranges = [], cur = 0;
|
| 467 |
+
for (var i = 0; i < data.refs.length; i++) {
|
| 468 |
+
var ref = data.refs[i];
|
| 469 |
+
if (ref.file == name) {
|
| 470 |
+
ranges.push({anchor: ref.start, head: ref.end});
|
| 471 |
+
if (cmpPos(cur, ref.start) >= 0 && cmpPos(cur, ref.end) <= 0)
|
| 472 |
+
cur = ranges.length - 1;
|
| 473 |
+
}
|
| 474 |
+
}
|
| 475 |
+
cm.setSelections(ranges, cur);
|
| 476 |
+
});
|
| 477 |
+
}
|
| 478 |
+
|
| 479 |
+
var nextChangeOrig = 0;
|
| 480 |
+
function applyChanges(ts, changes) {
|
| 481 |
+
var perFile = Object.create(null);
|
| 482 |
+
for (var i = 0; i < changes.length; ++i) {
|
| 483 |
+
var ch = changes[i];
|
| 484 |
+
(perFile[ch.file] || (perFile[ch.file] = [])).push(ch);
|
| 485 |
+
}
|
| 486 |
+
for (var file in perFile) {
|
| 487 |
+
var known = ts.docs[file], chs = perFile[file];;
|
| 488 |
+
if (!known) continue;
|
| 489 |
+
chs.sort(function(a, b) { return cmpPos(b.start, a.start); });
|
| 490 |
+
var origin = "*rename" + (++nextChangeOrig);
|
| 491 |
+
for (var i = 0; i < chs.length; ++i) {
|
| 492 |
+
var ch = chs[i];
|
| 493 |
+
known.doc.replaceRange(ch.text, ch.start, ch.end, origin);
|
| 494 |
+
}
|
| 495 |
+
}
|
| 496 |
+
}
|
| 497 |
+
|
| 498 |
+
// Generic request-building helper
|
| 499 |
+
|
| 500 |
+
function buildRequest(ts, doc, query, pos) {
|
| 501 |
+
var files = [], offsetLines = 0, allowFragments = !query.fullDocs;
|
| 502 |
+
if (!allowFragments) delete query.fullDocs;
|
| 503 |
+
if (typeof query == "string") query = {type: query};
|
| 504 |
+
query.lineCharPositions = true;
|
| 505 |
+
if (query.end == null) {
|
| 506 |
+
query.end = pos || doc.doc.getCursor("end");
|
| 507 |
+
if (doc.doc.somethingSelected())
|
| 508 |
+
query.start = doc.doc.getCursor("start");
|
| 509 |
+
}
|
| 510 |
+
var startPos = query.start || query.end;
|
| 511 |
+
|
| 512 |
+
if (doc.changed) {
|
| 513 |
+
if (doc.doc.lineCount() > bigDoc && allowFragments !== false &&
|
| 514 |
+
doc.changed.to - doc.changed.from < 100 &&
|
| 515 |
+
doc.changed.from <= startPos.line && doc.changed.to > query.end.line) {
|
| 516 |
+
files.push(getFragmentAround(doc, startPos, query.end));
|
| 517 |
+
query.file = "#0";
|
| 518 |
+
var offsetLines = files[0].offsetLines;
|
| 519 |
+
if (query.start != null) query.start = Pos(query.start.line - -offsetLines, query.start.ch);
|
| 520 |
+
query.end = Pos(query.end.line - offsetLines, query.end.ch);
|
| 521 |
+
} else {
|
| 522 |
+
files.push({type: "full",
|
| 523 |
+
name: doc.name,
|
| 524 |
+
text: docValue(ts, doc)});
|
| 525 |
+
query.file = doc.name;
|
| 526 |
+
doc.changed = null;
|
| 527 |
+
}
|
| 528 |
+
} else {
|
| 529 |
+
query.file = doc.name;
|
| 530 |
+
}
|
| 531 |
+
for (var name in ts.docs) {
|
| 532 |
+
var cur = ts.docs[name];
|
| 533 |
+
if (cur.changed && cur != doc) {
|
| 534 |
+
files.push({type: "full", name: cur.name, text: docValue(ts, cur)});
|
| 535 |
+
cur.changed = null;
|
| 536 |
+
}
|
| 537 |
+
}
|
| 538 |
+
|
| 539 |
+
return {query: query, files: files};
|
| 540 |
+
}
|
| 541 |
+
|
| 542 |
+
function getFragmentAround(data, start, end) {
|
| 543 |
+
var doc = data.doc;
|
| 544 |
+
var minIndent = null, minLine = null, endLine, tabSize = 4;
|
| 545 |
+
for (var p = start.line - 1, min = Math.max(0, p - 50); p >= min; --p) {
|
| 546 |
+
var line = doc.getLine(p), fn = line.search(/\bfunction\b/);
|
| 547 |
+
if (fn < 0) continue;
|
| 548 |
+
var indent = CodeMirror.countColumn(line, null, tabSize);
|
| 549 |
+
if (minIndent != null && minIndent <= indent) continue;
|
| 550 |
+
minIndent = indent;
|
| 551 |
+
minLine = p;
|
| 552 |
+
}
|
| 553 |
+
if (minLine == null) minLine = min;
|
| 554 |
+
var max = Math.min(doc.lastLine(), end.line + 20);
|
| 555 |
+
if (minIndent == null || minIndent == CodeMirror.countColumn(doc.getLine(start.line), null, tabSize))
|
| 556 |
+
endLine = max;
|
| 557 |
+
else for (endLine = end.line + 1; endLine < max; ++endLine) {
|
| 558 |
+
var indent = CodeMirror.countColumn(doc.getLine(endLine), null, tabSize);
|
| 559 |
+
if (indent <= minIndent) break;
|
| 560 |
+
}
|
| 561 |
+
var from = Pos(minLine, 0);
|
| 562 |
+
|
| 563 |
+
return {type: "part",
|
| 564 |
+
name: data.name,
|
| 565 |
+
offsetLines: from.line,
|
| 566 |
+
text: doc.getRange(from, Pos(endLine, 0))};
|
| 567 |
+
}
|
| 568 |
+
|
| 569 |
+
// Generic utilities
|
| 570 |
+
|
| 571 |
+
var cmpPos = CodeMirror.cmpPos;
|
| 572 |
+
|
| 573 |
+
function elt(tagname, cls /*, ... elts*/) {
|
| 574 |
+
var e = document.createElement(tagname);
|
| 575 |
+
if (cls) e.className = cls;
|
| 576 |
+
for (var i = 2; i < arguments.length; ++i) {
|
| 577 |
+
var elt = arguments[i];
|
| 578 |
+
if (typeof elt == "string") elt = document.createTextNode(elt);
|
| 579 |
+
e.appendChild(elt);
|
| 580 |
+
}
|
| 581 |
+
return e;
|
| 582 |
+
}
|
| 583 |
+
|
| 584 |
+
function dialog(cm, text, f) {
|
| 585 |
+
if (cm.openDialog)
|
| 586 |
+
cm.openDialog(text + ": <input type=text>", f);
|
| 587 |
+
else
|
| 588 |
+
f(prompt(text, ""));
|
| 589 |
+
}
|
| 590 |
+
|
| 591 |
+
// Tooltips
|
| 592 |
+
|
| 593 |
+
function tempTooltip(cm, content) {
|
| 594 |
+
if (cm.state.ternTooltip) remove(cm.state.ternTooltip);
|
| 595 |
+
var where = cm.cursorCoords();
|
| 596 |
+
var tip = cm.state.ternTooltip = makeTooltip(where.right + 1, where.bottom, content);
|
| 597 |
+
function maybeClear() {
|
| 598 |
+
old = true;
|
| 599 |
+
if (!mouseOnTip) clear();
|
| 600 |
+
}
|
| 601 |
+
function clear() {
|
| 602 |
+
cm.state.ternTooltip = null;
|
| 603 |
+
if (!tip.parentNode) return;
|
| 604 |
+
cm.off("cursorActivity", clear);
|
| 605 |
+
cm.off('blur', clear);
|
| 606 |
+
cm.off('scroll', clear);
|
| 607 |
+
fadeOut(tip);
|
| 608 |
+
}
|
| 609 |
+
var mouseOnTip = false, old = false;
|
| 610 |
+
CodeMirror.on(tip, "mousemove", function() { mouseOnTip = true; });
|
| 611 |
+
CodeMirror.on(tip, "mouseout", function(e) {
|
| 612 |
+
if (!CodeMirror.contains(tip, e.relatedTarget || e.toElement)) {
|
| 613 |
+
if (old) clear();
|
| 614 |
+
else mouseOnTip = false;
|
| 615 |
+
}
|
| 616 |
+
});
|
| 617 |
+
setTimeout(maybeClear, 1700);
|
| 618 |
+
cm.on("cursorActivity", clear);
|
| 619 |
+
cm.on('blur', clear);
|
| 620 |
+
cm.on('scroll', clear);
|
| 621 |
+
}
|
| 622 |
+
|
| 623 |
+
function makeTooltip(x, y, content) {
|
| 624 |
+
var node = elt("div", cls + "tooltip", content);
|
| 625 |
+
node.style.left = x + "px";
|
| 626 |
+
node.style.top = y + "px";
|
| 627 |
+
document.body.appendChild(node);
|
| 628 |
+
return node;
|
| 629 |
+
}
|
| 630 |
+
|
| 631 |
+
function remove(node) {
|
| 632 |
+
var p = node && node.parentNode;
|
| 633 |
+
if (p) p.removeChild(node);
|
| 634 |
+
}
|
| 635 |
+
|
| 636 |
+
function fadeOut(tooltip) {
|
| 637 |
+
tooltip.style.opacity = "0";
|
| 638 |
+
setTimeout(function() { remove(tooltip); }, 1100);
|
| 639 |
+
}
|
| 640 |
+
|
| 641 |
+
function showError(ts, cm, msg) {
|
| 642 |
+
if (ts.options.showError)
|
| 643 |
+
ts.options.showError(cm, msg);
|
| 644 |
+
else
|
| 645 |
+
tempTooltip(cm, String(msg));
|
| 646 |
+
}
|
| 647 |
+
|
| 648 |
+
function closeArgHints(ts) {
|
| 649 |
+
if (ts.activeArgHints) { remove(ts.activeArgHints); ts.activeArgHints = null; }
|
| 650 |
+
}
|
| 651 |
+
|
| 652 |
+
function docValue(ts, doc) {
|
| 653 |
+
var val = doc.doc.getValue();
|
| 654 |
+
if (ts.options.fileFilter) val = ts.options.fileFilter(val, doc.name, doc.doc);
|
| 655 |
+
return val;
|
| 656 |
+
}
|
| 657 |
+
|
| 658 |
+
// Worker wrapper
|
| 659 |
+
|
| 660 |
+
function WorkerServer(ts) {
|
| 661 |
+
var worker = ts.worker = new Worker(ts.options.workerScript);
|
| 662 |
+
worker.postMessage({type: "init",
|
| 663 |
+
defs: ts.options.defs,
|
| 664 |
+
plugins: ts.options.plugins,
|
| 665 |
+
scripts: ts.options.workerDeps});
|
| 666 |
+
var msgId = 0, pending = {};
|
| 667 |
+
|
| 668 |
+
function send(data, c) {
|
| 669 |
+
if (c) {
|
| 670 |
+
data.id = ++msgId;
|
| 671 |
+
pending[msgId] = c;
|
| 672 |
+
}
|
| 673 |
+
worker.postMessage(data);
|
| 674 |
+
}
|
| 675 |
+
worker.onmessage = function(e) {
|
| 676 |
+
var data = e.data;
|
| 677 |
+
if (data.type == "getFile") {
|
| 678 |
+
getFile(ts, data.name, function(err, text) {
|
| 679 |
+
send({type: "getFile", err: String(err), text: text, id: data.id});
|
| 680 |
+
});
|
| 681 |
+
} else if (data.type == "debug") {
|
| 682 |
+
window.console.log(data.message);
|
| 683 |
+
} else if (data.id && pending[data.id]) {
|
| 684 |
+
pending[data.id](data.err, data.body);
|
| 685 |
+
delete pending[data.id];
|
| 686 |
+
}
|
| 687 |
+
};
|
| 688 |
+
worker.onerror = function(e) {
|
| 689 |
+
for (var id in pending) pending[id](e);
|
| 690 |
+
pending = {};
|
| 691 |
+
};
|
| 692 |
+
|
| 693 |
+
this.addFile = function(name, text) { send({type: "add", name: name, text: text}); };
|
| 694 |
+
this.delFile = function(name) { send({type: "del", name: name}); };
|
| 695 |
+
this.request = function(body, c) { send({type: "req", body: body}, c); };
|
| 696 |
+
}
|
| 697 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/tern/worker.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
// declare global: tern, server
|
| 5 |
+
|
| 6 |
+
var server;
|
| 7 |
+
|
| 8 |
+
this.onmessage = function(e) {
|
| 9 |
+
var data = e.data;
|
| 10 |
+
switch (data.type) {
|
| 11 |
+
case "init": return startServer(data.defs, data.plugins, data.scripts);
|
| 12 |
+
case "add": return server.addFile(data.name, data.text);
|
| 13 |
+
case "del": return server.delFile(data.name);
|
| 14 |
+
case "req": return server.request(data.body, function(err, reqData) {
|
| 15 |
+
postMessage({id: data.id, body: reqData, err: err && String(err)});
|
| 16 |
+
});
|
| 17 |
+
case "getFile":
|
| 18 |
+
var c = pending[data.id];
|
| 19 |
+
delete pending[data.id];
|
| 20 |
+
return c(data.err, data.text);
|
| 21 |
+
default: throw new Error("Unknown message type: " + data.type);
|
| 22 |
+
}
|
| 23 |
+
};
|
| 24 |
+
|
| 25 |
+
var nextId = 0, pending = {};
|
| 26 |
+
function getFile(file, c) {
|
| 27 |
+
postMessage({type: "getFile", name: file, id: ++nextId});
|
| 28 |
+
pending[nextId] = c;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
function startServer(defs, plugins, scripts) {
|
| 32 |
+
if (scripts) importScripts.apply(null, scripts);
|
| 33 |
+
|
| 34 |
+
server = new tern.Server({
|
| 35 |
+
getFile: getFile,
|
| 36 |
+
async: true,
|
| 37 |
+
defs: defs,
|
| 38 |
+
plugins: plugins
|
| 39 |
+
});
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
this.console = {
|
| 43 |
+
log: function(v) { postMessage({type: "debug", message: v}); }
|
| 44 |
+
};
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/addon/wrap/hardwrap.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
"use strict";
|
| 13 |
+
|
| 14 |
+
var Pos = CodeMirror.Pos;
|
| 15 |
+
|
| 16 |
+
function findParagraph(cm, pos, options) {
|
| 17 |
+
var startRE = options.paragraphStart || cm.getHelper(pos, "paragraphStart");
|
| 18 |
+
for (var start = pos.line, first = cm.firstLine(); start > first; --start) {
|
| 19 |
+
var line = cm.getLine(start);
|
| 20 |
+
if (startRE && startRE.test(line)) break;
|
| 21 |
+
if (!/\S/.test(line)) { ++start; break; }
|
| 22 |
+
}
|
| 23 |
+
var endRE = options.paragraphEnd || cm.getHelper(pos, "paragraphEnd");
|
| 24 |
+
for (var end = pos.line + 1, last = cm.lastLine(); end <= last; ++end) {
|
| 25 |
+
var line = cm.getLine(end);
|
| 26 |
+
if (endRE && endRE.test(line)) { ++end; break; }
|
| 27 |
+
if (!/\S/.test(line)) break;
|
| 28 |
+
}
|
| 29 |
+
return {from: start, to: end};
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
function findBreakPoint(text, column, wrapOn, killTrailingSpace) {
|
| 33 |
+
for (var at = column; at > 0; --at)
|
| 34 |
+
if (wrapOn.test(text.slice(at - 1, at + 1))) break;
|
| 35 |
+
if (at == 0) at = column;
|
| 36 |
+
var endOfText = at;
|
| 37 |
+
if (killTrailingSpace)
|
| 38 |
+
while (text.charAt(endOfText - 1) == " ") --endOfText;
|
| 39 |
+
return {from: endOfText, to: at};
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
function wrapRange(cm, from, to, options) {
|
| 43 |
+
from = cm.clipPos(from); to = cm.clipPos(to);
|
| 44 |
+
var column = options.column || 80;
|
| 45 |
+
var wrapOn = options.wrapOn || /\s\S|-[^\.\d]/;
|
| 46 |
+
var killTrailing = options.killTrailingSpace !== false;
|
| 47 |
+
var changes = [], curLine = "", curNo = from.line;
|
| 48 |
+
var lines = cm.getRange(from, to, false);
|
| 49 |
+
if (!lines.length) return null;
|
| 50 |
+
var leadingSpace = lines[0].match(/^[ \t]*/)[0];
|
| 51 |
+
|
| 52 |
+
for (var i = 0; i < lines.length; ++i) {
|
| 53 |
+
var text = lines[i], oldLen = curLine.length, spaceInserted = 0;
|
| 54 |
+
if (curLine && text && !wrapOn.test(curLine.charAt(curLine.length - 1) + text.charAt(0))) {
|
| 55 |
+
curLine += " ";
|
| 56 |
+
spaceInserted = 1;
|
| 57 |
+
}
|
| 58 |
+
var spaceTrimmed = "";
|
| 59 |
+
if (i) {
|
| 60 |
+
spaceTrimmed = text.match(/^\s*/)[0];
|
| 61 |
+
text = text.slice(spaceTrimmed.length);
|
| 62 |
+
}
|
| 63 |
+
curLine += text;
|
| 64 |
+
if (i) {
|
| 65 |
+
var firstBreak = curLine.length > column && leadingSpace == spaceTrimmed &&
|
| 66 |
+
findBreakPoint(curLine, column, wrapOn, killTrailing);
|
| 67 |
+
// If this isn't broken, or is broken at a different point, remove old break
|
| 68 |
+
if (!firstBreak || firstBreak.from != oldLen || firstBreak.to != oldLen + spaceInserted) {
|
| 69 |
+
changes.push({text: [spaceInserted ? " " : ""],
|
| 70 |
+
from: Pos(curNo, oldLen),
|
| 71 |
+
to: Pos(curNo + 1, spaceTrimmed.length)});
|
| 72 |
+
} else {
|
| 73 |
+
curLine = leadingSpace + text;
|
| 74 |
+
++curNo;
|
| 75 |
+
}
|
| 76 |
+
}
|
| 77 |
+
while (curLine.length > column) {
|
| 78 |
+
var bp = findBreakPoint(curLine, column, wrapOn, killTrailing);
|
| 79 |
+
changes.push({text: ["", leadingSpace],
|
| 80 |
+
from: Pos(curNo, bp.from),
|
| 81 |
+
to: Pos(curNo, bp.to)});
|
| 82 |
+
curLine = leadingSpace + curLine.slice(bp.to);
|
| 83 |
+
++curNo;
|
| 84 |
+
}
|
| 85 |
+
}
|
| 86 |
+
if (changes.length) cm.operation(function() {
|
| 87 |
+
for (var i = 0; i < changes.length; ++i) {
|
| 88 |
+
var change = changes[i];
|
| 89 |
+
cm.replaceRange(change.text, change.from, change.to);
|
| 90 |
+
}
|
| 91 |
+
});
|
| 92 |
+
return changes.length ? {from: changes[0].from, to: CodeMirror.changeEnd(changes[changes.length - 1])} : null;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
CodeMirror.defineExtension("wrapParagraph", function(pos, options) {
|
| 96 |
+
options = options || {};
|
| 97 |
+
if (!pos) pos = this.getCursor();
|
| 98 |
+
var para = findParagraph(this, pos, options);
|
| 99 |
+
return wrapRange(this, Pos(para.from, 0), Pos(para.to - 1), options);
|
| 100 |
+
});
|
| 101 |
+
|
| 102 |
+
CodeMirror.commands.wrapLines = function(cm) {
|
| 103 |
+
cm.operation(function() {
|
| 104 |
+
var ranges = cm.listSelections(), at = cm.lastLine() + 1;
|
| 105 |
+
for (var i = ranges.length - 1; i >= 0; i--) {
|
| 106 |
+
var range = ranges[i], span;
|
| 107 |
+
if (range.empty()) {
|
| 108 |
+
var para = findParagraph(cm, range.head, {});
|
| 109 |
+
span = {from: Pos(para.from, 0), to: Pos(para.to - 1)};
|
| 110 |
+
} else {
|
| 111 |
+
span = {from: range.from(), to: range.to()};
|
| 112 |
+
}
|
| 113 |
+
if (span.to.line >= at) continue;
|
| 114 |
+
at = span.from.line;
|
| 115 |
+
wrapRange(cm, span.from, span.to, {});
|
| 116 |
+
}
|
| 117 |
+
});
|
| 118 |
+
};
|
| 119 |
+
|
| 120 |
+
CodeMirror.defineExtension("wrapRange", function(from, to, options) {
|
| 121 |
+
return wrapRange(this, from, to, options || {});
|
| 122 |
+
});
|
| 123 |
+
|
| 124 |
+
CodeMirror.defineExtension("wrapParagraphsInRange", function(from, to, options) {
|
| 125 |
+
options = options || {};
|
| 126 |
+
var cm = this, paras = [];
|
| 127 |
+
for (var line = from.line; line <= to.line;) {
|
| 128 |
+
var para = findParagraph(cm, Pos(line, 0), options);
|
| 129 |
+
paras.push(para);
|
| 130 |
+
line = para.to;
|
| 131 |
+
}
|
| 132 |
+
var madeChange = false;
|
| 133 |
+
if (paras.length) cm.operation(function() {
|
| 134 |
+
for (var i = paras.length - 1; i >= 0; --i)
|
| 135 |
+
madeChange = madeChange || wrapRange(cm, Pos(paras[i].from, 0), Pos(paras[i].to - 1), options);
|
| 136 |
+
});
|
| 137 |
+
return madeChange;
|
| 138 |
+
});
|
| 139 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/keymap/emacs.js
ADDED
|
@@ -0,0 +1,412 @@
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../lib/codemirror"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../lib/codemirror"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
"use strict";
|
| 13 |
+
|
| 14 |
+
var Pos = CodeMirror.Pos;
|
| 15 |
+
function posEq(a, b) { return a.line == b.line && a.ch == b.ch; }
|
| 16 |
+
|
| 17 |
+
// Kill 'ring'
|
| 18 |
+
|
| 19 |
+
var killRing = [];
|
| 20 |
+
function addToRing(str) {
|
| 21 |
+
killRing.push(str);
|
| 22 |
+
if (killRing.length > 50) killRing.shift();
|
| 23 |
+
}
|
| 24 |
+
function growRingTop(str) {
|
| 25 |
+
if (!killRing.length) return addToRing(str);
|
| 26 |
+
killRing[killRing.length - 1] += str;
|
| 27 |
+
}
|
| 28 |
+
function getFromRing(n) { return killRing[killRing.length - (n ? Math.min(n, 1) : 1)] || ""; }
|
| 29 |
+
function popFromRing() { if (killRing.length > 1) killRing.pop(); return getFromRing(); }
|
| 30 |
+
|
| 31 |
+
var lastKill = null;
|
| 32 |
+
|
| 33 |
+
function kill(cm, from, to, mayGrow, text) {
|
| 34 |
+
if (text == null) text = cm.getRange(from, to);
|
| 35 |
+
|
| 36 |
+
if (mayGrow && lastKill && lastKill.cm == cm && posEq(from, lastKill.pos) && cm.isClean(lastKill.gen))
|
| 37 |
+
growRingTop(text);
|
| 38 |
+
else
|
| 39 |
+
addToRing(text);
|
| 40 |
+
cm.replaceRange("", from, to, "+delete");
|
| 41 |
+
|
| 42 |
+
if (mayGrow) lastKill = {cm: cm, pos: from, gen: cm.changeGeneration()};
|
| 43 |
+
else lastKill = null;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
// Boundaries of various units
|
| 47 |
+
|
| 48 |
+
function byChar(cm, pos, dir) {
|
| 49 |
+
return cm.findPosH(pos, dir, "char", true);
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
function byWord(cm, pos, dir) {
|
| 53 |
+
return cm.findPosH(pos, dir, "word", true);
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
function byLine(cm, pos, dir) {
|
| 57 |
+
return cm.findPosV(pos, dir, "line", cm.doc.sel.goalColumn);
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
function byPage(cm, pos, dir) {
|
| 61 |
+
return cm.findPosV(pos, dir, "page", cm.doc.sel.goalColumn);
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
function byParagraph(cm, pos, dir) {
|
| 65 |
+
var no = pos.line, line = cm.getLine(no);
|
| 66 |
+
var sawText = /\S/.test(dir < 0 ? line.slice(0, pos.ch) : line.slice(pos.ch));
|
| 67 |
+
var fst = cm.firstLine(), lst = cm.lastLine();
|
| 68 |
+
for (;;) {
|
| 69 |
+
no += dir;
|
| 70 |
+
if (no < fst || no > lst)
|
| 71 |
+
return cm.clipPos(Pos(no - dir, dir < 0 ? 0 : null));
|
| 72 |
+
line = cm.getLine(no);
|
| 73 |
+
var hasText = /\S/.test(line);
|
| 74 |
+
if (hasText) sawText = true;
|
| 75 |
+
else if (sawText) return Pos(no, 0);
|
| 76 |
+
}
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
function bySentence(cm, pos, dir) {
|
| 80 |
+
var line = pos.line, ch = pos.ch;
|
| 81 |
+
var text = cm.getLine(pos.line), sawWord = false;
|
| 82 |
+
for (;;) {
|
| 83 |
+
var next = text.charAt(ch + (dir < 0 ? -1 : 0));
|
| 84 |
+
if (!next) { // End/beginning of line reached
|
| 85 |
+
if (line == (dir < 0 ? cm.firstLine() : cm.lastLine())) return Pos(line, ch);
|
| 86 |
+
text = cm.getLine(line + dir);
|
| 87 |
+
if (!/\S/.test(text)) return Pos(line, ch);
|
| 88 |
+
line += dir;
|
| 89 |
+
ch = dir < 0 ? text.length : 0;
|
| 90 |
+
continue;
|
| 91 |
+
}
|
| 92 |
+
if (sawWord && /[!?.]/.test(next)) return Pos(line, ch + (dir > 0 ? 1 : 0));
|
| 93 |
+
if (!sawWord) sawWord = /\w/.test(next);
|
| 94 |
+
ch += dir;
|
| 95 |
+
}
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
function byExpr(cm, pos, dir) {
|
| 99 |
+
var wrap;
|
| 100 |
+
if (cm.findMatchingBracket && (wrap = cm.findMatchingBracket(pos, true))
|
| 101 |
+
&& wrap.match && (wrap.forward ? 1 : -1) == dir)
|
| 102 |
+
return dir > 0 ? Pos(wrap.to.line, wrap.to.ch + 1) : wrap.to;
|
| 103 |
+
|
| 104 |
+
for (var first = true;; first = false) {
|
| 105 |
+
var token = cm.getTokenAt(pos);
|
| 106 |
+
var after = Pos(pos.line, dir < 0 ? token.start : token.end);
|
| 107 |
+
if (first && dir > 0 && token.end == pos.ch || !/\w/.test(token.string)) {
|
| 108 |
+
var newPos = cm.findPosH(after, dir, "char");
|
| 109 |
+
if (posEq(after, newPos)) return pos;
|
| 110 |
+
else pos = newPos;
|
| 111 |
+
} else {
|
| 112 |
+
return after;
|
| 113 |
+
}
|
| 114 |
+
}
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
// Prefixes (only crudely supported)
|
| 118 |
+
|
| 119 |
+
function getPrefix(cm, precise) {
|
| 120 |
+
var digits = cm.state.emacsPrefix;
|
| 121 |
+
if (!digits) return precise ? null : 1;
|
| 122 |
+
clearPrefix(cm);
|
| 123 |
+
return digits == "-" ? -1 : Number(digits);
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
function repeated(cmd) {
|
| 127 |
+
var f = typeof cmd == "string" ? function(cm) { cm.execCommand(cmd); } : cmd;
|
| 128 |
+
return function(cm) {
|
| 129 |
+
var prefix = getPrefix(cm);
|
| 130 |
+
f(cm);
|
| 131 |
+
for (var i = 1; i < prefix; ++i) f(cm);
|
| 132 |
+
};
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
function findEnd(cm, pos, by, dir) {
|
| 136 |
+
var prefix = getPrefix(cm);
|
| 137 |
+
if (prefix < 0) { dir = -dir; prefix = -prefix; }
|
| 138 |
+
for (var i = 0; i < prefix; ++i) {
|
| 139 |
+
var newPos = by(cm, pos, dir);
|
| 140 |
+
if (posEq(newPos, pos)) break;
|
| 141 |
+
pos = newPos;
|
| 142 |
+
}
|
| 143 |
+
return pos;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
function move(by, dir) {
|
| 147 |
+
var f = function(cm) {
|
| 148 |
+
cm.extendSelection(findEnd(cm, cm.getCursor(), by, dir));
|
| 149 |
+
};
|
| 150 |
+
f.motion = true;
|
| 151 |
+
return f;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
function killTo(cm, by, dir) {
|
| 155 |
+
var selections = cm.listSelections(), cursor;
|
| 156 |
+
var i = selections.length;
|
| 157 |
+
while (i--) {
|
| 158 |
+
cursor = selections[i].head;
|
| 159 |
+
kill(cm, cursor, findEnd(cm, cursor, by, dir), true);
|
| 160 |
+
}
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
function killRegion(cm) {
|
| 164 |
+
if (cm.somethingSelected()) {
|
| 165 |
+
var selections = cm.listSelections(), selection;
|
| 166 |
+
var i = selections.length;
|
| 167 |
+
while (i--) {
|
| 168 |
+
selection = selections[i];
|
| 169 |
+
kill(cm, selection.anchor, selection.head);
|
| 170 |
+
}
|
| 171 |
+
return true;
|
| 172 |
+
}
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
function addPrefix(cm, digit) {
|
| 176 |
+
if (cm.state.emacsPrefix) {
|
| 177 |
+
if (digit != "-") cm.state.emacsPrefix += digit;
|
| 178 |
+
return;
|
| 179 |
+
}
|
| 180 |
+
// Not active yet
|
| 181 |
+
cm.state.emacsPrefix = digit;
|
| 182 |
+
cm.on("keyHandled", maybeClearPrefix);
|
| 183 |
+
cm.on("inputRead", maybeDuplicateInput);
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
var prefixPreservingKeys = {"Alt-G": true, "Ctrl-X": true, "Ctrl-Q": true, "Ctrl-U": true};
|
| 187 |
+
|
| 188 |
+
function maybeClearPrefix(cm, arg) {
|
| 189 |
+
if (!cm.state.emacsPrefixMap && !prefixPreservingKeys.hasOwnProperty(arg))
|
| 190 |
+
clearPrefix(cm);
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
function clearPrefix(cm) {
|
| 194 |
+
cm.state.emacsPrefix = null;
|
| 195 |
+
cm.off("keyHandled", maybeClearPrefix);
|
| 196 |
+
cm.off("inputRead", maybeDuplicateInput);
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
function maybeDuplicateInput(cm, event) {
|
| 200 |
+
var dup = getPrefix(cm);
|
| 201 |
+
if (dup > 1 && event.origin == "+input") {
|
| 202 |
+
var one = event.text.join("\n"), txt = "";
|
| 203 |
+
for (var i = 1; i < dup; ++i) txt += one;
|
| 204 |
+
cm.replaceSelection(txt);
|
| 205 |
+
}
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
function addPrefixMap(cm) {
|
| 209 |
+
cm.state.emacsPrefixMap = true;
|
| 210 |
+
cm.addKeyMap(prefixMap);
|
| 211 |
+
cm.on("keyHandled", maybeRemovePrefixMap);
|
| 212 |
+
cm.on("inputRead", maybeRemovePrefixMap);
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
function maybeRemovePrefixMap(cm, arg) {
|
| 216 |
+
if (typeof arg == "string" && (/^\d$/.test(arg) || arg == "Ctrl-U")) return;
|
| 217 |
+
cm.removeKeyMap(prefixMap);
|
| 218 |
+
cm.state.emacsPrefixMap = false;
|
| 219 |
+
cm.off("keyHandled", maybeRemovePrefixMap);
|
| 220 |
+
cm.off("inputRead", maybeRemovePrefixMap);
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
// Utilities
|
| 224 |
+
|
| 225 |
+
function setMark(cm) {
|
| 226 |
+
cm.setCursor(cm.getCursor());
|
| 227 |
+
cm.setExtending(!cm.getExtending());
|
| 228 |
+
cm.on("change", function() { cm.setExtending(false); });
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
function clearMark(cm) {
|
| 232 |
+
cm.setExtending(false);
|
| 233 |
+
cm.setCursor(cm.getCursor());
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
function getInput(cm, msg, f) {
|
| 237 |
+
if (cm.openDialog)
|
| 238 |
+
cm.openDialog(msg + ": <input type=\"text\" style=\"width: 10em\"/>", f, {bottom: true});
|
| 239 |
+
else
|
| 240 |
+
f(prompt(msg, ""));
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
function operateOnWord(cm, op) {
|
| 244 |
+
var start = cm.getCursor(), end = cm.findPosH(start, 1, "word");
|
| 245 |
+
cm.replaceRange(op(cm.getRange(start, end)), start, end);
|
| 246 |
+
cm.setCursor(end);
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
function toEnclosingExpr(cm) {
|
| 250 |
+
var pos = cm.getCursor(), line = pos.line, ch = pos.ch;
|
| 251 |
+
var stack = [];
|
| 252 |
+
while (line >= cm.firstLine()) {
|
| 253 |
+
var text = cm.getLine(line);
|
| 254 |
+
for (var i = ch == null ? text.length : ch; i > 0;) {
|
| 255 |
+
var ch = text.charAt(--i);
|
| 256 |
+
if (ch == ")")
|
| 257 |
+
stack.push("(");
|
| 258 |
+
else if (ch == "]")
|
| 259 |
+
stack.push("[");
|
| 260 |
+
else if (ch == "}")
|
| 261 |
+
stack.push("{");
|
| 262 |
+
else if (/[\(\{\[]/.test(ch) && (!stack.length || stack.pop() != ch))
|
| 263 |
+
return cm.extendSelection(Pos(line, i));
|
| 264 |
+
}
|
| 265 |
+
--line; ch = null;
|
| 266 |
+
}
|
| 267 |
+
}
|
| 268 |
+
|
| 269 |
+
function quit(cm) {
|
| 270 |
+
cm.execCommand("clearSearch");
|
| 271 |
+
clearMark(cm);
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
// Actual keymap
|
| 275 |
+
|
| 276 |
+
var keyMap = CodeMirror.keyMap.emacs = CodeMirror.normalizeKeyMap({
|
| 277 |
+
"Ctrl-W": function(cm) {kill(cm, cm.getCursor("start"), cm.getCursor("end"));},
|
| 278 |
+
"Ctrl-K": repeated(function(cm) {
|
| 279 |
+
var start = cm.getCursor(), end = cm.clipPos(Pos(start.line));
|
| 280 |
+
var text = cm.getRange(start, end);
|
| 281 |
+
if (!/\S/.test(text)) {
|
| 282 |
+
text += "\n";
|
| 283 |
+
end = Pos(start.line + 1, 0);
|
| 284 |
+
}
|
| 285 |
+
kill(cm, start, end, true, text);
|
| 286 |
+
}),
|
| 287 |
+
"Alt-W": function(cm) {
|
| 288 |
+
addToRing(cm.getSelection());
|
| 289 |
+
clearMark(cm);
|
| 290 |
+
},
|
| 291 |
+
"Ctrl-Y": function(cm) {
|
| 292 |
+
var start = cm.getCursor();
|
| 293 |
+
cm.replaceRange(getFromRing(getPrefix(cm)), start, start, "paste");
|
| 294 |
+
cm.setSelection(start, cm.getCursor());
|
| 295 |
+
},
|
| 296 |
+
"Alt-Y": function(cm) {cm.replaceSelection(popFromRing(), "around", "paste");},
|
| 297 |
+
|
| 298 |
+
"Ctrl-Space": setMark, "Ctrl-Shift-2": setMark,
|
| 299 |
+
|
| 300 |
+
"Ctrl-F": move(byChar, 1), "Ctrl-B": move(byChar, -1),
|
| 301 |
+
"Right": move(byChar, 1), "Left": move(byChar, -1),
|
| 302 |
+
"Ctrl-D": function(cm) { killTo(cm, byChar, 1); },
|
| 303 |
+
"Delete": function(cm) { killRegion(cm) || killTo(cm, byChar, 1); },
|
| 304 |
+
"Ctrl-H": function(cm) { killTo(cm, byChar, -1); },
|
| 305 |
+
"Backspace": function(cm) { killRegion(cm) || killTo(cm, byChar, -1); },
|
| 306 |
+
|
| 307 |
+
"Alt-F": move(byWord, 1), "Alt-B": move(byWord, -1),
|
| 308 |
+
"Alt-D": function(cm) { killTo(cm, byWord, 1); },
|
| 309 |
+
"Alt-Backspace": function(cm) { killTo(cm, byWord, -1); },
|
| 310 |
+
|
| 311 |
+
"Ctrl-N": move(byLine, 1), "Ctrl-P": move(byLine, -1),
|
| 312 |
+
"Down": move(byLine, 1), "Up": move(byLine, -1),
|
| 313 |
+
"Ctrl-A": "goLineStart", "Ctrl-E": "goLineEnd",
|
| 314 |
+
"End": "goLineEnd", "Home": "goLineStart",
|
| 315 |
+
|
| 316 |
+
"Alt-V": move(byPage, -1), "Ctrl-V": move(byPage, 1),
|
| 317 |
+
"PageUp": move(byPage, -1), "PageDown": move(byPage, 1),
|
| 318 |
+
|
| 319 |
+
"Ctrl-Up": move(byParagraph, -1), "Ctrl-Down": move(byParagraph, 1),
|
| 320 |
+
|
| 321 |
+
"Alt-A": move(bySentence, -1), "Alt-E": move(bySentence, 1),
|
| 322 |
+
"Alt-K": function(cm) { killTo(cm, bySentence, 1); },
|
| 323 |
+
|
| 324 |
+
"Ctrl-Alt-K": function(cm) { killTo(cm, byExpr, 1); },
|
| 325 |
+
"Ctrl-Alt-Backspace": function(cm) { killTo(cm, byExpr, -1); },
|
| 326 |
+
"Ctrl-Alt-F": move(byExpr, 1), "Ctrl-Alt-B": move(byExpr, -1),
|
| 327 |
+
|
| 328 |
+
"Shift-Ctrl-Alt-2": function(cm) {
|
| 329 |
+
var cursor = cm.getCursor();
|
| 330 |
+
cm.setSelection(findEnd(cm, cursor, byExpr, 1), cursor);
|
| 331 |
+
},
|
| 332 |
+
"Ctrl-Alt-T": function(cm) {
|
| 333 |
+
var leftStart = byExpr(cm, cm.getCursor(), -1), leftEnd = byExpr(cm, leftStart, 1);
|
| 334 |
+
var rightEnd = byExpr(cm, leftEnd, 1), rightStart = byExpr(cm, rightEnd, -1);
|
| 335 |
+
cm.replaceRange(cm.getRange(rightStart, rightEnd) + cm.getRange(leftEnd, rightStart) +
|
| 336 |
+
cm.getRange(leftStart, leftEnd), leftStart, rightEnd);
|
| 337 |
+
},
|
| 338 |
+
"Ctrl-Alt-U": repeated(toEnclosingExpr),
|
| 339 |
+
|
| 340 |
+
"Alt-Space": function(cm) {
|
| 341 |
+
var pos = cm.getCursor(), from = pos.ch, to = pos.ch, text = cm.getLine(pos.line);
|
| 342 |
+
while (from && /\s/.test(text.charAt(from - 1))) --from;
|
| 343 |
+
while (to < text.length && /\s/.test(text.charAt(to))) ++to;
|
| 344 |
+
cm.replaceRange(" ", Pos(pos.line, from), Pos(pos.line, to));
|
| 345 |
+
},
|
| 346 |
+
"Ctrl-O": repeated(function(cm) { cm.replaceSelection("\n", "start"); }),
|
| 347 |
+
"Ctrl-T": repeated(function(cm) {
|
| 348 |
+
cm.execCommand("transposeChars");
|
| 349 |
+
}),
|
| 350 |
+
|
| 351 |
+
"Alt-C": repeated(function(cm) {
|
| 352 |
+
operateOnWord(cm, function(w) {
|
| 353 |
+
var letter = w.search(/\w/);
|
| 354 |
+
if (letter == -1) return w;
|
| 355 |
+
return w.slice(0, letter) + w.charAt(letter).toUpperCase() + w.slice(letter + 1).toLowerCase();
|
| 356 |
+
});
|
| 357 |
+
}),
|
| 358 |
+
"Alt-U": repeated(function(cm) {
|
| 359 |
+
operateOnWord(cm, function(w) { return w.toUpperCase(); });
|
| 360 |
+
}),
|
| 361 |
+
"Alt-L": repeated(function(cm) {
|
| 362 |
+
operateOnWord(cm, function(w) { return w.toLowerCase(); });
|
| 363 |
+
}),
|
| 364 |
+
|
| 365 |
+
"Alt-;": "toggleComment",
|
| 366 |
+
|
| 367 |
+
"Ctrl-/": repeated("undo"), "Shift-Ctrl--": repeated("undo"),
|
| 368 |
+
"Ctrl-Z": repeated("undo"), "Cmd-Z": repeated("undo"),
|
| 369 |
+
"Shift-Alt-,": "goDocStart", "Shift-Alt-.": "goDocEnd",
|
| 370 |
+
"Ctrl-S": "findNext", "Ctrl-R": "findPrev", "Ctrl-G": quit, "Shift-Alt-5": "replace",
|
| 371 |
+
"Alt-/": "autocomplete",
|
| 372 |
+
"Ctrl-J": "newlineAndIndent", "Enter": false, "Tab": "indentAuto",
|
| 373 |
+
|
| 374 |
+
"Alt-G G": function(cm) {
|
| 375 |
+
var prefix = getPrefix(cm, true);
|
| 376 |
+
if (prefix != null && prefix > 0) return cm.setCursor(prefix - 1);
|
| 377 |
+
|
| 378 |
+
getInput(cm, "Goto line", function(str) {
|
| 379 |
+
var num;
|
| 380 |
+
if (str && !isNaN(num = Number(str)) && num == num|0 && num > 0)
|
| 381 |
+
cm.setCursor(num - 1);
|
| 382 |
+
});
|
| 383 |
+
},
|
| 384 |
+
|
| 385 |
+
"Ctrl-X Tab": function(cm) {
|
| 386 |
+
cm.indentSelection(getPrefix(cm, true) || cm.getOption("indentUnit"));
|
| 387 |
+
},
|
| 388 |
+
"Ctrl-X Ctrl-X": function(cm) {
|
| 389 |
+
cm.setSelection(cm.getCursor("head"), cm.getCursor("anchor"));
|
| 390 |
+
},
|
| 391 |
+
"Ctrl-X Ctrl-S": "save",
|
| 392 |
+
"Ctrl-X Ctrl-W": "save",
|
| 393 |
+
"Ctrl-X S": "saveAll",
|
| 394 |
+
"Ctrl-X F": "open",
|
| 395 |
+
"Ctrl-X U": repeated("undo"),
|
| 396 |
+
"Ctrl-X K": "close",
|
| 397 |
+
"Ctrl-X Delete": function(cm) { kill(cm, cm.getCursor(), bySentence(cm, cm.getCursor(), 1), true); },
|
| 398 |
+
"Ctrl-X H": "selectAll",
|
| 399 |
+
|
| 400 |
+
"Ctrl-Q Tab": repeated("insertTab"),
|
| 401 |
+
"Ctrl-U": addPrefixMap
|
| 402 |
+
});
|
| 403 |
+
|
| 404 |
+
var prefixMap = {"Ctrl-G": clearPrefix};
|
| 405 |
+
function regPrefix(d) {
|
| 406 |
+
prefixMap[d] = function(cm) { addPrefix(cm, d); };
|
| 407 |
+
keyMap["Ctrl-" + d] = function(cm) { addPrefix(cm, d); };
|
| 408 |
+
prefixPreservingKeys["Ctrl-" + d] = true;
|
| 409 |
+
}
|
| 410 |
+
for (var i = 0; i < 10; ++i) regPrefix(String(i));
|
| 411 |
+
regPrefix("-");
|
| 412 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/keymap/sublime.js
ADDED
|
@@ -0,0 +1,553 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
// A rough approximation of Sublime Text's keybindings
|
| 5 |
+
// Depends on addon/search/searchcursor.js and optionally addon/dialog/dialogs.js
|
| 6 |
+
|
| 7 |
+
(function(mod) {
|
| 8 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 9 |
+
mod(require("../lib/codemirror"), require("../addon/search/searchcursor"), require("../addon/edit/matchbrackets"));
|
| 10 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 11 |
+
define(["../lib/codemirror", "../addon/search/searchcursor", "../addon/edit/matchbrackets"], mod);
|
| 12 |
+
else // Plain browser env
|
| 13 |
+
mod(CodeMirror);
|
| 14 |
+
})(function(CodeMirror) {
|
| 15 |
+
"use strict";
|
| 16 |
+
|
| 17 |
+
var map = CodeMirror.keyMap.sublime = {fallthrough: "default"};
|
| 18 |
+
var cmds = CodeMirror.commands;
|
| 19 |
+
var Pos = CodeMirror.Pos;
|
| 20 |
+
var mac = CodeMirror.keyMap["default"] == CodeMirror.keyMap.macDefault;
|
| 21 |
+
var ctrl = mac ? "Cmd-" : "Ctrl-";
|
| 22 |
+
|
| 23 |
+
// This is not exactly Sublime's algorithm. I couldn't make heads or tails of that.
|
| 24 |
+
function findPosSubword(doc, start, dir) {
|
| 25 |
+
if (dir < 0 && start.ch == 0) return doc.clipPos(Pos(start.line - 1));
|
| 26 |
+
var line = doc.getLine(start.line);
|
| 27 |
+
if (dir > 0 && start.ch >= line.length) return doc.clipPos(Pos(start.line + 1, 0));
|
| 28 |
+
var state = "start", type;
|
| 29 |
+
for (var pos = start.ch, e = dir < 0 ? 0 : line.length, i = 0; pos != e; pos += dir, i++) {
|
| 30 |
+
var next = line.charAt(dir < 0 ? pos - 1 : pos);
|
| 31 |
+
var cat = next != "_" && CodeMirror.isWordChar(next) ? "w" : "o";
|
| 32 |
+
if (cat == "w" && next.toUpperCase() == next) cat = "W";
|
| 33 |
+
if (state == "start") {
|
| 34 |
+
if (cat != "o") { state = "in"; type = cat; }
|
| 35 |
+
} else if (state == "in") {
|
| 36 |
+
if (type != cat) {
|
| 37 |
+
if (type == "w" && cat == "W" && dir < 0) pos--;
|
| 38 |
+
if (type == "W" && cat == "w" && dir > 0) { type = "w"; continue; }
|
| 39 |
+
break;
|
| 40 |
+
}
|
| 41 |
+
}
|
| 42 |
+
}
|
| 43 |
+
return Pos(start.line, pos);
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
function moveSubword(cm, dir) {
|
| 47 |
+
cm.extendSelectionsBy(function(range) {
|
| 48 |
+
if (cm.display.shift || cm.doc.extend || range.empty())
|
| 49 |
+
return findPosSubword(cm.doc, range.head, dir);
|
| 50 |
+
else
|
| 51 |
+
return dir < 0 ? range.from() : range.to();
|
| 52 |
+
});
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
cmds[map["Alt-Left"] = "goSubwordLeft"] = function(cm) { moveSubword(cm, -1); };
|
| 56 |
+
cmds[map["Alt-Right"] = "goSubwordRight"] = function(cm) { moveSubword(cm, 1); };
|
| 57 |
+
|
| 58 |
+
cmds[map[ctrl + "Up"] = "scrollLineUp"] = function(cm) {
|
| 59 |
+
var info = cm.getScrollInfo();
|
| 60 |
+
if (!cm.somethingSelected()) {
|
| 61 |
+
var visibleBottomLine = cm.lineAtHeight(info.top + info.clientHeight, "local");
|
| 62 |
+
if (cm.getCursor().line >= visibleBottomLine)
|
| 63 |
+
cm.execCommand("goLineUp");
|
| 64 |
+
}
|
| 65 |
+
cm.scrollTo(null, info.top - cm.defaultTextHeight());
|
| 66 |
+
};
|
| 67 |
+
cmds[map[ctrl + "Down"] = "scrollLineDown"] = function(cm) {
|
| 68 |
+
var info = cm.getScrollInfo();
|
| 69 |
+
if (!cm.somethingSelected()) {
|
| 70 |
+
var visibleTopLine = cm.lineAtHeight(info.top, "local")+1;
|
| 71 |
+
if (cm.getCursor().line <= visibleTopLine)
|
| 72 |
+
cm.execCommand("goLineDown");
|
| 73 |
+
}
|
| 74 |
+
cm.scrollTo(null, info.top + cm.defaultTextHeight());
|
| 75 |
+
};
|
| 76 |
+
|
| 77 |
+
cmds[map["Shift-" + ctrl + "L"] = "splitSelectionByLine"] = function(cm) {
|
| 78 |
+
var ranges = cm.listSelections(), lineRanges = [];
|
| 79 |
+
for (var i = 0; i < ranges.length; i++) {
|
| 80 |
+
var from = ranges[i].from(), to = ranges[i].to();
|
| 81 |
+
for (var line = from.line; line <= to.line; ++line)
|
| 82 |
+
if (!(to.line > from.line && line == to.line && to.ch == 0))
|
| 83 |
+
lineRanges.push({anchor: line == from.line ? from : Pos(line, 0),
|
| 84 |
+
head: line == to.line ? to : Pos(line)});
|
| 85 |
+
}
|
| 86 |
+
cm.setSelections(lineRanges, 0);
|
| 87 |
+
};
|
| 88 |
+
|
| 89 |
+
map["Shift-Tab"] = "indentLess";
|
| 90 |
+
|
| 91 |
+
cmds[map["Esc"] = "singleSelectionTop"] = function(cm) {
|
| 92 |
+
var range = cm.listSelections()[0];
|
| 93 |
+
cm.setSelection(range.anchor, range.head, {scroll: false});
|
| 94 |
+
};
|
| 95 |
+
|
| 96 |
+
cmds[map[ctrl + "L"] = "selectLine"] = function(cm) {
|
| 97 |
+
var ranges = cm.listSelections(), extended = [];
|
| 98 |
+
for (var i = 0; i < ranges.length; i++) {
|
| 99 |
+
var range = ranges[i];
|
| 100 |
+
extended.push({anchor: Pos(range.from().line, 0),
|
| 101 |
+
head: Pos(range.to().line + 1, 0)});
|
| 102 |
+
}
|
| 103 |
+
cm.setSelections(extended);
|
| 104 |
+
};
|
| 105 |
+
|
| 106 |
+
map["Shift-" + ctrl + "K"] = "deleteLine";
|
| 107 |
+
|
| 108 |
+
function insertLine(cm, above) {
|
| 109 |
+
cm.operation(function() {
|
| 110 |
+
var len = cm.listSelections().length, newSelection = [], last = -1;
|
| 111 |
+
for (var i = 0; i < len; i++) {
|
| 112 |
+
var head = cm.listSelections()[i].head;
|
| 113 |
+
if (head.line <= last) continue;
|
| 114 |
+
var at = Pos(head.line + (above ? 0 : 1), 0);
|
| 115 |
+
cm.replaceRange("\n", at, null, "+insertLine");
|
| 116 |
+
cm.indentLine(at.line, null, true);
|
| 117 |
+
newSelection.push({head: at, anchor: at});
|
| 118 |
+
last = head.line + 1;
|
| 119 |
+
}
|
| 120 |
+
cm.setSelections(newSelection);
|
| 121 |
+
});
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
cmds[map[ctrl + "Enter"] = "insertLineAfter"] = function(cm) { insertLine(cm, false); };
|
| 125 |
+
|
| 126 |
+
cmds[map["Shift-" + ctrl + "Enter"] = "insertLineBefore"] = function(cm) { insertLine(cm, true); };
|
| 127 |
+
|
| 128 |
+
function wordAt(cm, pos) {
|
| 129 |
+
var start = pos.ch, end = start, line = cm.getLine(pos.line);
|
| 130 |
+
while (start && CodeMirror.isWordChar(line.charAt(start - 1))) --start;
|
| 131 |
+
while (end < line.length && CodeMirror.isWordChar(line.charAt(end))) ++end;
|
| 132 |
+
return {from: Pos(pos.line, start), to: Pos(pos.line, end), word: line.slice(start, end)};
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
cmds[map[ctrl + "D"] = "selectNextOccurrence"] = function(cm) {
|
| 136 |
+
var from = cm.getCursor("from"), to = cm.getCursor("to");
|
| 137 |
+
var fullWord = cm.state.sublimeFindFullWord == cm.doc.sel;
|
| 138 |
+
if (CodeMirror.cmpPos(from, to) == 0) {
|
| 139 |
+
var word = wordAt(cm, from);
|
| 140 |
+
if (!word.word) return;
|
| 141 |
+
cm.setSelection(word.from, word.to);
|
| 142 |
+
fullWord = true;
|
| 143 |
+
} else {
|
| 144 |
+
var text = cm.getRange(from, to);
|
| 145 |
+
var query = fullWord ? new RegExp("\\b" + text + "\\b") : text;
|
| 146 |
+
var cur = cm.getSearchCursor(query, to);
|
| 147 |
+
if (cur.findNext()) {
|
| 148 |
+
cm.addSelection(cur.from(), cur.to());
|
| 149 |
+
} else {
|
| 150 |
+
cur = cm.getSearchCursor(query, Pos(cm.firstLine(), 0));
|
| 151 |
+
if (cur.findNext())
|
| 152 |
+
cm.addSelection(cur.from(), cur.to());
|
| 153 |
+
}
|
| 154 |
+
}
|
| 155 |
+
if (fullWord)
|
| 156 |
+
cm.state.sublimeFindFullWord = cm.doc.sel;
|
| 157 |
+
};
|
| 158 |
+
|
| 159 |
+
var mirror = "(){}[]";
|
| 160 |
+
function selectBetweenBrackets(cm) {
|
| 161 |
+
var pos = cm.getCursor(), opening = cm.scanForBracket(pos, -1);
|
| 162 |
+
if (!opening) return;
|
| 163 |
+
for (;;) {
|
| 164 |
+
var closing = cm.scanForBracket(pos, 1);
|
| 165 |
+
if (!closing) return;
|
| 166 |
+
if (closing.ch == mirror.charAt(mirror.indexOf(opening.ch) + 1)) {
|
| 167 |
+
cm.setSelection(Pos(opening.pos.line, opening.pos.ch + 1), closing.pos, false);
|
| 168 |
+
return true;
|
| 169 |
+
}
|
| 170 |
+
pos = Pos(closing.pos.line, closing.pos.ch + 1);
|
| 171 |
+
}
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
cmds[map["Shift-" + ctrl + "Space"] = "selectScope"] = function(cm) {
|
| 175 |
+
selectBetweenBrackets(cm) || cm.execCommand("selectAll");
|
| 176 |
+
};
|
| 177 |
+
cmds[map["Shift-" + ctrl + "M"] = "selectBetweenBrackets"] = function(cm) {
|
| 178 |
+
if (!selectBetweenBrackets(cm)) return CodeMirror.Pass;
|
| 179 |
+
};
|
| 180 |
+
|
| 181 |
+
cmds[map[ctrl + "M"] = "goToBracket"] = function(cm) {
|
| 182 |
+
cm.extendSelectionsBy(function(range) {
|
| 183 |
+
var next = cm.scanForBracket(range.head, 1);
|
| 184 |
+
if (next && CodeMirror.cmpPos(next.pos, range.head) != 0) return next.pos;
|
| 185 |
+
var prev = cm.scanForBracket(range.head, -1);
|
| 186 |
+
return prev && Pos(prev.pos.line, prev.pos.ch + 1) || range.head;
|
| 187 |
+
});
|
| 188 |
+
};
|
| 189 |
+
|
| 190 |
+
var swapLineCombo = mac ? "Cmd-Ctrl-" : "Shift-Ctrl-";
|
| 191 |
+
|
| 192 |
+
cmds[map[swapLineCombo + "Up"] = "swapLineUp"] = function(cm) {
|
| 193 |
+
var ranges = cm.listSelections(), linesToMove = [], at = cm.firstLine() - 1, newSels = [];
|
| 194 |
+
for (var i = 0; i < ranges.length; i++) {
|
| 195 |
+
var range = ranges[i], from = range.from().line - 1, to = range.to().line;
|
| 196 |
+
newSels.push({anchor: Pos(range.anchor.line - 1, range.anchor.ch),
|
| 197 |
+
head: Pos(range.head.line - 1, range.head.ch)});
|
| 198 |
+
if (range.to().ch == 0 && !range.empty()) --to;
|
| 199 |
+
if (from > at) linesToMove.push(from, to);
|
| 200 |
+
else if (linesToMove.length) linesToMove[linesToMove.length - 1] = to;
|
| 201 |
+
at = to;
|
| 202 |
+
}
|
| 203 |
+
cm.operation(function() {
|
| 204 |
+
for (var i = 0; i < linesToMove.length; i += 2) {
|
| 205 |
+
var from = linesToMove[i], to = linesToMove[i + 1];
|
| 206 |
+
var line = cm.getLine(from);
|
| 207 |
+
cm.replaceRange("", Pos(from, 0), Pos(from + 1, 0), "+swapLine");
|
| 208 |
+
if (to > cm.lastLine())
|
| 209 |
+
cm.replaceRange("\n" + line, Pos(cm.lastLine()), null, "+swapLine");
|
| 210 |
+
else
|
| 211 |
+
cm.replaceRange(line + "\n", Pos(to, 0), null, "+swapLine");
|
| 212 |
+
}
|
| 213 |
+
cm.setSelections(newSels);
|
| 214 |
+
cm.scrollIntoView();
|
| 215 |
+
});
|
| 216 |
+
};
|
| 217 |
+
|
| 218 |
+
cmds[map[swapLineCombo + "Down"] = "swapLineDown"] = function(cm) {
|
| 219 |
+
var ranges = cm.listSelections(), linesToMove = [], at = cm.lastLine() + 1;
|
| 220 |
+
for (var i = ranges.length - 1; i >= 0; i--) {
|
| 221 |
+
var range = ranges[i], from = range.to().line + 1, to = range.from().line;
|
| 222 |
+
if (range.to().ch == 0 && !range.empty()) from--;
|
| 223 |
+
if (from < at) linesToMove.push(from, to);
|
| 224 |
+
else if (linesToMove.length) linesToMove[linesToMove.length - 1] = to;
|
| 225 |
+
at = to;
|
| 226 |
+
}
|
| 227 |
+
cm.operation(function() {
|
| 228 |
+
for (var i = linesToMove.length - 2; i >= 0; i -= 2) {
|
| 229 |
+
var from = linesToMove[i], to = linesToMove[i + 1];
|
| 230 |
+
var line = cm.getLine(from);
|
| 231 |
+
if (from == cm.lastLine())
|
| 232 |
+
cm.replaceRange("", Pos(from - 1), Pos(from), "+swapLine");
|
| 233 |
+
else
|
| 234 |
+
cm.replaceRange("", Pos(from, 0), Pos(from + 1, 0), "+swapLine");
|
| 235 |
+
cm.replaceRange(line + "\n", Pos(to, 0), null, "+swapLine");
|
| 236 |
+
}
|
| 237 |
+
cm.scrollIntoView();
|
| 238 |
+
});
|
| 239 |
+
};
|
| 240 |
+
|
| 241 |
+
map[ctrl + "/"] = "toggleComment";
|
| 242 |
+
|
| 243 |
+
cmds[map[ctrl + "J"] = "joinLines"] = function(cm) {
|
| 244 |
+
var ranges = cm.listSelections(), joined = [];
|
| 245 |
+
for (var i = 0; i < ranges.length; i++) {
|
| 246 |
+
var range = ranges[i], from = range.from();
|
| 247 |
+
var start = from.line, end = range.to().line;
|
| 248 |
+
while (i < ranges.length - 1 && ranges[i + 1].from().line == end)
|
| 249 |
+
end = ranges[++i].to().line;
|
| 250 |
+
joined.push({start: start, end: end, anchor: !range.empty() && from});
|
| 251 |
+
}
|
| 252 |
+
cm.operation(function() {
|
| 253 |
+
var offset = 0, ranges = [];
|
| 254 |
+
for (var i = 0; i < joined.length; i++) {
|
| 255 |
+
var obj = joined[i];
|
| 256 |
+
var anchor = obj.anchor && Pos(obj.anchor.line - offset, obj.anchor.ch), head;
|
| 257 |
+
for (var line = obj.start; line <= obj.end; line++) {
|
| 258 |
+
var actual = line - offset;
|
| 259 |
+
if (line == obj.end) head = Pos(actual, cm.getLine(actual).length + 1);
|
| 260 |
+
if (actual < cm.lastLine()) {
|
| 261 |
+
cm.replaceRange(" ", Pos(actual), Pos(actual + 1, /^\s*/.exec(cm.getLine(actual + 1))[0].length));
|
| 262 |
+
++offset;
|
| 263 |
+
}
|
| 264 |
+
}
|
| 265 |
+
ranges.push({anchor: anchor || head, head: head});
|
| 266 |
+
}
|
| 267 |
+
cm.setSelections(ranges, 0);
|
| 268 |
+
});
|
| 269 |
+
};
|
| 270 |
+
|
| 271 |
+
cmds[map["Shift-" + ctrl + "D"] = "duplicateLine"] = function(cm) {
|
| 272 |
+
cm.operation(function() {
|
| 273 |
+
var rangeCount = cm.listSelections().length;
|
| 274 |
+
for (var i = 0; i < rangeCount; i++) {
|
| 275 |
+
var range = cm.listSelections()[i];
|
| 276 |
+
if (range.empty())
|
| 277 |
+
cm.replaceRange(cm.getLine(range.head.line) + "\n", Pos(range.head.line, 0));
|
| 278 |
+
else
|
| 279 |
+
cm.replaceRange(cm.getRange(range.from(), range.to()), range.from());
|
| 280 |
+
}
|
| 281 |
+
cm.scrollIntoView();
|
| 282 |
+
});
|
| 283 |
+
};
|
| 284 |
+
|
| 285 |
+
map[ctrl + "T"] = "transposeChars";
|
| 286 |
+
|
| 287 |
+
function sortLines(cm, caseSensitive) {
|
| 288 |
+
var ranges = cm.listSelections(), toSort = [], selected;
|
| 289 |
+
for (var i = 0; i < ranges.length; i++) {
|
| 290 |
+
var range = ranges[i];
|
| 291 |
+
if (range.empty()) continue;
|
| 292 |
+
var from = range.from().line, to = range.to().line;
|
| 293 |
+
while (i < ranges.length - 1 && ranges[i + 1].from().line == to)
|
| 294 |
+
to = range[++i].to().line;
|
| 295 |
+
toSort.push(from, to);
|
| 296 |
+
}
|
| 297 |
+
if (toSort.length) selected = true;
|
| 298 |
+
else toSort.push(cm.firstLine(), cm.lastLine());
|
| 299 |
+
|
| 300 |
+
cm.operation(function() {
|
| 301 |
+
var ranges = [];
|
| 302 |
+
for (var i = 0; i < toSort.length; i += 2) {
|
| 303 |
+
var from = toSort[i], to = toSort[i + 1];
|
| 304 |
+
var start = Pos(from, 0), end = Pos(to);
|
| 305 |
+
var lines = cm.getRange(start, end, false);
|
| 306 |
+
if (caseSensitive)
|
| 307 |
+
lines.sort();
|
| 308 |
+
else
|
| 309 |
+
lines.sort(function(a, b) {
|
| 310 |
+
var au = a.toUpperCase(), bu = b.toUpperCase();
|
| 311 |
+
if (au != bu) { a = au; b = bu; }
|
| 312 |
+
return a < b ? -1 : a == b ? 0 : 1;
|
| 313 |
+
});
|
| 314 |
+
cm.replaceRange(lines, start, end);
|
| 315 |
+
if (selected) ranges.push({anchor: start, head: end});
|
| 316 |
+
}
|
| 317 |
+
if (selected) cm.setSelections(ranges, 0);
|
| 318 |
+
});
|
| 319 |
+
}
|
| 320 |
+
|
| 321 |
+
cmds[map["F9"] = "sortLines"] = function(cm) { sortLines(cm, true); };
|
| 322 |
+
cmds[map[ctrl + "F9"] = "sortLinesInsensitive"] = function(cm) { sortLines(cm, false); };
|
| 323 |
+
|
| 324 |
+
cmds[map["F2"] = "nextBookmark"] = function(cm) {
|
| 325 |
+
var marks = cm.state.sublimeBookmarks;
|
| 326 |
+
if (marks) while (marks.length) {
|
| 327 |
+
var current = marks.shift();
|
| 328 |
+
var found = current.find();
|
| 329 |
+
if (found) {
|
| 330 |
+
marks.push(current);
|
| 331 |
+
return cm.setSelection(found.from, found.to);
|
| 332 |
+
}
|
| 333 |
+
}
|
| 334 |
+
};
|
| 335 |
+
|
| 336 |
+
cmds[map["Shift-F2"] = "prevBookmark"] = function(cm) {
|
| 337 |
+
var marks = cm.state.sublimeBookmarks;
|
| 338 |
+
if (marks) while (marks.length) {
|
| 339 |
+
marks.unshift(marks.pop());
|
| 340 |
+
var found = marks[marks.length - 1].find();
|
| 341 |
+
if (!found)
|
| 342 |
+
marks.pop();
|
| 343 |
+
else
|
| 344 |
+
return cm.setSelection(found.from, found.to);
|
| 345 |
+
}
|
| 346 |
+
};
|
| 347 |
+
|
| 348 |
+
cmds[map[ctrl + "F2"] = "toggleBookmark"] = function(cm) {
|
| 349 |
+
var ranges = cm.listSelections();
|
| 350 |
+
var marks = cm.state.sublimeBookmarks || (cm.state.sublimeBookmarks = []);
|
| 351 |
+
for (var i = 0; i < ranges.length; i++) {
|
| 352 |
+
var from = ranges[i].from(), to = ranges[i].to();
|
| 353 |
+
var found = cm.findMarks(from, to);
|
| 354 |
+
for (var j = 0; j < found.length; j++) {
|
| 355 |
+
if (found[j].sublimeBookmark) {
|
| 356 |
+
found[j].clear();
|
| 357 |
+
for (var k = 0; k < marks.length; k++)
|
| 358 |
+
if (marks[k] == found[j])
|
| 359 |
+
marks.splice(k--, 1);
|
| 360 |
+
break;
|
| 361 |
+
}
|
| 362 |
+
}
|
| 363 |
+
if (j == found.length)
|
| 364 |
+
marks.push(cm.markText(from, to, {sublimeBookmark: true, clearWhenEmpty: false}));
|
| 365 |
+
}
|
| 366 |
+
};
|
| 367 |
+
|
| 368 |
+
cmds[map["Shift-" + ctrl + "F2"] = "clearBookmarks"] = function(cm) {
|
| 369 |
+
var marks = cm.state.sublimeBookmarks;
|
| 370 |
+
if (marks) for (var i = 0; i < marks.length; i++) marks[i].clear();
|
| 371 |
+
marks.length = 0;
|
| 372 |
+
};
|
| 373 |
+
|
| 374 |
+
cmds[map["Alt-F2"] = "selectBookmarks"] = function(cm) {
|
| 375 |
+
var marks = cm.state.sublimeBookmarks, ranges = [];
|
| 376 |
+
if (marks) for (var i = 0; i < marks.length; i++) {
|
| 377 |
+
var found = marks[i].find();
|
| 378 |
+
if (!found)
|
| 379 |
+
marks.splice(i--, 0);
|
| 380 |
+
else
|
| 381 |
+
ranges.push({anchor: found.from, head: found.to});
|
| 382 |
+
}
|
| 383 |
+
if (ranges.length)
|
| 384 |
+
cm.setSelections(ranges, 0);
|
| 385 |
+
};
|
| 386 |
+
|
| 387 |
+
map["Alt-Q"] = "wrapLines";
|
| 388 |
+
|
| 389 |
+
var cK = ctrl + "K ";
|
| 390 |
+
|
| 391 |
+
function modifyWordOrSelection(cm, mod) {
|
| 392 |
+
cm.operation(function() {
|
| 393 |
+
var ranges = cm.listSelections(), indices = [], replacements = [];
|
| 394 |
+
for (var i = 0; i < ranges.length; i++) {
|
| 395 |
+
var range = ranges[i];
|
| 396 |
+
if (range.empty()) { indices.push(i); replacements.push(""); }
|
| 397 |
+
else replacements.push(mod(cm.getRange(range.from(), range.to())));
|
| 398 |
+
}
|
| 399 |
+
cm.replaceSelections(replacements, "around", "case");
|
| 400 |
+
for (var i = indices.length - 1, at; i >= 0; i--) {
|
| 401 |
+
var range = ranges[indices[i]];
|
| 402 |
+
if (at && CodeMirror.cmpPos(range.head, at) > 0) continue;
|
| 403 |
+
var word = wordAt(cm, range.head);
|
| 404 |
+
at = word.from;
|
| 405 |
+
cm.replaceRange(mod(word.word), word.from, word.to);
|
| 406 |
+
}
|
| 407 |
+
});
|
| 408 |
+
}
|
| 409 |
+
|
| 410 |
+
map[cK + ctrl + "Backspace"] = "delLineLeft";
|
| 411 |
+
|
| 412 |
+
cmds[map["Backspace"] = "smartBackspace"] = function(cm) {
|
| 413 |
+
if (cm.somethingSelected()) return CodeMirror.Pass;
|
| 414 |
+
|
| 415 |
+
var cursor = cm.getCursor();
|
| 416 |
+
var toStartOfLine = cm.getRange({line: cursor.line, ch: 0}, cursor);
|
| 417 |
+
var column = CodeMirror.countColumn(toStartOfLine, null, cm.getOption("tabSize"));
|
| 418 |
+
|
| 419 |
+
if (toStartOfLine && !/\S/.test(toStartOfLine) && column % cm.getOption("indentUnit") == 0)
|
| 420 |
+
return cm.indentSelection("subtract");
|
| 421 |
+
else
|
| 422 |
+
return CodeMirror.Pass;
|
| 423 |
+
};
|
| 424 |
+
|
| 425 |
+
cmds[map[cK + ctrl + "K"] = "delLineRight"] = function(cm) {
|
| 426 |
+
cm.operation(function() {
|
| 427 |
+
var ranges = cm.listSelections();
|
| 428 |
+
for (var i = ranges.length - 1; i >= 0; i--)
|
| 429 |
+
cm.replaceRange("", ranges[i].anchor, Pos(ranges[i].to().line), "+delete");
|
| 430 |
+
cm.scrollIntoView();
|
| 431 |
+
});
|
| 432 |
+
};
|
| 433 |
+
|
| 434 |
+
cmds[map[cK + ctrl + "U"] = "upcaseAtCursor"] = function(cm) {
|
| 435 |
+
modifyWordOrSelection(cm, function(str) { return str.toUpperCase(); });
|
| 436 |
+
};
|
| 437 |
+
cmds[map[cK + ctrl + "L"] = "downcaseAtCursor"] = function(cm) {
|
| 438 |
+
modifyWordOrSelection(cm, function(str) { return str.toLowerCase(); });
|
| 439 |
+
};
|
| 440 |
+
|
| 441 |
+
cmds[map[cK + ctrl + "Space"] = "setSublimeMark"] = function(cm) {
|
| 442 |
+
if (cm.state.sublimeMark) cm.state.sublimeMark.clear();
|
| 443 |
+
cm.state.sublimeMark = cm.setBookmark(cm.getCursor());
|
| 444 |
+
};
|
| 445 |
+
cmds[map[cK + ctrl + "A"] = "selectToSublimeMark"] = function(cm) {
|
| 446 |
+
var found = cm.state.sublimeMark && cm.state.sublimeMark.find();
|
| 447 |
+
if (found) cm.setSelection(cm.getCursor(), found);
|
| 448 |
+
};
|
| 449 |
+
cmds[map[cK + ctrl + "W"] = "deleteToSublimeMark"] = function(cm) {
|
| 450 |
+
var found = cm.state.sublimeMark && cm.state.sublimeMark.find();
|
| 451 |
+
if (found) {
|
| 452 |
+
var from = cm.getCursor(), to = found;
|
| 453 |
+
if (CodeMirror.cmpPos(from, to) > 0) { var tmp = to; to = from; from = tmp; }
|
| 454 |
+
cm.state.sublimeKilled = cm.getRange(from, to);
|
| 455 |
+
cm.replaceRange("", from, to);
|
| 456 |
+
}
|
| 457 |
+
};
|
| 458 |
+
cmds[map[cK + ctrl + "X"] = "swapWithSublimeMark"] = function(cm) {
|
| 459 |
+
var found = cm.state.sublimeMark && cm.state.sublimeMark.find();
|
| 460 |
+
if (found) {
|
| 461 |
+
cm.state.sublimeMark.clear();
|
| 462 |
+
cm.state.sublimeMark = cm.setBookmark(cm.getCursor());
|
| 463 |
+
cm.setCursor(found);
|
| 464 |
+
}
|
| 465 |
+
};
|
| 466 |
+
cmds[map[cK + ctrl + "Y"] = "sublimeYank"] = function(cm) {
|
| 467 |
+
if (cm.state.sublimeKilled != null)
|
| 468 |
+
cm.replaceSelection(cm.state.sublimeKilled, null, "paste");
|
| 469 |
+
};
|
| 470 |
+
|
| 471 |
+
map[cK + ctrl + "G"] = "clearBookmarks";
|
| 472 |
+
cmds[map[cK + ctrl + "C"] = "showInCenter"] = function(cm) {
|
| 473 |
+
var pos = cm.cursorCoords(null, "local");
|
| 474 |
+
cm.scrollTo(null, (pos.top + pos.bottom) / 2 - cm.getScrollInfo().clientHeight / 2);
|
| 475 |
+
};
|
| 476 |
+
|
| 477 |
+
cmds[map["Shift-Alt-Up"] = "selectLinesUpward"] = function(cm) {
|
| 478 |
+
cm.operation(function() {
|
| 479 |
+
var ranges = cm.listSelections();
|
| 480 |
+
for (var i = 0; i < ranges.length; i++) {
|
| 481 |
+
var range = ranges[i];
|
| 482 |
+
if (range.head.line > cm.firstLine())
|
| 483 |
+
cm.addSelection(Pos(range.head.line - 1, range.head.ch));
|
| 484 |
+
}
|
| 485 |
+
});
|
| 486 |
+
};
|
| 487 |
+
cmds[map["Shift-Alt-Down"] = "selectLinesDownward"] = function(cm) {
|
| 488 |
+
cm.operation(function() {
|
| 489 |
+
var ranges = cm.listSelections();
|
| 490 |
+
for (var i = 0; i < ranges.length; i++) {
|
| 491 |
+
var range = ranges[i];
|
| 492 |
+
if (range.head.line < cm.lastLine())
|
| 493 |
+
cm.addSelection(Pos(range.head.line + 1, range.head.ch));
|
| 494 |
+
}
|
| 495 |
+
});
|
| 496 |
+
};
|
| 497 |
+
|
| 498 |
+
function getTarget(cm) {
|
| 499 |
+
var from = cm.getCursor("from"), to = cm.getCursor("to");
|
| 500 |
+
if (CodeMirror.cmpPos(from, to) == 0) {
|
| 501 |
+
var word = wordAt(cm, from);
|
| 502 |
+
if (!word.word) return;
|
| 503 |
+
from = word.from;
|
| 504 |
+
to = word.to;
|
| 505 |
+
}
|
| 506 |
+
return {from: from, to: to, query: cm.getRange(from, to), word: word};
|
| 507 |
+
}
|
| 508 |
+
|
| 509 |
+
function findAndGoTo(cm, forward) {
|
| 510 |
+
var target = getTarget(cm);
|
| 511 |
+
if (!target) return;
|
| 512 |
+
var query = target.query;
|
| 513 |
+
var cur = cm.getSearchCursor(query, forward ? target.to : target.from);
|
| 514 |
+
|
| 515 |
+
if (forward ? cur.findNext() : cur.findPrevious()) {
|
| 516 |
+
cm.setSelection(cur.from(), cur.to());
|
| 517 |
+
} else {
|
| 518 |
+
cur = cm.getSearchCursor(query, forward ? Pos(cm.firstLine(), 0)
|
| 519 |
+
: cm.clipPos(Pos(cm.lastLine())));
|
| 520 |
+
if (forward ? cur.findNext() : cur.findPrevious())
|
| 521 |
+
cm.setSelection(cur.from(), cur.to());
|
| 522 |
+
else if (target.word)
|
| 523 |
+
cm.setSelection(target.from, target.to);
|
| 524 |
+
}
|
| 525 |
+
};
|
| 526 |
+
cmds[map[ctrl + "F3"] = "findUnder"] = function(cm) { findAndGoTo(cm, true); };
|
| 527 |
+
cmds[map["Shift-" + ctrl + "F3"] = "findUnderPrevious"] = function(cm) { findAndGoTo(cm,false); };
|
| 528 |
+
cmds[map["Alt-F3"] = "findAllUnder"] = function(cm) {
|
| 529 |
+
var target = getTarget(cm);
|
| 530 |
+
if (!target) return;
|
| 531 |
+
var cur = cm.getSearchCursor(target.query);
|
| 532 |
+
var matches = [];
|
| 533 |
+
var primaryIndex = -1;
|
| 534 |
+
while (cur.findNext()) {
|
| 535 |
+
matches.push({anchor: cur.from(), head: cur.to()});
|
| 536 |
+
if (cur.from().line <= target.from.line && cur.from().ch <= target.from.ch)
|
| 537 |
+
primaryIndex++;
|
| 538 |
+
}
|
| 539 |
+
cm.setSelections(matches, primaryIndex);
|
| 540 |
+
};
|
| 541 |
+
|
| 542 |
+
map["Shift-" + ctrl + "["] = "fold";
|
| 543 |
+
map["Shift-" + ctrl + "]"] = "unfold";
|
| 544 |
+
map[cK + ctrl + "0"] = map[cK + ctrl + "j"] = "unfoldAll";
|
| 545 |
+
|
| 546 |
+
map[ctrl + "I"] = "findIncremental";
|
| 547 |
+
map["Shift-" + ctrl + "I"] = "findIncrementalReverse";
|
| 548 |
+
map[ctrl + "H"] = "replace";
|
| 549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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
/**
|
| 5 |
+
* Supported keybindings:
|
| 6 |
+
* Too many to list. Refer to defaultKeyMap below.
|
| 7 |
+
*
|
| 8 |
+
* Supported Ex commands:
|
| 9 |
+
* Refer to defaultExCommandMap below.
|
| 10 |
+
*
|
| 11 |
+
* Registers: unnamed, -, a-z, A-Z, 0-9
|
| 12 |
+
* (Does not respect the special case for number registers when delete
|
| 13 |
+
* operator is made with these commands: %, (, ), , /, ?, n, N, {, } )
|
| 14 |
+
* TODO: Implement the remaining registers.
|
| 15 |
+
*
|
| 16 |
+
* Marks: a-z, A-Z, and 0-9
|
| 17 |
+
* TODO: Implement the remaining special marks. They have more complex
|
| 18 |
+
* behavior.
|
| 19 |
+
*
|
| 20 |
+
* Events:
|
| 21 |
+
* 'vim-mode-change' - raised on the editor anytime the current mode changes,
|
| 22 |
+
* Event object: {mode: "visual", subMode: "linewise"}
|
| 23 |
+
*
|
| 24 |
+
* Code structure:
|
| 25 |
+
* 1. Default keymap
|
| 26 |
+
* 2. Variable declarations and short basic helpers
|
| 27 |
+
* 3. Instance (External API) implementation
|
| 28 |
+
* 4. Internal state tracking objects (input state, counter) implementation
|
| 29 |
+
* and instanstiation
|
| 30 |
+
* 5. Key handler (the main command dispatcher) implementation
|
| 31 |
+
* 6. Motion, operator, and action implementations
|
| 32 |
+
* 7. Helper functions for the key handler, motions, operators, and actions
|
| 33 |
+
* 8. Set up Vim to work as a keymap for CodeMirror.
|
| 34 |
+
* 9. Ex command implementations.
|
| 35 |
+
*/
|
| 36 |
+
|
| 37 |
+
(function(mod) {
|
| 38 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 39 |
+
mod(require("../lib/codemirror"), require("../addon/search/searchcursor"), require("../addon/dialog/dialog"), require("../addon/edit/matchbrackets.js"));
|
| 40 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 41 |
+
define(["../lib/codemirror", "../addon/search/searchcursor", "../addon/dialog/dialog", "../addon/edit/matchbrackets"], mod);
|
| 42 |
+
else // Plain browser env
|
| 43 |
+
mod(CodeMirror);
|
| 44 |
+
})(function(CodeMirror) {
|
| 45 |
+
'use strict';
|
| 46 |
+
|
| 47 |
+
var defaultKeymap = [
|
| 48 |
+
// Key to key mapping. This goes first to make it possible to override
|
| 49 |
+
// existing mappings.
|
| 50 |
+
{ keys: '<Left>', type: 'keyToKey', toKeys: 'h' },
|
| 51 |
+
{ keys: '<Right>', type: 'keyToKey', toKeys: 'l' },
|
| 52 |
+
{ keys: '<Up>', type: 'keyToKey', toKeys: 'k' },
|
| 53 |
+
{ keys: '<Down>', type: 'keyToKey', toKeys: 'j' },
|
| 54 |
+
{ keys: '<Space>', type: 'keyToKey', toKeys: 'l' },
|
| 55 |
+
{ keys: '<BS>', type: 'keyToKey', toKeys: 'h', context: 'normal'},
|
| 56 |
+
{ keys: '<C-Space>', type: 'keyToKey', toKeys: 'W' },
|
| 57 |
+
{ keys: '<C-BS>', type: 'keyToKey', toKeys: 'B', context: 'normal' },
|
| 58 |
+
{ keys: '<S-Space>', type: 'keyToKey', toKeys: 'w' },
|
| 59 |
+
{ keys: '<S-BS>', type: 'keyToKey', toKeys: 'b', context: 'normal' },
|
| 60 |
+
{ keys: '<C-n>', type: 'keyToKey', toKeys: 'j' },
|
| 61 |
+
{ keys: '<C-p>', type: 'keyToKey', toKeys: 'k' },
|
| 62 |
+
{ keys: '<C-[>', type: 'keyToKey', toKeys: '<Esc>' },
|
| 63 |
+
{ keys: '<C-c>', type: 'keyToKey', toKeys: '<Esc>' },
|
| 64 |
+
{ keys: '<C-[>', type: 'keyToKey', toKeys: '<Esc>', context: 'insert' },
|
| 65 |
+
{ keys: '<C-c>', type: 'keyToKey', toKeys: '<Esc>', context: 'insert' },
|
| 66 |
+
{ keys: 's', type: 'keyToKey', toKeys: 'cl', context: 'normal' },
|
| 67 |
+
{ keys: 's', type: 'keyToKey', toKeys: 'xi', context: 'visual'},
|
| 68 |
+
{ keys: 'S', type: 'keyToKey', toKeys: 'cc', context: 'normal' },
|
| 69 |
+
{ keys: 'S', type: 'keyToKey', toKeys: 'dcc', context: 'visual' },
|
| 70 |
+
{ keys: '<Home>', type: 'keyToKey', toKeys: '0' },
|
| 71 |
+
{ keys: '<End>', type: 'keyToKey', toKeys: '$' },
|
| 72 |
+
{ keys: '<PageUp>', type: 'keyToKey', toKeys: '<C-b>' },
|
| 73 |
+
{ keys: '<PageDown>', type: 'keyToKey', toKeys: '<C-f>' },
|
| 74 |
+
{ keys: '<CR>', type: 'keyToKey', toKeys: 'j^', context: 'normal' },
|
| 75 |
+
// Motions
|
| 76 |
+
{ keys: 'H', type: 'motion', motion: 'moveToTopLine', motionArgs: { linewise: true, toJumplist: true }},
|
| 77 |
+
{ keys: 'M', type: 'motion', motion: 'moveToMiddleLine', motionArgs: { linewise: true, toJumplist: true }},
|
| 78 |
+
{ keys: 'L', type: 'motion', motion: 'moveToBottomLine', motionArgs: { linewise: true, toJumplist: true }},
|
| 79 |
+
{ keys: 'h', type: 'motion', motion: 'moveByCharacters', motionArgs: { forward: false }},
|
| 80 |
+
{ keys: 'l', type: 'motion', motion: 'moveByCharacters', motionArgs: { forward: true }},
|
| 81 |
+
{ keys: 'j', type: 'motion', motion: 'moveByLines', motionArgs: { forward: true, linewise: true }},
|
| 82 |
+
{ keys: 'k', type: 'motion', motion: 'moveByLines', motionArgs: { forward: false, linewise: true }},
|
| 83 |
+
{ keys: 'gj', type: 'motion', motion: 'moveByDisplayLines', motionArgs: { forward: true }},
|
| 84 |
+
{ keys: 'gk', type: 'motion', motion: 'moveByDisplayLines', motionArgs: { forward: false }},
|
| 85 |
+
{ keys: 'w', type: 'motion', motion: 'moveByWords', motionArgs: { forward: true, wordEnd: false }},
|
| 86 |
+
{ keys: 'W', type: 'motion', motion: 'moveByWords', motionArgs: { forward: true, wordEnd: false, bigWord: true }},
|
| 87 |
+
{ keys: 'e', type: 'motion', motion: 'moveByWords', motionArgs: { forward: true, wordEnd: true, inclusive: true }},
|
| 88 |
+
{ keys: 'E', type: 'motion', motion: 'moveByWords', motionArgs: { forward: true, wordEnd: true, bigWord: true, inclusive: true }},
|
| 89 |
+
{ keys: 'b', type: 'motion', motion: 'moveByWords', motionArgs: { forward: false, wordEnd: false }},
|
| 90 |
+
{ keys: 'B', type: 'motion', motion: 'moveByWords', motionArgs: { forward: false, wordEnd: false, bigWord: true }},
|
| 91 |
+
{ keys: 'ge', type: 'motion', motion: 'moveByWords', motionArgs: { forward: false, wordEnd: true, inclusive: true }},
|
| 92 |
+
{ keys: 'gE', type: 'motion', motion: 'moveByWords', motionArgs: { forward: false, wordEnd: true, bigWord: true, inclusive: true }},
|
| 93 |
+
{ keys: '{', type: 'motion', motion: 'moveByParagraph', motionArgs: { forward: false, toJumplist: true }},
|
| 94 |
+
{ keys: '}', type: 'motion', motion: 'moveByParagraph', motionArgs: { forward: true, toJumplist: true }},
|
| 95 |
+
{ keys: '<C-f>', type: 'motion', motion: 'moveByPage', motionArgs: { forward: true }},
|
| 96 |
+
{ keys: '<C-b>', type: 'motion', motion: 'moveByPage', motionArgs: { forward: false }},
|
| 97 |
+
{ keys: '<C-d>', type: 'motion', motion: 'moveByScroll', motionArgs: { forward: true, explicitRepeat: true }},
|
| 98 |
+
{ keys: '<C-u>', type: 'motion', motion: 'moveByScroll', motionArgs: { forward: false, explicitRepeat: true }},
|
| 99 |
+
{ keys: 'gg', type: 'motion', motion: 'moveToLineOrEdgeOfDocument', motionArgs: { forward: false, explicitRepeat: true, linewise: true, toJumplist: true }},
|
| 100 |
+
{ keys: 'G', type: 'motion', motion: 'moveToLineOrEdgeOfDocument', motionArgs: { forward: true, explicitRepeat: true, linewise: true, toJumplist: true }},
|
| 101 |
+
{ keys: '0', type: 'motion', motion: 'moveToStartOfLine' },
|
| 102 |
+
{ keys: '^', type: 'motion', motion: 'moveToFirstNonWhiteSpaceCharacter' },
|
| 103 |
+
{ keys: '+', type: 'motion', motion: 'moveByLines', motionArgs: { forward: true, toFirstChar:true }},
|
| 104 |
+
{ keys: '-', type: 'motion', motion: 'moveByLines', motionArgs: { forward: false, toFirstChar:true }},
|
| 105 |
+
{ keys: '_', type: 'motion', motion: 'moveByLines', motionArgs: { forward: true, toFirstChar:true, repeatOffset:-1 }},
|
| 106 |
+
{ keys: '$', type: 'motion', motion: 'moveToEol', motionArgs: { inclusive: true }},
|
| 107 |
+
{ keys: '%', type: 'motion', motion: 'moveToMatchedSymbol', motionArgs: { inclusive: true, toJumplist: true }},
|
| 108 |
+
{ keys: 'f<character>', type: 'motion', motion: 'moveToCharacter', motionArgs: { forward: true , inclusive: true }},
|
| 109 |
+
{ keys: 'F<character>', type: 'motion', motion: 'moveToCharacter', motionArgs: { forward: false }},
|
| 110 |
+
{ keys: 't<character>', type: 'motion', motion: 'moveTillCharacter', motionArgs: { forward: true, inclusive: true }},
|
| 111 |
+
{ keys: 'T<character>', type: 'motion', motion: 'moveTillCharacter', motionArgs: { forward: false }},
|
| 112 |
+
{ keys: ';', type: 'motion', motion: 'repeatLastCharacterSearch', motionArgs: { forward: true }},
|
| 113 |
+
{ keys: ',', type: 'motion', motion: 'repeatLastCharacterSearch', motionArgs: { forward: false }},
|
| 114 |
+
{ keys: '\'<character>', type: 'motion', motion: 'goToMark', motionArgs: {toJumplist: true, linewise: true}},
|
| 115 |
+
{ keys: '`<character>', type: 'motion', motion: 'goToMark', motionArgs: {toJumplist: true}},
|
| 116 |
+
{ keys: ']`', type: 'motion', motion: 'jumpToMark', motionArgs: { forward: true } },
|
| 117 |
+
{ keys: '[`', type: 'motion', motion: 'jumpToMark', motionArgs: { forward: false } },
|
| 118 |
+
{ keys: ']\'', type: 'motion', motion: 'jumpToMark', motionArgs: { forward: true, linewise: true } },
|
| 119 |
+
{ keys: '[\'', type: 'motion', motion: 'jumpToMark', motionArgs: { forward: false, linewise: true } },
|
| 120 |
+
// the next two aren't motions but must come before more general motion declarations
|
| 121 |
+
{ keys: ']p', type: 'action', action: 'paste', isEdit: true, actionArgs: { after: true, isEdit: true, matchIndent: true}},
|
| 122 |
+
{ keys: '[p', type: 'action', action: 'paste', isEdit: true, actionArgs: { after: false, isEdit: true, matchIndent: true}},
|
| 123 |
+
{ keys: ']<character>', type: 'motion', motion: 'moveToSymbol', motionArgs: { forward: true, toJumplist: true}},
|
| 124 |
+
{ keys: '[<character>', type: 'motion', motion: 'moveToSymbol', motionArgs: { forward: false, toJumplist: true}},
|
| 125 |
+
{ keys: '|', type: 'motion', motion: 'moveToColumn'},
|
| 126 |
+
{ keys: 'o', type: 'motion', motion: 'moveToOtherHighlightedEnd', context:'visual'},
|
| 127 |
+
{ keys: 'O', type: 'motion', motion: 'moveToOtherHighlightedEnd', motionArgs: {sameLine: true}, context:'visual'},
|
| 128 |
+
// Operators
|
| 129 |
+
{ keys: 'd', type: 'operator', operator: 'delete' },
|
| 130 |
+
{ keys: 'y', type: 'operator', operator: 'yank' },
|
| 131 |
+
{ keys: 'c', type: 'operator', operator: 'change' },
|
| 132 |
+
{ keys: '>', type: 'operator', operator: 'indent', operatorArgs: { indentRight: true }},
|
| 133 |
+
{ keys: '<', type: 'operator', operator: 'indent', operatorArgs: { indentRight: false }},
|
| 134 |
+
{ keys: 'g~', type: 'operator', operator: 'changeCase' },
|
| 135 |
+
{ keys: 'gu', type: 'operator', operator: 'changeCase', operatorArgs: {toLower: true}, isEdit: true },
|
| 136 |
+
{ keys: 'gU', type: 'operator', operator: 'changeCase', operatorArgs: {toLower: false}, isEdit: true },
|
| 137 |
+
{ keys: 'n', type: 'motion', motion: 'findNext', motionArgs: { forward: true, toJumplist: true }},
|
| 138 |
+
{ keys: 'N', type: 'motion', motion: 'findNext', motionArgs: { forward: false, toJumplist: true }},
|
| 139 |
+
// Operator-Motion dual commands
|
| 140 |
+
{ keys: 'x', type: 'operatorMotion', operator: 'delete', motion: 'moveByCharacters', motionArgs: { forward: true }, operatorMotionArgs: { visualLine: false }},
|
| 141 |
+
{ keys: 'X', type: 'operatorMotion', operator: 'delete', motion: 'moveByCharacters', motionArgs: { forward: false }, operatorMotionArgs: { visualLine: true }},
|
| 142 |
+
{ keys: 'D', type: 'operatorMotion', operator: 'delete', motion: 'moveToEol', motionArgs: { inclusive: true }, context: 'normal'},
|
| 143 |
+
{ keys: 'D', type: 'operator', operator: 'delete', operatorArgs: { linewise: true }, context: 'visual'},
|
| 144 |
+
{ keys: 'Y', type: 'operatorMotion', operator: 'yank', motion: 'moveToEol', motionArgs: { inclusive: true }, context: 'normal'},
|
| 145 |
+
{ keys: 'Y', type: 'operator', operator: 'yank', operatorArgs: { linewise: true }, context: 'visual'},
|
| 146 |
+
{ keys: 'C', type: 'operatorMotion', operator: 'change', motion: 'moveToEol', motionArgs: { inclusive: true }, context: 'normal'},
|
| 147 |
+
{ keys: 'C', type: 'operator', operator: 'change', operatorArgs: { linewise: true }, context: 'visual'},
|
| 148 |
+
{ keys: '~', type: 'operatorMotion', operator: 'changeCase', motion: 'moveByCharacters', motionArgs: { forward: true }, operatorArgs: { shouldMoveCursor: true }, context: 'normal'},
|
| 149 |
+
{ keys: '~', type: 'operator', operator: 'changeCase', context: 'visual'},
|
| 150 |
+
{ keys: '<C-w>', type: 'operatorMotion', operator: 'delete', motion: 'moveByWords', motionArgs: { forward: false, wordEnd: false }, context: 'insert' },
|
| 151 |
+
// Actions
|
| 152 |
+
{ keys: '<C-i>', type: 'action', action: 'jumpListWalk', actionArgs: { forward: true }},
|
| 153 |
+
{ keys: '<C-o>', type: 'action', action: 'jumpListWalk', actionArgs: { forward: false }},
|
| 154 |
+
{ keys: '<C-e>', type: 'action', action: 'scroll', actionArgs: { forward: true, linewise: true }},
|
| 155 |
+
{ keys: '<C-y>', type: 'action', action: 'scroll', actionArgs: { forward: false, linewise: true }},
|
| 156 |
+
{ keys: 'a', type: 'action', action: 'enterInsertMode', isEdit: true, actionArgs: { insertAt: 'charAfter' }, context: 'normal' },
|
| 157 |
+
{ keys: 'A', type: 'action', action: 'enterInsertMode', isEdit: true, actionArgs: { insertAt: 'eol' }, context: 'normal' },
|
| 158 |
+
{ keys: 'A', type: 'action', action: 'enterInsertMode', isEdit: true, actionArgs: { insertAt: 'endOfSelectedArea' }, context: 'visual' },
|
| 159 |
+
{ keys: 'i', type: 'action', action: 'enterInsertMode', isEdit: true, actionArgs: { insertAt: 'inplace' }, context: 'normal' },
|
| 160 |
+
{ keys: 'I', type: 'action', action: 'enterInsertMode', isEdit: true, actionArgs: { insertAt: 'firstNonBlank'}, context: 'normal' },
|
| 161 |
+
{ keys: 'I', type: 'action', action: 'enterInsertMode', isEdit: true, actionArgs: { insertAt: 'startOfSelectedArea' }, context: 'visual' },
|
| 162 |
+
{ keys: 'o', type: 'action', action: 'newLineAndEnterInsertMode', isEdit: true, interlaceInsertRepeat: true, actionArgs: { after: true }, context: 'normal' },
|
| 163 |
+
{ keys: 'O', type: 'action', action: 'newLineAndEnterInsertMode', isEdit: true, interlaceInsertRepeat: true, actionArgs: { after: false }, context: 'normal' },
|
| 164 |
+
{ keys: 'v', type: 'action', action: 'toggleVisualMode' },
|
| 165 |
+
{ keys: 'V', type: 'action', action: 'toggleVisualMode', actionArgs: { linewise: true }},
|
| 166 |
+
{ keys: '<C-v>', type: 'action', action: 'toggleVisualMode', actionArgs: { blockwise: true }},
|
| 167 |
+
{ keys: 'gv', type: 'action', action: 'reselectLastSelection' },
|
| 168 |
+
{ keys: 'J', type: 'action', action: 'joinLines', isEdit: true },
|
| 169 |
+
{ keys: 'p', type: 'action', action: 'paste', isEdit: true, actionArgs: { after: true, isEdit: true }},
|
| 170 |
+
{ keys: 'P', type: 'action', action: 'paste', isEdit: true, actionArgs: { after: false, isEdit: true }},
|
| 171 |
+
{ keys: 'r<character>', type: 'action', action: 'replace', isEdit: true },
|
| 172 |
+
{ keys: '@<character>', type: 'action', action: 'replayMacro' },
|
| 173 |
+
{ keys: 'q<character>', type: 'action', action: 'enterMacroRecordMode' },
|
| 174 |
+
// Handle Replace-mode as a special case of insert mode.
|
| 175 |
+
{ keys: 'R', type: 'action', action: 'enterInsertMode', isEdit: true, actionArgs: { replace: true }},
|
| 176 |
+
{ keys: 'u', type: 'action', action: 'undo', context: 'normal' },
|
| 177 |
+
{ keys: 'u', type: 'operator', operator: 'changeCase', operatorArgs: {toLower: true}, context: 'visual', isEdit: true },
|
| 178 |
+
{ keys: 'U', type: 'operator', operator: 'changeCase', operatorArgs: {toLower: false}, context: 'visual', isEdit: true },
|
| 179 |
+
{ keys: '<C-r>', type: 'action', action: 'redo' },
|
| 180 |
+
{ keys: 'm<character>', type: 'action', action: 'setMark' },
|
| 181 |
+
{ keys: '"<character>', type: 'action', action: 'setRegister' },
|
| 182 |
+
{ keys: 'zz', type: 'action', action: 'scrollToCursor', actionArgs: { position: 'center' }},
|
| 183 |
+
{ keys: 'z.', type: 'action', action: 'scrollToCursor', actionArgs: { position: 'center' }, motion: 'moveToFirstNonWhiteSpaceCharacter' },
|
| 184 |
+
{ keys: 'zt', type: 'action', action: 'scrollToCursor', actionArgs: { position: 'top' }},
|
| 185 |
+
{ keys: 'z<CR>', type: 'action', action: 'scrollToCursor', actionArgs: { position: 'top' }, motion: 'moveToFirstNonWhiteSpaceCharacter' },
|
| 186 |
+
{ keys: 'z-', type: 'action', action: 'scrollToCursor', actionArgs: { position: 'bottom' }},
|
| 187 |
+
{ keys: 'zb', type: 'action', action: 'scrollToCursor', actionArgs: { position: 'bottom' }, motion: 'moveToFirstNonWhiteSpaceCharacter' },
|
| 188 |
+
{ keys: '.', type: 'action', action: 'repeatLastEdit' },
|
| 189 |
+
{ keys: '<C-a>', type: 'action', action: 'incrementNumberToken', isEdit: true, actionArgs: {increase: true, backtrack: false}},
|
| 190 |
+
{ keys: '<C-x>', type: 'action', action: 'incrementNumberToken', isEdit: true, actionArgs: {increase: false, backtrack: false}},
|
| 191 |
+
// Text object motions
|
| 192 |
+
{ keys: 'a<character>', type: 'motion', motion: 'textObjectManipulation' },
|
| 193 |
+
{ keys: 'i<character>', type: 'motion', motion: 'textObjectManipulation', motionArgs: { textObjectInner: true }},
|
| 194 |
+
// Search
|
| 195 |
+
{ keys: '/', type: 'search', searchArgs: { forward: true, querySrc: 'prompt', toJumplist: true }},
|
| 196 |
+
{ keys: '?', type: 'search', searchArgs: { forward: false, querySrc: 'prompt', toJumplist: true }},
|
| 197 |
+
{ keys: '*', type: 'search', searchArgs: { forward: true, querySrc: 'wordUnderCursor', wholeWordOnly: true, toJumplist: true }},
|
| 198 |
+
{ keys: '#', type: 'search', searchArgs: { forward: false, querySrc: 'wordUnderCursor', wholeWordOnly: true, toJumplist: true }},
|
| 199 |
+
{ keys: 'g*', type: 'search', searchArgs: { forward: true, querySrc: 'wordUnderCursor', toJumplist: true }},
|
| 200 |
+
{ keys: 'g#', type: 'search', searchArgs: { forward: false, querySrc: 'wordUnderCursor', toJumplist: true }},
|
| 201 |
+
// Ex command
|
| 202 |
+
{ keys: ':', type: 'ex' }
|
| 203 |
+
];
|
| 204 |
+
|
| 205 |
+
/**
|
| 206 |
+
* Ex commands
|
| 207 |
+
* Care must be taken when adding to the default Ex command map. For any
|
| 208 |
+
* pair of commands that have a shared prefix, at least one of their
|
| 209 |
+
* shortNames must not match the prefix of the other command.
|
| 210 |
+
*/
|
| 211 |
+
var defaultExCommandMap = [
|
| 212 |
+
{ name: 'colorscheme', shortName: 'colo' },
|
| 213 |
+
{ name: 'map' },
|
| 214 |
+
{ name: 'imap', shortName: 'im' },
|
| 215 |
+
{ name: 'nmap', shortName: 'nm' },
|
| 216 |
+
{ name: 'vmap', shortName: 'vm' },
|
| 217 |
+
{ name: 'unmap' },
|
| 218 |
+
{ name: 'write', shortName: 'w' },
|
| 219 |
+
{ name: 'undo', shortName: 'u' },
|
| 220 |
+
{ name: 'redo', shortName: 'red' },
|
| 221 |
+
{ name: 'set', shortName: 'se' },
|
| 222 |
+
{ name: 'set', shortName: 'se' },
|
| 223 |
+
{ name: 'setlocal', shortName: 'setl' },
|
| 224 |
+
{ name: 'setglobal', shortName: 'setg' },
|
| 225 |
+
{ name: 'sort', shortName: 'sor' },
|
| 226 |
+
{ name: 'substitute', shortName: 's', possiblyAsync: true },
|
| 227 |
+
{ name: 'nohlsearch', shortName: 'noh' },
|
| 228 |
+
{ name: 'delmarks', shortName: 'delm' },
|
| 229 |
+
{ name: 'registers', shortName: 'reg', excludeFromCommandHistory: true },
|
| 230 |
+
{ name: 'global', shortName: 'g' }
|
| 231 |
+
];
|
| 232 |
+
|
| 233 |
+
var Pos = CodeMirror.Pos;
|
| 234 |
+
|
| 235 |
+
var Vim = function() {
|
| 236 |
+
function enterVimMode(cm) {
|
| 237 |
+
cm.setOption('disableInput', true);
|
| 238 |
+
cm.setOption('showCursorWhenSelecting', false);
|
| 239 |
+
CodeMirror.signal(cm, "vim-mode-change", {mode: "normal"});
|
| 240 |
+
cm.on('cursorActivity', onCursorActivity);
|
| 241 |
+
maybeInitVimState(cm);
|
| 242 |
+
CodeMirror.on(cm.getInputField(), 'paste', getOnPasteFn(cm));
|
| 243 |
+
}
|
| 244 |
+
|
| 245 |
+
function leaveVimMode(cm) {
|
| 246 |
+
cm.setOption('disableInput', false);
|
| 247 |
+
cm.off('cursorActivity', onCursorActivity);
|
| 248 |
+
CodeMirror.off(cm.getInputField(), 'paste', getOnPasteFn(cm));
|
| 249 |
+
cm.state.vim = null;
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
function detachVimMap(cm, next) {
|
| 253 |
+
if (this == CodeMirror.keyMap.vim)
|
| 254 |
+
CodeMirror.rmClass(cm.getWrapperElement(), "cm-fat-cursor");
|
| 255 |
+
|
| 256 |
+
if (!next || next.attach != attachVimMap)
|
| 257 |
+
leaveVimMode(cm, false);
|
| 258 |
+
}
|
| 259 |
+
function attachVimMap(cm, prev) {
|
| 260 |
+
if (this == CodeMirror.keyMap.vim)
|
| 261 |
+
CodeMirror.addClass(cm.getWrapperElement(), "cm-fat-cursor");
|
| 262 |
+
|
| 263 |
+
if (!prev || prev.attach != attachVimMap)
|
| 264 |
+
enterVimMode(cm);
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
// Deprecated, simply setting the keymap works again.
|
| 268 |
+
CodeMirror.defineOption('vimMode', false, function(cm, val, prev) {
|
| 269 |
+
if (val && cm.getOption("keyMap") != "vim")
|
| 270 |
+
cm.setOption("keyMap", "vim");
|
| 271 |
+
else if (!val && prev != CodeMirror.Init && /^vim/.test(cm.getOption("keyMap")))
|
| 272 |
+
cm.setOption("keyMap", "default");
|
| 273 |
+
});
|
| 274 |
+
|
| 275 |
+
function cmKey(key, cm) {
|
| 276 |
+
if (!cm) { return undefined; }
|
| 277 |
+
var vimKey = cmKeyToVimKey(key);
|
| 278 |
+
if (!vimKey) {
|
| 279 |
+
return false;
|
| 280 |
+
}
|
| 281 |
+
var cmd = CodeMirror.Vim.findKey(cm, vimKey);
|
| 282 |
+
if (typeof cmd == 'function') {
|
| 283 |
+
CodeMirror.signal(cm, 'vim-keypress', vimKey);
|
| 284 |
+
}
|
| 285 |
+
return cmd;
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
var modifiers = {'Shift': 'S', 'Ctrl': 'C', 'Alt': 'A', 'Cmd': 'D', 'Mod': 'A'};
|
| 289 |
+
var specialKeys = {Enter:'CR',Backspace:'BS',Delete:'Del'};
|
| 290 |
+
function cmKeyToVimKey(key) {
|
| 291 |
+
if (key.charAt(0) == '\'') {
|
| 292 |
+
// Keypress character binding of format "'a'"
|
| 293 |
+
return key.charAt(1);
|
| 294 |
+
}
|
| 295 |
+
var pieces = key.split('-');
|
| 296 |
+
if (/-$/.test(key)) {
|
| 297 |
+
// If the - key was typed, split will result in 2 extra empty strings
|
| 298 |
+
// in the array. Replace them with 1 '-'.
|
| 299 |
+
pieces.splice(-2, 2, '-');
|
| 300 |
+
}
|
| 301 |
+
var lastPiece = pieces[pieces.length - 1];
|
| 302 |
+
if (pieces.length == 1 && pieces[0].length == 1) {
|
| 303 |
+
// No-modifier bindings use literal character bindings above. Skip.
|
| 304 |
+
return false;
|
| 305 |
+
} else if (pieces.length == 2 && pieces[0] == 'Shift' && lastPiece.length == 1) {
|
| 306 |
+
// Ignore Shift+char bindings as they should be handled by literal character.
|
| 307 |
+
return false;
|
| 308 |
+
}
|
| 309 |
+
var hasCharacter = false;
|
| 310 |
+
for (var i = 0; i < pieces.length; i++) {
|
| 311 |
+
var piece = pieces[i];
|
| 312 |
+
if (piece in modifiers) { pieces[i] = modifiers[piece]; }
|
| 313 |
+
else { hasCharacter = true; }
|
| 314 |
+
if (piece in specialKeys) { pieces[i] = specialKeys[piece]; }
|
| 315 |
+
}
|
| 316 |
+
if (!hasCharacter) {
|
| 317 |
+
// Vim does not support modifier only keys.
|
| 318 |
+
return false;
|
| 319 |
+
}
|
| 320 |
+
// TODO: Current bindings expect the character to be lower case, but
|
| 321 |
+
// it looks like vim key notation uses upper case.
|
| 322 |
+
if (isUpperCase(lastPiece)) {
|
| 323 |
+
pieces[pieces.length - 1] = lastPiece.toLowerCase();
|
| 324 |
+
}
|
| 325 |
+
return '<' + pieces.join('-') + '>';
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
function getOnPasteFn(cm) {
|
| 329 |
+
var vim = cm.state.vim;
|
| 330 |
+
if (!vim.onPasteFn) {
|
| 331 |
+
vim.onPasteFn = function() {
|
| 332 |
+
if (!vim.insertMode) {
|
| 333 |
+
cm.setCursor(offsetCursor(cm.getCursor(), 0, 1));
|
| 334 |
+
actions.enterInsertMode(cm, {}, vim);
|
| 335 |
+
}
|
| 336 |
+
};
|
| 337 |
+
}
|
| 338 |
+
return vim.onPasteFn;
|
| 339 |
+
}
|
| 340 |
+
|
| 341 |
+
var numberRegex = /[\d]/;
|
| 342 |
+
var wordCharTest = [CodeMirror.isWordChar, function(ch) {
|
| 343 |
+
return ch && !CodeMirror.isWordChar(ch) && !/\s/.test(ch);
|
| 344 |
+
}], bigWordCharTest = [function(ch) {
|
| 345 |
+
return /\S/.test(ch);
|
| 346 |
+
}];
|
| 347 |
+
function makeKeyRange(start, size) {
|
| 348 |
+
var keys = [];
|
| 349 |
+
for (var i = start; i < start + size; i++) {
|
| 350 |
+
keys.push(String.fromCharCode(i));
|
| 351 |
+
}
|
| 352 |
+
return keys;
|
| 353 |
+
}
|
| 354 |
+
var upperCaseAlphabet = makeKeyRange(65, 26);
|
| 355 |
+
var lowerCaseAlphabet = makeKeyRange(97, 26);
|
| 356 |
+
var numbers = makeKeyRange(48, 10);
|
| 357 |
+
var validMarks = [].concat(upperCaseAlphabet, lowerCaseAlphabet, numbers, ['<', '>']);
|
| 358 |
+
var validRegisters = [].concat(upperCaseAlphabet, lowerCaseAlphabet, numbers, ['-', '"', '.', ':', '/']);
|
| 359 |
+
|
| 360 |
+
function isLine(cm, line) {
|
| 361 |
+
return line >= cm.firstLine() && line <= cm.lastLine();
|
| 362 |
+
}
|
| 363 |
+
function isLowerCase(k) {
|
| 364 |
+
return (/^[a-z]$/).test(k);
|
| 365 |
+
}
|
| 366 |
+
function isMatchableSymbol(k) {
|
| 367 |
+
return '()[]{}'.indexOf(k) != -1;
|
| 368 |
+
}
|
| 369 |
+
function isNumber(k) {
|
| 370 |
+
return numberRegex.test(k);
|
| 371 |
+
}
|
| 372 |
+
function isUpperCase(k) {
|
| 373 |
+
return (/^[A-Z]$/).test(k);
|
| 374 |
+
}
|
| 375 |
+
function isWhiteSpaceString(k) {
|
| 376 |
+
return (/^\s*$/).test(k);
|
| 377 |
+
}
|
| 378 |
+
function inArray(val, arr) {
|
| 379 |
+
for (var i = 0; i < arr.length; i++) {
|
| 380 |
+
if (arr[i] == val) {
|
| 381 |
+
return true;
|
| 382 |
+
}
|
| 383 |
+
}
|
| 384 |
+
return false;
|
| 385 |
+
}
|
| 386 |
+
|
| 387 |
+
var options = {};
|
| 388 |
+
function defineOption(name, defaultValue, type, aliases, callback) {
|
| 389 |
+
if (defaultValue === undefined && !callback) {
|
| 390 |
+
throw Error('defaultValue is required unless callback is provided');
|
| 391 |
+
}
|
| 392 |
+
if (!type) { type = 'string'; }
|
| 393 |
+
options[name] = {
|
| 394 |
+
type: type,
|
| 395 |
+
defaultValue: defaultValue,
|
| 396 |
+
callback: callback
|
| 397 |
+
};
|
| 398 |
+
if (aliases) {
|
| 399 |
+
for (var i = 0; i < aliases.length; i++) {
|
| 400 |
+
options[aliases[i]] = options[name];
|
| 401 |
+
}
|
| 402 |
+
}
|
| 403 |
+
if (defaultValue) {
|
| 404 |
+
setOption(name, defaultValue);
|
| 405 |
+
}
|
| 406 |
+
}
|
| 407 |
+
|
| 408 |
+
function setOption(name, value, cm, cfg) {
|
| 409 |
+
var option = options[name];
|
| 410 |
+
cfg = cfg || {};
|
| 411 |
+
var scope = cfg.scope;
|
| 412 |
+
if (!option) {
|
| 413 |
+
throw Error('Unknown option: ' + name);
|
| 414 |
+
}
|
| 415 |
+
if (option.type == 'boolean') {
|
| 416 |
+
if (value && value !== true) {
|
| 417 |
+
throw Error('Invalid argument: ' + name + '=' + value);
|
| 418 |
+
} else if (value !== false) {
|
| 419 |
+
// Boolean options are set to true if value is not defined.
|
| 420 |
+
value = true;
|
| 421 |
+
}
|
| 422 |
+
}
|
| 423 |
+
if (option.callback) {
|
| 424 |
+
if (scope !== 'local') {
|
| 425 |
+
option.callback(value, undefined);
|
| 426 |
+
}
|
| 427 |
+
if (scope !== 'global' && cm) {
|
| 428 |
+
option.callback(value, cm);
|
| 429 |
+
}
|
| 430 |
+
} else {
|
| 431 |
+
if (scope !== 'local') {
|
| 432 |
+
option.value = option.type == 'boolean' ? !!value : value;
|
| 433 |
+
}
|
| 434 |
+
if (scope !== 'global' && cm) {
|
| 435 |
+
cm.state.vim.options[name] = {value: value};
|
| 436 |
+
}
|
| 437 |
+
}
|
| 438 |
+
}
|
| 439 |
+
|
| 440 |
+
function getOption(name, cm, cfg) {
|
| 441 |
+
var option = options[name];
|
| 442 |
+
cfg = cfg || {};
|
| 443 |
+
var scope = cfg.scope;
|
| 444 |
+
if (!option) {
|
| 445 |
+
throw Error('Unknown option: ' + name);
|
| 446 |
+
}
|
| 447 |
+
if (option.callback) {
|
| 448 |
+
var local = cm && option.callback(undefined, cm);
|
| 449 |
+
if (scope !== 'global' && local !== undefined) {
|
| 450 |
+
return local;
|
| 451 |
+
}
|
| 452 |
+
if (scope !== 'local') {
|
| 453 |
+
return option.callback();
|
| 454 |
+
}
|
| 455 |
+
return;
|
| 456 |
+
} else {
|
| 457 |
+
var local = (scope !== 'global') && (cm && cm.state.vim.options[name]);
|
| 458 |
+
return (local || (scope !== 'local') && option || {}).value;
|
| 459 |
+
}
|
| 460 |
+
}
|
| 461 |
+
|
| 462 |
+
defineOption('filetype', undefined, 'string', ['ft'], function(name, cm) {
|
| 463 |
+
// Option is local. Do nothing for global.
|
| 464 |
+
if (cm === undefined) {
|
| 465 |
+
return;
|
| 466 |
+
}
|
| 467 |
+
// The 'filetype' option proxies to the CodeMirror 'mode' option.
|
| 468 |
+
if (name === undefined) {
|
| 469 |
+
var mode = cm.getOption('mode');
|
| 470 |
+
return mode == 'null' ? '' : mode;
|
| 471 |
+
} else {
|
| 472 |
+
var mode = name == '' ? 'null' : name;
|
| 473 |
+
cm.setOption('mode', mode);
|
| 474 |
+
}
|
| 475 |
+
});
|
| 476 |
+
|
| 477 |
+
var createCircularJumpList = function() {
|
| 478 |
+
var size = 100;
|
| 479 |
+
var pointer = -1;
|
| 480 |
+
var head = 0;
|
| 481 |
+
var tail = 0;
|
| 482 |
+
var buffer = new Array(size);
|
| 483 |
+
function add(cm, oldCur, newCur) {
|
| 484 |
+
var current = pointer % size;
|
| 485 |
+
var curMark = buffer[current];
|
| 486 |
+
function useNextSlot(cursor) {
|
| 487 |
+
var next = ++pointer % size;
|
| 488 |
+
var trashMark = buffer[next];
|
| 489 |
+
if (trashMark) {
|
| 490 |
+
trashMark.clear();
|
| 491 |
+
}
|
| 492 |
+
buffer[next] = cm.setBookmark(cursor);
|
| 493 |
+
}
|
| 494 |
+
if (curMark) {
|
| 495 |
+
var markPos = curMark.find();
|
| 496 |
+
// avoid recording redundant cursor position
|
| 497 |
+
if (markPos && !cursorEqual(markPos, oldCur)) {
|
| 498 |
+
useNextSlot(oldCur);
|
| 499 |
+
}
|
| 500 |
+
} else {
|
| 501 |
+
useNextSlot(oldCur);
|
| 502 |
+
}
|
| 503 |
+
useNextSlot(newCur);
|
| 504 |
+
head = pointer;
|
| 505 |
+
tail = pointer - size + 1;
|
| 506 |
+
if (tail < 0) {
|
| 507 |
+
tail = 0;
|
| 508 |
+
}
|
| 509 |
+
}
|
| 510 |
+
function move(cm, offset) {
|
| 511 |
+
pointer += offset;
|
| 512 |
+
if (pointer > head) {
|
| 513 |
+
pointer = head;
|
| 514 |
+
} else if (pointer < tail) {
|
| 515 |
+
pointer = tail;
|
| 516 |
+
}
|
| 517 |
+
var mark = buffer[(size + pointer) % size];
|
| 518 |
+
// skip marks that are temporarily removed from text buffer
|
| 519 |
+
if (mark && !mark.find()) {
|
| 520 |
+
var inc = offset > 0 ? 1 : -1;
|
| 521 |
+
var newCur;
|
| 522 |
+
var oldCur = cm.getCursor();
|
| 523 |
+
do {
|
| 524 |
+
pointer += inc;
|
| 525 |
+
mark = buffer[(size + pointer) % size];
|
| 526 |
+
// skip marks that are the same as current position
|
| 527 |
+
if (mark &&
|
| 528 |
+
(newCur = mark.find()) &&
|
| 529 |
+
!cursorEqual(oldCur, newCur)) {
|
| 530 |
+
break;
|
| 531 |
+
}
|
| 532 |
+
} while (pointer < head && pointer > tail);
|
| 533 |
+
}
|
| 534 |
+
return mark;
|
| 535 |
+
}
|
| 536 |
+
return {
|
| 537 |
+
cachedCursor: undefined, //used for # and * jumps
|
| 538 |
+
add: add,
|
| 539 |
+
move: move
|
| 540 |
+
};
|
| 541 |
+
};
|
| 542 |
+
|
| 543 |
+
// Returns an object to track the changes associated insert mode. It
|
| 544 |
+
// clones the object that is passed in, or creates an empty object one if
|
| 545 |
+
// none is provided.
|
| 546 |
+
var createInsertModeChanges = function(c) {
|
| 547 |
+
if (c) {
|
| 548 |
+
// Copy construction
|
| 549 |
+
return {
|
| 550 |
+
changes: c.changes,
|
| 551 |
+
expectCursorActivityForChange: c.expectCursorActivityForChange
|
| 552 |
+
};
|
| 553 |
+
}
|
| 554 |
+
return {
|
| 555 |
+
// Change list
|
| 556 |
+
changes: [],
|
| 557 |
+
// Set to true on change, false on cursorActivity.
|
| 558 |
+
expectCursorActivityForChange: false
|
| 559 |
+
};
|
| 560 |
+
};
|
| 561 |
+
|
| 562 |
+
function MacroModeState() {
|
| 563 |
+
this.latestRegister = undefined;
|
| 564 |
+
this.isPlaying = false;
|
| 565 |
+
this.isRecording = false;
|
| 566 |
+
this.replaySearchQueries = [];
|
| 567 |
+
this.onRecordingDone = undefined;
|
| 568 |
+
this.lastInsertModeChanges = createInsertModeChanges();
|
| 569 |
+
}
|
| 570 |
+
MacroModeState.prototype = {
|
| 571 |
+
exitMacroRecordMode: function() {
|
| 572 |
+
var macroModeState = vimGlobalState.macroModeState;
|
| 573 |
+
if (macroModeState.onRecordingDone) {
|
| 574 |
+
macroModeState.onRecordingDone(); // close dialog
|
| 575 |
+
}
|
| 576 |
+
macroModeState.onRecordingDone = undefined;
|
| 577 |
+
macroModeState.isRecording = false;
|
| 578 |
+
},
|
| 579 |
+
enterMacroRecordMode: function(cm, registerName) {
|
| 580 |
+
var register =
|
| 581 |
+
vimGlobalState.registerController.getRegister(registerName);
|
| 582 |
+
if (register) {
|
| 583 |
+
register.clear();
|
| 584 |
+
this.latestRegister = registerName;
|
| 585 |
+
if (cm.openDialog) {
|
| 586 |
+
this.onRecordingDone = cm.openDialog(
|
| 587 |
+
'(recording)['+registerName+']', null, {bottom:true});
|
| 588 |
+
}
|
| 589 |
+
this.isRecording = true;
|
| 590 |
+
}
|
| 591 |
+
}
|
| 592 |
+
};
|
| 593 |
+
|
| 594 |
+
function maybeInitVimState(cm) {
|
| 595 |
+
if (!cm.state.vim) {
|
| 596 |
+
// Store instance state in the CodeMirror object.
|
| 597 |
+
cm.state.vim = {
|
| 598 |
+
inputState: new InputState(),
|
| 599 |
+
// Vim's input state that triggered the last edit, used to repeat
|
| 600 |
+
// motions and operators with '.'.
|
| 601 |
+
lastEditInputState: undefined,
|
| 602 |
+
// Vim's action command before the last edit, used to repeat actions
|
| 603 |
+
// with '.' and insert mode repeat.
|
| 604 |
+
lastEditActionCommand: undefined,
|
| 605 |
+
// When using jk for navigation, if you move from a longer line to a
|
| 606 |
+
// shorter line, the cursor may clip to the end of the shorter line.
|
| 607 |
+
// If j is pressed again and cursor goes to the next line, the
|
| 608 |
+
// cursor should go back to its horizontal position on the longer
|
| 609 |
+
// line if it can. This is to keep track of the horizontal position.
|
| 610 |
+
lastHPos: -1,
|
| 611 |
+
// Doing the same with screen-position for gj/gk
|
| 612 |
+
lastHSPos: -1,
|
| 613 |
+
// The last motion command run. Cleared if a non-motion command gets
|
| 614 |
+
// executed in between.
|
| 615 |
+
lastMotion: null,
|
| 616 |
+
marks: {},
|
| 617 |
+
// Mark for rendering fake cursor for visual mode.
|
| 618 |
+
fakeCursor: null,
|
| 619 |
+
insertMode: false,
|
| 620 |
+
// Repeat count for changes made in insert mode, triggered by key
|
| 621 |
+
// sequences like 3,i. Only exists when insertMode is true.
|
| 622 |
+
insertModeRepeat: undefined,
|
| 623 |
+
visualMode: false,
|
| 624 |
+
// If we are in visual line mode. No effect if visualMode is false.
|
| 625 |
+
visualLine: false,
|
| 626 |
+
visualBlock: false,
|
| 627 |
+
lastSelection: null,
|
| 628 |
+
lastPastedText: null,
|
| 629 |
+
sel: {},
|
| 630 |
+
// Buffer-local/window-local values of vim options.
|
| 631 |
+
options: {}
|
| 632 |
+
};
|
| 633 |
+
}
|
| 634 |
+
return cm.state.vim;
|
| 635 |
+
}
|
| 636 |
+
var vimGlobalState;
|
| 637 |
+
function resetVimGlobalState() {
|
| 638 |
+
vimGlobalState = {
|
| 639 |
+
// The current search query.
|
| 640 |
+
searchQuery: null,
|
| 641 |
+
// Whether we are searching backwards.
|
| 642 |
+
searchIsReversed: false,
|
| 643 |
+
// Replace part of the last substituted pattern
|
| 644 |
+
lastSubstituteReplacePart: undefined,
|
| 645 |
+
jumpList: createCircularJumpList(),
|
| 646 |
+
macroModeState: new MacroModeState,
|
| 647 |
+
// Recording latest f, t, F or T motion command.
|
| 648 |
+
lastChararacterSearch: {increment:0, forward:true, selectedCharacter:''},
|
| 649 |
+
registerController: new RegisterController({}),
|
| 650 |
+
// search history buffer
|
| 651 |
+
searchHistoryController: new HistoryController({}),
|
| 652 |
+
// ex Command history buffer
|
| 653 |
+
exCommandHistoryController : new HistoryController({})
|
| 654 |
+
};
|
| 655 |
+
for (var optionName in options) {
|
| 656 |
+
var option = options[optionName];
|
| 657 |
+
option.value = option.defaultValue;
|
| 658 |
+
}
|
| 659 |
+
}
|
| 660 |
+
|
| 661 |
+
var lastInsertModeKeyTimer;
|
| 662 |
+
var vimApi= {
|
| 663 |
+
buildKeyMap: function() {
|
| 664 |
+
// TODO: Convert keymap into dictionary format for fast lookup.
|
| 665 |
+
},
|
| 666 |
+
// Testing hook, though it might be useful to expose the register
|
| 667 |
+
// controller anyways.
|
| 668 |
+
getRegisterController: function() {
|
| 669 |
+
return vimGlobalState.registerController;
|
| 670 |
+
},
|
| 671 |
+
// Testing hook.
|
| 672 |
+
resetVimGlobalState_: resetVimGlobalState,
|
| 673 |
+
|
| 674 |
+
// Testing hook.
|
| 675 |
+
getVimGlobalState_: function() {
|
| 676 |
+
return vimGlobalState;
|
| 677 |
+
},
|
| 678 |
+
|
| 679 |
+
// Testing hook.
|
| 680 |
+
maybeInitVimState_: maybeInitVimState,
|
| 681 |
+
|
| 682 |
+
suppressErrorLogging: false,
|
| 683 |
+
|
| 684 |
+
InsertModeKey: InsertModeKey,
|
| 685 |
+
map: function(lhs, rhs, ctx) {
|
| 686 |
+
// Add user defined key bindings.
|
| 687 |
+
exCommandDispatcher.map(lhs, rhs, ctx);
|
| 688 |
+
},
|
| 689 |
+
// TODO: Expose setOption and getOption as instance methods. Need to decide how to namespace
|
| 690 |
+
// them, or somehow make them work with the existing CodeMirror setOption/getOption API.
|
| 691 |
+
setOption: setOption,
|
| 692 |
+
getOption: getOption,
|
| 693 |
+
defineOption: defineOption,
|
| 694 |
+
defineEx: function(name, prefix, func){
|
| 695 |
+
if (!prefix) {
|
| 696 |
+
prefix = name;
|
| 697 |
+
} else if (name.indexOf(prefix) !== 0) {
|
| 698 |
+
throw new Error('(Vim.defineEx) "'+prefix+'" is not a prefix of "'+name+'", command not registered');
|
| 699 |
+
}
|
| 700 |
+
exCommands[name]=func;
|
| 701 |
+
exCommandDispatcher.commandMap_[prefix]={name:name, shortName:prefix, type:'api'};
|
| 702 |
+
},
|
| 703 |
+
handleKey: function (cm, key, origin) {
|
| 704 |
+
var command = this.findKey(cm, key, origin);
|
| 705 |
+
if (typeof command === 'function') {
|
| 706 |
+
return command();
|
| 707 |
+
}
|
| 708 |
+
},
|
| 709 |
+
/**
|
| 710 |
+
* This is the outermost function called by CodeMirror, after keys have
|
| 711 |
+
* been mapped to their Vim equivalents.
|
| 712 |
+
*
|
| 713 |
+
* Finds a command based on the key (and cached keys if there is a
|
| 714 |
+
* multi-key sequence). Returns `undefined` if no key is matched, a noop
|
| 715 |
+
* function if a partial match is found (multi-key), and a function to
|
| 716 |
+
* execute the bound command if a a key is matched. The function always
|
| 717 |
+
* returns true.
|
| 718 |
+
*/
|
| 719 |
+
findKey: function(cm, key, origin) {
|
| 720 |
+
var vim = maybeInitVimState(cm);
|
| 721 |
+
function handleMacroRecording() {
|
| 722 |
+
var macroModeState = vimGlobalState.macroModeState;
|
| 723 |
+
if (macroModeState.isRecording) {
|
| 724 |
+
if (key == 'q') {
|
| 725 |
+
macroModeState.exitMacroRecordMode();
|
| 726 |
+
clearInputState(cm);
|
| 727 |
+
return true;
|
| 728 |
+
}
|
| 729 |
+
if (origin != 'mapping') {
|
| 730 |
+
logKey(macroModeState, key);
|
| 731 |
+
}
|
| 732 |
+
}
|
| 733 |
+
}
|
| 734 |
+
function handleEsc() {
|
| 735 |
+
if (key == '<Esc>') {
|
| 736 |
+
// Clear input state and get back to normal mode.
|
| 737 |
+
clearInputState(cm);
|
| 738 |
+
if (vim.visualMode) {
|
| 739 |
+
exitVisualMode(cm);
|
| 740 |
+
} else if (vim.insertMode) {
|
| 741 |
+
exitInsertMode(cm);
|
| 742 |
+
}
|
| 743 |
+
return true;
|
| 744 |
+
}
|
| 745 |
+
}
|
| 746 |
+
function doKeyToKey(keys) {
|
| 747 |
+
// TODO: prevent infinite recursion.
|
| 748 |
+
var match;
|
| 749 |
+
while (keys) {
|
| 750 |
+
// Pull off one command key, which is either a single character
|
| 751 |
+
// or a special sequence wrapped in '<' and '>', e.g. '<Space>'.
|
| 752 |
+
match = (/<\w+-.+?>|<\w+>|./).exec(keys);
|
| 753 |
+
key = match[0];
|
| 754 |
+
keys = keys.substring(match.index + key.length);
|
| 755 |
+
CodeMirror.Vim.handleKey(cm, key, 'mapping');
|
| 756 |
+
}
|
| 757 |
+
}
|
| 758 |
+
|
| 759 |
+
function handleKeyInsertMode() {
|
| 760 |
+
if (handleEsc()) { return true; }
|
| 761 |
+
var keys = vim.inputState.keyBuffer = vim.inputState.keyBuffer + key;
|
| 762 |
+
var keysAreChars = key.length == 1;
|
| 763 |
+
var match = commandDispatcher.matchCommand(keys, defaultKeymap, vim.inputState, 'insert');
|
| 764 |
+
// Need to check all key substrings in insert mode.
|
| 765 |
+
while (keys.length > 1 && match.type != 'full') {
|
| 766 |
+
var keys = vim.inputState.keyBuffer = keys.slice(1);
|
| 767 |
+
var thisMatch = commandDispatcher.matchCommand(keys, defaultKeymap, vim.inputState, 'insert');
|
| 768 |
+
if (thisMatch.type != 'none') { match = thisMatch; }
|
| 769 |
+
}
|
| 770 |
+
if (match.type == 'none') { clearInputState(cm); return false; }
|
| 771 |
+
else if (match.type == 'partial') {
|
| 772 |
+
if (lastInsertModeKeyTimer) { window.clearTimeout(lastInsertModeKeyTimer); }
|
| 773 |
+
lastInsertModeKeyTimer = window.setTimeout(
|
| 774 |
+
function() { if (vim.insertMode && vim.inputState.keyBuffer) { clearInputState(cm); } },
|
| 775 |
+
getOption('insertModeEscKeysTimeout'));
|
| 776 |
+
return !keysAreChars;
|
| 777 |
+
}
|
| 778 |
+
|
| 779 |
+
if (lastInsertModeKeyTimer) { window.clearTimeout(lastInsertModeKeyTimer); }
|
| 780 |
+
if (keysAreChars) {
|
| 781 |
+
var here = cm.getCursor();
|
| 782 |
+
cm.replaceRange('', offsetCursor(here, 0, -(keys.length - 1)), here, '+input');
|
| 783 |
+
}
|
| 784 |
+
clearInputState(cm);
|
| 785 |
+
return match.command;
|
| 786 |
+
}
|
| 787 |
+
|
| 788 |
+
function handleKeyNonInsertMode() {
|
| 789 |
+
if (handleMacroRecording() || handleEsc()) { return true; };
|
| 790 |
+
|
| 791 |
+
var keys = vim.inputState.keyBuffer = vim.inputState.keyBuffer + key;
|
| 792 |
+
if (/^[1-9]\d*$/.test(keys)) { return true; }
|
| 793 |
+
|
| 794 |
+
var keysMatcher = /^(\d*)(.*)$/.exec(keys);
|
| 795 |
+
if (!keysMatcher) { clearInputState(cm); return false; }
|
| 796 |
+
var context = vim.visualMode ? 'visual' :
|
| 797 |
+
'normal';
|
| 798 |
+
var match = commandDispatcher.matchCommand(keysMatcher[2] || keysMatcher[1], defaultKeymap, vim.inputState, context);
|
| 799 |
+
if (match.type == 'none') { clearInputState(cm); return false; }
|
| 800 |
+
else if (match.type == 'partial') { return true; }
|
| 801 |
+
|
| 802 |
+
vim.inputState.keyBuffer = '';
|
| 803 |
+
var keysMatcher = /^(\d*)(.*)$/.exec(keys);
|
| 804 |
+
if (keysMatcher[1] && keysMatcher[1] != '0') {
|
| 805 |
+
vim.inputState.pushRepeatDigit(keysMatcher[1]);
|
| 806 |
+
}
|
| 807 |
+
return match.command;
|
| 808 |
+
}
|
| 809 |
+
|
| 810 |
+
var command;
|
| 811 |
+
if (vim.insertMode) { command = handleKeyInsertMode(); }
|
| 812 |
+
else { command = handleKeyNonInsertMode(); }
|
| 813 |
+
if (command === false) {
|
| 814 |
+
return undefined;
|
| 815 |
+
} else if (command === true) {
|
| 816 |
+
// TODO: Look into using CodeMirror's multi-key handling.
|
| 817 |
+
// Return no-op since we are caching the key. Counts as handled, but
|
| 818 |
+
// don't want act on it just yet.
|
| 819 |
+
return function() {};
|
| 820 |
+
} else {
|
| 821 |
+
return function() {
|
| 822 |
+
return cm.operation(function() {
|
| 823 |
+
cm.curOp.isVimOp = true;
|
| 824 |
+
try {
|
| 825 |
+
if (command.type == 'keyToKey') {
|
| 826 |
+
doKeyToKey(command.toKeys);
|
| 827 |
+
} else {
|
| 828 |
+
commandDispatcher.processCommand(cm, vim, command);
|
| 829 |
+
}
|
| 830 |
+
} catch (e) {
|
| 831 |
+
// clear VIM state in case it's in a bad state.
|
| 832 |
+
cm.state.vim = undefined;
|
| 833 |
+
maybeInitVimState(cm);
|
| 834 |
+
if (!CodeMirror.Vim.suppressErrorLogging) {
|
| 835 |
+
console['log'](e);
|
| 836 |
+
}
|
| 837 |
+
throw e;
|
| 838 |
+
}
|
| 839 |
+
return true;
|
| 840 |
+
});
|
| 841 |
+
};
|
| 842 |
+
}
|
| 843 |
+
},
|
| 844 |
+
handleEx: function(cm, input) {
|
| 845 |
+
exCommandDispatcher.processCommand(cm, input);
|
| 846 |
+
},
|
| 847 |
+
|
| 848 |
+
defineMotion: defineMotion,
|
| 849 |
+
defineAction: defineAction,
|
| 850 |
+
defineOperator: defineOperator,
|
| 851 |
+
mapCommand: mapCommand,
|
| 852 |
+
_mapCommand: _mapCommand,
|
| 853 |
+
|
| 854 |
+
exitVisualMode: exitVisualMode,
|
| 855 |
+
exitInsertMode: exitInsertMode
|
| 856 |
+
};
|
| 857 |
+
|
| 858 |
+
// Represents the current input state.
|
| 859 |
+
function InputState() {
|
| 860 |
+
this.prefixRepeat = [];
|
| 861 |
+
this.motionRepeat = [];
|
| 862 |
+
|
| 863 |
+
this.operator = null;
|
| 864 |
+
this.operatorArgs = null;
|
| 865 |
+
this.motion = null;
|
| 866 |
+
this.motionArgs = null;
|
| 867 |
+
this.keyBuffer = []; // For matching multi-key commands.
|
| 868 |
+
this.registerName = null; // Defaults to the unnamed register.
|
| 869 |
+
}
|
| 870 |
+
InputState.prototype.pushRepeatDigit = function(n) {
|
| 871 |
+
if (!this.operator) {
|
| 872 |
+
this.prefixRepeat = this.prefixRepeat.concat(n);
|
| 873 |
+
} else {
|
| 874 |
+
this.motionRepeat = this.motionRepeat.concat(n);
|
| 875 |
+
}
|
| 876 |
+
};
|
| 877 |
+
InputState.prototype.getRepeat = function() {
|
| 878 |
+
var repeat = 0;
|
| 879 |
+
if (this.prefixRepeat.length > 0 || this.motionRepeat.length > 0) {
|
| 880 |
+
repeat = 1;
|
| 881 |
+
if (this.prefixRepeat.length > 0) {
|
| 882 |
+
repeat *= parseInt(this.prefixRepeat.join(''), 10);
|
| 883 |
+
}
|
| 884 |
+
if (this.motionRepeat.length > 0) {
|
| 885 |
+
repeat *= parseInt(this.motionRepeat.join(''), 10);
|
| 886 |
+
}
|
| 887 |
+
}
|
| 888 |
+
return repeat;
|
| 889 |
+
};
|
| 890 |
+
|
| 891 |
+
function clearInputState(cm, reason) {
|
| 892 |
+
cm.state.vim.inputState = new InputState();
|
| 893 |
+
CodeMirror.signal(cm, 'vim-command-done', reason);
|
| 894 |
+
}
|
| 895 |
+
|
| 896 |
+
/*
|
| 897 |
+
* Register stores information about copy and paste registers. Besides
|
| 898 |
+
* text, a register must store whether it is linewise (i.e., when it is
|
| 899 |
+
* pasted, should it insert itself into a new line, or should the text be
|
| 900 |
+
* inserted at the cursor position.)
|
| 901 |
+
*/
|
| 902 |
+
function Register(text, linewise, blockwise) {
|
| 903 |
+
this.clear();
|
| 904 |
+
this.keyBuffer = [text || ''];
|
| 905 |
+
this.insertModeChanges = [];
|
| 906 |
+
this.searchQueries = [];
|
| 907 |
+
this.linewise = !!linewise;
|
| 908 |
+
this.blockwise = !!blockwise;
|
| 909 |
+
}
|
| 910 |
+
Register.prototype = {
|
| 911 |
+
setText: function(text, linewise, blockwise) {
|
| 912 |
+
this.keyBuffer = [text || ''];
|
| 913 |
+
this.linewise = !!linewise;
|
| 914 |
+
this.blockwise = !!blockwise;
|
| 915 |
+
},
|
| 916 |
+
pushText: function(text, linewise) {
|
| 917 |
+
// if this register has ever been set to linewise, use linewise.
|
| 918 |
+
if (linewise) {
|
| 919 |
+
if (!this.linewise) {
|
| 920 |
+
this.keyBuffer.push('\n');
|
| 921 |
+
}
|
| 922 |
+
this.linewise = true;
|
| 923 |
+
}
|
| 924 |
+
this.keyBuffer.push(text);
|
| 925 |
+
},
|
| 926 |
+
pushInsertModeChanges: function(changes) {
|
| 927 |
+
this.insertModeChanges.push(createInsertModeChanges(changes));
|
| 928 |
+
},
|
| 929 |
+
pushSearchQuery: function(query) {
|
| 930 |
+
this.searchQueries.push(query);
|
| 931 |
+
},
|
| 932 |
+
clear: function() {
|
| 933 |
+
this.keyBuffer = [];
|
| 934 |
+
this.insertModeChanges = [];
|
| 935 |
+
this.searchQueries = [];
|
| 936 |
+
this.linewise = false;
|
| 937 |
+
},
|
| 938 |
+
toString: function() {
|
| 939 |
+
return this.keyBuffer.join('');
|
| 940 |
+
}
|
| 941 |
+
};
|
| 942 |
+
|
| 943 |
+
/*
|
| 944 |
+
* vim registers allow you to keep many independent copy and paste buffers.
|
| 945 |
+
* See http://usevim.com/2012/04/13/registers/ for an introduction.
|
| 946 |
+
*
|
| 947 |
+
* RegisterController keeps the state of all the registers. An initial
|
| 948 |
+
* state may be passed in. The unnamed register '"' will always be
|
| 949 |
+
* overridden.
|
| 950 |
+
*/
|
| 951 |
+
function RegisterController(registers) {
|
| 952 |
+
this.registers = registers;
|
| 953 |
+
this.unnamedRegister = registers['"'] = new Register();
|
| 954 |
+
registers['.'] = new Register();
|
| 955 |
+
registers[':'] = new Register();
|
| 956 |
+
registers['/'] = new Register();
|
| 957 |
+
}
|
| 958 |
+
RegisterController.prototype = {
|
| 959 |
+
pushText: function(registerName, operator, text, linewise, blockwise) {
|
| 960 |
+
if (linewise && text.charAt(0) == '\n') {
|
| 961 |
+
text = text.slice(1) + '\n';
|
| 962 |
+
}
|
| 963 |
+
if (linewise && text.charAt(text.length - 1) !== '\n'){
|
| 964 |
+
text += '\n';
|
| 965 |
+
}
|
| 966 |
+
// Lowercase and uppercase registers refer to the same register.
|
| 967 |
+
// Uppercase just means append.
|
| 968 |
+
var register = this.isValidRegister(registerName) ?
|
| 969 |
+
this.getRegister(registerName) : null;
|
| 970 |
+
// if no register/an invalid register was specified, things go to the
|
| 971 |
+
// default registers
|
| 972 |
+
if (!register) {
|
| 973 |
+
switch (operator) {
|
| 974 |
+
case 'yank':
|
| 975 |
+
// The 0 register contains the text from the most recent yank.
|
| 976 |
+
this.registers['0'] = new Register(text, linewise, blockwise);
|
| 977 |
+
break;
|
| 978 |
+
case 'delete':
|
| 979 |
+
case 'change':
|
| 980 |
+
if (text.indexOf('\n') == -1) {
|
| 981 |
+
// Delete less than 1 line. Update the small delete register.
|
| 982 |
+
this.registers['-'] = new Register(text, linewise);
|
| 983 |
+
} else {
|
| 984 |
+
// Shift down the contents of the numbered registers and put the
|
| 985 |
+
// deleted text into register 1.
|
| 986 |
+
this.shiftNumericRegisters_();
|
| 987 |
+
this.registers['1'] = new Register(text, linewise);
|
| 988 |
+
}
|
| 989 |
+
break;
|
| 990 |
+
}
|
| 991 |
+
// Make sure the unnamed register is set to what just happened
|
| 992 |
+
this.unnamedRegister.setText(text, linewise, blockwise);
|
| 993 |
+
return;
|
| 994 |
+
}
|
| 995 |
+
|
| 996 |
+
// If we've gotten to this point, we've actually specified a register
|
| 997 |
+
var append = isUpperCase(registerName);
|
| 998 |
+
if (append) {
|
| 999 |
+
register.pushText(text, linewise);
|
| 1000 |
+
} else {
|
| 1001 |
+
register.setText(text, linewise, blockwise);
|
| 1002 |
+
}
|
| 1003 |
+
// The unnamed register always has the same value as the last used
|
| 1004 |
+
// register.
|
| 1005 |
+
this.unnamedRegister.setText(register.toString(), linewise);
|
| 1006 |
+
},
|
| 1007 |
+
// Gets the register named @name. If one of @name doesn't already exist,
|
| 1008 |
+
// create it. If @name is invalid, return the unnamedRegister.
|
| 1009 |
+
getRegister: function(name) {
|
| 1010 |
+
if (!this.isValidRegister(name)) {
|
| 1011 |
+
return this.unnamedRegister;
|
| 1012 |
+
}
|
| 1013 |
+
name = name.toLowerCase();
|
| 1014 |
+
if (!this.registers[name]) {
|
| 1015 |
+
this.registers[name] = new Register();
|
| 1016 |
+
}
|
| 1017 |
+
return this.registers[name];
|
| 1018 |
+
},
|
| 1019 |
+
isValidRegister: function(name) {
|
| 1020 |
+
return name && inArray(name, validRegisters);
|
| 1021 |
+
},
|
| 1022 |
+
shiftNumericRegisters_: function() {
|
| 1023 |
+
for (var i = 9; i >= 2; i--) {
|
| 1024 |
+
this.registers[i] = this.getRegister('' + (i - 1));
|
| 1025 |
+
}
|
| 1026 |
+
}
|
| 1027 |
+
};
|
| 1028 |
+
function HistoryController() {
|
| 1029 |
+
this.historyBuffer = [];
|
| 1030 |
+
this.iterator;
|
| 1031 |
+
this.initialPrefix = null;
|
| 1032 |
+
}
|
| 1033 |
+
HistoryController.prototype = {
|
| 1034 |
+
// the input argument here acts a user entered prefix for a small time
|
| 1035 |
+
// until we start autocompletion in which case it is the autocompleted.
|
| 1036 |
+
nextMatch: function (input, up) {
|
| 1037 |
+
var historyBuffer = this.historyBuffer;
|
| 1038 |
+
var dir = up ? -1 : 1;
|
| 1039 |
+
if (this.initialPrefix === null) this.initialPrefix = input;
|
| 1040 |
+
for (var i = this.iterator + dir; up ? i >= 0 : i < historyBuffer.length; i+= dir) {
|
| 1041 |
+
var element = historyBuffer[i];
|
| 1042 |
+
for (var j = 0; j <= element.length; j++) {
|
| 1043 |
+
if (this.initialPrefix == element.substring(0, j)) {
|
| 1044 |
+
this.iterator = i;
|
| 1045 |
+
return element;
|
| 1046 |
+
}
|
| 1047 |
+
}
|
| 1048 |
+
}
|
| 1049 |
+
// should return the user input in case we reach the end of buffer.
|
| 1050 |
+
if (i >= historyBuffer.length) {
|
| 1051 |
+
this.iterator = historyBuffer.length;
|
| 1052 |
+
return this.initialPrefix;
|
| 1053 |
+
}
|
| 1054 |
+
// return the last autocompleted query or exCommand as it is.
|
| 1055 |
+
if (i < 0 ) return input;
|
| 1056 |
+
},
|
| 1057 |
+
pushInput: function(input) {
|
| 1058 |
+
var index = this.historyBuffer.indexOf(input);
|
| 1059 |
+
if (index > -1) this.historyBuffer.splice(index, 1);
|
| 1060 |
+
if (input.length) this.historyBuffer.push(input);
|
| 1061 |
+
},
|
| 1062 |
+
reset: function() {
|
| 1063 |
+
this.initialPrefix = null;
|
| 1064 |
+
this.iterator = this.historyBuffer.length;
|
| 1065 |
+
}
|
| 1066 |
+
};
|
| 1067 |
+
var commandDispatcher = {
|
| 1068 |
+
matchCommand: function(keys, keyMap, inputState, context) {
|
| 1069 |
+
var matches = commandMatches(keys, keyMap, context, inputState);
|
| 1070 |
+
if (!matches.full && !matches.partial) {
|
| 1071 |
+
return {type: 'none'};
|
| 1072 |
+
} else if (!matches.full && matches.partial) {
|
| 1073 |
+
return {type: 'partial'};
|
| 1074 |
+
}
|
| 1075 |
+
|
| 1076 |
+
var bestMatch;
|
| 1077 |
+
for (var i = 0; i < matches.full.length; i++) {
|
| 1078 |
+
var match = matches.full[i];
|
| 1079 |
+
if (!bestMatch) {
|
| 1080 |
+
bestMatch = match;
|
| 1081 |
+
}
|
| 1082 |
+
}
|
| 1083 |
+
if (bestMatch.keys.slice(-11) == '<character>') {
|
| 1084 |
+
inputState.selectedCharacter = lastChar(keys);
|
| 1085 |
+
}
|
| 1086 |
+
return {type: 'full', command: bestMatch};
|
| 1087 |
+
},
|
| 1088 |
+
processCommand: function(cm, vim, command) {
|
| 1089 |
+
vim.inputState.repeatOverride = command.repeatOverride;
|
| 1090 |
+
switch (command.type) {
|
| 1091 |
+
case 'motion':
|
| 1092 |
+
this.processMotion(cm, vim, command);
|
| 1093 |
+
break;
|
| 1094 |
+
case 'operator':
|
| 1095 |
+
this.processOperator(cm, vim, command);
|
| 1096 |
+
break;
|
| 1097 |
+
case 'operatorMotion':
|
| 1098 |
+
this.processOperatorMotion(cm, vim, command);
|
| 1099 |
+
break;
|
| 1100 |
+
case 'action':
|
| 1101 |
+
this.processAction(cm, vim, command);
|
| 1102 |
+
break;
|
| 1103 |
+
case 'search':
|
| 1104 |
+
this.processSearch(cm, vim, command);
|
| 1105 |
+
break;
|
| 1106 |
+
case 'ex':
|
| 1107 |
+
case 'keyToEx':
|
| 1108 |
+
this.processEx(cm, vim, command);
|
| 1109 |
+
break;
|
| 1110 |
+
default:
|
| 1111 |
+
break;
|
| 1112 |
+
}
|
| 1113 |
+
},
|
| 1114 |
+
processMotion: function(cm, vim, command) {
|
| 1115 |
+
vim.inputState.motion = command.motion;
|
| 1116 |
+
vim.inputState.motionArgs = copyArgs(command.motionArgs);
|
| 1117 |
+
this.evalInput(cm, vim);
|
| 1118 |
+
},
|
| 1119 |
+
processOperator: function(cm, vim, command) {
|
| 1120 |
+
var inputState = vim.inputState;
|
| 1121 |
+
if (inputState.operator) {
|
| 1122 |
+
if (inputState.operator == command.operator) {
|
| 1123 |
+
// Typing an operator twice like 'dd' makes the operator operate
|
| 1124 |
+
// linewise
|
| 1125 |
+
inputState.motion = 'expandToLine';
|
| 1126 |
+
inputState.motionArgs = { linewise: true };
|
| 1127 |
+
this.evalInput(cm, vim);
|
| 1128 |
+
return;
|
| 1129 |
+
} else {
|
| 1130 |
+
// 2 different operators in a row doesn't make sense.
|
| 1131 |
+
clearInputState(cm);
|
| 1132 |
+
}
|
| 1133 |
+
}
|
| 1134 |
+
inputState.operator = command.operator;
|
| 1135 |
+
inputState.operatorArgs = copyArgs(command.operatorArgs);
|
| 1136 |
+
if (vim.visualMode) {
|
| 1137 |
+
// Operating on a selection in visual mode. We don't need a motion.
|
| 1138 |
+
this.evalInput(cm, vim);
|
| 1139 |
+
}
|
| 1140 |
+
},
|
| 1141 |
+
processOperatorMotion: function(cm, vim, command) {
|
| 1142 |
+
var visualMode = vim.visualMode;
|
| 1143 |
+
var operatorMotionArgs = copyArgs(command.operatorMotionArgs);
|
| 1144 |
+
if (operatorMotionArgs) {
|
| 1145 |
+
// Operator motions may have special behavior in visual mode.
|
| 1146 |
+
if (visualMode && operatorMotionArgs.visualLine) {
|
| 1147 |
+
vim.visualLine = true;
|
| 1148 |
+
}
|
| 1149 |
+
}
|
| 1150 |
+
this.processOperator(cm, vim, command);
|
| 1151 |
+
if (!visualMode) {
|
| 1152 |
+
this.processMotion(cm, vim, command);
|
| 1153 |
+
}
|
| 1154 |
+
},
|
| 1155 |
+
processAction: function(cm, vim, command) {
|
| 1156 |
+
var inputState = vim.inputState;
|
| 1157 |
+
var repeat = inputState.getRepeat();
|
| 1158 |
+
var repeatIsExplicit = !!repeat;
|
| 1159 |
+
var actionArgs = copyArgs(command.actionArgs) || {};
|
| 1160 |
+
if (inputState.selectedCharacter) {
|
| 1161 |
+
actionArgs.selectedCharacter = inputState.selectedCharacter;
|
| 1162 |
+
}
|
| 1163 |
+
// Actions may or may not have motions and operators. Do these first.
|
| 1164 |
+
if (command.operator) {
|
| 1165 |
+
this.processOperator(cm, vim, command);
|
| 1166 |
+
}
|
| 1167 |
+
if (command.motion) {
|
| 1168 |
+
this.processMotion(cm, vim, command);
|
| 1169 |
+
}
|
| 1170 |
+
if (command.motion || command.operator) {
|
| 1171 |
+
this.evalInput(cm, vim);
|
| 1172 |
+
}
|
| 1173 |
+
actionArgs.repeat = repeat || 1;
|
| 1174 |
+
actionArgs.repeatIsExplicit = repeatIsExplicit;
|
| 1175 |
+
actionArgs.registerName = inputState.registerName;
|
| 1176 |
+
clearInputState(cm);
|
| 1177 |
+
vim.lastMotion = null;
|
| 1178 |
+
if (command.isEdit) {
|
| 1179 |
+
this.recordLastEdit(vim, inputState, command);
|
| 1180 |
+
}
|
| 1181 |
+
actions[command.action](cm, actionArgs, vim);
|
| 1182 |
+
},
|
| 1183 |
+
processSearch: function(cm, vim, command) {
|
| 1184 |
+
if (!cm.getSearchCursor) {
|
| 1185 |
+
// Search depends on SearchCursor.
|
| 1186 |
+
return;
|
| 1187 |
+
}
|
| 1188 |
+
var forward = command.searchArgs.forward;
|
| 1189 |
+
var wholeWordOnly = command.searchArgs.wholeWordOnly;
|
| 1190 |
+
getSearchState(cm).setReversed(!forward);
|
| 1191 |
+
var promptPrefix = (forward) ? '/' : '?';
|
| 1192 |
+
var originalQuery = getSearchState(cm).getQuery();
|
| 1193 |
+
var originalScrollPos = cm.getScrollInfo();
|
| 1194 |
+
function handleQuery(query, ignoreCase, smartCase) {
|
| 1195 |
+
vimGlobalState.searchHistoryController.pushInput(query);
|
| 1196 |
+
vimGlobalState.searchHistoryController.reset();
|
| 1197 |
+
try {
|
| 1198 |
+
updateSearchQuery(cm, query, ignoreCase, smartCase);
|
| 1199 |
+
} catch (e) {
|
| 1200 |
+
showConfirm(cm, 'Invalid regex: ' + query);
|
| 1201 |
+
clearInputState(cm);
|
| 1202 |
+
return;
|
| 1203 |
+
}
|
| 1204 |
+
commandDispatcher.processMotion(cm, vim, {
|
| 1205 |
+
type: 'motion',
|
| 1206 |
+
motion: 'findNext',
|
| 1207 |
+
motionArgs: { forward: true, toJumplist: command.searchArgs.toJumplist }
|
| 1208 |
+
});
|
| 1209 |
+
}
|
| 1210 |
+
function onPromptClose(query) {
|
| 1211 |
+
cm.scrollTo(originalScrollPos.left, originalScrollPos.top);
|
| 1212 |
+
handleQuery(query, true /** ignoreCase */, true /** smartCase */);
|
| 1213 |
+
var macroModeState = vimGlobalState.macroModeState;
|
| 1214 |
+
if (macroModeState.isRecording) {
|
| 1215 |
+
logSearchQuery(macroModeState, query);
|
| 1216 |
+
}
|
| 1217 |
+
}
|
| 1218 |
+
function onPromptKeyUp(e, query, close) {
|
| 1219 |
+
var keyName = CodeMirror.keyName(e), up;
|
| 1220 |
+
if (keyName == 'Up' || keyName == 'Down') {
|
| 1221 |
+
up = keyName == 'Up' ? true : false;
|
| 1222 |
+
query = vimGlobalState.searchHistoryController.nextMatch(query, up) || '';
|
| 1223 |
+
close(query);
|
| 1224 |
+
} else {
|
| 1225 |
+
if ( keyName != 'Left' && keyName != 'Right' && keyName != 'Ctrl' && keyName != 'Alt' && keyName != 'Shift')
|
| 1226 |
+
vimGlobalState.searchHistoryController.reset();
|
| 1227 |
+
}
|
| 1228 |
+
var parsedQuery;
|
| 1229 |
+
try {
|
| 1230 |
+
parsedQuery = updateSearchQuery(cm, query,
|
| 1231 |
+
true /** ignoreCase */, true /** smartCase */);
|
| 1232 |
+
} catch (e) {
|
| 1233 |
+
// Swallow bad regexes for incremental search.
|
| 1234 |
+
}
|
| 1235 |
+
if (parsedQuery) {
|
| 1236 |
+
cm.scrollIntoView(findNext(cm, !forward, parsedQuery), 30);
|
| 1237 |
+
} else {
|
| 1238 |
+
clearSearchHighlight(cm);
|
| 1239 |
+
cm.scrollTo(originalScrollPos.left, originalScrollPos.top);
|
| 1240 |
+
}
|
| 1241 |
+
}
|
| 1242 |
+
function onPromptKeyDown(e, query, close) {
|
| 1243 |
+
var keyName = CodeMirror.keyName(e);
|
| 1244 |
+
if (keyName == 'Esc' || keyName == 'Ctrl-C' || keyName == 'Ctrl-[' ||
|
| 1245 |
+
(keyName == 'Backspace' && query == '')) {
|
| 1246 |
+
vimGlobalState.searchHistoryController.pushInput(query);
|
| 1247 |
+
vimGlobalState.searchHistoryController.reset();
|
| 1248 |
+
updateSearchQuery(cm, originalQuery);
|
| 1249 |
+
clearSearchHighlight(cm);
|
| 1250 |
+
cm.scrollTo(originalScrollPos.left, originalScrollPos.top);
|
| 1251 |
+
CodeMirror.e_stop(e);
|
| 1252 |
+
clearInputState(cm);
|
| 1253 |
+
close();
|
| 1254 |
+
cm.focus();
|
| 1255 |
+
} else if (keyName == 'Ctrl-U') {
|
| 1256 |
+
// Ctrl-U clears input.
|
| 1257 |
+
CodeMirror.e_stop(e);
|
| 1258 |
+
close('');
|
| 1259 |
+
}
|
| 1260 |
+
}
|
| 1261 |
+
switch (command.searchArgs.querySrc) {
|
| 1262 |
+
case 'prompt':
|
| 1263 |
+
var macroModeState = vimGlobalState.macroModeState;
|
| 1264 |
+
if (macroModeState.isPlaying) {
|
| 1265 |
+
var query = macroModeState.replaySearchQueries.shift();
|
| 1266 |
+
handleQuery(query, true /** ignoreCase */, false /** smartCase */);
|
| 1267 |
+
} else {
|
| 1268 |
+
showPrompt(cm, {
|
| 1269 |
+
onClose: onPromptClose,
|
| 1270 |
+
prefix: promptPrefix,
|
| 1271 |
+
desc: searchPromptDesc,
|
| 1272 |
+
onKeyUp: onPromptKeyUp,
|
| 1273 |
+
onKeyDown: onPromptKeyDown
|
| 1274 |
+
});
|
| 1275 |
+
}
|
| 1276 |
+
break;
|
| 1277 |
+
case 'wordUnderCursor':
|
| 1278 |
+
var word = expandWordUnderCursor(cm, false /** inclusive */,
|
| 1279 |
+
true /** forward */, false /** bigWord */,
|
| 1280 |
+
true /** noSymbol */);
|
| 1281 |
+
var isKeyword = true;
|
| 1282 |
+
if (!word) {
|
| 1283 |
+
word = expandWordUnderCursor(cm, false /** inclusive */,
|
| 1284 |
+
true /** forward */, false /** bigWord */,
|
| 1285 |
+
false /** noSymbol */);
|
| 1286 |
+
isKeyword = false;
|
| 1287 |
+
}
|
| 1288 |
+
if (!word) {
|
| 1289 |
+
return;
|
| 1290 |
+
}
|
| 1291 |
+
var query = cm.getLine(word.start.line).substring(word.start.ch,
|
| 1292 |
+
word.end.ch);
|
| 1293 |
+
if (isKeyword && wholeWordOnly) {
|
| 1294 |
+
query = '\\b' + query + '\\b';
|
| 1295 |
+
} else {
|
| 1296 |
+
query = escapeRegex(query);
|
| 1297 |
+
}
|
| 1298 |
+
|
| 1299 |
+
// cachedCursor is used to save the old position of the cursor
|
| 1300 |
+
// when * or # causes vim to seek for the nearest word and shift
|
| 1301 |
+
// the cursor before entering the motion.
|
| 1302 |
+
vimGlobalState.jumpList.cachedCursor = cm.getCursor();
|
| 1303 |
+
cm.setCursor(word.start);
|
| 1304 |
+
|
| 1305 |
+
handleQuery(query, true /** ignoreCase */, false /** smartCase */);
|
| 1306 |
+
break;
|
| 1307 |
+
}
|
| 1308 |
+
},
|
| 1309 |
+
processEx: function(cm, vim, command) {
|
| 1310 |
+
function onPromptClose(input) {
|
| 1311 |
+
// Give the prompt some time to close so that if processCommand shows
|
| 1312 |
+
// an error, the elements don't overlap.
|
| 1313 |
+
vimGlobalState.exCommandHistoryController.pushInput(input);
|
| 1314 |
+
vimGlobalState.exCommandHistoryController.reset();
|
| 1315 |
+
exCommandDispatcher.processCommand(cm, input);
|
| 1316 |
+
}
|
| 1317 |
+
function onPromptKeyDown(e, input, close) {
|
| 1318 |
+
var keyName = CodeMirror.keyName(e), up;
|
| 1319 |
+
if (keyName == 'Esc' || keyName == 'Ctrl-C' || keyName == 'Ctrl-[' ||
|
| 1320 |
+
(keyName == 'Backspace' && input == '')) {
|
| 1321 |
+
vimGlobalState.exCommandHistoryController.pushInput(input);
|
| 1322 |
+
vimGlobalState.exCommandHistoryController.reset();
|
| 1323 |
+
CodeMirror.e_stop(e);
|
| 1324 |
+
clearInputState(cm);
|
| 1325 |
+
close();
|
| 1326 |
+
cm.focus();
|
| 1327 |
+
}
|
| 1328 |
+
if (keyName == 'Up' || keyName == 'Down') {
|
| 1329 |
+
up = keyName == 'Up' ? true : false;
|
| 1330 |
+
input = vimGlobalState.exCommandHistoryController.nextMatch(input, up) || '';
|
| 1331 |
+
close(input);
|
| 1332 |
+
} else if (keyName == 'Ctrl-U') {
|
| 1333 |
+
// Ctrl-U clears input.
|
| 1334 |
+
CodeMirror.e_stop(e);
|
| 1335 |
+
close('');
|
| 1336 |
+
} else {
|
| 1337 |
+
if ( keyName != 'Left' && keyName != 'Right' && keyName != 'Ctrl' && keyName != 'Alt' && keyName != 'Shift')
|
| 1338 |
+
vimGlobalState.exCommandHistoryController.reset();
|
| 1339 |
+
}
|
| 1340 |
+
}
|
| 1341 |
+
if (command.type == 'keyToEx') {
|
| 1342 |
+
// Handle user defined Ex to Ex mappings
|
| 1343 |
+
exCommandDispatcher.processCommand(cm, command.exArgs.input);
|
| 1344 |
+
} else {
|
| 1345 |
+
if (vim.visualMode) {
|
| 1346 |
+
showPrompt(cm, { onClose: onPromptClose, prefix: ':', value: '\'<,\'>',
|
| 1347 |
+
onKeyDown: onPromptKeyDown});
|
| 1348 |
+
} else {
|
| 1349 |
+
showPrompt(cm, { onClose: onPromptClose, prefix: ':',
|
| 1350 |
+
onKeyDown: onPromptKeyDown});
|
| 1351 |
+
}
|
| 1352 |
+
}
|
| 1353 |
+
},
|
| 1354 |
+
evalInput: function(cm, vim) {
|
| 1355 |
+
// If the motion comand is set, execute both the operator and motion.
|
| 1356 |
+
// Otherwise return.
|
| 1357 |
+
var inputState = vim.inputState;
|
| 1358 |
+
var motion = inputState.motion;
|
| 1359 |
+
var motionArgs = inputState.motionArgs || {};
|
| 1360 |
+
var operator = inputState.operator;
|
| 1361 |
+
var operatorArgs = inputState.operatorArgs || {};
|
| 1362 |
+
var registerName = inputState.registerName;
|
| 1363 |
+
var sel = vim.sel;
|
| 1364 |
+
// TODO: Make sure cm and vim selections are identical outside visual mode.
|
| 1365 |
+
var origHead = copyCursor(vim.visualMode ? clipCursorToContent(cm, sel.head): cm.getCursor('head'));
|
| 1366 |
+
var origAnchor = copyCursor(vim.visualMode ? clipCursorToContent(cm, sel.anchor) : cm.getCursor('anchor'));
|
| 1367 |
+
var oldHead = copyCursor(origHead);
|
| 1368 |
+
var oldAnchor = copyCursor(origAnchor);
|
| 1369 |
+
var newHead, newAnchor;
|
| 1370 |
+
var repeat;
|
| 1371 |
+
if (operator) {
|
| 1372 |
+
this.recordLastEdit(vim, inputState);
|
| 1373 |
+
}
|
| 1374 |
+
if (inputState.repeatOverride !== undefined) {
|
| 1375 |
+
// If repeatOverride is specified, that takes precedence over the
|
| 1376 |
+
// input state's repeat. Used by Ex mode and can be user defined.
|
| 1377 |
+
repeat = inputState.repeatOverride;
|
| 1378 |
+
} else {
|
| 1379 |
+
repeat = inputState.getRepeat();
|
| 1380 |
+
}
|
| 1381 |
+
if (repeat > 0 && motionArgs.explicitRepeat) {
|
| 1382 |
+
motionArgs.repeatIsExplicit = true;
|
| 1383 |
+
} else if (motionArgs.noRepeat ||
|
| 1384 |
+
(!motionArgs.explicitRepeat && repeat === 0)) {
|
| 1385 |
+
repeat = 1;
|
| 1386 |
+
motionArgs.repeatIsExplicit = false;
|
| 1387 |
+
}
|
| 1388 |
+
if (inputState.selectedCharacter) {
|
| 1389 |
+
// If there is a character input, stick it in all of the arg arrays.
|
| 1390 |
+
motionArgs.selectedCharacter = operatorArgs.selectedCharacter =
|
| 1391 |
+
inputState.selectedCharacter;
|
| 1392 |
+
}
|
| 1393 |
+
motionArgs.repeat = repeat;
|
| 1394 |
+
clearInputState(cm);
|
| 1395 |
+
if (motion) {
|
| 1396 |
+
var motionResult = motions[motion](cm, origHead, motionArgs, vim);
|
| 1397 |
+
vim.lastMotion = motions[motion];
|
| 1398 |
+
if (!motionResult) {
|
| 1399 |
+
return;
|
| 1400 |
+
}
|
| 1401 |
+
if (motionArgs.toJumplist) {
|
| 1402 |
+
var jumpList = vimGlobalState.jumpList;
|
| 1403 |
+
// if the current motion is # or *, use cachedCursor
|
| 1404 |
+
var cachedCursor = jumpList.cachedCursor;
|
| 1405 |
+
if (cachedCursor) {
|
| 1406 |
+
recordJumpPosition(cm, cachedCursor, motionResult);
|
| 1407 |
+
delete jumpList.cachedCursor;
|
| 1408 |
+
} else {
|
| 1409 |
+
recordJumpPosition(cm, origHead, motionResult);
|
| 1410 |
+
}
|
| 1411 |
+
}
|
| 1412 |
+
if (motionResult instanceof Array) {
|
| 1413 |
+
newAnchor = motionResult[0];
|
| 1414 |
+
newHead = motionResult[1];
|
| 1415 |
+
} else {
|
| 1416 |
+
newHead = motionResult;
|
| 1417 |
+
}
|
| 1418 |
+
// TODO: Handle null returns from motion commands better.
|
| 1419 |
+
if (!newHead) {
|
| 1420 |
+
newHead = copyCursor(origHead);
|
| 1421 |
+
}
|
| 1422 |
+
if (vim.visualMode) {
|
| 1423 |
+
if (!(vim.visualBlock && newHead.ch === Infinity)) {
|
| 1424 |
+
newHead = clipCursorToContent(cm, newHead, vim.visualBlock);
|
| 1425 |
+
}
|
| 1426 |
+
if (newAnchor) {
|
| 1427 |
+
newAnchor = clipCursorToContent(cm, newAnchor, true);
|
| 1428 |
+
}
|
| 1429 |
+
newAnchor = newAnchor || oldAnchor;
|
| 1430 |
+
sel.anchor = newAnchor;
|
| 1431 |
+
sel.head = newHead;
|
| 1432 |
+
updateCmSelection(cm);
|
| 1433 |
+
updateMark(cm, vim, '<',
|
| 1434 |
+
cursorIsBefore(newAnchor, newHead) ? newAnchor
|
| 1435 |
+
: newHead);
|
| 1436 |
+
updateMark(cm, vim, '>',
|
| 1437 |
+
cursorIsBefore(newAnchor, newHead) ? newHead
|
| 1438 |
+
: newAnchor);
|
| 1439 |
+
} else if (!operator) {
|
| 1440 |
+
newHead = clipCursorToContent(cm, newHead);
|
| 1441 |
+
cm.setCursor(newHead.line, newHead.ch);
|
| 1442 |
+
}
|
| 1443 |
+
}
|
| 1444 |
+
if (operator) {
|
| 1445 |
+
if (operatorArgs.lastSel) {
|
| 1446 |
+
// Replaying a visual mode operation
|
| 1447 |
+
newAnchor = oldAnchor;
|
| 1448 |
+
var lastSel = operatorArgs.lastSel;
|
| 1449 |
+
var lineOffset = Math.abs(lastSel.head.line - lastSel.anchor.line);
|
| 1450 |
+
var chOffset = Math.abs(lastSel.head.ch - lastSel.anchor.ch);
|
| 1451 |
+
if (lastSel.visualLine) {
|
| 1452 |
+
// Linewise Visual mode: The same number of lines.
|
| 1453 |
+
newHead = Pos(oldAnchor.line + lineOffset, oldAnchor.ch);
|
| 1454 |
+
} else if (lastSel.visualBlock) {
|
| 1455 |
+
// Blockwise Visual mode: The same number of lines and columns.
|
| 1456 |
+
newHead = Pos(oldAnchor.line + lineOffset, oldAnchor.ch + chOffset);
|
| 1457 |
+
} else if (lastSel.head.line == lastSel.anchor.line) {
|
| 1458 |
+
// Normal Visual mode within one line: The same number of characters.
|
| 1459 |
+
newHead = Pos(oldAnchor.line, oldAnchor.ch + chOffset);
|
| 1460 |
+
} else {
|
| 1461 |
+
// Normal Visual mode with several lines: The same number of lines, in the
|
| 1462 |
+
// last line the same number of characters as in the last line the last time.
|
| 1463 |
+
newHead = Pos(oldAnchor.line + lineOffset, oldAnchor.ch);
|
| 1464 |
+
}
|
| 1465 |
+
vim.visualMode = true;
|
| 1466 |
+
vim.visualLine = lastSel.visualLine;
|
| 1467 |
+
vim.visualBlock = lastSel.visualBlock;
|
| 1468 |
+
sel = vim.sel = {
|
| 1469 |
+
anchor: newAnchor,
|
| 1470 |
+
head: newHead
|
| 1471 |
+
};
|
| 1472 |
+
updateCmSelection(cm);
|
| 1473 |
+
} else if (vim.visualMode) {
|
| 1474 |
+
operatorArgs.lastSel = {
|
| 1475 |
+
anchor: copyCursor(sel.anchor),
|
| 1476 |
+
head: copyCursor(sel.head),
|
| 1477 |
+
visualBlock: vim.visualBlock,
|
| 1478 |
+
visualLine: vim.visualLine
|
| 1479 |
+
};
|
| 1480 |
+
}
|
| 1481 |
+
var curStart, curEnd, linewise, mode;
|
| 1482 |
+
var cmSel;
|
| 1483 |
+
if (vim.visualMode) {
|
| 1484 |
+
// Init visual op
|
| 1485 |
+
curStart = cursorMin(sel.head, sel.anchor);
|
| 1486 |
+
curEnd = cursorMax(sel.head, sel.anchor);
|
| 1487 |
+
linewise = vim.visualLine || operatorArgs.linewise;
|
| 1488 |
+
mode = vim.visualBlock ? 'block' :
|
| 1489 |
+
linewise ? 'line' :
|
| 1490 |
+
'char';
|
| 1491 |
+
cmSel = makeCmSelection(cm, {
|
| 1492 |
+
anchor: curStart,
|
| 1493 |
+
head: curEnd
|
| 1494 |
+
}, mode);
|
| 1495 |
+
if (linewise) {
|
| 1496 |
+
var ranges = cmSel.ranges;
|
| 1497 |
+
if (mode == 'block') {
|
| 1498 |
+
// Linewise operators in visual block mode extend to end of line
|
| 1499 |
+
for (var i = 0; i < ranges.length; i++) {
|
| 1500 |
+
ranges[i].head.ch = lineLength(cm, ranges[i].head.line);
|
| 1501 |
+
}
|
| 1502 |
+
} else if (mode == 'line') {
|
| 1503 |
+
ranges[0].head = Pos(ranges[0].head.line + 1, 0);
|
| 1504 |
+
}
|
| 1505 |
+
}
|
| 1506 |
+
} else {
|
| 1507 |
+
// Init motion op
|
| 1508 |
+
curStart = copyCursor(newAnchor || oldAnchor);
|
| 1509 |
+
curEnd = copyCursor(newHead || oldHead);
|
| 1510 |
+
if (cursorIsBefore(curEnd, curStart)) {
|
| 1511 |
+
var tmp = curStart;
|
| 1512 |
+
curStart = curEnd;
|
| 1513 |
+
curEnd = tmp;
|
| 1514 |
+
}
|
| 1515 |
+
linewise = motionArgs.linewise || operatorArgs.linewise;
|
| 1516 |
+
if (linewise) {
|
| 1517 |
+
// Expand selection to entire line.
|
| 1518 |
+
expandSelectionToLine(cm, curStart, curEnd);
|
| 1519 |
+
} else if (motionArgs.forward) {
|
| 1520 |
+
// Clip to trailing newlines only if the motion goes forward.
|
| 1521 |
+
clipToLine(cm, curStart, curEnd);
|
| 1522 |
+
}
|
| 1523 |
+
mode = 'char';
|
| 1524 |
+
var exclusive = !motionArgs.inclusive || linewise;
|
| 1525 |
+
cmSel = makeCmSelection(cm, {
|
| 1526 |
+
anchor: curStart,
|
| 1527 |
+
head: curEnd
|
| 1528 |
+
}, mode, exclusive);
|
| 1529 |
+
}
|
| 1530 |
+
cm.setSelections(cmSel.ranges, cmSel.primary);
|
| 1531 |
+
vim.lastMotion = null;
|
| 1532 |
+
operatorArgs.repeat = repeat; // For indent in visual mode.
|
| 1533 |
+
operatorArgs.registerName = registerName;
|
| 1534 |
+
// Keep track of linewise as it affects how paste and change behave.
|
| 1535 |
+
operatorArgs.linewise = linewise;
|
| 1536 |
+
var operatorMoveTo = operators[operator](
|
| 1537 |
+
cm, operatorArgs, cmSel.ranges, oldAnchor, newHead);
|
| 1538 |
+
if (vim.visualMode) {
|
| 1539 |
+
exitVisualMode(cm, operatorMoveTo != null);
|
| 1540 |
+
}
|
| 1541 |
+
if (operatorMoveTo) {
|
| 1542 |
+
cm.setCursor(operatorMoveTo);
|
| 1543 |
+
}
|
| 1544 |
+
}
|
| 1545 |
+
},
|
| 1546 |
+
recordLastEdit: function(vim, inputState, actionCommand) {
|
| 1547 |
+
var macroModeState = vimGlobalState.macroModeState;
|
| 1548 |
+
if (macroModeState.isPlaying) { return; }
|
| 1549 |
+
vim.lastEditInputState = inputState;
|
| 1550 |
+
vim.lastEditActionCommand = actionCommand;
|
| 1551 |
+
macroModeState.lastInsertModeChanges.changes = [];
|
| 1552 |
+
macroModeState.lastInsertModeChanges.expectCursorActivityForChange = false;
|
| 1553 |
+
}
|
| 1554 |
+
};
|
| 1555 |
+
|
| 1556 |
+
/**
|
| 1557 |
+
* typedef {Object{line:number,ch:number}} Cursor An object containing the
|
| 1558 |
+
* position of the cursor.
|
| 1559 |
+
*/
|
| 1560 |
+
// All of the functions below return Cursor objects.
|
| 1561 |
+
var motions = {
|
| 1562 |
+
moveToTopLine: function(cm, _head, motionArgs) {
|
| 1563 |
+
var line = getUserVisibleLines(cm).top + motionArgs.repeat -1;
|
| 1564 |
+
return Pos(line, findFirstNonWhiteSpaceCharacter(cm.getLine(line)));
|
| 1565 |
+
},
|
| 1566 |
+
moveToMiddleLine: function(cm) {
|
| 1567 |
+
var range = getUserVisibleLines(cm);
|
| 1568 |
+
var line = Math.floor((range.top + range.bottom) * 0.5);
|
| 1569 |
+
return Pos(line, findFirstNonWhiteSpaceCharacter(cm.getLine(line)));
|
| 1570 |
+
},
|
| 1571 |
+
moveToBottomLine: function(cm, _head, motionArgs) {
|
| 1572 |
+
var line = getUserVisibleLines(cm).bottom - motionArgs.repeat +1;
|
| 1573 |
+
return Pos(line, findFirstNonWhiteSpaceCharacter(cm.getLine(line)));
|
| 1574 |
+
},
|
| 1575 |
+
expandToLine: function(_cm, head, motionArgs) {
|
| 1576 |
+
// Expands forward to end of line, and then to next line if repeat is
|
| 1577 |
+
// >1. Does not handle backward motion!
|
| 1578 |
+
var cur = head;
|
| 1579 |
+
return Pos(cur.line + motionArgs.repeat - 1, Infinity);
|
| 1580 |
+
},
|
| 1581 |
+
findNext: function(cm, _head, motionArgs) {
|
| 1582 |
+
var state = getSearchState(cm);
|
| 1583 |
+
var query = state.getQuery();
|
| 1584 |
+
if (!query) {
|
| 1585 |
+
return;
|
| 1586 |
+
}
|
| 1587 |
+
var prev = !motionArgs.forward;
|
| 1588 |
+
// If search is initiated with ? instead of /, negate direction.
|
| 1589 |
+
prev = (state.isReversed()) ? !prev : prev;
|
| 1590 |
+
highlightSearchMatches(cm, query);
|
| 1591 |
+
return findNext(cm, prev/** prev */, query, motionArgs.repeat);
|
| 1592 |
+
},
|
| 1593 |
+
goToMark: function(cm, _head, motionArgs, vim) {
|
| 1594 |
+
var mark = vim.marks[motionArgs.selectedCharacter];
|
| 1595 |
+
if (mark) {
|
| 1596 |
+
var pos = mark.find();
|
| 1597 |
+
return motionArgs.linewise ? { line: pos.line, ch: findFirstNonWhiteSpaceCharacter(cm.getLine(pos.line)) } : pos;
|
| 1598 |
+
}
|
| 1599 |
+
return null;
|
| 1600 |
+
},
|
| 1601 |
+
moveToOtherHighlightedEnd: function(cm, _head, motionArgs, vim) {
|
| 1602 |
+
if (vim.visualBlock && motionArgs.sameLine) {
|
| 1603 |
+
var sel = vim.sel;
|
| 1604 |
+
return [
|
| 1605 |
+
clipCursorToContent(cm, Pos(sel.anchor.line, sel.head.ch)),
|
| 1606 |
+
clipCursorToContent(cm, Pos(sel.head.line, sel.anchor.ch))
|
| 1607 |
+
];
|
| 1608 |
+
} else {
|
| 1609 |
+
return ([vim.sel.head, vim.sel.anchor]);
|
| 1610 |
+
}
|
| 1611 |
+
},
|
| 1612 |
+
jumpToMark: function(cm, head, motionArgs, vim) {
|
| 1613 |
+
var best = head;
|
| 1614 |
+
for (var i = 0; i < motionArgs.repeat; i++) {
|
| 1615 |
+
var cursor = best;
|
| 1616 |
+
for (var key in vim.marks) {
|
| 1617 |
+
if (!isLowerCase(key)) {
|
| 1618 |
+
continue;
|
| 1619 |
+
}
|
| 1620 |
+
var mark = vim.marks[key].find();
|
| 1621 |
+
var isWrongDirection = (motionArgs.forward) ?
|
| 1622 |
+
cursorIsBefore(mark, cursor) : cursorIsBefore(cursor, mark);
|
| 1623 |
+
|
| 1624 |
+
if (isWrongDirection) {
|
| 1625 |
+
continue;
|
| 1626 |
+
}
|
| 1627 |
+
if (motionArgs.linewise && (mark.line == cursor.line)) {
|
| 1628 |
+
continue;
|
| 1629 |
+
}
|
| 1630 |
+
|
| 1631 |
+
var equal = cursorEqual(cursor, best);
|
| 1632 |
+
var between = (motionArgs.forward) ?
|
| 1633 |
+
cursorIsBetween(cursor, mark, best) :
|
| 1634 |
+
cursorIsBetween(best, mark, cursor);
|
| 1635 |
+
|
| 1636 |
+
if (equal || between) {
|
| 1637 |
+
best = mark;
|
| 1638 |
+
}
|
| 1639 |
+
}
|
| 1640 |
+
}
|
| 1641 |
+
|
| 1642 |
+
if (motionArgs.linewise) {
|
| 1643 |
+
// Vim places the cursor on the first non-whitespace character of
|
| 1644 |
+
// the line if there is one, else it places the cursor at the end
|
| 1645 |
+
// of the line, regardless of whether a mark was found.
|
| 1646 |
+
best = Pos(best.line, findFirstNonWhiteSpaceCharacter(cm.getLine(best.line)));
|
| 1647 |
+
}
|
| 1648 |
+
return best;
|
| 1649 |
+
},
|
| 1650 |
+
moveByCharacters: function(_cm, head, motionArgs) {
|
| 1651 |
+
var cur = head;
|
| 1652 |
+
var repeat = motionArgs.repeat;
|
| 1653 |
+
var ch = motionArgs.forward ? cur.ch + repeat : cur.ch - repeat;
|
| 1654 |
+
return Pos(cur.line, ch);
|
| 1655 |
+
},
|
| 1656 |
+
moveByLines: function(cm, head, motionArgs, vim) {
|
| 1657 |
+
var cur = head;
|
| 1658 |
+
var endCh = cur.ch;
|
| 1659 |
+
// Depending what our last motion was, we may want to do different
|
| 1660 |
+
// things. If our last motion was moving vertically, we want to
|
| 1661 |
+
// preserve the HPos from our last horizontal move. If our last motion
|
| 1662 |
+
// was going to the end of a line, moving vertically we should go to
|
| 1663 |
+
// the end of the line, etc.
|
| 1664 |
+
switch (vim.lastMotion) {
|
| 1665 |
+
case this.moveByLines:
|
| 1666 |
+
case this.moveByDisplayLines:
|
| 1667 |
+
case this.moveByScroll:
|
| 1668 |
+
case this.moveToColumn:
|
| 1669 |
+
case this.moveToEol:
|
| 1670 |
+
endCh = vim.lastHPos;
|
| 1671 |
+
break;
|
| 1672 |
+
default:
|
| 1673 |
+
vim.lastHPos = endCh;
|
| 1674 |
+
}
|
| 1675 |
+
var repeat = motionArgs.repeat+(motionArgs.repeatOffset||0);
|
| 1676 |
+
var line = motionArgs.forward ? cur.line + repeat : cur.line - repeat;
|
| 1677 |
+
var first = cm.firstLine();
|
| 1678 |
+
var last = cm.lastLine();
|
| 1679 |
+
// Vim cancels linewise motions that start on an edge and move beyond
|
| 1680 |
+
// that edge. It does not cancel motions that do not start on an edge.
|
| 1681 |
+
if ((line < first && cur.line == first) ||
|
| 1682 |
+
(line > last && cur.line == last)) {
|
| 1683 |
+
return;
|
| 1684 |
+
}
|
| 1685 |
+
if (motionArgs.toFirstChar){
|
| 1686 |
+
endCh=findFirstNonWhiteSpaceCharacter(cm.getLine(line));
|
| 1687 |
+
vim.lastHPos = endCh;
|
| 1688 |
+
}
|
| 1689 |
+
vim.lastHSPos = cm.charCoords(Pos(line, endCh),'div').left;
|
| 1690 |
+
return Pos(line, endCh);
|
| 1691 |
+
},
|
| 1692 |
+
moveByDisplayLines: function(cm, head, motionArgs, vim) {
|
| 1693 |
+
var cur = head;
|
| 1694 |
+
switch (vim.lastMotion) {
|
| 1695 |
+
case this.moveByDisplayLines:
|
| 1696 |
+
case this.moveByScroll:
|
| 1697 |
+
case this.moveByLines:
|
| 1698 |
+
case this.moveToColumn:
|
| 1699 |
+
case this.moveToEol:
|
| 1700 |
+
break;
|
| 1701 |
+
default:
|
| 1702 |
+
vim.lastHSPos = cm.charCoords(cur,'div').left;
|
| 1703 |
+
}
|
| 1704 |
+
var repeat = motionArgs.repeat;
|
| 1705 |
+
var res=cm.findPosV(cur,(motionArgs.forward ? repeat : -repeat),'line',vim.lastHSPos);
|
| 1706 |
+
if (res.hitSide) {
|
| 1707 |
+
if (motionArgs.forward) {
|
| 1708 |
+
var lastCharCoords = cm.charCoords(res, 'div');
|
| 1709 |
+
var goalCoords = { top: lastCharCoords.top + 8, left: vim.lastHSPos };
|
| 1710 |
+
var res = cm.coordsChar(goalCoords, 'div');
|
| 1711 |
+
} else {
|
| 1712 |
+
var resCoords = cm.charCoords(Pos(cm.firstLine(), 0), 'div');
|
| 1713 |
+
resCoords.left = vim.lastHSPos;
|
| 1714 |
+
res = cm.coordsChar(resCoords, 'div');
|
| 1715 |
+
}
|
| 1716 |
+
}
|
| 1717 |
+
vim.lastHPos = res.ch;
|
| 1718 |
+
return res;
|
| 1719 |
+
},
|
| 1720 |
+
moveByPage: function(cm, head, motionArgs) {
|
| 1721 |
+
// CodeMirror only exposes functions that move the cursor page down, so
|
| 1722 |
+
// doing this bad hack to move the cursor and move it back. evalInput
|
| 1723 |
+
// will move the cursor to where it should be in the end.
|
| 1724 |
+
var curStart = head;
|
| 1725 |
+
var repeat = motionArgs.repeat;
|
| 1726 |
+
return cm.findPosV(curStart, (motionArgs.forward ? repeat : -repeat), 'page');
|
| 1727 |
+
},
|
| 1728 |
+
moveByParagraph: function(cm, head, motionArgs) {
|
| 1729 |
+
var dir = motionArgs.forward ? 1 : -1;
|
| 1730 |
+
return findParagraph(cm, head, motionArgs.repeat, dir);
|
| 1731 |
+
},
|
| 1732 |
+
moveByScroll: function(cm, head, motionArgs, vim) {
|
| 1733 |
+
var scrollbox = cm.getScrollInfo();
|
| 1734 |
+
var curEnd = null;
|
| 1735 |
+
var repeat = motionArgs.repeat;
|
| 1736 |
+
if (!repeat) {
|
| 1737 |
+
repeat = scrollbox.clientHeight / (2 * cm.defaultTextHeight());
|
| 1738 |
+
}
|
| 1739 |
+
var orig = cm.charCoords(head, 'local');
|
| 1740 |
+
motionArgs.repeat = repeat;
|
| 1741 |
+
var curEnd = motions.moveByDisplayLines(cm, head, motionArgs, vim);
|
| 1742 |
+
if (!curEnd) {
|
| 1743 |
+
return null;
|
| 1744 |
+
}
|
| 1745 |
+
var dest = cm.charCoords(curEnd, 'local');
|
| 1746 |
+
cm.scrollTo(null, scrollbox.top + dest.top - orig.top);
|
| 1747 |
+
return curEnd;
|
| 1748 |
+
},
|
| 1749 |
+
moveByWords: function(cm, head, motionArgs) {
|
| 1750 |
+
return moveToWord(cm, head, motionArgs.repeat, !!motionArgs.forward,
|
| 1751 |
+
!!motionArgs.wordEnd, !!motionArgs.bigWord);
|
| 1752 |
+
},
|
| 1753 |
+
moveTillCharacter: function(cm, _head, motionArgs) {
|
| 1754 |
+
var repeat = motionArgs.repeat;
|
| 1755 |
+
var curEnd = moveToCharacter(cm, repeat, motionArgs.forward,
|
| 1756 |
+
motionArgs.selectedCharacter);
|
| 1757 |
+
var increment = motionArgs.forward ? -1 : 1;
|
| 1758 |
+
recordLastCharacterSearch(increment, motionArgs);
|
| 1759 |
+
if (!curEnd) return null;
|
| 1760 |
+
curEnd.ch += increment;
|
| 1761 |
+
return curEnd;
|
| 1762 |
+
},
|
| 1763 |
+
moveToCharacter: function(cm, head, motionArgs) {
|
| 1764 |
+
var repeat = motionArgs.repeat;
|
| 1765 |
+
recordLastCharacterSearch(0, motionArgs);
|
| 1766 |
+
return moveToCharacter(cm, repeat, motionArgs.forward,
|
| 1767 |
+
motionArgs.selectedCharacter) || head;
|
| 1768 |
+
},
|
| 1769 |
+
moveToSymbol: function(cm, head, motionArgs) {
|
| 1770 |
+
var repeat = motionArgs.repeat;
|
| 1771 |
+
return findSymbol(cm, repeat, motionArgs.forward,
|
| 1772 |
+
motionArgs.selectedCharacter) || head;
|
| 1773 |
+
},
|
| 1774 |
+
moveToColumn: function(cm, head, motionArgs, vim) {
|
| 1775 |
+
var repeat = motionArgs.repeat;
|
| 1776 |
+
// repeat is equivalent to which column we want to move to!
|
| 1777 |
+
vim.lastHPos = repeat - 1;
|
| 1778 |
+
vim.lastHSPos = cm.charCoords(head,'div').left;
|
| 1779 |
+
return moveToColumn(cm, repeat);
|
| 1780 |
+
},
|
| 1781 |
+
moveToEol: function(cm, head, motionArgs, vim) {
|
| 1782 |
+
var cur = head;
|
| 1783 |
+
vim.lastHPos = Infinity;
|
| 1784 |
+
var retval= Pos(cur.line + motionArgs.repeat - 1, Infinity);
|
| 1785 |
+
var end=cm.clipPos(retval);
|
| 1786 |
+
end.ch--;
|
| 1787 |
+
vim.lastHSPos = cm.charCoords(end,'div').left;
|
| 1788 |
+
return retval;
|
| 1789 |
+
},
|
| 1790 |
+
moveToFirstNonWhiteSpaceCharacter: function(cm, head) {
|
| 1791 |
+
// Go to the start of the line where the text begins, or the end for
|
| 1792 |
+
// whitespace-only lines
|
| 1793 |
+
var cursor = head;
|
| 1794 |
+
return Pos(cursor.line,
|
| 1795 |
+
findFirstNonWhiteSpaceCharacter(cm.getLine(cursor.line)));
|
| 1796 |
+
},
|
| 1797 |
+
moveToMatchedSymbol: function(cm, head) {
|
| 1798 |
+
var cursor = head;
|
| 1799 |
+
var line = cursor.line;
|
| 1800 |
+
var ch = cursor.ch;
|
| 1801 |
+
var lineText = cm.getLine(line);
|
| 1802 |
+
var symbol;
|
| 1803 |
+
do {
|
| 1804 |
+
symbol = lineText.charAt(ch++);
|
| 1805 |
+
if (symbol && isMatchableSymbol(symbol)) {
|
| 1806 |
+
var style = cm.getTokenTypeAt(Pos(line, ch));
|
| 1807 |
+
if (style !== "string" && style !== "comment") {
|
| 1808 |
+
break;
|
| 1809 |
+
}
|
| 1810 |
+
}
|
| 1811 |
+
} while (symbol);
|
| 1812 |
+
if (symbol) {
|
| 1813 |
+
var matched = cm.findMatchingBracket(Pos(line, ch));
|
| 1814 |
+
return matched.to;
|
| 1815 |
+
} else {
|
| 1816 |
+
return cursor;
|
| 1817 |
+
}
|
| 1818 |
+
},
|
| 1819 |
+
moveToStartOfLine: function(_cm, head) {
|
| 1820 |
+
return Pos(head.line, 0);
|
| 1821 |
+
},
|
| 1822 |
+
moveToLineOrEdgeOfDocument: function(cm, _head, motionArgs) {
|
| 1823 |
+
var lineNum = motionArgs.forward ? cm.lastLine() : cm.firstLine();
|
| 1824 |
+
if (motionArgs.repeatIsExplicit) {
|
| 1825 |
+
lineNum = motionArgs.repeat - cm.getOption('firstLineNumber');
|
| 1826 |
+
}
|
| 1827 |
+
return Pos(lineNum,
|
| 1828 |
+
findFirstNonWhiteSpaceCharacter(cm.getLine(lineNum)));
|
| 1829 |
+
},
|
| 1830 |
+
textObjectManipulation: function(cm, head, motionArgs, vim) {
|
| 1831 |
+
// TODO: lots of possible exceptions that can be thrown here. Try da(
|
| 1832 |
+
// outside of a () block.
|
| 1833 |
+
|
| 1834 |
+
// TODO: adding <> >< to this map doesn't work, presumably because
|
| 1835 |
+
// they're operators
|
| 1836 |
+
var mirroredPairs = {'(': ')', ')': '(',
|
| 1837 |
+
'{': '}', '}': '{',
|
| 1838 |
+
'[': ']', ']': '['};
|
| 1839 |
+
var selfPaired = {'\'': true, '"': true};
|
| 1840 |
+
|
| 1841 |
+
var character = motionArgs.selectedCharacter;
|
| 1842 |
+
// 'b' refers to '()' block.
|
| 1843 |
+
// 'B' refers to '{}' block.
|
| 1844 |
+
if (character == 'b') {
|
| 1845 |
+
character = '(';
|
| 1846 |
+
} else if (character == 'B') {
|
| 1847 |
+
character = '{';
|
| 1848 |
+
}
|
| 1849 |
+
|
| 1850 |
+
// Inclusive is the difference between a and i
|
| 1851 |
+
// TODO: Instead of using the additional text object map to perform text
|
| 1852 |
+
// object operations, merge the map into the defaultKeyMap and use
|
| 1853 |
+
// motionArgs to define behavior. Define separate entries for 'aw',
|
| 1854 |
+
// 'iw', 'a[', 'i[', etc.
|
| 1855 |
+
var inclusive = !motionArgs.textObjectInner;
|
| 1856 |
+
|
| 1857 |
+
var tmp;
|
| 1858 |
+
if (mirroredPairs[character]) {
|
| 1859 |
+
tmp = selectCompanionObject(cm, head, character, inclusive);
|
| 1860 |
+
} else if (selfPaired[character]) {
|
| 1861 |
+
tmp = findBeginningAndEnd(cm, head, character, inclusive);
|
| 1862 |
+
} else if (character === 'W') {
|
| 1863 |
+
tmp = expandWordUnderCursor(cm, inclusive, true /** forward */,
|
| 1864 |
+
true /** bigWord */);
|
| 1865 |
+
} else if (character === 'w') {
|
| 1866 |
+
tmp = expandWordUnderCursor(cm, inclusive, true /** forward */,
|
| 1867 |
+
false /** bigWord */);
|
| 1868 |
+
} else if (character === 'p') {
|
| 1869 |
+
tmp = findParagraph(cm, head, motionArgs.repeat, 0, inclusive);
|
| 1870 |
+
motionArgs.linewise = true;
|
| 1871 |
+
if (vim.visualMode) {
|
| 1872 |
+
if (!vim.visualLine) { vim.visualLine = true; }
|
| 1873 |
+
} else {
|
| 1874 |
+
var operatorArgs = vim.inputState.operatorArgs;
|
| 1875 |
+
if (operatorArgs) { operatorArgs.linewise = true; }
|
| 1876 |
+
tmp.end.line--;
|
| 1877 |
+
}
|
| 1878 |
+
} else {
|
| 1879 |
+
// No text object defined for this, don't move.
|
| 1880 |
+
return null;
|
| 1881 |
+
}
|
| 1882 |
+
|
| 1883 |
+
if (!cm.state.vim.visualMode) {
|
| 1884 |
+
return [tmp.start, tmp.end];
|
| 1885 |
+
} else {
|
| 1886 |
+
return expandSelection(cm, tmp.start, tmp.end);
|
| 1887 |
+
}
|
| 1888 |
+
},
|
| 1889 |
+
|
| 1890 |
+
repeatLastCharacterSearch: function(cm, head, motionArgs) {
|
| 1891 |
+
var lastSearch = vimGlobalState.lastChararacterSearch;
|
| 1892 |
+
var repeat = motionArgs.repeat;
|
| 1893 |
+
var forward = motionArgs.forward === lastSearch.forward;
|
| 1894 |
+
var increment = (lastSearch.increment ? 1 : 0) * (forward ? -1 : 1);
|
| 1895 |
+
cm.moveH(-increment, 'char');
|
| 1896 |
+
motionArgs.inclusive = forward ? true : false;
|
| 1897 |
+
var curEnd = moveToCharacter(cm, repeat, forward, lastSearch.selectedCharacter);
|
| 1898 |
+
if (!curEnd) {
|
| 1899 |
+
cm.moveH(increment, 'char');
|
| 1900 |
+
return head;
|
| 1901 |
+
}
|
| 1902 |
+
curEnd.ch += increment;
|
| 1903 |
+
return curEnd;
|
| 1904 |
+
}
|
| 1905 |
+
};
|
| 1906 |
+
|
| 1907 |
+
function defineMotion(name, fn) {
|
| 1908 |
+
motions[name] = fn;
|
| 1909 |
+
}
|
| 1910 |
+
|
| 1911 |
+
function fillArray(val, times) {
|
| 1912 |
+
var arr = [];
|
| 1913 |
+
for (var i = 0; i < times; i++) {
|
| 1914 |
+
arr.push(val);
|
| 1915 |
+
}
|
| 1916 |
+
return arr;
|
| 1917 |
+
}
|
| 1918 |
+
/**
|
| 1919 |
+
* An operator acts on a text selection. It receives the list of selections
|
| 1920 |
+
* as input. The corresponding CodeMirror selection is guaranteed to
|
| 1921 |
+
* match the input selection.
|
| 1922 |
+
*/
|
| 1923 |
+
var operators = {
|
| 1924 |
+
change: function(cm, args, ranges) {
|
| 1925 |
+
var finalHead, text;
|
| 1926 |
+
var vim = cm.state.vim;
|
| 1927 |
+
vimGlobalState.macroModeState.lastInsertModeChanges.inVisualBlock = vim.visualBlock;
|
| 1928 |
+
if (!vim.visualMode) {
|
| 1929 |
+
var anchor = ranges[0].anchor,
|
| 1930 |
+
head = ranges[0].head;
|
| 1931 |
+
text = cm.getRange(anchor, head);
|
| 1932 |
+
var lastState = vim.lastEditInputState || {};
|
| 1933 |
+
if (lastState.motion == "moveByWords" && !isWhiteSpaceString(text)) {
|
| 1934 |
+
// Exclude trailing whitespace if the range is not all whitespace.
|
| 1935 |
+
var match = (/\s+$/).exec(text);
|
| 1936 |
+
if (match && lastState.motionArgs && lastState.motionArgs.forward) {
|
| 1937 |
+
head = offsetCursor(head, 0, - match[0].length);
|
| 1938 |
+
text = text.slice(0, - match[0].length);
|
| 1939 |
+
}
|
| 1940 |
+
}
|
| 1941 |
+
var wasLastLine = head.line - 1 == cm.lastLine();
|
| 1942 |
+
cm.replaceRange('', anchor, head);
|
| 1943 |
+
if (args.linewise && !wasLastLine) {
|
| 1944 |
+
// Push the next line back down, if there is a next line.
|
| 1945 |
+
CodeMirror.commands.newlineAndIndent(cm);
|
| 1946 |
+
// null ch so setCursor moves to end of line.
|
| 1947 |
+
anchor.ch = null;
|
| 1948 |
+
}
|
| 1949 |
+
finalHead = anchor;
|
| 1950 |
+
} else {
|
| 1951 |
+
text = cm.getSelection();
|
| 1952 |
+
var replacement = fillArray('', ranges.length);
|
| 1953 |
+
cm.replaceSelections(replacement);
|
| 1954 |
+
finalHead = cursorMin(ranges[0].head, ranges[0].anchor);
|
| 1955 |
+
}
|
| 1956 |
+
vimGlobalState.registerController.pushText(
|
| 1957 |
+
args.registerName, 'change', text,
|
| 1958 |
+
args.linewise, ranges.length > 1);
|
| 1959 |
+
actions.enterInsertMode(cm, {head: finalHead}, cm.state.vim);
|
| 1960 |
+
},
|
| 1961 |
+
// delete is a javascript keyword.
|
| 1962 |
+
'delete': function(cm, args, ranges) {
|
| 1963 |
+
var finalHead, text;
|
| 1964 |
+
var vim = cm.state.vim;
|
| 1965 |
+
if (!vim.visualBlock) {
|
| 1966 |
+
var anchor = ranges[0].anchor,
|
| 1967 |
+
head = ranges[0].head;
|
| 1968 |
+
if (args.linewise &&
|
| 1969 |
+
head.line != cm.firstLine() &&
|
| 1970 |
+
anchor.line == cm.lastLine() &&
|
| 1971 |
+
anchor.line == head.line - 1) {
|
| 1972 |
+
// Special case for dd on last line (and first line).
|
| 1973 |
+
if (anchor.line == cm.firstLine()) {
|
| 1974 |
+
anchor.ch = 0;
|
| 1975 |
+
} else {
|
| 1976 |
+
anchor = Pos(anchor.line - 1, lineLength(cm, anchor.line - 1));
|
| 1977 |
+
}
|
| 1978 |
+
}
|
| 1979 |
+
text = cm.getRange(anchor, head);
|
| 1980 |
+
cm.replaceRange('', anchor, head);
|
| 1981 |
+
finalHead = anchor;
|
| 1982 |
+
if (args.linewise) {
|
| 1983 |
+
finalHead = motions.moveToFirstNonWhiteSpaceCharacter(cm, anchor);
|
| 1984 |
+
}
|
| 1985 |
+
} else {
|
| 1986 |
+
text = cm.getSelection();
|
| 1987 |
+
var replacement = fillArray('', ranges.length);
|
| 1988 |
+
cm.replaceSelections(replacement);
|
| 1989 |
+
finalHead = ranges[0].anchor;
|
| 1990 |
+
}
|
| 1991 |
+
vimGlobalState.registerController.pushText(
|
| 1992 |
+
args.registerName, 'delete', text,
|
| 1993 |
+
args.linewise, vim.visualBlock);
|
| 1994 |
+
return clipCursorToContent(cm, finalHead);
|
| 1995 |
+
},
|
| 1996 |
+
indent: function(cm, args, ranges) {
|
| 1997 |
+
var vim = cm.state.vim;
|
| 1998 |
+
var startLine = ranges[0].anchor.line;
|
| 1999 |
+
var endLine = vim.visualBlock ?
|
| 2000 |
+
ranges[ranges.length - 1].anchor.line :
|
| 2001 |
+
ranges[0].head.line;
|
| 2002 |
+
// In visual mode, n> shifts the selection right n times, instead of
|
| 2003 |
+
// shifting n lines right once.
|
| 2004 |
+
var repeat = (vim.visualMode) ? args.repeat : 1;
|
| 2005 |
+
if (args.linewise) {
|
| 2006 |
+
// The only way to delete a newline is to delete until the start of
|
| 2007 |
+
// the next line, so in linewise mode evalInput will include the next
|
| 2008 |
+
// line. We don't want this in indent, so we go back a line.
|
| 2009 |
+
endLine--;
|
| 2010 |
+
}
|
| 2011 |
+
for (var i = startLine; i <= endLine; i++) {
|
| 2012 |
+
for (var j = 0; j < repeat; j++) {
|
| 2013 |
+
cm.indentLine(i, args.indentRight);
|
| 2014 |
+
}
|
| 2015 |
+
}
|
| 2016 |
+
return motions.moveToFirstNonWhiteSpaceCharacter(cm, ranges[0].anchor);
|
| 2017 |
+
},
|
| 2018 |
+
changeCase: function(cm, args, ranges, oldAnchor, newHead) {
|
| 2019 |
+
var selections = cm.getSelections();
|
| 2020 |
+
var swapped = [];
|
| 2021 |
+
var toLower = args.toLower;
|
| 2022 |
+
for (var j = 0; j < selections.length; j++) {
|
| 2023 |
+
var toSwap = selections[j];
|
| 2024 |
+
var text = '';
|
| 2025 |
+
if (toLower === true) {
|
| 2026 |
+
text = toSwap.toLowerCase();
|
| 2027 |
+
} else if (toLower === false) {
|
| 2028 |
+
text = toSwap.toUpperCase();
|
| 2029 |
+
} else {
|
| 2030 |
+
for (var i = 0; i < toSwap.length; i++) {
|
| 2031 |
+
var character = toSwap.charAt(i);
|
| 2032 |
+
text += isUpperCase(character) ? character.toLowerCase() :
|
| 2033 |
+
character.toUpperCase();
|
| 2034 |
+
}
|
| 2035 |
+
}
|
| 2036 |
+
swapped.push(text);
|
| 2037 |
+
}
|
| 2038 |
+
cm.replaceSelections(swapped);
|
| 2039 |
+
if (args.shouldMoveCursor){
|
| 2040 |
+
return newHead;
|
| 2041 |
+
} else if (!cm.state.vim.visualMode && args.linewise && ranges[0].anchor.line + 1 == ranges[0].head.line) {
|
| 2042 |
+
return motions.moveToFirstNonWhiteSpaceCharacter(cm, oldAnchor);
|
| 2043 |
+
} else if (args.linewise){
|
| 2044 |
+
return oldAnchor;
|
| 2045 |
+
} else {
|
| 2046 |
+
return cursorMin(ranges[0].anchor, ranges[0].head);
|
| 2047 |
+
}
|
| 2048 |
+
},
|
| 2049 |
+
yank: function(cm, args, ranges, oldAnchor) {
|
| 2050 |
+
var vim = cm.state.vim;
|
| 2051 |
+
var text = cm.getSelection();
|
| 2052 |
+
var endPos = vim.visualMode
|
| 2053 |
+
? cursorMin(vim.sel.anchor, vim.sel.head, ranges[0].head, ranges[0].anchor)
|
| 2054 |
+
: oldAnchor;
|
| 2055 |
+
vimGlobalState.registerController.pushText(
|
| 2056 |
+
args.registerName, 'yank',
|
| 2057 |
+
text, args.linewise, vim.visualBlock);
|
| 2058 |
+
return endPos;
|
| 2059 |
+
}
|
| 2060 |
+
};
|
| 2061 |
+
|
| 2062 |
+
function defineOperator(name, fn) {
|
| 2063 |
+
operators[name] = fn;
|
| 2064 |
+
}
|
| 2065 |
+
|
| 2066 |
+
var actions = {
|
| 2067 |
+
jumpListWalk: function(cm, actionArgs, vim) {
|
| 2068 |
+
if (vim.visualMode) {
|
| 2069 |
+
return;
|
| 2070 |
+
}
|
| 2071 |
+
var repeat = actionArgs.repeat;
|
| 2072 |
+
var forward = actionArgs.forward;
|
| 2073 |
+
var jumpList = vimGlobalState.jumpList;
|
| 2074 |
+
|
| 2075 |
+
var mark = jumpList.move(cm, forward ? repeat : -repeat);
|
| 2076 |
+
var markPos = mark ? mark.find() : undefined;
|
| 2077 |
+
markPos = markPos ? markPos : cm.getCursor();
|
| 2078 |
+
cm.setCursor(markPos);
|
| 2079 |
+
},
|
| 2080 |
+
scroll: function(cm, actionArgs, vim) {
|
| 2081 |
+
if (vim.visualMode) {
|
| 2082 |
+
return;
|
| 2083 |
+
}
|
| 2084 |
+
var repeat = actionArgs.repeat || 1;
|
| 2085 |
+
var lineHeight = cm.defaultTextHeight();
|
| 2086 |
+
var top = cm.getScrollInfo().top;
|
| 2087 |
+
var delta = lineHeight * repeat;
|
| 2088 |
+
var newPos = actionArgs.forward ? top + delta : top - delta;
|
| 2089 |
+
var cursor = copyCursor(cm.getCursor());
|
| 2090 |
+
var cursorCoords = cm.charCoords(cursor, 'local');
|
| 2091 |
+
if (actionArgs.forward) {
|
| 2092 |
+
if (newPos > cursorCoords.top) {
|
| 2093 |
+
cursor.line += (newPos - cursorCoords.top) / lineHeight;
|
| 2094 |
+
cursor.line = Math.ceil(cursor.line);
|
| 2095 |
+
cm.setCursor(cursor);
|
| 2096 |
+
cursorCoords = cm.charCoords(cursor, 'local');
|
| 2097 |
+
cm.scrollTo(null, cursorCoords.top);
|
| 2098 |
+
} else {
|
| 2099 |
+
// Cursor stays within bounds. Just reposition the scroll window.
|
| 2100 |
+
cm.scrollTo(null, newPos);
|
| 2101 |
+
}
|
| 2102 |
+
} else {
|
| 2103 |
+
var newBottom = newPos + cm.getScrollInfo().clientHeight;
|
| 2104 |
+
if (newBottom < cursorCoords.bottom) {
|
| 2105 |
+
cursor.line -= (cursorCoords.bottom - newBottom) / lineHeight;
|
| 2106 |
+
cursor.line = Math.floor(cursor.line);
|
| 2107 |
+
cm.setCursor(cursor);
|
| 2108 |
+
cursorCoords = cm.charCoords(cursor, 'local');
|
| 2109 |
+
cm.scrollTo(
|
| 2110 |
+
null, cursorCoords.bottom - cm.getScrollInfo().clientHeight);
|
| 2111 |
+
} else {
|
| 2112 |
+
// Cursor stays within bounds. Just reposition the scroll window.
|
| 2113 |
+
cm.scrollTo(null, newPos);
|
| 2114 |
+
}
|
| 2115 |
+
}
|
| 2116 |
+
},
|
| 2117 |
+
scrollToCursor: function(cm, actionArgs) {
|
| 2118 |
+
var lineNum = cm.getCursor().line;
|
| 2119 |
+
var charCoords = cm.charCoords(Pos(lineNum, 0), 'local');
|
| 2120 |
+
var height = cm.getScrollInfo().clientHeight;
|
| 2121 |
+
var y = charCoords.top;
|
| 2122 |
+
var lineHeight = charCoords.bottom - y;
|
| 2123 |
+
switch (actionArgs.position) {
|
| 2124 |
+
case 'center': y = y - (height / 2) + lineHeight;
|
| 2125 |
+
break;
|
| 2126 |
+
case 'bottom': y = y - height + lineHeight*1.4;
|
| 2127 |
+
break;
|
| 2128 |
+
case 'top': y = y + lineHeight*0.4;
|
| 2129 |
+
break;
|
| 2130 |
+
}
|
| 2131 |
+
cm.scrollTo(null, y);
|
| 2132 |
+
},
|
| 2133 |
+
replayMacro: function(cm, actionArgs, vim) {
|
| 2134 |
+
var registerName = actionArgs.selectedCharacter;
|
| 2135 |
+
var repeat = actionArgs.repeat;
|
| 2136 |
+
var macroModeState = vimGlobalState.macroModeState;
|
| 2137 |
+
if (registerName == '@') {
|
| 2138 |
+
registerName = macroModeState.latestRegister;
|
| 2139 |
+
}
|
| 2140 |
+
while(repeat--){
|
| 2141 |
+
executeMacroRegister(cm, vim, macroModeState, registerName);
|
| 2142 |
+
}
|
| 2143 |
+
},
|
| 2144 |
+
enterMacroRecordMode: function(cm, actionArgs) {
|
| 2145 |
+
var macroModeState = vimGlobalState.macroModeState;
|
| 2146 |
+
var registerName = actionArgs.selectedCharacter;
|
| 2147 |
+
macroModeState.enterMacroRecordMode(cm, registerName);
|
| 2148 |
+
},
|
| 2149 |
+
enterInsertMode: function(cm, actionArgs, vim) {
|
| 2150 |
+
if (cm.getOption('readOnly')) { return; }
|
| 2151 |
+
vim.insertMode = true;
|
| 2152 |
+
vim.insertModeRepeat = actionArgs && actionArgs.repeat || 1;
|
| 2153 |
+
var insertAt = (actionArgs) ? actionArgs.insertAt : null;
|
| 2154 |
+
var sel = vim.sel;
|
| 2155 |
+
var head = actionArgs.head || cm.getCursor('head');
|
| 2156 |
+
var height = cm.listSelections().length;
|
| 2157 |
+
if (insertAt == 'eol') {
|
| 2158 |
+
head = Pos(head.line, lineLength(cm, head.line));
|
| 2159 |
+
} else if (insertAt == 'charAfter') {
|
| 2160 |
+
head = offsetCursor(head, 0, 1);
|
| 2161 |
+
} else if (insertAt == 'firstNonBlank') {
|
| 2162 |
+
head = motions.moveToFirstNonWhiteSpaceCharacter(cm, head);
|
| 2163 |
+
} else if (insertAt == 'startOfSelectedArea') {
|
| 2164 |
+
if (!vim.visualBlock) {
|
| 2165 |
+
if (sel.head.line < sel.anchor.line) {
|
| 2166 |
+
head = sel.head;
|
| 2167 |
+
} else {
|
| 2168 |
+
head = Pos(sel.anchor.line, 0);
|
| 2169 |
+
}
|
| 2170 |
+
} else {
|
| 2171 |
+
head = Pos(
|
| 2172 |
+
Math.min(sel.head.line, sel.anchor.line),
|
| 2173 |
+
Math.min(sel.head.ch, sel.anchor.ch));
|
| 2174 |
+
height = Math.abs(sel.head.line - sel.anchor.line) + 1;
|
| 2175 |
+
}
|
| 2176 |
+
} else if (insertAt == 'endOfSelectedArea') {
|
| 2177 |
+
if (!vim.visualBlock) {
|
| 2178 |
+
if (sel.head.line >= sel.anchor.line) {
|
| 2179 |
+
head = offsetCursor(sel.head, 0, 1);
|
| 2180 |
+
} else {
|
| 2181 |
+
head = Pos(sel.anchor.line, 0);
|
| 2182 |
+
}
|
| 2183 |
+
} else {
|
| 2184 |
+
head = Pos(
|
| 2185 |
+
Math.min(sel.head.line, sel.anchor.line),
|
| 2186 |
+
Math.max(sel.head.ch + 1, sel.anchor.ch));
|
| 2187 |
+
height = Math.abs(sel.head.line - sel.anchor.line) + 1;
|
| 2188 |
+
}
|
| 2189 |
+
} else if (insertAt == 'inplace') {
|
| 2190 |
+
if (vim.visualMode){
|
| 2191 |
+
return;
|
| 2192 |
+
}
|
| 2193 |
+
}
|
| 2194 |
+
cm.setOption('keyMap', 'vim-insert');
|
| 2195 |
+
cm.setOption('disableInput', false);
|
| 2196 |
+
if (actionArgs && actionArgs.replace) {
|
| 2197 |
+
// Handle Replace-mode as a special case of insert mode.
|
| 2198 |
+
cm.toggleOverwrite(true);
|
| 2199 |
+
cm.setOption('keyMap', 'vim-replace');
|
| 2200 |
+
CodeMirror.signal(cm, "vim-mode-change", {mode: "replace"});
|
| 2201 |
+
} else {
|
| 2202 |
+
cm.setOption('keyMap', 'vim-insert');
|
| 2203 |
+
CodeMirror.signal(cm, "vim-mode-change", {mode: "insert"});
|
| 2204 |
+
}
|
| 2205 |
+
if (!vimGlobalState.macroModeState.isPlaying) {
|
| 2206 |
+
// Only record if not replaying.
|
| 2207 |
+
cm.on('change', onChange);
|
| 2208 |
+
CodeMirror.on(cm.getInputField(), 'keydown', onKeyEventTargetKeyDown);
|
| 2209 |
+
}
|
| 2210 |
+
if (vim.visualMode) {
|
| 2211 |
+
exitVisualMode(cm);
|
| 2212 |
+
}
|
| 2213 |
+
selectForInsert(cm, head, height);
|
| 2214 |
+
},
|
| 2215 |
+
toggleVisualMode: function(cm, actionArgs, vim) {
|
| 2216 |
+
var repeat = actionArgs.repeat;
|
| 2217 |
+
var anchor = cm.getCursor();
|
| 2218 |
+
var head;
|
| 2219 |
+
// TODO: The repeat should actually select number of characters/lines
|
| 2220 |
+
// equal to the repeat times the size of the previous visual
|
| 2221 |
+
// operation.
|
| 2222 |
+
if (!vim.visualMode) {
|
| 2223 |
+
// Entering visual mode
|
| 2224 |
+
vim.visualMode = true;
|
| 2225 |
+
vim.visualLine = !!actionArgs.linewise;
|
| 2226 |
+
vim.visualBlock = !!actionArgs.blockwise;
|
| 2227 |
+
head = clipCursorToContent(
|
| 2228 |
+
cm, Pos(anchor.line, anchor.ch + repeat - 1),
|
| 2229 |
+
true /** includeLineBreak */);
|
| 2230 |
+
vim.sel = {
|
| 2231 |
+
anchor: anchor,
|
| 2232 |
+
head: head
|
| 2233 |
+
};
|
| 2234 |
+
CodeMirror.signal(cm, "vim-mode-change", {mode: "visual", subMode: vim.visualLine ? "linewise" : vim.visualBlock ? "blockwise" : ""});
|
| 2235 |
+
updateCmSelection(cm);
|
| 2236 |
+
updateMark(cm, vim, '<', cursorMin(anchor, head));
|
| 2237 |
+
updateMark(cm, vim, '>', cursorMax(anchor, head));
|
| 2238 |
+
} else if (vim.visualLine ^ actionArgs.linewise ||
|
| 2239 |
+
vim.visualBlock ^ actionArgs.blockwise) {
|
| 2240 |
+
// Toggling between modes
|
| 2241 |
+
vim.visualLine = !!actionArgs.linewise;
|
| 2242 |
+
vim.visualBlock = !!actionArgs.blockwise;
|
| 2243 |
+
CodeMirror.signal(cm, "vim-mode-change", {mode: "visual", subMode: vim.visualLine ? "linewise" : vim.visualBlock ? "blockwise" : ""});
|
| 2244 |
+
updateCmSelection(cm);
|
| 2245 |
+
} else {
|
| 2246 |
+
exitVisualMode(cm);
|
| 2247 |
+
}
|
| 2248 |
+
},
|
| 2249 |
+
reselectLastSelection: function(cm, _actionArgs, vim) {
|
| 2250 |
+
var lastSelection = vim.lastSelection;
|
| 2251 |
+
if (vim.visualMode) {
|
| 2252 |
+
updateLastSelection(cm, vim);
|
| 2253 |
+
}
|
| 2254 |
+
if (lastSelection) {
|
| 2255 |
+
var anchor = lastSelection.anchorMark.find();
|
| 2256 |
+
var head = lastSelection.headMark.find();
|
| 2257 |
+
if (!anchor || !head) {
|
| 2258 |
+
// If the marks have been destroyed due to edits, do nothing.
|
| 2259 |
+
return;
|
| 2260 |
+
}
|
| 2261 |
+
vim.sel = {
|
| 2262 |
+
anchor: anchor,
|
| 2263 |
+
head: head
|
| 2264 |
+
};
|
| 2265 |
+
vim.visualMode = true;
|
| 2266 |
+
vim.visualLine = lastSelection.visualLine;
|
| 2267 |
+
vim.visualBlock = lastSelection.visualBlock;
|
| 2268 |
+
updateCmSelection(cm);
|
| 2269 |
+
updateMark(cm, vim, '<', cursorMin(anchor, head));
|
| 2270 |
+
updateMark(cm, vim, '>', cursorMax(anchor, head));
|
| 2271 |
+
CodeMirror.signal(cm, 'vim-mode-change', {
|
| 2272 |
+
mode: 'visual',
|
| 2273 |
+
subMode: vim.visualLine ? 'linewise' :
|
| 2274 |
+
vim.visualBlock ? 'blockwise' : ''});
|
| 2275 |
+
}
|
| 2276 |
+
},
|
| 2277 |
+
joinLines: function(cm, actionArgs, vim) {
|
| 2278 |
+
var curStart, curEnd;
|
| 2279 |
+
if (vim.visualMode) {
|
| 2280 |
+
curStart = cm.getCursor('anchor');
|
| 2281 |
+
curEnd = cm.getCursor('head');
|
| 2282 |
+
if (cursorIsBefore(curEnd, curStart)) {
|
| 2283 |
+
var tmp = curEnd;
|
| 2284 |
+
curEnd = curStart;
|
| 2285 |
+
curStart = tmp;
|
| 2286 |
+
}
|
| 2287 |
+
curEnd.ch = lineLength(cm, curEnd.line) - 1;
|
| 2288 |
+
} else {
|
| 2289 |
+
// Repeat is the number of lines to join. Minimum 2 lines.
|
| 2290 |
+
var repeat = Math.max(actionArgs.repeat, 2);
|
| 2291 |
+
curStart = cm.getCursor();
|
| 2292 |
+
curEnd = clipCursorToContent(cm, Pos(curStart.line + repeat - 1,
|
| 2293 |
+
Infinity));
|
| 2294 |
+
}
|
| 2295 |
+
var finalCh = 0;
|
| 2296 |
+
for (var i = curStart.line; i < curEnd.line; i++) {
|
| 2297 |
+
finalCh = lineLength(cm, curStart.line);
|
| 2298 |
+
var tmp = Pos(curStart.line + 1,
|
| 2299 |
+
lineLength(cm, curStart.line + 1));
|
| 2300 |
+
var text = cm.getRange(curStart, tmp);
|
| 2301 |
+
text = text.replace(/\n\s*/g, ' ');
|
| 2302 |
+
cm.replaceRange(text, curStart, tmp);
|
| 2303 |
+
}
|
| 2304 |
+
var curFinalPos = Pos(curStart.line, finalCh);
|
| 2305 |
+
if (vim.visualMode) {
|
| 2306 |
+
exitVisualMode(cm, false);
|
| 2307 |
+
}
|
| 2308 |
+
cm.setCursor(curFinalPos);
|
| 2309 |
+
},
|
| 2310 |
+
newLineAndEnterInsertMode: function(cm, actionArgs, vim) {
|
| 2311 |
+
vim.insertMode = true;
|
| 2312 |
+
var insertAt = copyCursor(cm.getCursor());
|
| 2313 |
+
if (insertAt.line === cm.firstLine() && !actionArgs.after) {
|
| 2314 |
+
// Special case for inserting newline before start of document.
|
| 2315 |
+
cm.replaceRange('\n', Pos(cm.firstLine(), 0));
|
| 2316 |
+
cm.setCursor(cm.firstLine(), 0);
|
| 2317 |
+
} else {
|
| 2318 |
+
insertAt.line = (actionArgs.after) ? insertAt.line :
|
| 2319 |
+
insertAt.line - 1;
|
| 2320 |
+
insertAt.ch = lineLength(cm, insertAt.line);
|
| 2321 |
+
cm.setCursor(insertAt);
|
| 2322 |
+
var newlineFn = CodeMirror.commands.newlineAndIndentContinueComment ||
|
| 2323 |
+
CodeMirror.commands.newlineAndIndent;
|
| 2324 |
+
newlineFn(cm);
|
| 2325 |
+
}
|
| 2326 |
+
this.enterInsertMode(cm, { repeat: actionArgs.repeat }, vim);
|
| 2327 |
+
},
|
| 2328 |
+
paste: function(cm, actionArgs, vim) {
|
| 2329 |
+
var cur = copyCursor(cm.getCursor());
|
| 2330 |
+
var register = vimGlobalState.registerController.getRegister(
|
| 2331 |
+
actionArgs.registerName);
|
| 2332 |
+
var text = register.toString();
|
| 2333 |
+
if (!text) {
|
| 2334 |
+
return;
|
| 2335 |
+
}
|
| 2336 |
+
if (actionArgs.matchIndent) {
|
| 2337 |
+
var tabSize = cm.getOption("tabSize");
|
| 2338 |
+
// length that considers tabs and tabSize
|
| 2339 |
+
var whitespaceLength = function(str) {
|
| 2340 |
+
var tabs = (str.split("\t").length - 1);
|
| 2341 |
+
var spaces = (str.split(" ").length - 1);
|
| 2342 |
+
return tabs * tabSize + spaces * 1;
|
| 2343 |
+
};
|
| 2344 |
+
var currentLine = cm.getLine(cm.getCursor().line);
|
| 2345 |
+
var indent = whitespaceLength(currentLine.match(/^\s*/)[0]);
|
| 2346 |
+
// chomp last newline b/c don't want it to match /^\s*/gm
|
| 2347 |
+
var chompedText = text.replace(/\n$/, '');
|
| 2348 |
+
var wasChomped = text !== chompedText;
|
| 2349 |
+
var firstIndent = whitespaceLength(text.match(/^\s*/)[0]);
|
| 2350 |
+
var text = chompedText.replace(/^\s*/gm, function(wspace) {
|
| 2351 |
+
var newIndent = indent + (whitespaceLength(wspace) - firstIndent);
|
| 2352 |
+
if (newIndent < 0) {
|
| 2353 |
+
return "";
|
| 2354 |
+
}
|
| 2355 |
+
else if (cm.getOption("indentWithTabs")) {
|
| 2356 |
+
var quotient = Math.floor(newIndent / tabSize);
|
| 2357 |
+
return Array(quotient + 1).join('\t');
|
| 2358 |
+
}
|
| 2359 |
+
else {
|
| 2360 |
+
return Array(newIndent + 1).join(' ');
|
| 2361 |
+
}
|
| 2362 |
+
});
|
| 2363 |
+
text += wasChomped ? "\n" : "";
|
| 2364 |
+
}
|
| 2365 |
+
if (actionArgs.repeat > 1) {
|
| 2366 |
+
var text = Array(actionArgs.repeat + 1).join(text);
|
| 2367 |
+
}
|
| 2368 |
+
var linewise = register.linewise;
|
| 2369 |
+
var blockwise = register.blockwise;
|
| 2370 |
+
if (linewise) {
|
| 2371 |
+
if(vim.visualMode) {
|
| 2372 |
+
text = vim.visualLine ? text.slice(0, -1) : '\n' + text.slice(0, text.length - 1) + '\n';
|
| 2373 |
+
} else if (actionArgs.after) {
|
| 2374 |
+
// Move the newline at the end to the start instead, and paste just
|
| 2375 |
+
// before the newline character of the line we are on right now.
|
| 2376 |
+
text = '\n' + text.slice(0, text.length - 1);
|
| 2377 |
+
cur.ch = lineLength(cm, cur.line);
|
| 2378 |
+
} else {
|
| 2379 |
+
cur.ch = 0;
|
| 2380 |
+
}
|
| 2381 |
+
} else {
|
| 2382 |
+
if (blockwise) {
|
| 2383 |
+
text = text.split('\n');
|
| 2384 |
+
for (var i = 0; i < text.length; i++) {
|
| 2385 |
+
text[i] = (text[i] == '') ? ' ' : text[i];
|
| 2386 |
+
}
|
| 2387 |
+
}
|
| 2388 |
+
cur.ch += actionArgs.after ? 1 : 0;
|
| 2389 |
+
}
|
| 2390 |
+
var curPosFinal;
|
| 2391 |
+
var idx;
|
| 2392 |
+
if (vim.visualMode) {
|
| 2393 |
+
// save the pasted text for reselection if the need arises
|
| 2394 |
+
vim.lastPastedText = text;
|
| 2395 |
+
var lastSelectionCurEnd;
|
| 2396 |
+
var selectedArea = getSelectedAreaRange(cm, vim);
|
| 2397 |
+
var selectionStart = selectedArea[0];
|
| 2398 |
+
var selectionEnd = selectedArea[1];
|
| 2399 |
+
var selectedText = cm.getSelection();
|
| 2400 |
+
var selections = cm.listSelections();
|
| 2401 |
+
var emptyStrings = new Array(selections.length).join('1').split('1');
|
| 2402 |
+
// save the curEnd marker before it get cleared due to cm.replaceRange.
|
| 2403 |
+
if (vim.lastSelection) {
|
| 2404 |
+
lastSelectionCurEnd = vim.lastSelection.headMark.find();
|
| 2405 |
+
}
|
| 2406 |
+
// push the previously selected text to unnamed register
|
| 2407 |
+
vimGlobalState.registerController.unnamedRegister.setText(selectedText);
|
| 2408 |
+
if (blockwise) {
|
| 2409 |
+
// first delete the selected text
|
| 2410 |
+
cm.replaceSelections(emptyStrings);
|
| 2411 |
+
// Set new selections as per the block length of the yanked text
|
| 2412 |
+
selectionEnd = Pos(selectionStart.line + text.length-1, selectionStart.ch);
|
| 2413 |
+
cm.setCursor(selectionStart);
|
| 2414 |
+
selectBlock(cm, selectionEnd);
|
| 2415 |
+
cm.replaceSelections(text);
|
| 2416 |
+
curPosFinal = selectionStart;
|
| 2417 |
+
} else if (vim.visualBlock) {
|
| 2418 |
+
cm.replaceSelections(emptyStrings);
|
| 2419 |
+
cm.setCursor(selectionStart);
|
| 2420 |
+
cm.replaceRange(text, selectionStart, selectionStart);
|
| 2421 |
+
curPosFinal = selectionStart;
|
| 2422 |
+
} else {
|
| 2423 |
+
cm.replaceRange(text, selectionStart, selectionEnd);
|
| 2424 |
+
curPosFinal = cm.posFromIndex(cm.indexFromPos(selectionStart) + text.length - 1);
|
| 2425 |
+
}
|
| 2426 |
+
// restore the the curEnd marker
|
| 2427 |
+
if(lastSelectionCurEnd) {
|
| 2428 |
+
vim.lastSelection.headMark = cm.setBookmark(lastSelectionCurEnd);
|
| 2429 |
+
}
|
| 2430 |
+
if (linewise) {
|
| 2431 |
+
curPosFinal.ch=0;
|
| 2432 |
+
}
|
| 2433 |
+
} else {
|
| 2434 |
+
if (blockwise) {
|
| 2435 |
+
cm.setCursor(cur);
|
| 2436 |
+
for (var i = 0; i < text.length; i++) {
|
| 2437 |
+
var line = cur.line+i;
|
| 2438 |
+
if (line > cm.lastLine()) {
|
| 2439 |
+
cm.replaceRange('\n', Pos(line, 0));
|
| 2440 |
+
}
|
| 2441 |
+
var lastCh = lineLength(cm, line);
|
| 2442 |
+
if (lastCh < cur.ch) {
|
| 2443 |
+
extendLineToColumn(cm, line, cur.ch);
|
| 2444 |
+
}
|
| 2445 |
+
}
|
| 2446 |
+
cm.setCursor(cur);
|
| 2447 |
+
selectBlock(cm, Pos(cur.line + text.length-1, cur.ch));
|
| 2448 |
+
cm.replaceSelections(text);
|
| 2449 |
+
curPosFinal = cur;
|
| 2450 |
+
} else {
|
| 2451 |
+
cm.replaceRange(text, cur);
|
| 2452 |
+
// Now fine tune the cursor to where we want it.
|
| 2453 |
+
if (linewise && actionArgs.after) {
|
| 2454 |
+
curPosFinal = Pos(
|
| 2455 |
+
cur.line + 1,
|
| 2456 |
+
findFirstNonWhiteSpaceCharacter(cm.getLine(cur.line + 1)));
|
| 2457 |
+
} else if (linewise && !actionArgs.after) {
|
| 2458 |
+
curPosFinal = Pos(
|
| 2459 |
+
cur.line,
|
| 2460 |
+
findFirstNonWhiteSpaceCharacter(cm.getLine(cur.line)));
|
| 2461 |
+
} else if (!linewise && actionArgs.after) {
|
| 2462 |
+
idx = cm.indexFromPos(cur);
|
| 2463 |
+
curPosFinal = cm.posFromIndex(idx + text.length - 1);
|
| 2464 |
+
} else {
|
| 2465 |
+
idx = cm.indexFromPos(cur);
|
| 2466 |
+
curPosFinal = cm.posFromIndex(idx + text.length);
|
| 2467 |
+
}
|
| 2468 |
+
}
|
| 2469 |
+
}
|
| 2470 |
+
if (vim.visualMode) {
|
| 2471 |
+
exitVisualMode(cm, false);
|
| 2472 |
+
}
|
| 2473 |
+
cm.setCursor(curPosFinal);
|
| 2474 |
+
},
|
| 2475 |
+
undo: function(cm, actionArgs) {
|
| 2476 |
+
cm.operation(function() {
|
| 2477 |
+
repeatFn(cm, CodeMirror.commands.undo, actionArgs.repeat)();
|
| 2478 |
+
cm.setCursor(cm.getCursor('anchor'));
|
| 2479 |
+
});
|
| 2480 |
+
},
|
| 2481 |
+
redo: function(cm, actionArgs) {
|
| 2482 |
+
repeatFn(cm, CodeMirror.commands.redo, actionArgs.repeat)();
|
| 2483 |
+
},
|
| 2484 |
+
setRegister: function(_cm, actionArgs, vim) {
|
| 2485 |
+
vim.inputState.registerName = actionArgs.selectedCharacter;
|
| 2486 |
+
},
|
| 2487 |
+
setMark: function(cm, actionArgs, vim) {
|
| 2488 |
+
var markName = actionArgs.selectedCharacter;
|
| 2489 |
+
updateMark(cm, vim, markName, cm.getCursor());
|
| 2490 |
+
},
|
| 2491 |
+
replace: function(cm, actionArgs, vim) {
|
| 2492 |
+
var replaceWith = actionArgs.selectedCharacter;
|
| 2493 |
+
var curStart = cm.getCursor();
|
| 2494 |
+
var replaceTo;
|
| 2495 |
+
var curEnd;
|
| 2496 |
+
var selections = cm.listSelections();
|
| 2497 |
+
if (vim.visualMode) {
|
| 2498 |
+
curStart = cm.getCursor('start');
|
| 2499 |
+
curEnd = cm.getCursor('end');
|
| 2500 |
+
} else {
|
| 2501 |
+
var line = cm.getLine(curStart.line);
|
| 2502 |
+
replaceTo = curStart.ch + actionArgs.repeat;
|
| 2503 |
+
if (replaceTo > line.length) {
|
| 2504 |
+
replaceTo=line.length;
|
| 2505 |
+
}
|
| 2506 |
+
curEnd = Pos(curStart.line, replaceTo);
|
| 2507 |
+
}
|
| 2508 |
+
if (replaceWith=='\n') {
|
| 2509 |
+
if (!vim.visualMode) cm.replaceRange('', curStart, curEnd);
|
| 2510 |
+
// special case, where vim help says to replace by just one line-break
|
| 2511 |
+
(CodeMirror.commands.newlineAndIndentContinueComment || CodeMirror.commands.newlineAndIndent)(cm);
|
| 2512 |
+
} else {
|
| 2513 |
+
var replaceWithStr = cm.getRange(curStart, curEnd);
|
| 2514 |
+
//replace all characters in range by selected, but keep linebreaks
|
| 2515 |
+
replaceWithStr = replaceWithStr.replace(/[^\n]/g, replaceWith);
|
| 2516 |
+
if (vim.visualBlock) {
|
| 2517 |
+
// Tabs are split in visua block before replacing
|
| 2518 |
+
var spaces = new Array(cm.getOption("tabSize")+1).join(' ');
|
| 2519 |
+
replaceWithStr = cm.getSelection();
|
| 2520 |
+
replaceWithStr = replaceWithStr.replace(/\t/g, spaces).replace(/[^\n]/g, replaceWith).split('\n');
|
| 2521 |
+
cm.replaceSelections(replaceWithStr);
|
| 2522 |
+
} else {
|
| 2523 |
+
cm.replaceRange(replaceWithStr, curStart, curEnd);
|
| 2524 |
+
}
|
| 2525 |
+
if (vim.visualMode) {
|
| 2526 |
+
curStart = cursorIsBefore(selections[0].anchor, selections[0].head) ?
|
| 2527 |
+
selections[0].anchor : selections[0].head;
|
| 2528 |
+
cm.setCursor(curStart);
|
| 2529 |
+
exitVisualMode(cm, false);
|
| 2530 |
+
} else {
|
| 2531 |
+
cm.setCursor(offsetCursor(curEnd, 0, -1));
|
| 2532 |
+
}
|
| 2533 |
+
}
|
| 2534 |
+
},
|
| 2535 |
+
incrementNumberToken: function(cm, actionArgs) {
|
| 2536 |
+
var cur = cm.getCursor();
|
| 2537 |
+
var lineStr = cm.getLine(cur.line);
|
| 2538 |
+
var re = /-?\d+/g;
|
| 2539 |
+
var match;
|
| 2540 |
+
var start;
|
| 2541 |
+
var end;
|
| 2542 |
+
var numberStr;
|
| 2543 |
+
var token;
|
| 2544 |
+
while ((match = re.exec(lineStr)) !== null) {
|
| 2545 |
+
token = match[0];
|
| 2546 |
+
start = match.index;
|
| 2547 |
+
end = start + token.length;
|
| 2548 |
+
if (cur.ch < end)break;
|
| 2549 |
+
}
|
| 2550 |
+
if (!actionArgs.backtrack && (end <= cur.ch))return;
|
| 2551 |
+
if (token) {
|
| 2552 |
+
var increment = actionArgs.increase ? 1 : -1;
|
| 2553 |
+
var number = parseInt(token) + (increment * actionArgs.repeat);
|
| 2554 |
+
var from = Pos(cur.line, start);
|
| 2555 |
+
var to = Pos(cur.line, end);
|
| 2556 |
+
numberStr = number.toString();
|
| 2557 |
+
cm.replaceRange(numberStr, from, to);
|
| 2558 |
+
} else {
|
| 2559 |
+
return;
|
| 2560 |
+
}
|
| 2561 |
+
cm.setCursor(Pos(cur.line, start + numberStr.length - 1));
|
| 2562 |
+
},
|
| 2563 |
+
repeatLastEdit: function(cm, actionArgs, vim) {
|
| 2564 |
+
var lastEditInputState = vim.lastEditInputState;
|
| 2565 |
+
if (!lastEditInputState) { return; }
|
| 2566 |
+
var repeat = actionArgs.repeat;
|
| 2567 |
+
if (repeat && actionArgs.repeatIsExplicit) {
|
| 2568 |
+
vim.lastEditInputState.repeatOverride = repeat;
|
| 2569 |
+
} else {
|
| 2570 |
+
repeat = vim.lastEditInputState.repeatOverride || repeat;
|
| 2571 |
+
}
|
| 2572 |
+
repeatLastEdit(cm, vim, repeat, false /** repeatForInsert */);
|
| 2573 |
+
},
|
| 2574 |
+
exitInsertMode: exitInsertMode
|
| 2575 |
+
};
|
| 2576 |
+
|
| 2577 |
+
function defineAction(name, fn) {
|
| 2578 |
+
actions[name] = fn;
|
| 2579 |
+
}
|
| 2580 |
+
|
| 2581 |
+
/*
|
| 2582 |
+
* Below are miscellaneous utility functions used by vim.js
|
| 2583 |
+
*/
|
| 2584 |
+
|
| 2585 |
+
/**
|
| 2586 |
+
* Clips cursor to ensure that line is within the buffer's range
|
| 2587 |
+
* If includeLineBreak is true, then allow cur.ch == lineLength.
|
| 2588 |
+
*/
|
| 2589 |
+
function clipCursorToContent(cm, cur, includeLineBreak) {
|
| 2590 |
+
var line = Math.min(Math.max(cm.firstLine(), cur.line), cm.lastLine() );
|
| 2591 |
+
var maxCh = lineLength(cm, line) - 1;
|
| 2592 |
+
maxCh = (includeLineBreak) ? maxCh + 1 : maxCh;
|
| 2593 |
+
var ch = Math.min(Math.max(0, cur.ch), maxCh);
|
| 2594 |
+
return Pos(line, ch);
|
| 2595 |
+
}
|
| 2596 |
+
function copyArgs(args) {
|
| 2597 |
+
var ret = {};
|
| 2598 |
+
for (var prop in args) {
|
| 2599 |
+
if (args.hasOwnProperty(prop)) {
|
| 2600 |
+
ret[prop] = args[prop];
|
| 2601 |
+
}
|
| 2602 |
+
}
|
| 2603 |
+
return ret;
|
| 2604 |
+
}
|
| 2605 |
+
function offsetCursor(cur, offsetLine, offsetCh) {
|
| 2606 |
+
if (typeof offsetLine === 'object') {
|
| 2607 |
+
offsetCh = offsetLine.ch;
|
| 2608 |
+
offsetLine = offsetLine.line;
|
| 2609 |
+
}
|
| 2610 |
+
return Pos(cur.line + offsetLine, cur.ch + offsetCh);
|
| 2611 |
+
}
|
| 2612 |
+
function getOffset(anchor, head) {
|
| 2613 |
+
return {
|
| 2614 |
+
line: head.line - anchor.line,
|
| 2615 |
+
ch: head.line - anchor.line
|
| 2616 |
+
};
|
| 2617 |
+
}
|
| 2618 |
+
function commandMatches(keys, keyMap, context, inputState) {
|
| 2619 |
+
// Partial matches are not applied. They inform the key handler
|
| 2620 |
+
// that the current key sequence is a subsequence of a valid key
|
| 2621 |
+
// sequence, so that the key buffer is not cleared.
|
| 2622 |
+
var match, partial = [], full = [];
|
| 2623 |
+
for (var i = 0; i < keyMap.length; i++) {
|
| 2624 |
+
var command = keyMap[i];
|
| 2625 |
+
if (context == 'insert' && command.context != 'insert' ||
|
| 2626 |
+
command.context && command.context != context ||
|
| 2627 |
+
inputState.operator && command.type == 'action' ||
|
| 2628 |
+
!(match = commandMatch(keys, command.keys))) { continue; }
|
| 2629 |
+
if (match == 'partial') { partial.push(command); }
|
| 2630 |
+
if (match == 'full') { full.push(command); }
|
| 2631 |
+
}
|
| 2632 |
+
return {
|
| 2633 |
+
partial: partial.length && partial,
|
| 2634 |
+
full: full.length && full
|
| 2635 |
+
};
|
| 2636 |
+
}
|
| 2637 |
+
function commandMatch(pressed, mapped) {
|
| 2638 |
+
if (mapped.slice(-11) == '<character>') {
|
| 2639 |
+
// Last character matches anything.
|
| 2640 |
+
var prefixLen = mapped.length - 11;
|
| 2641 |
+
var pressedPrefix = pressed.slice(0, prefixLen);
|
| 2642 |
+
var mappedPrefix = mapped.slice(0, prefixLen);
|
| 2643 |
+
return pressedPrefix == mappedPrefix && pressed.length > prefixLen ? 'full' :
|
| 2644 |
+
mappedPrefix.indexOf(pressedPrefix) == 0 ? 'partial' : false;
|
| 2645 |
+
} else {
|
| 2646 |
+
return pressed == mapped ? 'full' :
|
| 2647 |
+
mapped.indexOf(pressed) == 0 ? 'partial' : false;
|
| 2648 |
+
}
|
| 2649 |
+
}
|
| 2650 |
+
function lastChar(keys) {
|
| 2651 |
+
var match = /^.*(<[\w\-]+>)$/.exec(keys);
|
| 2652 |
+
var selectedCharacter = match ? match[1] : keys.slice(-1);
|
| 2653 |
+
if (selectedCharacter.length > 1){
|
| 2654 |
+
switch(selectedCharacter){
|
| 2655 |
+
case '<CR>':
|
| 2656 |
+
selectedCharacter='\n';
|
| 2657 |
+
break;
|
| 2658 |
+
case '<Space>':
|
| 2659 |
+
selectedCharacter=' ';
|
| 2660 |
+
break;
|
| 2661 |
+
default:
|
| 2662 |
+
break;
|
| 2663 |
+
}
|
| 2664 |
+
}
|
| 2665 |
+
return selectedCharacter;
|
| 2666 |
+
}
|
| 2667 |
+
function repeatFn(cm, fn, repeat) {
|
| 2668 |
+
return function() {
|
| 2669 |
+
for (var i = 0; i < repeat; i++) {
|
| 2670 |
+
fn(cm);
|
| 2671 |
+
}
|
| 2672 |
+
};
|
| 2673 |
+
}
|
| 2674 |
+
function copyCursor(cur) {
|
| 2675 |
+
return Pos(cur.line, cur.ch);
|
| 2676 |
+
}
|
| 2677 |
+
function cursorEqual(cur1, cur2) {
|
| 2678 |
+
return cur1.ch == cur2.ch && cur1.line == cur2.line;
|
| 2679 |
+
}
|
| 2680 |
+
function cursorIsBefore(cur1, cur2) {
|
| 2681 |
+
if (cur1.line < cur2.line) {
|
| 2682 |
+
return true;
|
| 2683 |
+
}
|
| 2684 |
+
if (cur1.line == cur2.line && cur1.ch < cur2.ch) {
|
| 2685 |
+
return true;
|
| 2686 |
+
}
|
| 2687 |
+
return false;
|
| 2688 |
+
}
|
| 2689 |
+
function cursorMin(cur1, cur2) {
|
| 2690 |
+
if (arguments.length > 2) {
|
| 2691 |
+
cur2 = cursorMin.apply(undefined, Array.prototype.slice.call(arguments, 1));
|
| 2692 |
+
}
|
| 2693 |
+
return cursorIsBefore(cur1, cur2) ? cur1 : cur2;
|
| 2694 |
+
}
|
| 2695 |
+
function cursorMax(cur1, cur2) {
|
| 2696 |
+
if (arguments.length > 2) {
|
| 2697 |
+
cur2 = cursorMax.apply(undefined, Array.prototype.slice.call(arguments, 1));
|
| 2698 |
+
}
|
| 2699 |
+
return cursorIsBefore(cur1, cur2) ? cur2 : cur1;
|
| 2700 |
+
}
|
| 2701 |
+
function cursorIsBetween(cur1, cur2, cur3) {
|
| 2702 |
+
// returns true if cur2 is between cur1 and cur3.
|
| 2703 |
+
var cur1before2 = cursorIsBefore(cur1, cur2);
|
| 2704 |
+
var cur2before3 = cursorIsBefore(cur2, cur3);
|
| 2705 |
+
return cur1before2 && cur2before3;
|
| 2706 |
+
}
|
| 2707 |
+
function lineLength(cm, lineNum) {
|
| 2708 |
+
return cm.getLine(lineNum).length;
|
| 2709 |
+
}
|
| 2710 |
+
function trim(s) {
|
| 2711 |
+
if (s.trim) {
|
| 2712 |
+
return s.trim();
|
| 2713 |
+
}
|
| 2714 |
+
return s.replace(/^\s+|\s+$/g, '');
|
| 2715 |
+
}
|
| 2716 |
+
function escapeRegex(s) {
|
| 2717 |
+
return s.replace(/([.?*+$\[\]\/\\(){}|\-])/g, '\\$1');
|
| 2718 |
+
}
|
| 2719 |
+
function extendLineToColumn(cm, lineNum, column) {
|
| 2720 |
+
var endCh = lineLength(cm, lineNum);
|
| 2721 |
+
var spaces = new Array(column-endCh+1).join(' ');
|
| 2722 |
+
cm.setCursor(Pos(lineNum, endCh));
|
| 2723 |
+
cm.replaceRange(spaces, cm.getCursor());
|
| 2724 |
+
}
|
| 2725 |
+
// This functions selects a rectangular block
|
| 2726 |
+
// of text with selectionEnd as any of its corner
|
| 2727 |
+
// Height of block:
|
| 2728 |
+
// Difference in selectionEnd.line and first/last selection.line
|
| 2729 |
+
// Width of the block:
|
| 2730 |
+
// Distance between selectionEnd.ch and any(first considered here) selection.ch
|
| 2731 |
+
function selectBlock(cm, selectionEnd) {
|
| 2732 |
+
var selections = [], ranges = cm.listSelections();
|
| 2733 |
+
var head = copyCursor(cm.clipPos(selectionEnd));
|
| 2734 |
+
var isClipped = !cursorEqual(selectionEnd, head);
|
| 2735 |
+
var curHead = cm.getCursor('head');
|
| 2736 |
+
var primIndex = getIndex(ranges, curHead);
|
| 2737 |
+
var wasClipped = cursorEqual(ranges[primIndex].head, ranges[primIndex].anchor);
|
| 2738 |
+
var max = ranges.length - 1;
|
| 2739 |
+
var index = max - primIndex > primIndex ? max : 0;
|
| 2740 |
+
var base = ranges[index].anchor;
|
| 2741 |
+
|
| 2742 |
+
var firstLine = Math.min(base.line, head.line);
|
| 2743 |
+
var lastLine = Math.max(base.line, head.line);
|
| 2744 |
+
var baseCh = base.ch, headCh = head.ch;
|
| 2745 |
+
|
| 2746 |
+
var dir = ranges[index].head.ch - baseCh;
|
| 2747 |
+
var newDir = headCh - baseCh;
|
| 2748 |
+
if (dir > 0 && newDir <= 0) {
|
| 2749 |
+
baseCh++;
|
| 2750 |
+
if (!isClipped) { headCh--; }
|
| 2751 |
+
} else if (dir < 0 && newDir >= 0) {
|
| 2752 |
+
baseCh--;
|
| 2753 |
+
if (!wasClipped) { headCh++; }
|
| 2754 |
+
} else if (dir < 0 && newDir == -1) {
|
| 2755 |
+
baseCh--;
|
| 2756 |
+
headCh++;
|
| 2757 |
+
}
|
| 2758 |
+
for (var line = firstLine; line <= lastLine; line++) {
|
| 2759 |
+
var range = {anchor: new Pos(line, baseCh), head: new Pos(line, headCh)};
|
| 2760 |
+
selections.push(range);
|
| 2761 |
+
}
|
| 2762 |
+
primIndex = head.line == lastLine ? selections.length - 1 : 0;
|
| 2763 |
+
cm.setSelections(selections);
|
| 2764 |
+
selectionEnd.ch = headCh;
|
| 2765 |
+
base.ch = baseCh;
|
| 2766 |
+
return base;
|
| 2767 |
+
}
|
| 2768 |
+
function selectForInsert(cm, head, height) {
|
| 2769 |
+
var sel = [];
|
| 2770 |
+
for (var i = 0; i < height; i++) {
|
| 2771 |
+
var lineHead = offsetCursor(head, i, 0);
|
| 2772 |
+
sel.push({anchor: lineHead, head: lineHead});
|
| 2773 |
+
}
|
| 2774 |
+
cm.setSelections(sel, 0);
|
| 2775 |
+
}
|
| 2776 |
+
// getIndex returns the index of the cursor in the selections.
|
| 2777 |
+
function getIndex(ranges, cursor, end) {
|
| 2778 |
+
for (var i = 0; i < ranges.length; i++) {
|
| 2779 |
+
var atAnchor = end != 'head' && cursorEqual(ranges[i].anchor, cursor);
|
| 2780 |
+
var atHead = end != 'anchor' && cursorEqual(ranges[i].head, cursor);
|
| 2781 |
+
if (atAnchor || atHead) {
|
| 2782 |
+
return i;
|
| 2783 |
+
}
|
| 2784 |
+
}
|
| 2785 |
+
return -1;
|
| 2786 |
+
}
|
| 2787 |
+
function getSelectedAreaRange(cm, vim) {
|
| 2788 |
+
var lastSelection = vim.lastSelection;
|
| 2789 |
+
var getCurrentSelectedAreaRange = function() {
|
| 2790 |
+
var selections = cm.listSelections();
|
| 2791 |
+
var start = selections[0];
|
| 2792 |
+
var end = selections[selections.length-1];
|
| 2793 |
+
var selectionStart = cursorIsBefore(start.anchor, start.head) ? start.anchor : start.head;
|
| 2794 |
+
var selectionEnd = cursorIsBefore(end.anchor, end.head) ? end.head : end.anchor;
|
| 2795 |
+
return [selectionStart, selectionEnd];
|
| 2796 |
+
};
|
| 2797 |
+
var getLastSelectedAreaRange = function() {
|
| 2798 |
+
var selectionStart = cm.getCursor();
|
| 2799 |
+
var selectionEnd = cm.getCursor();
|
| 2800 |
+
var block = lastSelection.visualBlock;
|
| 2801 |
+
if (block) {
|
| 2802 |
+
var width = block.width;
|
| 2803 |
+
var height = block.height;
|
| 2804 |
+
selectionEnd = Pos(selectionStart.line + height, selectionStart.ch + width);
|
| 2805 |
+
var selections = [];
|
| 2806 |
+
// selectBlock creates a 'proper' rectangular block.
|
| 2807 |
+
// We do not want that in all cases, so we manually set selections.
|
| 2808 |
+
for (var i = selectionStart.line; i < selectionEnd.line; i++) {
|
| 2809 |
+
var anchor = Pos(i, selectionStart.ch);
|
| 2810 |
+
var head = Pos(i, selectionEnd.ch);
|
| 2811 |
+
var range = {anchor: anchor, head: head};
|
| 2812 |
+
selections.push(range);
|
| 2813 |
+
}
|
| 2814 |
+
cm.setSelections(selections);
|
| 2815 |
+
} else {
|
| 2816 |
+
var start = lastSelection.anchorMark.find();
|
| 2817 |
+
var end = lastSelection.headMark.find();
|
| 2818 |
+
var line = end.line - start.line;
|
| 2819 |
+
var ch = end.ch - start.ch;
|
| 2820 |
+
selectionEnd = {line: selectionEnd.line + line, ch: line ? selectionEnd.ch : ch + selectionEnd.ch};
|
| 2821 |
+
if (lastSelection.visualLine) {
|
| 2822 |
+
selectionStart = Pos(selectionStart.line, 0);
|
| 2823 |
+
selectionEnd = Pos(selectionEnd.line, lineLength(cm, selectionEnd.line));
|
| 2824 |
+
}
|
| 2825 |
+
cm.setSelection(selectionStart, selectionEnd);
|
| 2826 |
+
}
|
| 2827 |
+
return [selectionStart, selectionEnd];
|
| 2828 |
+
};
|
| 2829 |
+
if (!vim.visualMode) {
|
| 2830 |
+
// In case of replaying the action.
|
| 2831 |
+
return getLastSelectedAreaRange();
|
| 2832 |
+
} else {
|
| 2833 |
+
return getCurrentSelectedAreaRange();
|
| 2834 |
+
}
|
| 2835 |
+
}
|
| 2836 |
+
// Updates the previous selection with the current selection's values. This
|
| 2837 |
+
// should only be called in visual mode.
|
| 2838 |
+
function updateLastSelection(cm, vim) {
|
| 2839 |
+
var anchor = vim.sel.anchor;
|
| 2840 |
+
var head = vim.sel.head;
|
| 2841 |
+
// To accommodate the effect of lastPastedText in the last selection
|
| 2842 |
+
if (vim.lastPastedText) {
|
| 2843 |
+
head = cm.posFromIndex(cm.indexFromPos(anchor) + vim.lastPastedText.length);
|
| 2844 |
+
vim.lastPastedText = null;
|
| 2845 |
+
}
|
| 2846 |
+
vim.lastSelection = {'anchorMark': cm.setBookmark(anchor),
|
| 2847 |
+
'headMark': cm.setBookmark(head),
|
| 2848 |
+
'anchor': copyCursor(anchor),
|
| 2849 |
+
'head': copyCursor(head),
|
| 2850 |
+
'visualMode': vim.visualMode,
|
| 2851 |
+
'visualLine': vim.visualLine,
|
| 2852 |
+
'visualBlock': vim.visualBlock};
|
| 2853 |
+
}
|
| 2854 |
+
function expandSelection(cm, start, end) {
|
| 2855 |
+
var sel = cm.state.vim.sel;
|
| 2856 |
+
var head = sel.head;
|
| 2857 |
+
var anchor = sel.anchor;
|
| 2858 |
+
var tmp;
|
| 2859 |
+
if (cursorIsBefore(end, start)) {
|
| 2860 |
+
tmp = end;
|
| 2861 |
+
end = start;
|
| 2862 |
+
start = tmp;
|
| 2863 |
+
}
|
| 2864 |
+
if (cursorIsBefore(head, anchor)) {
|
| 2865 |
+
head = cursorMin(start, head);
|
| 2866 |
+
anchor = cursorMax(anchor, end);
|
| 2867 |
+
} else {
|
| 2868 |
+
anchor = cursorMin(start, anchor);
|
| 2869 |
+
head = cursorMax(head, end);
|
| 2870 |
+
head = offsetCursor(head, 0, -1);
|
| 2871 |
+
if (head.ch == -1 && head.line != cm.firstLine()) {
|
| 2872 |
+
head = Pos(head.line - 1, lineLength(cm, head.line - 1));
|
| 2873 |
+
}
|
| 2874 |
+
}
|
| 2875 |
+
return [anchor, head];
|
| 2876 |
+
}
|
| 2877 |
+
/**
|
| 2878 |
+
* Updates the CodeMirror selection to match the provided vim selection.
|
| 2879 |
+
* If no arguments are given, it uses the current vim selection state.
|
| 2880 |
+
*/
|
| 2881 |
+
function updateCmSelection(cm, sel, mode) {
|
| 2882 |
+
var vim = cm.state.vim;
|
| 2883 |
+
sel = sel || vim.sel;
|
| 2884 |
+
var mode = mode ||
|
| 2885 |
+
vim.visualLine ? 'line' : vim.visualBlock ? 'block' : 'char';
|
| 2886 |
+
var cmSel = makeCmSelection(cm, sel, mode);
|
| 2887 |
+
cm.setSelections(cmSel.ranges, cmSel.primary);
|
| 2888 |
+
updateFakeCursor(cm);
|
| 2889 |
+
}
|
| 2890 |
+
function makeCmSelection(cm, sel, mode, exclusive) {
|
| 2891 |
+
var head = copyCursor(sel.head);
|
| 2892 |
+
var anchor = copyCursor(sel.anchor);
|
| 2893 |
+
if (mode == 'char') {
|
| 2894 |
+
var headOffset = !exclusive && !cursorIsBefore(sel.head, sel.anchor) ? 1 : 0;
|
| 2895 |
+
var anchorOffset = cursorIsBefore(sel.head, sel.anchor) ? 1 : 0;
|
| 2896 |
+
head = offsetCursor(sel.head, 0, headOffset);
|
| 2897 |
+
anchor = offsetCursor(sel.anchor, 0, anchorOffset);
|
| 2898 |
+
return {
|
| 2899 |
+
ranges: [{anchor: anchor, head: head}],
|
| 2900 |
+
primary: 0
|
| 2901 |
+
};
|
| 2902 |
+
} else if (mode == 'line') {
|
| 2903 |
+
if (!cursorIsBefore(sel.head, sel.anchor)) {
|
| 2904 |
+
anchor.ch = 0;
|
| 2905 |
+
|
| 2906 |
+
var lastLine = cm.lastLine();
|
| 2907 |
+
if (head.line > lastLine) {
|
| 2908 |
+
head.line = lastLine;
|
| 2909 |
+
}
|
| 2910 |
+
head.ch = lineLength(cm, head.line);
|
| 2911 |
+
} else {
|
| 2912 |
+
head.ch = 0;
|
| 2913 |
+
anchor.ch = lineLength(cm, anchor.line);
|
| 2914 |
+
}
|
| 2915 |
+
return {
|
| 2916 |
+
ranges: [{anchor: anchor, head: head}],
|
| 2917 |
+
primary: 0
|
| 2918 |
+
};
|
| 2919 |
+
} else if (mode == 'block') {
|
| 2920 |
+
var top = Math.min(anchor.line, head.line),
|
| 2921 |
+
left = Math.min(anchor.ch, head.ch),
|
| 2922 |
+
bottom = Math.max(anchor.line, head.line),
|
| 2923 |
+
right = Math.max(anchor.ch, head.ch) + 1;
|
| 2924 |
+
var height = bottom - top + 1;
|
| 2925 |
+
var primary = head.line == top ? 0 : height - 1;
|
| 2926 |
+
var ranges = [];
|
| 2927 |
+
for (var i = 0; i < height; i++) {
|
| 2928 |
+
ranges.push({
|
| 2929 |
+
anchor: Pos(top + i, left),
|
| 2930 |
+
head: Pos(top + i, right)
|
| 2931 |
+
});
|
| 2932 |
+
}
|
| 2933 |
+
return {
|
| 2934 |
+
ranges: ranges,
|
| 2935 |
+
primary: primary
|
| 2936 |
+
};
|
| 2937 |
+
}
|
| 2938 |
+
}
|
| 2939 |
+
function getHead(cm) {
|
| 2940 |
+
var cur = cm.getCursor('head');
|
| 2941 |
+
if (cm.getSelection().length == 1) {
|
| 2942 |
+
// Small corner case when only 1 character is selected. The "real"
|
| 2943 |
+
// head is the left of head and anchor.
|
| 2944 |
+
cur = cursorMin(cur, cm.getCursor('anchor'));
|
| 2945 |
+
}
|
| 2946 |
+
return cur;
|
| 2947 |
+
}
|
| 2948 |
+
|
| 2949 |
+
/**
|
| 2950 |
+
* If moveHead is set to false, the CodeMirror selection will not be
|
| 2951 |
+
* touched. The caller assumes the responsibility of putting the cursor
|
| 2952 |
+
* in the right place.
|
| 2953 |
+
*/
|
| 2954 |
+
function exitVisualMode(cm, moveHead) {
|
| 2955 |
+
var vim = cm.state.vim;
|
| 2956 |
+
if (moveHead !== false) {
|
| 2957 |
+
cm.setCursor(clipCursorToContent(cm, vim.sel.head));
|
| 2958 |
+
}
|
| 2959 |
+
updateLastSelection(cm, vim);
|
| 2960 |
+
vim.visualMode = false;
|
| 2961 |
+
vim.visualLine = false;
|
| 2962 |
+
vim.visualBlock = false;
|
| 2963 |
+
CodeMirror.signal(cm, "vim-mode-change", {mode: "normal"});
|
| 2964 |
+
if (vim.fakeCursor) {
|
| 2965 |
+
vim.fakeCursor.clear();
|
| 2966 |
+
}
|
| 2967 |
+
}
|
| 2968 |
+
|
| 2969 |
+
// Remove any trailing newlines from the selection. For
|
| 2970 |
+
// example, with the caret at the start of the last word on the line,
|
| 2971 |
+
// 'dw' should word, but not the newline, while 'w' should advance the
|
| 2972 |
+
// caret to the first character of the next line.
|
| 2973 |
+
function clipToLine(cm, curStart, curEnd) {
|
| 2974 |
+
var selection = cm.getRange(curStart, curEnd);
|
| 2975 |
+
// Only clip if the selection ends with trailing newline + whitespace
|
| 2976 |
+
if (/\n\s*$/.test(selection)) {
|
| 2977 |
+
var lines = selection.split('\n');
|
| 2978 |
+
// We know this is all whitepsace.
|
| 2979 |
+
lines.pop();
|
| 2980 |
+
|
| 2981 |
+
// Cases:
|
| 2982 |
+
// 1. Last word is an empty line - do not clip the trailing '\n'
|
| 2983 |
+
// 2. Last word is not an empty line - clip the trailing '\n'
|
| 2984 |
+
var line;
|
| 2985 |
+
// Find the line containing the last word, and clip all whitespace up
|
| 2986 |
+
// to it.
|
| 2987 |
+
for (var line = lines.pop(); lines.length > 0 && line && isWhiteSpaceString(line); line = lines.pop()) {
|
| 2988 |
+
curEnd.line--;
|
| 2989 |
+
curEnd.ch = 0;
|
| 2990 |
+
}
|
| 2991 |
+
// If the last word is not an empty line, clip an additional newline
|
| 2992 |
+
if (line) {
|
| 2993 |
+
curEnd.line--;
|
| 2994 |
+
curEnd.ch = lineLength(cm, curEnd.line);
|
| 2995 |
+
} else {
|
| 2996 |
+
curEnd.ch = 0;
|
| 2997 |
+
}
|
| 2998 |
+
}
|
| 2999 |
+
}
|
| 3000 |
+
|
| 3001 |
+
// Expand the selection to line ends.
|
| 3002 |
+
function expandSelectionToLine(_cm, curStart, curEnd) {
|
| 3003 |
+
curStart.ch = 0;
|
| 3004 |
+
curEnd.ch = 0;
|
| 3005 |
+
curEnd.line++;
|
| 3006 |
+
}
|
| 3007 |
+
|
| 3008 |
+
function findFirstNonWhiteSpaceCharacter(text) {
|
| 3009 |
+
if (!text) {
|
| 3010 |
+
return 0;
|
| 3011 |
+
}
|
| 3012 |
+
var firstNonWS = text.search(/\S/);
|
| 3013 |
+
return firstNonWS == -1 ? text.length : firstNonWS;
|
| 3014 |
+
}
|
| 3015 |
+
|
| 3016 |
+
function expandWordUnderCursor(cm, inclusive, _forward, bigWord, noSymbol) {
|
| 3017 |
+
var cur = getHead(cm);
|
| 3018 |
+
var line = cm.getLine(cur.line);
|
| 3019 |
+
var idx = cur.ch;
|
| 3020 |
+
|
| 3021 |
+
// Seek to first word or non-whitespace character, depending on if
|
| 3022 |
+
// noSymbol is true.
|
| 3023 |
+
var test = noSymbol ? wordCharTest[0] : bigWordCharTest [0];
|
| 3024 |
+
while (!test(line.charAt(idx))) {
|
| 3025 |
+
idx++;
|
| 3026 |
+
if (idx >= line.length) { return null; }
|
| 3027 |
+
}
|
| 3028 |
+
|
| 3029 |
+
if (bigWord) {
|
| 3030 |
+
test = bigWordCharTest[0];
|
| 3031 |
+
} else {
|
| 3032 |
+
test = wordCharTest[0];
|
| 3033 |
+
if (!test(line.charAt(idx))) {
|
| 3034 |
+
test = wordCharTest[1];
|
| 3035 |
+
}
|
| 3036 |
+
}
|
| 3037 |
+
|
| 3038 |
+
var end = idx, start = idx;
|
| 3039 |
+
while (test(line.charAt(end)) && end < line.length) { end++; }
|
| 3040 |
+
while (test(line.charAt(start)) && start >= 0) { start--; }
|
| 3041 |
+
start++;
|
| 3042 |
+
|
| 3043 |
+
if (inclusive) {
|
| 3044 |
+
// If present, include all whitespace after word.
|
| 3045 |
+
// Otherwise, include all whitespace before word, except indentation.
|
| 3046 |
+
var wordEnd = end;
|
| 3047 |
+
while (/\s/.test(line.charAt(end)) && end < line.length) { end++; }
|
| 3048 |
+
if (wordEnd == end) {
|
| 3049 |
+
var wordStart = start;
|
| 3050 |
+
while (/\s/.test(line.charAt(start - 1)) && start > 0) { start--; }
|
| 3051 |
+
if (!start) { start = wordStart; }
|
| 3052 |
+
}
|
| 3053 |
+
}
|
| 3054 |
+
return { start: Pos(cur.line, start), end: Pos(cur.line, end) };
|
| 3055 |
+
}
|
| 3056 |
+
|
| 3057 |
+
function recordJumpPosition(cm, oldCur, newCur) {
|
| 3058 |
+
if (!cursorEqual(oldCur, newCur)) {
|
| 3059 |
+
vimGlobalState.jumpList.add(cm, oldCur, newCur);
|
| 3060 |
+
}
|
| 3061 |
+
}
|
| 3062 |
+
|
| 3063 |
+
function recordLastCharacterSearch(increment, args) {
|
| 3064 |
+
vimGlobalState.lastChararacterSearch.increment = increment;
|
| 3065 |
+
vimGlobalState.lastChararacterSearch.forward = args.forward;
|
| 3066 |
+
vimGlobalState.lastChararacterSearch.selectedCharacter = args.selectedCharacter;
|
| 3067 |
+
}
|
| 3068 |
+
|
| 3069 |
+
var symbolToMode = {
|
| 3070 |
+
'(': 'bracket', ')': 'bracket', '{': 'bracket', '}': 'bracket',
|
| 3071 |
+
'[': 'section', ']': 'section',
|
| 3072 |
+
'*': 'comment', '/': 'comment',
|
| 3073 |
+
'm': 'method', 'M': 'method',
|
| 3074 |
+
'#': 'preprocess'
|
| 3075 |
+
};
|
| 3076 |
+
var findSymbolModes = {
|
| 3077 |
+
bracket: {
|
| 3078 |
+
isComplete: function(state) {
|
| 3079 |
+
if (state.nextCh === state.symb) {
|
| 3080 |
+
state.depth++;
|
| 3081 |
+
if (state.depth >= 1)return true;
|
| 3082 |
+
} else if (state.nextCh === state.reverseSymb) {
|
| 3083 |
+
state.depth--;
|
| 3084 |
+
}
|
| 3085 |
+
return false;
|
| 3086 |
+
}
|
| 3087 |
+
},
|
| 3088 |
+
section: {
|
| 3089 |
+
init: function(state) {
|
| 3090 |
+
state.curMoveThrough = true;
|
| 3091 |
+
state.symb = (state.forward ? ']' : '[') === state.symb ? '{' : '}';
|
| 3092 |
+
},
|
| 3093 |
+
isComplete: function(state) {
|
| 3094 |
+
return state.index === 0 && state.nextCh === state.symb;
|
| 3095 |
+
}
|
| 3096 |
+
},
|
| 3097 |
+
comment: {
|
| 3098 |
+
isComplete: function(state) {
|
| 3099 |
+
var found = state.lastCh === '*' && state.nextCh === '/';
|
| 3100 |
+
state.lastCh = state.nextCh;
|
| 3101 |
+
return found;
|
| 3102 |
+
}
|
| 3103 |
+
},
|
| 3104 |
+
// TODO: The original Vim implementation only operates on level 1 and 2.
|
| 3105 |
+
// The current implementation doesn't check for code block level and
|
| 3106 |
+
// therefore it operates on any levels.
|
| 3107 |
+
method: {
|
| 3108 |
+
init: function(state) {
|
| 3109 |
+
state.symb = (state.symb === 'm' ? '{' : '}');
|
| 3110 |
+
state.reverseSymb = state.symb === '{' ? '}' : '{';
|
| 3111 |
+
},
|
| 3112 |
+
isComplete: function(state) {
|
| 3113 |
+
if (state.nextCh === state.symb)return true;
|
| 3114 |
+
return false;
|
| 3115 |
+
}
|
| 3116 |
+
},
|
| 3117 |
+
preprocess: {
|
| 3118 |
+
init: function(state) {
|
| 3119 |
+
state.index = 0;
|
| 3120 |
+
},
|
| 3121 |
+
isComplete: function(state) {
|
| 3122 |
+
if (state.nextCh === '#') {
|
| 3123 |
+
var token = state.lineText.match(/#(\w+)/)[1];
|
| 3124 |
+
if (token === 'endif') {
|
| 3125 |
+
if (state.forward && state.depth === 0) {
|
| 3126 |
+
return true;
|
| 3127 |
+
}
|
| 3128 |
+
state.depth++;
|
| 3129 |
+
} else if (token === 'if') {
|
| 3130 |
+
if (!state.forward && state.depth === 0) {
|
| 3131 |
+
return true;
|
| 3132 |
+
}
|
| 3133 |
+
state.depth--;
|
| 3134 |
+
}
|
| 3135 |
+
if (token === 'else' && state.depth === 0)return true;
|
| 3136 |
+
}
|
| 3137 |
+
return false;
|
| 3138 |
+
}
|
| 3139 |
+
}
|
| 3140 |
+
};
|
| 3141 |
+
function findSymbol(cm, repeat, forward, symb) {
|
| 3142 |
+
var cur = copyCursor(cm.getCursor());
|
| 3143 |
+
var increment = forward ? 1 : -1;
|
| 3144 |
+
var endLine = forward ? cm.lineCount() : -1;
|
| 3145 |
+
var curCh = cur.ch;
|
| 3146 |
+
var line = cur.line;
|
| 3147 |
+
var lineText = cm.getLine(line);
|
| 3148 |
+
var state = {
|
| 3149 |
+
lineText: lineText,
|
| 3150 |
+
nextCh: lineText.charAt(curCh),
|
| 3151 |
+
lastCh: null,
|
| 3152 |
+
index: curCh,
|
| 3153 |
+
symb: symb,
|
| 3154 |
+
reverseSymb: (forward ? { ')': '(', '}': '{' } : { '(': ')', '{': '}' })[symb],
|
| 3155 |
+
forward: forward,
|
| 3156 |
+
depth: 0,
|
| 3157 |
+
curMoveThrough: false
|
| 3158 |
+
};
|
| 3159 |
+
var mode = symbolToMode[symb];
|
| 3160 |
+
if (!mode)return cur;
|
| 3161 |
+
var init = findSymbolModes[mode].init;
|
| 3162 |
+
var isComplete = findSymbolModes[mode].isComplete;
|
| 3163 |
+
if (init) { init(state); }
|
| 3164 |
+
while (line !== endLine && repeat) {
|
| 3165 |
+
state.index += increment;
|
| 3166 |
+
state.nextCh = state.lineText.charAt(state.index);
|
| 3167 |
+
if (!state.nextCh) {
|
| 3168 |
+
line += increment;
|
| 3169 |
+
state.lineText = cm.getLine(line) || '';
|
| 3170 |
+
if (increment > 0) {
|
| 3171 |
+
state.index = 0;
|
| 3172 |
+
} else {
|
| 3173 |
+
var lineLen = state.lineText.length;
|
| 3174 |
+
state.index = (lineLen > 0) ? (lineLen-1) : 0;
|
| 3175 |
+
}
|
| 3176 |
+
state.nextCh = state.lineText.charAt(state.index);
|
| 3177 |
+
}
|
| 3178 |
+
if (isComplete(state)) {
|
| 3179 |
+
cur.line = line;
|
| 3180 |
+
cur.ch = state.index;
|
| 3181 |
+
repeat--;
|
| 3182 |
+
}
|
| 3183 |
+
}
|
| 3184 |
+
if (state.nextCh || state.curMoveThrough) {
|
| 3185 |
+
return Pos(line, state.index);
|
| 3186 |
+
}
|
| 3187 |
+
return cur;
|
| 3188 |
+
}
|
| 3189 |
+
|
| 3190 |
+
/*
|
| 3191 |
+
* Returns the boundaries of the next word. If the cursor in the middle of
|
| 3192 |
+
* the word, then returns the boundaries of the current word, starting at
|
| 3193 |
+
* the cursor. If the cursor is at the start/end of a word, and we are going
|
| 3194 |
+
* forward/backward, respectively, find the boundaries of the next word.
|
| 3195 |
+
*
|
| 3196 |
+
* @param {CodeMirror} cm CodeMirror object.
|
| 3197 |
+
* @param {Cursor} cur The cursor position.
|
| 3198 |
+
* @param {boolean} forward True to search forward. False to search
|
| 3199 |
+
* backward.
|
| 3200 |
+
* @param {boolean} bigWord True if punctuation count as part of the word.
|
| 3201 |
+
* False if only [a-zA-Z0-9] characters count as part of the word.
|
| 3202 |
+
* @param {boolean} emptyLineIsWord True if empty lines should be treated
|
| 3203 |
+
* as words.
|
| 3204 |
+
* @return {Object{from:number, to:number, line: number}} The boundaries of
|
| 3205 |
+
* the word, or null if there are no more words.
|
| 3206 |
+
*/
|
| 3207 |
+
function findWord(cm, cur, forward, bigWord, emptyLineIsWord) {
|
| 3208 |
+
var lineNum = cur.line;
|
| 3209 |
+
var pos = cur.ch;
|
| 3210 |
+
var line = cm.getLine(lineNum);
|
| 3211 |
+
var dir = forward ? 1 : -1;
|
| 3212 |
+
var charTests = bigWord ? bigWordCharTest: wordCharTest;
|
| 3213 |
+
|
| 3214 |
+
if (emptyLineIsWord && line == '') {
|
| 3215 |
+
lineNum += dir;
|
| 3216 |
+
line = cm.getLine(lineNum);
|
| 3217 |
+
if (!isLine(cm, lineNum)) {
|
| 3218 |
+
return null;
|
| 3219 |
+
}
|
| 3220 |
+
pos = (forward) ? 0 : line.length;
|
| 3221 |
+
}
|
| 3222 |
+
|
| 3223 |
+
while (true) {
|
| 3224 |
+
if (emptyLineIsWord && line == '') {
|
| 3225 |
+
return { from: 0, to: 0, line: lineNum };
|
| 3226 |
+
}
|
| 3227 |
+
var stop = (dir > 0) ? line.length : -1;
|
| 3228 |
+
var wordStart = stop, wordEnd = stop;
|
| 3229 |
+
// Find bounds of next word.
|
| 3230 |
+
while (pos != stop) {
|
| 3231 |
+
var foundWord = false;
|
| 3232 |
+
for (var i = 0; i < charTests.length && !foundWord; ++i) {
|
| 3233 |
+
if (charTests[i](line.charAt(pos))) {
|
| 3234 |
+
wordStart = pos;
|
| 3235 |
+
// Advance to end of word.
|
| 3236 |
+
while (pos != stop && charTests[i](line.charAt(pos))) {
|
| 3237 |
+
pos += dir;
|
| 3238 |
+
}
|
| 3239 |
+
wordEnd = pos;
|
| 3240 |
+
foundWord = wordStart != wordEnd;
|
| 3241 |
+
if (wordStart == cur.ch && lineNum == cur.line &&
|
| 3242 |
+
wordEnd == wordStart + dir) {
|
| 3243 |
+
// We started at the end of a word. Find the next one.
|
| 3244 |
+
continue;
|
| 3245 |
+
} else {
|
| 3246 |
+
return {
|
| 3247 |
+
from: Math.min(wordStart, wordEnd + 1),
|
| 3248 |
+
to: Math.max(wordStart, wordEnd),
|
| 3249 |
+
line: lineNum };
|
| 3250 |
+
}
|
| 3251 |
+
}
|
| 3252 |
+
}
|
| 3253 |
+
if (!foundWord) {
|
| 3254 |
+
pos += dir;
|
| 3255 |
+
}
|
| 3256 |
+
}
|
| 3257 |
+
// Advance to next/prev line.
|
| 3258 |
+
lineNum += dir;
|
| 3259 |
+
if (!isLine(cm, lineNum)) {
|
| 3260 |
+
return null;
|
| 3261 |
+
}
|
| 3262 |
+
line = cm.getLine(lineNum);
|
| 3263 |
+
pos = (dir > 0) ? 0 : line.length;
|
| 3264 |
+
}
|
| 3265 |
+
// Should never get here.
|
| 3266 |
+
throw new Error('The impossible happened.');
|
| 3267 |
+
}
|
| 3268 |
+
|
| 3269 |
+
/**
|
| 3270 |
+
* @param {CodeMirror} cm CodeMirror object.
|
| 3271 |
+
* @param {Pos} cur The position to start from.
|
| 3272 |
+
* @param {int} repeat Number of words to move past.
|
| 3273 |
+
* @param {boolean} forward True to search forward. False to search
|
| 3274 |
+
* backward.
|
| 3275 |
+
* @param {boolean} wordEnd True to move to end of word. False to move to
|
| 3276 |
+
* beginning of word.
|
| 3277 |
+
* @param {boolean} bigWord True if punctuation count as part of the word.
|
| 3278 |
+
* False if only alphabet characters count as part of the word.
|
| 3279 |
+
* @return {Cursor} The position the cursor should move to.
|
| 3280 |
+
*/
|
| 3281 |
+
function moveToWord(cm, cur, repeat, forward, wordEnd, bigWord) {
|
| 3282 |
+
var curStart = copyCursor(cur);
|
| 3283 |
+
var words = [];
|
| 3284 |
+
if (forward && !wordEnd || !forward && wordEnd) {
|
| 3285 |
+
repeat++;
|
| 3286 |
+
}
|
| 3287 |
+
// For 'e', empty lines are not considered words, go figure.
|
| 3288 |
+
var emptyLineIsWord = !(forward && wordEnd);
|
| 3289 |
+
for (var i = 0; i < repeat; i++) {
|
| 3290 |
+
var word = findWord(cm, cur, forward, bigWord, emptyLineIsWord);
|
| 3291 |
+
if (!word) {
|
| 3292 |
+
var eodCh = lineLength(cm, cm.lastLine());
|
| 3293 |
+
words.push(forward
|
| 3294 |
+
? {line: cm.lastLine(), from: eodCh, to: eodCh}
|
| 3295 |
+
: {line: 0, from: 0, to: 0});
|
| 3296 |
+
break;
|
| 3297 |
+
}
|
| 3298 |
+
words.push(word);
|
| 3299 |
+
cur = Pos(word.line, forward ? (word.to - 1) : word.from);
|
| 3300 |
+
}
|
| 3301 |
+
var shortCircuit = words.length != repeat;
|
| 3302 |
+
var firstWord = words[0];
|
| 3303 |
+
var lastWord = words.pop();
|
| 3304 |
+
if (forward && !wordEnd) {
|
| 3305 |
+
// w
|
| 3306 |
+
if (!shortCircuit && (firstWord.from != curStart.ch || firstWord.line != curStart.line)) {
|
| 3307 |
+
// We did not start in the middle of a word. Discard the extra word at the end.
|
| 3308 |
+
lastWord = words.pop();
|
| 3309 |
+
}
|
| 3310 |
+
return Pos(lastWord.line, lastWord.from);
|
| 3311 |
+
} else if (forward && wordEnd) {
|
| 3312 |
+
return Pos(lastWord.line, lastWord.to - 1);
|
| 3313 |
+
} else if (!forward && wordEnd) {
|
| 3314 |
+
// ge
|
| 3315 |
+
if (!shortCircuit && (firstWord.to != curStart.ch || firstWord.line != curStart.line)) {
|
| 3316 |
+
// We did not start in the middle of a word. Discard the extra word at the end.
|
| 3317 |
+
lastWord = words.pop();
|
| 3318 |
+
}
|
| 3319 |
+
return Pos(lastWord.line, lastWord.to);
|
| 3320 |
+
} else {
|
| 3321 |
+
// b
|
| 3322 |
+
return Pos(lastWord.line, lastWord.from);
|
| 3323 |
+
}
|
| 3324 |
+
}
|
| 3325 |
+
|
| 3326 |
+
function moveToCharacter(cm, repeat, forward, character) {
|
| 3327 |
+
var cur = cm.getCursor();
|
| 3328 |
+
var start = cur.ch;
|
| 3329 |
+
var idx;
|
| 3330 |
+
for (var i = 0; i < repeat; i ++) {
|
| 3331 |
+
var line = cm.getLine(cur.line);
|
| 3332 |
+
idx = charIdxInLine(start, line, character, forward, true);
|
| 3333 |
+
if (idx == -1) {
|
| 3334 |
+
return null;
|
| 3335 |
+
}
|
| 3336 |
+
start = idx;
|
| 3337 |
+
}
|
| 3338 |
+
return Pos(cm.getCursor().line, idx);
|
| 3339 |
+
}
|
| 3340 |
+
|
| 3341 |
+
function moveToColumn(cm, repeat) {
|
| 3342 |
+
// repeat is always >= 1, so repeat - 1 always corresponds
|
| 3343 |
+
// to the column we want to go to.
|
| 3344 |
+
var line = cm.getCursor().line;
|
| 3345 |
+
return clipCursorToContent(cm, Pos(line, repeat - 1));
|
| 3346 |
+
}
|
| 3347 |
+
|
| 3348 |
+
function updateMark(cm, vim, markName, pos) {
|
| 3349 |
+
if (!inArray(markName, validMarks)) {
|
| 3350 |
+
return;
|
| 3351 |
+
}
|
| 3352 |
+
if (vim.marks[markName]) {
|
| 3353 |
+
vim.marks[markName].clear();
|
| 3354 |
+
}
|
| 3355 |
+
vim.marks[markName] = cm.setBookmark(pos);
|
| 3356 |
+
}
|
| 3357 |
+
|
| 3358 |
+
function charIdxInLine(start, line, character, forward, includeChar) {
|
| 3359 |
+
// Search for char in line.
|
| 3360 |
+
// motion_options: {forward, includeChar}
|
| 3361 |
+
// If includeChar = true, include it too.
|
| 3362 |
+
// If forward = true, search forward, else search backwards.
|
| 3363 |
+
// If char is not found on this line, do nothing
|
| 3364 |
+
var idx;
|
| 3365 |
+
if (forward) {
|
| 3366 |
+
idx = line.indexOf(character, start + 1);
|
| 3367 |
+
if (idx != -1 && !includeChar) {
|
| 3368 |
+
idx -= 1;
|
| 3369 |
+
}
|
| 3370 |
+
} else {
|
| 3371 |
+
idx = line.lastIndexOf(character, start - 1);
|
| 3372 |
+
if (idx != -1 && !includeChar) {
|
| 3373 |
+
idx += 1;
|
| 3374 |
+
}
|
| 3375 |
+
}
|
| 3376 |
+
return idx;
|
| 3377 |
+
}
|
| 3378 |
+
|
| 3379 |
+
function findParagraph(cm, head, repeat, dir, inclusive) {
|
| 3380 |
+
var line = head.line;
|
| 3381 |
+
var min = cm.firstLine();
|
| 3382 |
+
var max = cm.lastLine();
|
| 3383 |
+
var start, end, i = line;
|
| 3384 |
+
function isEmpty(i) { return !cm.getLine(i); }
|
| 3385 |
+
function isBoundary(i, dir, any) {
|
| 3386 |
+
if (any) { return isEmpty(i) != isEmpty(i + dir); }
|
| 3387 |
+
return !isEmpty(i) && isEmpty(i + dir);
|
| 3388 |
+
}
|
| 3389 |
+
if (dir) {
|
| 3390 |
+
while (min <= i && i <= max && repeat > 0) {
|
| 3391 |
+
if (isBoundary(i, dir)) { repeat--; }
|
| 3392 |
+
i += dir;
|
| 3393 |
+
}
|
| 3394 |
+
return new Pos(i, 0);
|
| 3395 |
+
}
|
| 3396 |
+
|
| 3397 |
+
var vim = cm.state.vim;
|
| 3398 |
+
if (vim.visualLine && isBoundary(line, 1, true)) {
|
| 3399 |
+
var anchor = vim.sel.anchor;
|
| 3400 |
+
if (isBoundary(anchor.line, -1, true)) {
|
| 3401 |
+
if (!inclusive || anchor.line != line) {
|
| 3402 |
+
line += 1;
|
| 3403 |
+
}
|
| 3404 |
+
}
|
| 3405 |
+
}
|
| 3406 |
+
var startState = isEmpty(line);
|
| 3407 |
+
for (i = line; i <= max && repeat; i++) {
|
| 3408 |
+
if (isBoundary(i, 1, true)) {
|
| 3409 |
+
if (!inclusive || isEmpty(i) != startState) {
|
| 3410 |
+
repeat--;
|
| 3411 |
+
}
|
| 3412 |
+
}
|
| 3413 |
+
}
|
| 3414 |
+
end = new Pos(i, 0);
|
| 3415 |
+
// select boundary before paragraph for the last one
|
| 3416 |
+
if (i > max && !startState) { startState = true; }
|
| 3417 |
+
else { inclusive = false; }
|
| 3418 |
+
for (i = line; i > min; i--) {
|
| 3419 |
+
if (!inclusive || isEmpty(i) == startState || i == line) {
|
| 3420 |
+
if (isBoundary(i, -1, true)) { break; }
|
| 3421 |
+
}
|
| 3422 |
+
}
|
| 3423 |
+
start = new Pos(i, 0);
|
| 3424 |
+
return { start: start, end: end };
|
| 3425 |
+
}
|
| 3426 |
+
|
| 3427 |
+
// TODO: perhaps this finagling of start and end positions belonds
|
| 3428 |
+
// in codmirror/replaceRange?
|
| 3429 |
+
function selectCompanionObject(cm, head, symb, inclusive) {
|
| 3430 |
+
var cur = head, start, end;
|
| 3431 |
+
|
| 3432 |
+
var bracketRegexp = ({
|
| 3433 |
+
'(': /[()]/, ')': /[()]/,
|
| 3434 |
+
'[': /[[\]]/, ']': /[[\]]/,
|
| 3435 |
+
'{': /[{}]/, '}': /[{}]/})[symb];
|
| 3436 |
+
var openSym = ({
|
| 3437 |
+
'(': '(', ')': '(',
|
| 3438 |
+
'[': '[', ']': '[',
|
| 3439 |
+
'{': '{', '}': '{'})[symb];
|
| 3440 |
+
var curChar = cm.getLine(cur.line).charAt(cur.ch);
|
| 3441 |
+
// Due to the behavior of scanForBracket, we need to add an offset if the
|
| 3442 |
+
// cursor is on a matching open bracket.
|
| 3443 |
+
var offset = curChar === openSym ? 1 : 0;
|
| 3444 |
+
|
| 3445 |
+
start = cm.scanForBracket(Pos(cur.line, cur.ch + offset), -1, null, {'bracketRegex': bracketRegexp});
|
| 3446 |
+
end = cm.scanForBracket(Pos(cur.line, cur.ch + offset), 1, null, {'bracketRegex': bracketRegexp});
|
| 3447 |
+
|
| 3448 |
+
if (!start || !end) {
|
| 3449 |
+
return { start: cur, end: cur };
|
| 3450 |
+
}
|
| 3451 |
+
|
| 3452 |
+
start = start.pos;
|
| 3453 |
+
end = end.pos;
|
| 3454 |
+
|
| 3455 |
+
if ((start.line == end.line && start.ch > end.ch)
|
| 3456 |
+
|| (start.line > end.line)) {
|
| 3457 |
+
var tmp = start;
|
| 3458 |
+
start = end;
|
| 3459 |
+
end = tmp;
|
| 3460 |
+
}
|
| 3461 |
+
|
| 3462 |
+
if (inclusive) {
|
| 3463 |
+
end.ch += 1;
|
| 3464 |
+
} else {
|
| 3465 |
+
start.ch += 1;
|
| 3466 |
+
}
|
| 3467 |
+
|
| 3468 |
+
return { start: start, end: end };
|
| 3469 |
+
}
|
| 3470 |
+
|
| 3471 |
+
// Takes in a symbol and a cursor and tries to simulate text objects that
|
| 3472 |
+
// have identical opening and closing symbols
|
| 3473 |
+
// TODO support across multiple lines
|
| 3474 |
+
function findBeginningAndEnd(cm, head, symb, inclusive) {
|
| 3475 |
+
var cur = copyCursor(head);
|
| 3476 |
+
var line = cm.getLine(cur.line);
|
| 3477 |
+
var chars = line.split('');
|
| 3478 |
+
var start, end, i, len;
|
| 3479 |
+
var firstIndex = chars.indexOf(symb);
|
| 3480 |
+
|
| 3481 |
+
// the decision tree is to always look backwards for the beginning first,
|
| 3482 |
+
// but if the cursor is in front of the first instance of the symb,
|
| 3483 |
+
// then move the cursor forward
|
| 3484 |
+
if (cur.ch < firstIndex) {
|
| 3485 |
+
cur.ch = firstIndex;
|
| 3486 |
+
// Why is this line even here???
|
| 3487 |
+
// cm.setCursor(cur.line, firstIndex+1);
|
| 3488 |
+
}
|
| 3489 |
+
// otherwise if the cursor is currently on the closing symbol
|
| 3490 |
+
else if (firstIndex < cur.ch && chars[cur.ch] == symb) {
|
| 3491 |
+
end = cur.ch; // assign end to the current cursor
|
| 3492 |
+
--cur.ch; // make sure to look backwards
|
| 3493 |
+
}
|
| 3494 |
+
|
| 3495 |
+
// if we're currently on the symbol, we've got a start
|
| 3496 |
+
if (chars[cur.ch] == symb && !end) {
|
| 3497 |
+
start = cur.ch + 1; // assign start to ahead of the cursor
|
| 3498 |
+
} else {
|
| 3499 |
+
// go backwards to find the start
|
| 3500 |
+
for (i = cur.ch; i > -1 && !start; i--) {
|
| 3501 |
+
if (chars[i] == symb) {
|
| 3502 |
+
start = i + 1;
|
| 3503 |
+
}
|
| 3504 |
+
}
|
| 3505 |
+
}
|
| 3506 |
+
|
| 3507 |
+
// look forwards for the end symbol
|
| 3508 |
+
if (start && !end) {
|
| 3509 |
+
for (i = start, len = chars.length; i < len && !end; i++) {
|
| 3510 |
+
if (chars[i] == symb) {
|
| 3511 |
+
end = i;
|
| 3512 |
+
}
|
| 3513 |
+
}
|
| 3514 |
+
}
|
| 3515 |
+
|
| 3516 |
+
// nothing found
|
| 3517 |
+
if (!start || !end) {
|
| 3518 |
+
return { start: cur, end: cur };
|
| 3519 |
+
}
|
| 3520 |
+
|
| 3521 |
+
// include the symbols
|
| 3522 |
+
if (inclusive) {
|
| 3523 |
+
--start; ++end;
|
| 3524 |
+
}
|
| 3525 |
+
|
| 3526 |
+
return {
|
| 3527 |
+
start: Pos(cur.line, start),
|
| 3528 |
+
end: Pos(cur.line, end)
|
| 3529 |
+
};
|
| 3530 |
+
}
|
| 3531 |
+
|
| 3532 |
+
// Search functions
|
| 3533 |
+
defineOption('pcre', true, 'boolean');
|
| 3534 |
+
function SearchState() {}
|
| 3535 |
+
SearchState.prototype = {
|
| 3536 |
+
getQuery: function() {
|
| 3537 |
+
return vimGlobalState.query;
|
| 3538 |
+
},
|
| 3539 |
+
setQuery: function(query) {
|
| 3540 |
+
vimGlobalState.query = query;
|
| 3541 |
+
},
|
| 3542 |
+
getOverlay: function() {
|
| 3543 |
+
return this.searchOverlay;
|
| 3544 |
+
},
|
| 3545 |
+
setOverlay: function(overlay) {
|
| 3546 |
+
this.searchOverlay = overlay;
|
| 3547 |
+
},
|
| 3548 |
+
isReversed: function() {
|
| 3549 |
+
return vimGlobalState.isReversed;
|
| 3550 |
+
},
|
| 3551 |
+
setReversed: function(reversed) {
|
| 3552 |
+
vimGlobalState.isReversed = reversed;
|
| 3553 |
+
},
|
| 3554 |
+
getScrollbarAnnotate: function() {
|
| 3555 |
+
return this.annotate;
|
| 3556 |
+
},
|
| 3557 |
+
setScrollbarAnnotate: function(annotate) {
|
| 3558 |
+
this.annotate = annotate;
|
| 3559 |
+
}
|
| 3560 |
+
};
|
| 3561 |
+
function getSearchState(cm) {
|
| 3562 |
+
var vim = cm.state.vim;
|
| 3563 |
+
return vim.searchState_ || (vim.searchState_ = new SearchState());
|
| 3564 |
+
}
|
| 3565 |
+
function dialog(cm, template, shortText, onClose, options) {
|
| 3566 |
+
if (cm.openDialog) {
|
| 3567 |
+
cm.openDialog(template, onClose, { bottom: true, value: options.value,
|
| 3568 |
+
onKeyDown: options.onKeyDown, onKeyUp: options.onKeyUp,
|
| 3569 |
+
selectValueOnOpen: false});
|
| 3570 |
+
}
|
| 3571 |
+
else {
|
| 3572 |
+
onClose(prompt(shortText, ''));
|
| 3573 |
+
}
|
| 3574 |
+
}
|
| 3575 |
+
function splitBySlash(argString) {
|
| 3576 |
+
var slashes = findUnescapedSlashes(argString) || [];
|
| 3577 |
+
if (!slashes.length) return [];
|
| 3578 |
+
var tokens = [];
|
| 3579 |
+
// in case of strings like foo/bar
|
| 3580 |
+
if (slashes[0] !== 0) return;
|
| 3581 |
+
for (var i = 0; i < slashes.length; i++) {
|
| 3582 |
+
if (typeof slashes[i] == 'number')
|
| 3583 |
+
tokens.push(argString.substring(slashes[i] + 1, slashes[i+1]));
|
| 3584 |
+
}
|
| 3585 |
+
return tokens;
|
| 3586 |
+
}
|
| 3587 |
+
|
| 3588 |
+
function findUnescapedSlashes(str) {
|
| 3589 |
+
var escapeNextChar = false;
|
| 3590 |
+
var slashes = [];
|
| 3591 |
+
for (var i = 0; i < str.length; i++) {
|
| 3592 |
+
var c = str.charAt(i);
|
| 3593 |
+
if (!escapeNextChar && c == '/') {
|
| 3594 |
+
slashes.push(i);
|
| 3595 |
+
}
|
| 3596 |
+
escapeNextChar = !escapeNextChar && (c == '\\');
|
| 3597 |
+
}
|
| 3598 |
+
return slashes;
|
| 3599 |
+
}
|
| 3600 |
+
|
| 3601 |
+
// Translates a search string from ex (vim) syntax into javascript form.
|
| 3602 |
+
function translateRegex(str) {
|
| 3603 |
+
// When these match, add a '\' if unescaped or remove one if escaped.
|
| 3604 |
+
var specials = '|(){';
|
| 3605 |
+
// Remove, but never add, a '\' for these.
|
| 3606 |
+
var unescape = '}';
|
| 3607 |
+
var escapeNextChar = false;
|
| 3608 |
+
var out = [];
|
| 3609 |
+
for (var i = -1; i < str.length; i++) {
|
| 3610 |
+
var c = str.charAt(i) || '';
|
| 3611 |
+
var n = str.charAt(i+1) || '';
|
| 3612 |
+
var specialComesNext = (n && specials.indexOf(n) != -1);
|
| 3613 |
+
if (escapeNextChar) {
|
| 3614 |
+
if (c !== '\\' || !specialComesNext) {
|
| 3615 |
+
out.push(c);
|
| 3616 |
+
}
|
| 3617 |
+
escapeNextChar = false;
|
| 3618 |
+
} else {
|
| 3619 |
+
if (c === '\\') {
|
| 3620 |
+
escapeNextChar = true;
|
| 3621 |
+
// Treat the unescape list as special for removing, but not adding '\'.
|
| 3622 |
+
if (n && unescape.indexOf(n) != -1) {
|
| 3623 |
+
specialComesNext = true;
|
| 3624 |
+
}
|
| 3625 |
+
// Not passing this test means removing a '\'.
|
| 3626 |
+
if (!specialComesNext || n === '\\') {
|
| 3627 |
+
out.push(c);
|
| 3628 |
+
}
|
| 3629 |
+
} else {
|
| 3630 |
+
out.push(c);
|
| 3631 |
+
if (specialComesNext && n !== '\\') {
|
| 3632 |
+
out.push('\\');
|
| 3633 |
+
}
|
| 3634 |
+
}
|
| 3635 |
+
}
|
| 3636 |
+
}
|
| 3637 |
+
return out.join('');
|
| 3638 |
+
}
|
| 3639 |
+
|
| 3640 |
+
// Translates the replace part of a search and replace from ex (vim) syntax into
|
| 3641 |
+
// javascript form. Similar to translateRegex, but additionally fixes back references
|
| 3642 |
+
// (translates '\[0..9]' to '$[0..9]') and follows different rules for escaping '$'.
|
| 3643 |
+
function translateRegexReplace(str) {
|
| 3644 |
+
var escapeNextChar = false;
|
| 3645 |
+
var out = [];
|
| 3646 |
+
for (var i = -1; i < str.length; i++) {
|
| 3647 |
+
var c = str.charAt(i) || '';
|
| 3648 |
+
var n = str.charAt(i+1) || '';
|
| 3649 |
+
if (escapeNextChar) {
|
| 3650 |
+
// At any point in the loop, escapeNextChar is true if the previous
|
| 3651 |
+
// character was a '\' and was not escaped.
|
| 3652 |
+
out.push(c);
|
| 3653 |
+
escapeNextChar = false;
|
| 3654 |
+
} else {
|
| 3655 |
+
if (c === '\\') {
|
| 3656 |
+
escapeNextChar = true;
|
| 3657 |
+
if ((isNumber(n) || n === '$')) {
|
| 3658 |
+
out.push('$');
|
| 3659 |
+
} else if (n !== '/' && n !== '\\') {
|
| 3660 |
+
out.push('\\');
|
| 3661 |
+
}
|
| 3662 |
+
} else {
|
| 3663 |
+
if (c === '$') {
|
| 3664 |
+
out.push('$');
|
| 3665 |
+
}
|
| 3666 |
+
out.push(c);
|
| 3667 |
+
if (n === '/') {
|
| 3668 |
+
out.push('\\');
|
| 3669 |
+
}
|
| 3670 |
+
}
|
| 3671 |
+
}
|
| 3672 |
+
}
|
| 3673 |
+
return out.join('');
|
| 3674 |
+
}
|
| 3675 |
+
|
| 3676 |
+
// Unescape \ and / in the replace part, for PCRE mode.
|
| 3677 |
+
function unescapeRegexReplace(str) {
|
| 3678 |
+
var stream = new CodeMirror.StringStream(str);
|
| 3679 |
+
var output = [];
|
| 3680 |
+
while (!stream.eol()) {
|
| 3681 |
+
// Search for \.
|
| 3682 |
+
while (stream.peek() && stream.peek() != '\\') {
|
| 3683 |
+
output.push(stream.next());
|
| 3684 |
+
}
|
| 3685 |
+
if (stream.match('\\/', true)) {
|
| 3686 |
+
// \/ => /
|
| 3687 |
+
output.push('/');
|
| 3688 |
+
} else if (stream.match('\\\\', true)) {
|
| 3689 |
+
// \\ => \
|
| 3690 |
+
output.push('\\');
|
| 3691 |
+
} else {
|
| 3692 |
+
// Don't change anything
|
| 3693 |
+
output.push(stream.next());
|
| 3694 |
+
}
|
| 3695 |
+
}
|
| 3696 |
+
return output.join('');
|
| 3697 |
+
}
|
| 3698 |
+
|
| 3699 |
+
/**
|
| 3700 |
+
* Extract the regular expression from the query and return a Regexp object.
|
| 3701 |
+
* Returns null if the query is blank.
|
| 3702 |
+
* If ignoreCase is passed in, the Regexp object will have the 'i' flag set.
|
| 3703 |
+
* If smartCase is passed in, and the query contains upper case letters,
|
| 3704 |
+
* then ignoreCase is overridden, and the 'i' flag will not be set.
|
| 3705 |
+
* If the query contains the /i in the flag part of the regular expression,
|
| 3706 |
+
* then both ignoreCase and smartCase are ignored, and 'i' will be passed
|
| 3707 |
+
* through to the Regex object.
|
| 3708 |
+
*/
|
| 3709 |
+
function parseQuery(query, ignoreCase, smartCase) {
|
| 3710 |
+
// First update the last search register
|
| 3711 |
+
var lastSearchRegister = vimGlobalState.registerController.getRegister('/');
|
| 3712 |
+
lastSearchRegister.setText(query);
|
| 3713 |
+
// Check if the query is already a regex.
|
| 3714 |
+
if (query instanceof RegExp) { return query; }
|
| 3715 |
+
// First try to extract regex + flags from the input. If no flags found,
|
| 3716 |
+
// extract just the regex. IE does not accept flags directly defined in
|
| 3717 |
+
// the regex string in the form /regex/flags
|
| 3718 |
+
var slashes = findUnescapedSlashes(query);
|
| 3719 |
+
var regexPart;
|
| 3720 |
+
var forceIgnoreCase;
|
| 3721 |
+
if (!slashes.length) {
|
| 3722 |
+
// Query looks like 'regexp'
|
| 3723 |
+
regexPart = query;
|
| 3724 |
+
} else {
|
| 3725 |
+
// Query looks like 'regexp/...'
|
| 3726 |
+
regexPart = query.substring(0, slashes[0]);
|
| 3727 |
+
var flagsPart = query.substring(slashes[0]);
|
| 3728 |
+
forceIgnoreCase = (flagsPart.indexOf('i') != -1);
|
| 3729 |
+
}
|
| 3730 |
+
if (!regexPart) {
|
| 3731 |
+
return null;
|
| 3732 |
+
}
|
| 3733 |
+
if (!getOption('pcre')) {
|
| 3734 |
+
regexPart = translateRegex(regexPart);
|
| 3735 |
+
}
|
| 3736 |
+
if (smartCase) {
|
| 3737 |
+
ignoreCase = (/^[^A-Z]*$/).test(regexPart);
|
| 3738 |
+
}
|
| 3739 |
+
var regexp = new RegExp(regexPart,
|
| 3740 |
+
(ignoreCase || forceIgnoreCase) ? 'i' : undefined);
|
| 3741 |
+
return regexp;
|
| 3742 |
+
}
|
| 3743 |
+
function showConfirm(cm, text) {
|
| 3744 |
+
if (cm.openNotification) {
|
| 3745 |
+
cm.openNotification('<span style="color: red">' + text + '</span>',
|
| 3746 |
+
{bottom: true, duration: 5000});
|
| 3747 |
+
} else {
|
| 3748 |
+
alert(text);
|
| 3749 |
+
}
|
| 3750 |
+
}
|
| 3751 |
+
function makePrompt(prefix, desc) {
|
| 3752 |
+
var raw = '';
|
| 3753 |
+
if (prefix) {
|
| 3754 |
+
raw += '<span style="font-family: monospace">' + prefix + '</span>';
|
| 3755 |
+
}
|
| 3756 |
+
raw += '<input type="text"/> ' +
|
| 3757 |
+
'<span style="color: #888">';
|
| 3758 |
+
if (desc) {
|
| 3759 |
+
raw += '<span style="color: #888">';
|
| 3760 |
+
raw += desc;
|
| 3761 |
+
raw += '</span>';
|
| 3762 |
+
}
|
| 3763 |
+
return raw;
|
| 3764 |
+
}
|
| 3765 |
+
var searchPromptDesc = '(Javascript regexp)';
|
| 3766 |
+
function showPrompt(cm, options) {
|
| 3767 |
+
var shortText = (options.prefix || '') + ' ' + (options.desc || '');
|
| 3768 |
+
var prompt = makePrompt(options.prefix, options.desc);
|
| 3769 |
+
dialog(cm, prompt, shortText, options.onClose, options);
|
| 3770 |
+
}
|
| 3771 |
+
function regexEqual(r1, r2) {
|
| 3772 |
+
if (r1 instanceof RegExp && r2 instanceof RegExp) {
|
| 3773 |
+
var props = ['global', 'multiline', 'ignoreCase', 'source'];
|
| 3774 |
+
for (var i = 0; i < props.length; i++) {
|
| 3775 |
+
var prop = props[i];
|
| 3776 |
+
if (r1[prop] !== r2[prop]) {
|
| 3777 |
+
return false;
|
| 3778 |
+
}
|
| 3779 |
+
}
|
| 3780 |
+
return true;
|
| 3781 |
+
}
|
| 3782 |
+
return false;
|
| 3783 |
+
}
|
| 3784 |
+
// Returns true if the query is valid.
|
| 3785 |
+
function updateSearchQuery(cm, rawQuery, ignoreCase, smartCase) {
|
| 3786 |
+
if (!rawQuery) {
|
| 3787 |
+
return;
|
| 3788 |
+
}
|
| 3789 |
+
var state = getSearchState(cm);
|
| 3790 |
+
var query = parseQuery(rawQuery, !!ignoreCase, !!smartCase);
|
| 3791 |
+
if (!query) {
|
| 3792 |
+
return;
|
| 3793 |
+
}
|
| 3794 |
+
highlightSearchMatches(cm, query);
|
| 3795 |
+
if (regexEqual(query, state.getQuery())) {
|
| 3796 |
+
return query;
|
| 3797 |
+
}
|
| 3798 |
+
state.setQuery(query);
|
| 3799 |
+
return query;
|
| 3800 |
+
}
|
| 3801 |
+
function searchOverlay(query) {
|
| 3802 |
+
if (query.source.charAt(0) == '^') {
|
| 3803 |
+
var matchSol = true;
|
| 3804 |
+
}
|
| 3805 |
+
return {
|
| 3806 |
+
token: function(stream) {
|
| 3807 |
+
if (matchSol && !stream.sol()) {
|
| 3808 |
+
stream.skipToEnd();
|
| 3809 |
+
return;
|
| 3810 |
+
}
|
| 3811 |
+
var match = stream.match(query, false);
|
| 3812 |
+
if (match) {
|
| 3813 |
+
if (match[0].length == 0) {
|
| 3814 |
+
// Matched empty string, skip to next.
|
| 3815 |
+
stream.next();
|
| 3816 |
+
return 'searching';
|
| 3817 |
+
}
|
| 3818 |
+
if (!stream.sol()) {
|
| 3819 |
+
// Backtrack 1 to match \b
|
| 3820 |
+
stream.backUp(1);
|
| 3821 |
+
if (!query.exec(stream.next() + match[0])) {
|
| 3822 |
+
stream.next();
|
| 3823 |
+
return null;
|
| 3824 |
+
}
|
| 3825 |
+
}
|
| 3826 |
+
stream.match(query);
|
| 3827 |
+
return 'searching';
|
| 3828 |
+
}
|
| 3829 |
+
while (!stream.eol()) {
|
| 3830 |
+
stream.next();
|
| 3831 |
+
if (stream.match(query, false)) break;
|
| 3832 |
+
}
|
| 3833 |
+
},
|
| 3834 |
+
query: query
|
| 3835 |
+
};
|
| 3836 |
+
}
|
| 3837 |
+
function highlightSearchMatches(cm, query) {
|
| 3838 |
+
var searchState = getSearchState(cm);
|
| 3839 |
+
var overlay = searchState.getOverlay();
|
| 3840 |
+
if (!overlay || query != overlay.query) {
|
| 3841 |
+
if (overlay) {
|
| 3842 |
+
cm.removeOverlay(overlay);
|
| 3843 |
+
}
|
| 3844 |
+
overlay = searchOverlay(query);
|
| 3845 |
+
cm.addOverlay(overlay);
|
| 3846 |
+
if (cm.showMatchesOnScrollbar) {
|
| 3847 |
+
if (searchState.getScrollbarAnnotate()) {
|
| 3848 |
+
searchState.getScrollbarAnnotate().clear();
|
| 3849 |
+
}
|
| 3850 |
+
searchState.setScrollbarAnnotate(cm.showMatchesOnScrollbar(query));
|
| 3851 |
+
}
|
| 3852 |
+
searchState.setOverlay(overlay);
|
| 3853 |
+
}
|
| 3854 |
+
}
|
| 3855 |
+
function findNext(cm, prev, query, repeat) {
|
| 3856 |
+
if (repeat === undefined) { repeat = 1; }
|
| 3857 |
+
return cm.operation(function() {
|
| 3858 |
+
var pos = cm.getCursor();
|
| 3859 |
+
var cursor = cm.getSearchCursor(query, pos);
|
| 3860 |
+
for (var i = 0; i < repeat; i++) {
|
| 3861 |
+
var found = cursor.find(prev);
|
| 3862 |
+
if (i == 0 && found && cursorEqual(cursor.from(), pos)) { found = cursor.find(prev); }
|
| 3863 |
+
if (!found) {
|
| 3864 |
+
// SearchCursor may have returned null because it hit EOF, wrap
|
| 3865 |
+
// around and try again.
|
| 3866 |
+
cursor = cm.getSearchCursor(query,
|
| 3867 |
+
(prev) ? Pos(cm.lastLine()) : Pos(cm.firstLine(), 0) );
|
| 3868 |
+
if (!cursor.find(prev)) {
|
| 3869 |
+
return;
|
| 3870 |
+
}
|
| 3871 |
+
}
|
| 3872 |
+
}
|
| 3873 |
+
return cursor.from();
|
| 3874 |
+
});
|
| 3875 |
+
}
|
| 3876 |
+
function clearSearchHighlight(cm) {
|
| 3877 |
+
var state = getSearchState(cm);
|
| 3878 |
+
cm.removeOverlay(getSearchState(cm).getOverlay());
|
| 3879 |
+
state.setOverlay(null);
|
| 3880 |
+
if (state.getScrollbarAnnotate()) {
|
| 3881 |
+
state.getScrollbarAnnotate().clear();
|
| 3882 |
+
state.setScrollbarAnnotate(null);
|
| 3883 |
+
}
|
| 3884 |
+
}
|
| 3885 |
+
/**
|
| 3886 |
+
* Check if pos is in the specified range, INCLUSIVE.
|
| 3887 |
+
* Range can be specified with 1 or 2 arguments.
|
| 3888 |
+
* If the first range argument is an array, treat it as an array of line
|
| 3889 |
+
* numbers. Match pos against any of the lines.
|
| 3890 |
+
* If the first range argument is a number,
|
| 3891 |
+
* if there is only 1 range argument, check if pos has the same line
|
| 3892 |
+
* number
|
| 3893 |
+
* if there are 2 range arguments, then check if pos is in between the two
|
| 3894 |
+
* range arguments.
|
| 3895 |
+
*/
|
| 3896 |
+
function isInRange(pos, start, end) {
|
| 3897 |
+
if (typeof pos != 'number') {
|
| 3898 |
+
// Assume it is a cursor position. Get the line number.
|
| 3899 |
+
pos = pos.line;
|
| 3900 |
+
}
|
| 3901 |
+
if (start instanceof Array) {
|
| 3902 |
+
return inArray(pos, start);
|
| 3903 |
+
} else {
|
| 3904 |
+
if (end) {
|
| 3905 |
+
return (pos >= start && pos <= end);
|
| 3906 |
+
} else {
|
| 3907 |
+
return pos == start;
|
| 3908 |
+
}
|
| 3909 |
+
}
|
| 3910 |
+
}
|
| 3911 |
+
function getUserVisibleLines(cm) {
|
| 3912 |
+
var scrollInfo = cm.getScrollInfo();
|
| 3913 |
+
var occludeToleranceTop = 6;
|
| 3914 |
+
var occludeToleranceBottom = 10;
|
| 3915 |
+
var from = cm.coordsChar({left:0, top: occludeToleranceTop + scrollInfo.top}, 'local');
|
| 3916 |
+
var bottomY = scrollInfo.clientHeight - occludeToleranceBottom + scrollInfo.top;
|
| 3917 |
+
var to = cm.coordsChar({left:0, top: bottomY}, 'local');
|
| 3918 |
+
return {top: from.line, bottom: to.line};
|
| 3919 |
+
}
|
| 3920 |
+
|
| 3921 |
+
var ExCommandDispatcher = function() {
|
| 3922 |
+
this.buildCommandMap_();
|
| 3923 |
+
};
|
| 3924 |
+
ExCommandDispatcher.prototype = {
|
| 3925 |
+
processCommand: function(cm, input, opt_params) {
|
| 3926 |
+
var that = this;
|
| 3927 |
+
cm.operation(function () {
|
| 3928 |
+
cm.curOp.isVimOp = true;
|
| 3929 |
+
that._processCommand(cm, input, opt_params);
|
| 3930 |
+
});
|
| 3931 |
+
},
|
| 3932 |
+
_processCommand: function(cm, input, opt_params) {
|
| 3933 |
+
var vim = cm.state.vim;
|
| 3934 |
+
var commandHistoryRegister = vimGlobalState.registerController.getRegister(':');
|
| 3935 |
+
var previousCommand = commandHistoryRegister.toString();
|
| 3936 |
+
if (vim.visualMode) {
|
| 3937 |
+
exitVisualMode(cm);
|
| 3938 |
+
}
|
| 3939 |
+
var inputStream = new CodeMirror.StringStream(input);
|
| 3940 |
+
// update ": with the latest command whether valid or invalid
|
| 3941 |
+
commandHistoryRegister.setText(input);
|
| 3942 |
+
var params = opt_params || {};
|
| 3943 |
+
params.input = input;
|
| 3944 |
+
try {
|
| 3945 |
+
this.parseInput_(cm, inputStream, params);
|
| 3946 |
+
} catch(e) {
|
| 3947 |
+
showConfirm(cm, e);
|
| 3948 |
+
throw e;
|
| 3949 |
+
}
|
| 3950 |
+
var command;
|
| 3951 |
+
var commandName;
|
| 3952 |
+
if (!params.commandName) {
|
| 3953 |
+
// If only a line range is defined, move to the line.
|
| 3954 |
+
if (params.line !== undefined) {
|
| 3955 |
+
commandName = 'move';
|
| 3956 |
+
}
|
| 3957 |
+
} else {
|
| 3958 |
+
command = this.matchCommand_(params.commandName);
|
| 3959 |
+
if (command) {
|
| 3960 |
+
commandName = command.name;
|
| 3961 |
+
if (command.excludeFromCommandHistory) {
|
| 3962 |
+
commandHistoryRegister.setText(previousCommand);
|
| 3963 |
+
}
|
| 3964 |
+
this.parseCommandArgs_(inputStream, params, command);
|
| 3965 |
+
if (command.type == 'exToKey') {
|
| 3966 |
+
// Handle Ex to Key mapping.
|
| 3967 |
+
for (var i = 0; i < command.toKeys.length; i++) {
|
| 3968 |
+
CodeMirror.Vim.handleKey(cm, command.toKeys[i], 'mapping');
|
| 3969 |
+
}
|
| 3970 |
+
return;
|
| 3971 |
+
} else if (command.type == 'exToEx') {
|
| 3972 |
+
// Handle Ex to Ex mapping.
|
| 3973 |
+
this.processCommand(cm, command.toInput);
|
| 3974 |
+
return;
|
| 3975 |
+
}
|
| 3976 |
+
}
|
| 3977 |
+
}
|
| 3978 |
+
if (!commandName) {
|
| 3979 |
+
showConfirm(cm, 'Not an editor command ":' + input + '"');
|
| 3980 |
+
return;
|
| 3981 |
+
}
|
| 3982 |
+
try {
|
| 3983 |
+
exCommands[commandName](cm, params);
|
| 3984 |
+
// Possibly asynchronous commands (e.g. substitute, which might have a
|
| 3985 |
+
// user confirmation), are responsible for calling the callback when
|
| 3986 |
+
// done. All others have it taken care of for them here.
|
| 3987 |
+
if ((!command || !command.possiblyAsync) && params.callback) {
|
| 3988 |
+
params.callback();
|
| 3989 |
+
}
|
| 3990 |
+
} catch(e) {
|
| 3991 |
+
showConfirm(cm, e);
|
| 3992 |
+
throw e;
|
| 3993 |
+
}
|
| 3994 |
+
},
|
| 3995 |
+
parseInput_: function(cm, inputStream, result) {
|
| 3996 |
+
inputStream.eatWhile(':');
|
| 3997 |
+
// Parse range.
|
| 3998 |
+
if (inputStream.eat('%')) {
|
| 3999 |
+
result.line = cm.firstLine();
|
| 4000 |
+
result.lineEnd = cm.lastLine();
|
| 4001 |
+
} else {
|
| 4002 |
+
result.line = this.parseLineSpec_(cm, inputStream);
|
| 4003 |
+
if (result.line !== undefined && inputStream.eat(',')) {
|
| 4004 |
+
result.lineEnd = this.parseLineSpec_(cm, inputStream);
|
| 4005 |
+
}
|
| 4006 |
+
}
|
| 4007 |
+
|
| 4008 |
+
// Parse command name.
|
| 4009 |
+
var commandMatch = inputStream.match(/^(\w+)/);
|
| 4010 |
+
if (commandMatch) {
|
| 4011 |
+
result.commandName = commandMatch[1];
|
| 4012 |
+
} else {
|
| 4013 |
+
result.commandName = inputStream.match(/.*/)[0];
|
| 4014 |
+
}
|
| 4015 |
+
|
| 4016 |
+
return result;
|
| 4017 |
+
},
|
| 4018 |
+
parseLineSpec_: function(cm, inputStream) {
|
| 4019 |
+
var numberMatch = inputStream.match(/^(\d+)/);
|
| 4020 |
+
if (numberMatch) {
|
| 4021 |
+
return parseInt(numberMatch[1], 10) - 1;
|
| 4022 |
+
}
|
| 4023 |
+
switch (inputStream.next()) {
|
| 4024 |
+
case '.':
|
| 4025 |
+
return cm.getCursor().line;
|
| 4026 |
+
case '$':
|
| 4027 |
+
return cm.lastLine();
|
| 4028 |
+
case '\'':
|
| 4029 |
+
var mark = cm.state.vim.marks[inputStream.next()];
|
| 4030 |
+
if (mark && mark.find()) {
|
| 4031 |
+
return mark.find().line;
|
| 4032 |
+
}
|
| 4033 |
+
throw new Error('Mark not set');
|
| 4034 |
+
default:
|
| 4035 |
+
inputStream.backUp(1);
|
| 4036 |
+
return undefined;
|
| 4037 |
+
}
|
| 4038 |
+
},
|
| 4039 |
+
parseCommandArgs_: function(inputStream, params, command) {
|
| 4040 |
+
if (inputStream.eol()) {
|
| 4041 |
+
return;
|
| 4042 |
+
}
|
| 4043 |
+
params.argString = inputStream.match(/.*/)[0];
|
| 4044 |
+
// Parse command-line arguments
|
| 4045 |
+
var delim = command.argDelimiter || /\s+/;
|
| 4046 |
+
var args = trim(params.argString).split(delim);
|
| 4047 |
+
if (args.length && args[0]) {
|
| 4048 |
+
params.args = args;
|
| 4049 |
+
}
|
| 4050 |
+
},
|
| 4051 |
+
matchCommand_: function(commandName) {
|
| 4052 |
+
// Return the command in the command map that matches the shortest
|
| 4053 |
+
// prefix of the passed in command name. The match is guaranteed to be
|
| 4054 |
+
// unambiguous if the defaultExCommandMap's shortNames are set up
|
| 4055 |
+
// correctly. (see @code{defaultExCommandMap}).
|
| 4056 |
+
for (var i = commandName.length; i > 0; i--) {
|
| 4057 |
+
var prefix = commandName.substring(0, i);
|
| 4058 |
+
if (this.commandMap_[prefix]) {
|
| 4059 |
+
var command = this.commandMap_[prefix];
|
| 4060 |
+
if (command.name.indexOf(commandName) === 0) {
|
| 4061 |
+
return command;
|
| 4062 |
+
}
|
| 4063 |
+
}
|
| 4064 |
+
}
|
| 4065 |
+
return null;
|
| 4066 |
+
},
|
| 4067 |
+
buildCommandMap_: function() {
|
| 4068 |
+
this.commandMap_ = {};
|
| 4069 |
+
for (var i = 0; i < defaultExCommandMap.length; i++) {
|
| 4070 |
+
var command = defaultExCommandMap[i];
|
| 4071 |
+
var key = command.shortName || command.name;
|
| 4072 |
+
this.commandMap_[key] = command;
|
| 4073 |
+
}
|
| 4074 |
+
},
|
| 4075 |
+
map: function(lhs, rhs, ctx) {
|
| 4076 |
+
if (lhs != ':' && lhs.charAt(0) == ':') {
|
| 4077 |
+
if (ctx) { throw Error('Mode not supported for ex mappings'); }
|
| 4078 |
+
var commandName = lhs.substring(1);
|
| 4079 |
+
if (rhs != ':' && rhs.charAt(0) == ':') {
|
| 4080 |
+
// Ex to Ex mapping
|
| 4081 |
+
this.commandMap_[commandName] = {
|
| 4082 |
+
name: commandName,
|
| 4083 |
+
type: 'exToEx',
|
| 4084 |
+
toInput: rhs.substring(1),
|
| 4085 |
+
user: true
|
| 4086 |
+
};
|
| 4087 |
+
} else {
|
| 4088 |
+
// Ex to key mapping
|
| 4089 |
+
this.commandMap_[commandName] = {
|
| 4090 |
+
name: commandName,
|
| 4091 |
+
type: 'exToKey',
|
| 4092 |
+
toKeys: rhs,
|
| 4093 |
+
user: true
|
| 4094 |
+
};
|
| 4095 |
+
}
|
| 4096 |
+
} else {
|
| 4097 |
+
if (rhs != ':' && rhs.charAt(0) == ':') {
|
| 4098 |
+
// Key to Ex mapping.
|
| 4099 |
+
var mapping = {
|
| 4100 |
+
keys: lhs,
|
| 4101 |
+
type: 'keyToEx',
|
| 4102 |
+
exArgs: { input: rhs.substring(1) },
|
| 4103 |
+
user: true};
|
| 4104 |
+
if (ctx) { mapping.context = ctx; }
|
| 4105 |
+
defaultKeymap.unshift(mapping);
|
| 4106 |
+
} else {
|
| 4107 |
+
// Key to key mapping
|
| 4108 |
+
var mapping = {
|
| 4109 |
+
keys: lhs,
|
| 4110 |
+
type: 'keyToKey',
|
| 4111 |
+
toKeys: rhs,
|
| 4112 |
+
user: true
|
| 4113 |
+
};
|
| 4114 |
+
if (ctx) { mapping.context = ctx; }
|
| 4115 |
+
defaultKeymap.unshift(mapping);
|
| 4116 |
+
}
|
| 4117 |
+
}
|
| 4118 |
+
},
|
| 4119 |
+
unmap: function(lhs, ctx) {
|
| 4120 |
+
if (lhs != ':' && lhs.charAt(0) == ':') {
|
| 4121 |
+
// Ex to Ex or Ex to key mapping
|
| 4122 |
+
if (ctx) { throw Error('Mode not supported for ex mappings'); }
|
| 4123 |
+
var commandName = lhs.substring(1);
|
| 4124 |
+
if (this.commandMap_[commandName] && this.commandMap_[commandName].user) {
|
| 4125 |
+
delete this.commandMap_[commandName];
|
| 4126 |
+
return;
|
| 4127 |
+
}
|
| 4128 |
+
} else {
|
| 4129 |
+
// Key to Ex or key to key mapping
|
| 4130 |
+
var keys = lhs;
|
| 4131 |
+
for (var i = 0; i < defaultKeymap.length; i++) {
|
| 4132 |
+
if (keys == defaultKeymap[i].keys
|
| 4133 |
+
&& defaultKeymap[i].context === ctx
|
| 4134 |
+
&& defaultKeymap[i].user) {
|
| 4135 |
+
defaultKeymap.splice(i, 1);
|
| 4136 |
+
return;
|
| 4137 |
+
}
|
| 4138 |
+
}
|
| 4139 |
+
}
|
| 4140 |
+
throw Error('No such mapping.');
|
| 4141 |
+
}
|
| 4142 |
+
};
|
| 4143 |
+
|
| 4144 |
+
var exCommands = {
|
| 4145 |
+
colorscheme: function(cm, params) {
|
| 4146 |
+
if (!params.args || params.args.length < 1) {
|
| 4147 |
+
showConfirm(cm, cm.getOption('theme'));
|
| 4148 |
+
return;
|
| 4149 |
+
}
|
| 4150 |
+
cm.setOption('theme', params.args[0]);
|
| 4151 |
+
},
|
| 4152 |
+
map: function(cm, params, ctx) {
|
| 4153 |
+
var mapArgs = params.args;
|
| 4154 |
+
if (!mapArgs || mapArgs.length < 2) {
|
| 4155 |
+
if (cm) {
|
| 4156 |
+
showConfirm(cm, 'Invalid mapping: ' + params.input);
|
| 4157 |
+
}
|
| 4158 |
+
return;
|
| 4159 |
+
}
|
| 4160 |
+
exCommandDispatcher.map(mapArgs[0], mapArgs[1], ctx);
|
| 4161 |
+
},
|
| 4162 |
+
imap: function(cm, params) { this.map(cm, params, 'insert'); },
|
| 4163 |
+
nmap: function(cm, params) { this.map(cm, params, 'normal'); },
|
| 4164 |
+
vmap: function(cm, params) { this.map(cm, params, 'visual'); },
|
| 4165 |
+
unmap: function(cm, params, ctx) {
|
| 4166 |
+
var mapArgs = params.args;
|
| 4167 |
+
if (!mapArgs || mapArgs.length < 1) {
|
| 4168 |
+
if (cm) {
|
| 4169 |
+
showConfirm(cm, 'No such mapping: ' + params.input);
|
| 4170 |
+
}
|
| 4171 |
+
return;
|
| 4172 |
+
}
|
| 4173 |
+
exCommandDispatcher.unmap(mapArgs[0], ctx);
|
| 4174 |
+
},
|
| 4175 |
+
move: function(cm, params) {
|
| 4176 |
+
commandDispatcher.processCommand(cm, cm.state.vim, {
|
| 4177 |
+
type: 'motion',
|
| 4178 |
+
motion: 'moveToLineOrEdgeOfDocument',
|
| 4179 |
+
motionArgs: { forward: false, explicitRepeat: true,
|
| 4180 |
+
linewise: true },
|
| 4181 |
+
repeatOverride: params.line+1});
|
| 4182 |
+
},
|
| 4183 |
+
set: function(cm, params) {
|
| 4184 |
+
var setArgs = params.args;
|
| 4185 |
+
// Options passed through to the setOption/getOption calls. May be passed in by the
|
| 4186 |
+
// local/global versions of the set command
|
| 4187 |
+
var setCfg = params.setCfg || {};
|
| 4188 |
+
if (!setArgs || setArgs.length < 1) {
|
| 4189 |
+
if (cm) {
|
| 4190 |
+
showConfirm(cm, 'Invalid mapping: ' + params.input);
|
| 4191 |
+
}
|
| 4192 |
+
return;
|
| 4193 |
+
}
|
| 4194 |
+
var expr = setArgs[0].split('=');
|
| 4195 |
+
var optionName = expr[0];
|
| 4196 |
+
var value = expr[1];
|
| 4197 |
+
var forceGet = false;
|
| 4198 |
+
|
| 4199 |
+
if (optionName.charAt(optionName.length - 1) == '?') {
|
| 4200 |
+
// If post-fixed with ?, then the set is actually a get.
|
| 4201 |
+
if (value) { throw Error('Trailing characters: ' + params.argString); }
|
| 4202 |
+
optionName = optionName.substring(0, optionName.length - 1);
|
| 4203 |
+
forceGet = true;
|
| 4204 |
+
}
|
| 4205 |
+
if (value === undefined && optionName.substring(0, 2) == 'no') {
|
| 4206 |
+
// To set boolean options to false, the option name is prefixed with
|
| 4207 |
+
// 'no'.
|
| 4208 |
+
optionName = optionName.substring(2);
|
| 4209 |
+
value = false;
|
| 4210 |
+
}
|
| 4211 |
+
|
| 4212 |
+
var optionIsBoolean = options[optionName] && options[optionName].type == 'boolean';
|
| 4213 |
+
if (optionIsBoolean && value == undefined) {
|
| 4214 |
+
// Calling set with a boolean option sets it to true.
|
| 4215 |
+
value = true;
|
| 4216 |
+
}
|
| 4217 |
+
// If no value is provided, then we assume this is a get.
|
| 4218 |
+
if (!optionIsBoolean && value === undefined || forceGet) {
|
| 4219 |
+
var oldValue = getOption(optionName, cm, setCfg);
|
| 4220 |
+
if (oldValue === true || oldValue === false) {
|
| 4221 |
+
showConfirm(cm, ' ' + (oldValue ? '' : 'no') + optionName);
|
| 4222 |
+
} else {
|
| 4223 |
+
showConfirm(cm, ' ' + optionName + '=' + oldValue);
|
| 4224 |
+
}
|
| 4225 |
+
} else {
|
| 4226 |
+
setOption(optionName, value, cm, setCfg);
|
| 4227 |
+
}
|
| 4228 |
+
},
|
| 4229 |
+
setlocal: function (cm, params) {
|
| 4230 |
+
// setCfg is passed through to setOption
|
| 4231 |
+
params.setCfg = {scope: 'local'};
|
| 4232 |
+
this.set(cm, params);
|
| 4233 |
+
},
|
| 4234 |
+
setglobal: function (cm, params) {
|
| 4235 |
+
// setCfg is passed through to setOption
|
| 4236 |
+
params.setCfg = {scope: 'global'};
|
| 4237 |
+
this.set(cm, params);
|
| 4238 |
+
},
|
| 4239 |
+
registers: function(cm, params) {
|
| 4240 |
+
var regArgs = params.args;
|
| 4241 |
+
var registers = vimGlobalState.registerController.registers;
|
| 4242 |
+
var regInfo = '----------Registers----------<br><br>';
|
| 4243 |
+
if (!regArgs) {
|
| 4244 |
+
for (var registerName in registers) {
|
| 4245 |
+
var text = registers[registerName].toString();
|
| 4246 |
+
if (text.length) {
|
| 4247 |
+
regInfo += '"' + registerName + ' ' + text + '<br>';
|
| 4248 |
+
}
|
| 4249 |
+
}
|
| 4250 |
+
} else {
|
| 4251 |
+
var registerName;
|
| 4252 |
+
regArgs = regArgs.join('');
|
| 4253 |
+
for (var i = 0; i < regArgs.length; i++) {
|
| 4254 |
+
registerName = regArgs.charAt(i);
|
| 4255 |
+
if (!vimGlobalState.registerController.isValidRegister(registerName)) {
|
| 4256 |
+
continue;
|
| 4257 |
+
}
|
| 4258 |
+
var register = registers[registerName] || new Register();
|
| 4259 |
+
regInfo += '"' + registerName + ' ' + register.toString() + '<br>';
|
| 4260 |
+
}
|
| 4261 |
+
}
|
| 4262 |
+
showConfirm(cm, regInfo);
|
| 4263 |
+
},
|
| 4264 |
+
sort: function(cm, params) {
|
| 4265 |
+
var reverse, ignoreCase, unique, number;
|
| 4266 |
+
function parseArgs() {
|
| 4267 |
+
if (params.argString) {
|
| 4268 |
+
var args = new CodeMirror.StringStream(params.argString);
|
| 4269 |
+
if (args.eat('!')) { reverse = true; }
|
| 4270 |
+
if (args.eol()) { return; }
|
| 4271 |
+
if (!args.eatSpace()) { return 'Invalid arguments'; }
|
| 4272 |
+
var opts = args.match(/[a-z]+/);
|
| 4273 |
+
if (opts) {
|
| 4274 |
+
opts = opts[0];
|
| 4275 |
+
ignoreCase = opts.indexOf('i') != -1;
|
| 4276 |
+
unique = opts.indexOf('u') != -1;
|
| 4277 |
+
var decimal = opts.indexOf('d') != -1 && 1;
|
| 4278 |
+
var hex = opts.indexOf('x') != -1 && 1;
|
| 4279 |
+
var octal = opts.indexOf('o') != -1 && 1;
|
| 4280 |
+
if (decimal + hex + octal > 1) { return 'Invalid arguments'; }
|
| 4281 |
+
number = decimal && 'decimal' || hex && 'hex' || octal && 'octal';
|
| 4282 |
+
}
|
| 4283 |
+
if (args.eatSpace() && args.match(/\/.*\//)) { 'patterns not supported'; }
|
| 4284 |
+
}
|
| 4285 |
+
}
|
| 4286 |
+
var err = parseArgs();
|
| 4287 |
+
if (err) {
|
| 4288 |
+
showConfirm(cm, err + ': ' + params.argString);
|
| 4289 |
+
return;
|
| 4290 |
+
}
|
| 4291 |
+
var lineStart = params.line || cm.firstLine();
|
| 4292 |
+
var lineEnd = params.lineEnd || params.line || cm.lastLine();
|
| 4293 |
+
if (lineStart == lineEnd) { return; }
|
| 4294 |
+
var curStart = Pos(lineStart, 0);
|
| 4295 |
+
var curEnd = Pos(lineEnd, lineLength(cm, lineEnd));
|
| 4296 |
+
var text = cm.getRange(curStart, curEnd).split('\n');
|
| 4297 |
+
var numberRegex = (number == 'decimal') ? /(-?)([\d]+)/ :
|
| 4298 |
+
(number == 'hex') ? /(-?)(?:0x)?([0-9a-f]+)/i :
|
| 4299 |
+
(number == 'octal') ? /([0-7]+)/ : null;
|
| 4300 |
+
var radix = (number == 'decimal') ? 10 : (number == 'hex') ? 16 : (number == 'octal') ? 8 : null;
|
| 4301 |
+
var numPart = [], textPart = [];
|
| 4302 |
+
if (number) {
|
| 4303 |
+
for (var i = 0; i < text.length; i++) {
|
| 4304 |
+
if (numberRegex.exec(text[i])) {
|
| 4305 |
+
numPart.push(text[i]);
|
| 4306 |
+
} else {
|
| 4307 |
+
textPart.push(text[i]);
|
| 4308 |
+
}
|
| 4309 |
+
}
|
| 4310 |
+
} else {
|
| 4311 |
+
textPart = text;
|
| 4312 |
+
}
|
| 4313 |
+
function compareFn(a, b) {
|
| 4314 |
+
if (reverse) { var tmp; tmp = a; a = b; b = tmp; }
|
| 4315 |
+
if (ignoreCase) { a = a.toLowerCase(); b = b.toLowerCase(); }
|
| 4316 |
+
var anum = number && numberRegex.exec(a);
|
| 4317 |
+
var bnum = number && numberRegex.exec(b);
|
| 4318 |
+
if (!anum) { return a < b ? -1 : 1; }
|
| 4319 |
+
anum = parseInt((anum[1] + anum[2]).toLowerCase(), radix);
|
| 4320 |
+
bnum = parseInt((bnum[1] + bnum[2]).toLowerCase(), radix);
|
| 4321 |
+
return anum - bnum;
|
| 4322 |
+
}
|
| 4323 |
+
numPart.sort(compareFn);
|
| 4324 |
+
textPart.sort(compareFn);
|
| 4325 |
+
text = (!reverse) ? textPart.concat(numPart) : numPart.concat(textPart);
|
| 4326 |
+
if (unique) { // Remove duplicate lines
|
| 4327 |
+
var textOld = text;
|
| 4328 |
+
var lastLine;
|
| 4329 |
+
text = [];
|
| 4330 |
+
for (var i = 0; i < textOld.length; i++) {
|
| 4331 |
+
if (textOld[i] != lastLine) {
|
| 4332 |
+
text.push(textOld[i]);
|
| 4333 |
+
}
|
| 4334 |
+
lastLine = textOld[i];
|
| 4335 |
+
}
|
| 4336 |
+
}
|
| 4337 |
+
cm.replaceRange(text.join('\n'), curStart, curEnd);
|
| 4338 |
+
},
|
| 4339 |
+
global: function(cm, params) {
|
| 4340 |
+
// a global command is of the form
|
| 4341 |
+
// :[range]g/pattern/[cmd]
|
| 4342 |
+
// argString holds the string /pattern/[cmd]
|
| 4343 |
+
var argString = params.argString;
|
| 4344 |
+
if (!argString) {
|
| 4345 |
+
showConfirm(cm, 'Regular Expression missing from global');
|
| 4346 |
+
return;
|
| 4347 |
+
}
|
| 4348 |
+
// range is specified here
|
| 4349 |
+
var lineStart = (params.line !== undefined) ? params.line : cm.firstLine();
|
| 4350 |
+
var lineEnd = params.lineEnd || params.line || cm.lastLine();
|
| 4351 |
+
// get the tokens from argString
|
| 4352 |
+
var tokens = splitBySlash(argString);
|
| 4353 |
+
var regexPart = argString, cmd;
|
| 4354 |
+
if (tokens.length) {
|
| 4355 |
+
regexPart = tokens[0];
|
| 4356 |
+
cmd = tokens.slice(1, tokens.length).join('/');
|
| 4357 |
+
}
|
| 4358 |
+
if (regexPart) {
|
| 4359 |
+
// If regex part is empty, then use the previous query. Otherwise
|
| 4360 |
+
// use the regex part as the new query.
|
| 4361 |
+
try {
|
| 4362 |
+
updateSearchQuery(cm, regexPart, true /** ignoreCase */,
|
| 4363 |
+
true /** smartCase */);
|
| 4364 |
+
} catch (e) {
|
| 4365 |
+
showConfirm(cm, 'Invalid regex: ' + regexPart);
|
| 4366 |
+
return;
|
| 4367 |
+
}
|
| 4368 |
+
}
|
| 4369 |
+
// now that we have the regexPart, search for regex matches in the
|
| 4370 |
+
// specified range of lines
|
| 4371 |
+
var query = getSearchState(cm).getQuery();
|
| 4372 |
+
var matchedLines = [], content = '';
|
| 4373 |
+
for (var i = lineStart; i <= lineEnd; i++) {
|
| 4374 |
+
var matched = query.test(cm.getLine(i));
|
| 4375 |
+
if (matched) {
|
| 4376 |
+
matchedLines.push(i+1);
|
| 4377 |
+
content+= cm.getLine(i) + '<br>';
|
| 4378 |
+
}
|
| 4379 |
+
}
|
| 4380 |
+
// if there is no [cmd], just display the list of matched lines
|
| 4381 |
+
if (!cmd) {
|
| 4382 |
+
showConfirm(cm, content);
|
| 4383 |
+
return;
|
| 4384 |
+
}
|
| 4385 |
+
var index = 0;
|
| 4386 |
+
var nextCommand = function() {
|
| 4387 |
+
if (index < matchedLines.length) {
|
| 4388 |
+
var command = matchedLines[index] + cmd;
|
| 4389 |
+
exCommandDispatcher.processCommand(cm, command, {
|
| 4390 |
+
callback: nextCommand
|
| 4391 |
+
});
|
| 4392 |
+
}
|
| 4393 |
+
index++;
|
| 4394 |
+
};
|
| 4395 |
+
nextCommand();
|
| 4396 |
+
},
|
| 4397 |
+
substitute: function(cm, params) {
|
| 4398 |
+
if (!cm.getSearchCursor) {
|
| 4399 |
+
throw new Error('Search feature not available. Requires searchcursor.js or ' +
|
| 4400 |
+
'any other getSearchCursor implementation.');
|
| 4401 |
+
}
|
| 4402 |
+
var argString = params.argString;
|
| 4403 |
+
var tokens = argString ? splitBySlash(argString) : [];
|
| 4404 |
+
var regexPart, replacePart = '', trailing, flagsPart, count;
|
| 4405 |
+
var confirm = false; // Whether to confirm each replace.
|
| 4406 |
+
var global = false; // True to replace all instances on a line, false to replace only 1.
|
| 4407 |
+
if (tokens.length) {
|
| 4408 |
+
regexPart = tokens[0];
|
| 4409 |
+
replacePart = tokens[1];
|
| 4410 |
+
if (replacePart !== undefined) {
|
| 4411 |
+
if (getOption('pcre')) {
|
| 4412 |
+
replacePart = unescapeRegexReplace(replacePart);
|
| 4413 |
+
} else {
|
| 4414 |
+
replacePart = translateRegexReplace(replacePart);
|
| 4415 |
+
}
|
| 4416 |
+
vimGlobalState.lastSubstituteReplacePart = replacePart;
|
| 4417 |
+
}
|
| 4418 |
+
trailing = tokens[2] ? tokens[2].split(' ') : [];
|
| 4419 |
+
} else {
|
| 4420 |
+
// either the argString is empty or its of the form ' hello/world'
|
| 4421 |
+
// actually splitBySlash returns a list of tokens
|
| 4422 |
+
// only if the string starts with a '/'
|
| 4423 |
+
if (argString && argString.length) {
|
| 4424 |
+
showConfirm(cm, 'Substitutions should be of the form ' +
|
| 4425 |
+
':s/pattern/replace/');
|
| 4426 |
+
return;
|
| 4427 |
+
}
|
| 4428 |
+
}
|
| 4429 |
+
// After the 3rd slash, we can have flags followed by a space followed
|
| 4430 |
+
// by count.
|
| 4431 |
+
if (trailing) {
|
| 4432 |
+
flagsPart = trailing[0];
|
| 4433 |
+
count = parseInt(trailing[1]);
|
| 4434 |
+
if (flagsPart) {
|
| 4435 |
+
if (flagsPart.indexOf('c') != -1) {
|
| 4436 |
+
confirm = true;
|
| 4437 |
+
flagsPart.replace('c', '');
|
| 4438 |
+
}
|
| 4439 |
+
if (flagsPart.indexOf('g') != -1) {
|
| 4440 |
+
global = true;
|
| 4441 |
+
flagsPart.replace('g', '');
|
| 4442 |
+
}
|
| 4443 |
+
regexPart = regexPart + '/' + flagsPart;
|
| 4444 |
+
}
|
| 4445 |
+
}
|
| 4446 |
+
if (regexPart) {
|
| 4447 |
+
// If regex part is empty, then use the previous query. Otherwise use
|
| 4448 |
+
// the regex part as the new query.
|
| 4449 |
+
try {
|
| 4450 |
+
updateSearchQuery(cm, regexPart, true /** ignoreCase */,
|
| 4451 |
+
true /** smartCase */);
|
| 4452 |
+
} catch (e) {
|
| 4453 |
+
showConfirm(cm, 'Invalid regex: ' + regexPart);
|
| 4454 |
+
return;
|
| 4455 |
+
}
|
| 4456 |
+
}
|
| 4457 |
+
replacePart = replacePart || vimGlobalState.lastSubstituteReplacePart;
|
| 4458 |
+
if (replacePart === undefined) {
|
| 4459 |
+
showConfirm(cm, 'No previous substitute regular expression');
|
| 4460 |
+
return;
|
| 4461 |
+
}
|
| 4462 |
+
var state = getSearchState(cm);
|
| 4463 |
+
var query = state.getQuery();
|
| 4464 |
+
var lineStart = (params.line !== undefined) ? params.line : cm.getCursor().line;
|
| 4465 |
+
var lineEnd = params.lineEnd || lineStart;
|
| 4466 |
+
if (count) {
|
| 4467 |
+
lineStart = lineEnd;
|
| 4468 |
+
lineEnd = lineStart + count - 1;
|
| 4469 |
+
}
|
| 4470 |
+
var startPos = clipCursorToContent(cm, Pos(lineStart, 0));
|
| 4471 |
+
var cursor = cm.getSearchCursor(query, startPos);
|
| 4472 |
+
doReplace(cm, confirm, global, lineStart, lineEnd, cursor, query, replacePart, params.callback);
|
| 4473 |
+
},
|
| 4474 |
+
redo: CodeMirror.commands.redo,
|
| 4475 |
+
undo: CodeMirror.commands.undo,
|
| 4476 |
+
write: function(cm) {
|
| 4477 |
+
if (CodeMirror.commands.save) {
|
| 4478 |
+
// If a save command is defined, call it.
|
| 4479 |
+
CodeMirror.commands.save(cm);
|
| 4480 |
+
} else {
|
| 4481 |
+
// Saves to text area if no save command is defined.
|
| 4482 |
+
cm.save();
|
| 4483 |
+
}
|
| 4484 |
+
},
|
| 4485 |
+
nohlsearch: function(cm) {
|
| 4486 |
+
clearSearchHighlight(cm);
|
| 4487 |
+
},
|
| 4488 |
+
delmarks: function(cm, params) {
|
| 4489 |
+
if (!params.argString || !trim(params.argString)) {
|
| 4490 |
+
showConfirm(cm, 'Argument required');
|
| 4491 |
+
return;
|
| 4492 |
+
}
|
| 4493 |
+
|
| 4494 |
+
var state = cm.state.vim;
|
| 4495 |
+
var stream = new CodeMirror.StringStream(trim(params.argString));
|
| 4496 |
+
while (!stream.eol()) {
|
| 4497 |
+
stream.eatSpace();
|
| 4498 |
+
|
| 4499 |
+
// Record the streams position at the beginning of the loop for use
|
| 4500 |
+
// in error messages.
|
| 4501 |
+
var count = stream.pos;
|
| 4502 |
+
|
| 4503 |
+
if (!stream.match(/[a-zA-Z]/, false)) {
|
| 4504 |
+
showConfirm(cm, 'Invalid argument: ' + params.argString.substring(count));
|
| 4505 |
+
return;
|
| 4506 |
+
}
|
| 4507 |
+
|
| 4508 |
+
var sym = stream.next();
|
| 4509 |
+
// Check if this symbol is part of a range
|
| 4510 |
+
if (stream.match('-', true)) {
|
| 4511 |
+
// This symbol is part of a range.
|
| 4512 |
+
|
| 4513 |
+
// The range must terminate at an alphabetic character.
|
| 4514 |
+
if (!stream.match(/[a-zA-Z]/, false)) {
|
| 4515 |
+
showConfirm(cm, 'Invalid argument: ' + params.argString.substring(count));
|
| 4516 |
+
return;
|
| 4517 |
+
}
|
| 4518 |
+
|
| 4519 |
+
var startMark = sym;
|
| 4520 |
+
var finishMark = stream.next();
|
| 4521 |
+
// The range must terminate at an alphabetic character which
|
| 4522 |
+
// shares the same case as the start of the range.
|
| 4523 |
+
if (isLowerCase(startMark) && isLowerCase(finishMark) ||
|
| 4524 |
+
isUpperCase(startMark) && isUpperCase(finishMark)) {
|
| 4525 |
+
var start = startMark.charCodeAt(0);
|
| 4526 |
+
var finish = finishMark.charCodeAt(0);
|
| 4527 |
+
if (start >= finish) {
|
| 4528 |
+
showConfirm(cm, 'Invalid argument: ' + params.argString.substring(count));
|
| 4529 |
+
return;
|
| 4530 |
+
}
|
| 4531 |
+
|
| 4532 |
+
// Because marks are always ASCII values, and we have
|
| 4533 |
+
// determined that they are the same case, we can use
|
| 4534 |
+
// their char codes to iterate through the defined range.
|
| 4535 |
+
for (var j = 0; j <= finish - start; j++) {
|
| 4536 |
+
var mark = String.fromCharCode(start + j);
|
| 4537 |
+
delete state.marks[mark];
|
| 4538 |
+
}
|
| 4539 |
+
} else {
|
| 4540 |
+
showConfirm(cm, 'Invalid argument: ' + startMark + '-');
|
| 4541 |
+
return;
|
| 4542 |
+
}
|
| 4543 |
+
} else {
|
| 4544 |
+
// This symbol is a valid mark, and is not part of a range.
|
| 4545 |
+
delete state.marks[sym];
|
| 4546 |
+
}
|
| 4547 |
+
}
|
| 4548 |
+
}
|
| 4549 |
+
};
|
| 4550 |
+
|
| 4551 |
+
var exCommandDispatcher = new ExCommandDispatcher();
|
| 4552 |
+
|
| 4553 |
+
/**
|
| 4554 |
+
* @param {CodeMirror} cm CodeMirror instance we are in.
|
| 4555 |
+
* @param {boolean} confirm Whether to confirm each replace.
|
| 4556 |
+
* @param {Cursor} lineStart Line to start replacing from.
|
| 4557 |
+
* @param {Cursor} lineEnd Line to stop replacing at.
|
| 4558 |
+
* @param {RegExp} query Query for performing matches with.
|
| 4559 |
+
* @param {string} replaceWith Text to replace matches with. May contain $1,
|
| 4560 |
+
* $2, etc for replacing captured groups using Javascript replace.
|
| 4561 |
+
* @param {function()} callback A callback for when the replace is done.
|
| 4562 |
+
*/
|
| 4563 |
+
function doReplace(cm, confirm, global, lineStart, lineEnd, searchCursor, query,
|
| 4564 |
+
replaceWith, callback) {
|
| 4565 |
+
// Set up all the functions.
|
| 4566 |
+
cm.state.vim.exMode = true;
|
| 4567 |
+
var done = false;
|
| 4568 |
+
var lastPos = searchCursor.from();
|
| 4569 |
+
function replaceAll() {
|
| 4570 |
+
cm.operation(function() {
|
| 4571 |
+
while (!done) {
|
| 4572 |
+
replace();
|
| 4573 |
+
next();
|
| 4574 |
+
}
|
| 4575 |
+
stop();
|
| 4576 |
+
});
|
| 4577 |
+
}
|
| 4578 |
+
function replace() {
|
| 4579 |
+
var text = cm.getRange(searchCursor.from(), searchCursor.to());
|
| 4580 |
+
var newText = text.replace(query, replaceWith);
|
| 4581 |
+
searchCursor.replace(newText);
|
| 4582 |
+
}
|
| 4583 |
+
function next() {
|
| 4584 |
+
// The below only loops to skip over multiple occurrences on the same
|
| 4585 |
+
// line when 'global' is not true.
|
| 4586 |
+
while(searchCursor.findNext() &&
|
| 4587 |
+
isInRange(searchCursor.from(), lineStart, lineEnd)) {
|
| 4588 |
+
if (!global && lastPos && searchCursor.from().line == lastPos.line) {
|
| 4589 |
+
continue;
|
| 4590 |
+
}
|
| 4591 |
+
cm.scrollIntoView(searchCursor.from(), 30);
|
| 4592 |
+
cm.setSelection(searchCursor.from(), searchCursor.to());
|
| 4593 |
+
lastPos = searchCursor.from();
|
| 4594 |
+
done = false;
|
| 4595 |
+
return;
|
| 4596 |
+
}
|
| 4597 |
+
done = true;
|
| 4598 |
+
}
|
| 4599 |
+
function stop(close) {
|
| 4600 |
+
if (close) { close(); }
|
| 4601 |
+
cm.focus();
|
| 4602 |
+
if (lastPos) {
|
| 4603 |
+
cm.setCursor(lastPos);
|
| 4604 |
+
var vim = cm.state.vim;
|
| 4605 |
+
vim.exMode = false;
|
| 4606 |
+
vim.lastHPos = vim.lastHSPos = lastPos.ch;
|
| 4607 |
+
}
|
| 4608 |
+
if (callback) { callback(); }
|
| 4609 |
+
}
|
| 4610 |
+
function onPromptKeyDown(e, _value, close) {
|
| 4611 |
+
// Swallow all keys.
|
| 4612 |
+
CodeMirror.e_stop(e);
|
| 4613 |
+
var keyName = CodeMirror.keyName(e);
|
| 4614 |
+
switch (keyName) {
|
| 4615 |
+
case 'Y':
|
| 4616 |
+
replace(); next(); break;
|
| 4617 |
+
case 'N':
|
| 4618 |
+
next(); break;
|
| 4619 |
+
case 'A':
|
| 4620 |
+
// replaceAll contains a call to close of its own. We don't want it
|
| 4621 |
+
// to fire too early or multiple times.
|
| 4622 |
+
var savedCallback = callback;
|
| 4623 |
+
callback = undefined;
|
| 4624 |
+
cm.operation(replaceAll);
|
| 4625 |
+
callback = savedCallback;
|
| 4626 |
+
break;
|
| 4627 |
+
case 'L':
|
| 4628 |
+
replace();
|
| 4629 |
+
// fall through and exit.
|
| 4630 |
+
case 'Q':
|
| 4631 |
+
case 'Esc':
|
| 4632 |
+
case 'Ctrl-C':
|
| 4633 |
+
case 'Ctrl-[':
|
| 4634 |
+
stop(close);
|
| 4635 |
+
break;
|
| 4636 |
+
}
|
| 4637 |
+
if (done) { stop(close); }
|
| 4638 |
+
return true;
|
| 4639 |
+
}
|
| 4640 |
+
|
| 4641 |
+
// Actually do replace.
|
| 4642 |
+
next();
|
| 4643 |
+
if (done) {
|
| 4644 |
+
showConfirm(cm, 'No matches for ' + query.source);
|
| 4645 |
+
return;
|
| 4646 |
+
}
|
| 4647 |
+
if (!confirm) {
|
| 4648 |
+
replaceAll();
|
| 4649 |
+
if (callback) { callback(); };
|
| 4650 |
+
return;
|
| 4651 |
+
}
|
| 4652 |
+
showPrompt(cm, {
|
| 4653 |
+
prefix: 'replace with <strong>' + replaceWith + '</strong> (y/n/a/q/l)',
|
| 4654 |
+
onKeyDown: onPromptKeyDown
|
| 4655 |
+
});
|
| 4656 |
+
}
|
| 4657 |
+
|
| 4658 |
+
CodeMirror.keyMap.vim = {
|
| 4659 |
+
attach: attachVimMap,
|
| 4660 |
+
detach: detachVimMap,
|
| 4661 |
+
call: cmKey
|
| 4662 |
+
};
|
| 4663 |
+
|
| 4664 |
+
function exitInsertMode(cm) {
|
| 4665 |
+
var vim = cm.state.vim;
|
| 4666 |
+
var macroModeState = vimGlobalState.macroModeState;
|
| 4667 |
+
var insertModeChangeRegister = vimGlobalState.registerController.getRegister('.');
|
| 4668 |
+
var isPlaying = macroModeState.isPlaying;
|
| 4669 |
+
var lastChange = macroModeState.lastInsertModeChanges;
|
| 4670 |
+
// In case of visual block, the insertModeChanges are not saved as a
|
| 4671 |
+
// single word, so we convert them to a single word
|
| 4672 |
+
// so as to update the ". register as expected in real vim.
|
| 4673 |
+
var text = [];
|
| 4674 |
+
if (!isPlaying) {
|
| 4675 |
+
var selLength = lastChange.inVisualBlock ? vim.lastSelection.visualBlock.height : 1;
|
| 4676 |
+
var changes = lastChange.changes;
|
| 4677 |
+
var text = [];
|
| 4678 |
+
var i = 0;
|
| 4679 |
+
// In case of multiple selections in blockwise visual,
|
| 4680 |
+
// the inserted text, for example: 'f<Backspace>oo', is stored as
|
| 4681 |
+
// 'f', 'f', InsertModeKey 'o', 'o', 'o', 'o'. (if you have a block with 2 lines).
|
| 4682 |
+
// We push the contents of the changes array as per the following:
|
| 4683 |
+
// 1. In case of InsertModeKey, just increment by 1.
|
| 4684 |
+
// 2. In case of a character, jump by selLength (2 in the example).
|
| 4685 |
+
while (i < changes.length) {
|
| 4686 |
+
// This loop will convert 'ff<bs>oooo' to 'f<bs>oo'.
|
| 4687 |
+
text.push(changes[i]);
|
| 4688 |
+
if (changes[i] instanceof InsertModeKey) {
|
| 4689 |
+
i++;
|
| 4690 |
+
} else {
|
| 4691 |
+
i+= selLength;
|
| 4692 |
+
}
|
| 4693 |
+
}
|
| 4694 |
+
lastChange.changes = text;
|
| 4695 |
+
cm.off('change', onChange);
|
| 4696 |
+
CodeMirror.off(cm.getInputField(), 'keydown', onKeyEventTargetKeyDown);
|
| 4697 |
+
}
|
| 4698 |
+
if (!isPlaying && vim.insertModeRepeat > 1) {
|
| 4699 |
+
// Perform insert mode repeat for commands like 3,a and 3,o.
|
| 4700 |
+
repeatLastEdit(cm, vim, vim.insertModeRepeat - 1,
|
| 4701 |
+
true /** repeatForInsert */);
|
| 4702 |
+
vim.lastEditInputState.repeatOverride = vim.insertModeRepeat;
|
| 4703 |
+
}
|
| 4704 |
+
delete vim.insertModeRepeat;
|
| 4705 |
+
vim.insertMode = false;
|
| 4706 |
+
cm.setCursor(cm.getCursor().line, cm.getCursor().ch-1);
|
| 4707 |
+
cm.setOption('keyMap', 'vim');
|
| 4708 |
+
cm.setOption('disableInput', true);
|
| 4709 |
+
cm.toggleOverwrite(false); // exit replace mode if we were in it.
|
| 4710 |
+
// update the ". register before exiting insert mode
|
| 4711 |
+
insertModeChangeRegister.setText(lastChange.changes.join(''));
|
| 4712 |
+
CodeMirror.signal(cm, "vim-mode-change", {mode: "normal"});
|
| 4713 |
+
if (macroModeState.isRecording) {
|
| 4714 |
+
logInsertModeChange(macroModeState);
|
| 4715 |
+
}
|
| 4716 |
+
}
|
| 4717 |
+
|
| 4718 |
+
function _mapCommand(command) {
|
| 4719 |
+
defaultKeymap.push(command);
|
| 4720 |
+
}
|
| 4721 |
+
|
| 4722 |
+
function mapCommand(keys, type, name, args, extra) {
|
| 4723 |
+
var command = {keys: keys, type: type};
|
| 4724 |
+
command[type] = name;
|
| 4725 |
+
command[type + "Args"] = args;
|
| 4726 |
+
for (var key in extra)
|
| 4727 |
+
command[key] = extra[key];
|
| 4728 |
+
_mapCommand(command);
|
| 4729 |
+
}
|
| 4730 |
+
|
| 4731 |
+
// The timeout in milliseconds for the two-character ESC keymap should be
|
| 4732 |
+
// adjusted according to your typing speed to prevent false positives.
|
| 4733 |
+
defineOption('insertModeEscKeysTimeout', 200, 'number');
|
| 4734 |
+
|
| 4735 |
+
CodeMirror.keyMap['vim-insert'] = {
|
| 4736 |
+
// TODO: override navigation keys so that Esc will cancel automatic
|
| 4737 |
+
// indentation from o, O, i_<CR>
|
| 4738 |
+
'Ctrl-N': 'autocomplete',
|
| 4739 |
+
'Ctrl-P': 'autocomplete',
|
| 4740 |
+
'Enter': function(cm) {
|
| 4741 |
+
var fn = CodeMirror.commands.newlineAndIndentContinueComment ||
|
| 4742 |
+
CodeMirror.commands.newlineAndIndent;
|
| 4743 |
+
fn(cm);
|
| 4744 |
+
},
|
| 4745 |
+
fallthrough: ['default'],
|
| 4746 |
+
attach: attachVimMap,
|
| 4747 |
+
detach: detachVimMap,
|
| 4748 |
+
call: cmKey
|
| 4749 |
+
};
|
| 4750 |
+
|
| 4751 |
+
CodeMirror.keyMap['vim-replace'] = {
|
| 4752 |
+
'Backspace': 'goCharLeft',
|
| 4753 |
+
fallthrough: ['vim-insert'],
|
| 4754 |
+
attach: attachVimMap,
|
| 4755 |
+
detach: detachVimMap,
|
| 4756 |
+
call: cmKey
|
| 4757 |
+
};
|
| 4758 |
+
|
| 4759 |
+
function executeMacroRegister(cm, vim, macroModeState, registerName) {
|
| 4760 |
+
var register = vimGlobalState.registerController.getRegister(registerName);
|
| 4761 |
+
if (registerName == ':') {
|
| 4762 |
+
// Read-only register containing last Ex command.
|
| 4763 |
+
if (register.keyBuffer[0]) {
|
| 4764 |
+
exCommandDispatcher.processCommand(cm, register.keyBuffer[0]);
|
| 4765 |
+
}
|
| 4766 |
+
macroModeState.isPlaying = false;
|
| 4767 |
+
return;
|
| 4768 |
+
}
|
| 4769 |
+
var keyBuffer = register.keyBuffer;
|
| 4770 |
+
var imc = 0;
|
| 4771 |
+
macroModeState.isPlaying = true;
|
| 4772 |
+
macroModeState.replaySearchQueries = register.searchQueries.slice(0);
|
| 4773 |
+
for (var i = 0; i < keyBuffer.length; i++) {
|
| 4774 |
+
var text = keyBuffer[i];
|
| 4775 |
+
var match, key;
|
| 4776 |
+
while (text) {
|
| 4777 |
+
// Pull off one command key, which is either a single character
|
| 4778 |
+
// or a special sequence wrapped in '<' and '>', e.g. '<Space>'.
|
| 4779 |
+
match = (/<\w+-.+?>|<\w+>|./).exec(text);
|
| 4780 |
+
key = match[0];
|
| 4781 |
+
text = text.substring(match.index + key.length);
|
| 4782 |
+
CodeMirror.Vim.handleKey(cm, key, 'macro');
|
| 4783 |
+
if (vim.insertMode) {
|
| 4784 |
+
var changes = register.insertModeChanges[imc++].changes;
|
| 4785 |
+
vimGlobalState.macroModeState.lastInsertModeChanges.changes =
|
| 4786 |
+
changes;
|
| 4787 |
+
repeatInsertModeChanges(cm, changes, 1);
|
| 4788 |
+
exitInsertMode(cm);
|
| 4789 |
+
}
|
| 4790 |
+
}
|
| 4791 |
+
};
|
| 4792 |
+
macroModeState.isPlaying = false;
|
| 4793 |
+
}
|
| 4794 |
+
|
| 4795 |
+
function logKey(macroModeState, key) {
|
| 4796 |
+
if (macroModeState.isPlaying) { return; }
|
| 4797 |
+
var registerName = macroModeState.latestRegister;
|
| 4798 |
+
var register = vimGlobalState.registerController.getRegister(registerName);
|
| 4799 |
+
if (register) {
|
| 4800 |
+
register.pushText(key);
|
| 4801 |
+
}
|
| 4802 |
+
}
|
| 4803 |
+
|
| 4804 |
+
function logInsertModeChange(macroModeState) {
|
| 4805 |
+
if (macroModeState.isPlaying) { return; }
|
| 4806 |
+
var registerName = macroModeState.latestRegister;
|
| 4807 |
+
var register = vimGlobalState.registerController.getRegister(registerName);
|
| 4808 |
+
if (register) {
|
| 4809 |
+
register.pushInsertModeChanges(macroModeState.lastInsertModeChanges);
|
| 4810 |
+
}
|
| 4811 |
+
}
|
| 4812 |
+
|
| 4813 |
+
function logSearchQuery(macroModeState, query) {
|
| 4814 |
+
if (macroModeState.isPlaying) { return; }
|
| 4815 |
+
var registerName = macroModeState.latestRegister;
|
| 4816 |
+
var register = vimGlobalState.registerController.getRegister(registerName);
|
| 4817 |
+
if (register) {
|
| 4818 |
+
register.pushSearchQuery(query);
|
| 4819 |
+
}
|
| 4820 |
+
}
|
| 4821 |
+
|
| 4822 |
+
/**
|
| 4823 |
+
* Listens for changes made in insert mode.
|
| 4824 |
+
* Should only be active in insert mode.
|
| 4825 |
+
*/
|
| 4826 |
+
function onChange(_cm, changeObj) {
|
| 4827 |
+
var macroModeState = vimGlobalState.macroModeState;
|
| 4828 |
+
var lastChange = macroModeState.lastInsertModeChanges;
|
| 4829 |
+
if (!macroModeState.isPlaying) {
|
| 4830 |
+
while(changeObj) {
|
| 4831 |
+
lastChange.expectCursorActivityForChange = true;
|
| 4832 |
+
if (changeObj.origin == '+input' || changeObj.origin == 'paste'
|
| 4833 |
+
|| changeObj.origin === undefined /* only in testing */) {
|
| 4834 |
+
var text = changeObj.text.join('\n');
|
| 4835 |
+
lastChange.changes.push(text);
|
| 4836 |
+
}
|
| 4837 |
+
// Change objects may be chained with next.
|
| 4838 |
+
changeObj = changeObj.next;
|
| 4839 |
+
}
|
| 4840 |
+
}
|
| 4841 |
+
}
|
| 4842 |
+
|
| 4843 |
+
/**
|
| 4844 |
+
* Listens for any kind of cursor activity on CodeMirror.
|
| 4845 |
+
*/
|
| 4846 |
+
function onCursorActivity(cm) {
|
| 4847 |
+
var vim = cm.state.vim;
|
| 4848 |
+
if (vim.insertMode) {
|
| 4849 |
+
// Tracking cursor activity in insert mode (for macro support).
|
| 4850 |
+
var macroModeState = vimGlobalState.macroModeState;
|
| 4851 |
+
if (macroModeState.isPlaying) { return; }
|
| 4852 |
+
var lastChange = macroModeState.lastInsertModeChanges;
|
| 4853 |
+
if (lastChange.expectCursorActivityForChange) {
|
| 4854 |
+
lastChange.expectCursorActivityForChange = false;
|
| 4855 |
+
} else {
|
| 4856 |
+
// Cursor moved outside the context of an edit. Reset the change.
|
| 4857 |
+
lastChange.changes = [];
|
| 4858 |
+
}
|
| 4859 |
+
} else if (!cm.curOp.isVimOp) {
|
| 4860 |
+
handleExternalSelection(cm, vim);
|
| 4861 |
+
}
|
| 4862 |
+
if (vim.visualMode) {
|
| 4863 |
+
updateFakeCursor(cm);
|
| 4864 |
+
}
|
| 4865 |
+
}
|
| 4866 |
+
function updateFakeCursor(cm) {
|
| 4867 |
+
var vim = cm.state.vim;
|
| 4868 |
+
var from = clipCursorToContent(cm, copyCursor(vim.sel.head));
|
| 4869 |
+
var to = offsetCursor(from, 0, 1);
|
| 4870 |
+
if (vim.fakeCursor) {
|
| 4871 |
+
vim.fakeCursor.clear();
|
| 4872 |
+
}
|
| 4873 |
+
vim.fakeCursor = cm.markText(from, to, {className: 'cm-animate-fat-cursor'});
|
| 4874 |
+
}
|
| 4875 |
+
function handleExternalSelection(cm, vim) {
|
| 4876 |
+
var anchor = cm.getCursor('anchor');
|
| 4877 |
+
var head = cm.getCursor('head');
|
| 4878 |
+
// Enter or exit visual mode to match mouse selection.
|
| 4879 |
+
if (vim.visualMode && !cm.somethingSelected()) {
|
| 4880 |
+
exitVisualMode(cm, false);
|
| 4881 |
+
} else if (!vim.visualMode && !vim.insertMode && cm.somethingSelected()) {
|
| 4882 |
+
vim.visualMode = true;
|
| 4883 |
+
vim.visualLine = false;
|
| 4884 |
+
CodeMirror.signal(cm, "vim-mode-change", {mode: "visual"});
|
| 4885 |
+
}
|
| 4886 |
+
if (vim.visualMode) {
|
| 4887 |
+
// Bind CodeMirror selection model to vim selection model.
|
| 4888 |
+
// Mouse selections are considered visual characterwise.
|
| 4889 |
+
var headOffset = !cursorIsBefore(head, anchor) ? -1 : 0;
|
| 4890 |
+
var anchorOffset = cursorIsBefore(head, anchor) ? -1 : 0;
|
| 4891 |
+
head = offsetCursor(head, 0, headOffset);
|
| 4892 |
+
anchor = offsetCursor(anchor, 0, anchorOffset);
|
| 4893 |
+
vim.sel = {
|
| 4894 |
+
anchor: anchor,
|
| 4895 |
+
head: head
|
| 4896 |
+
};
|
| 4897 |
+
updateMark(cm, vim, '<', cursorMin(head, anchor));
|
| 4898 |
+
updateMark(cm, vim, '>', cursorMax(head, anchor));
|
| 4899 |
+
} else if (!vim.insertMode) {
|
| 4900 |
+
// Reset lastHPos if selection was modified by something outside of vim mode e.g. by mouse.
|
| 4901 |
+
vim.lastHPos = cm.getCursor().ch;
|
| 4902 |
+
}
|
| 4903 |
+
}
|
| 4904 |
+
|
| 4905 |
+
/** Wrapper for special keys pressed in insert mode */
|
| 4906 |
+
function InsertModeKey(keyName) {
|
| 4907 |
+
this.keyName = keyName;
|
| 4908 |
+
}
|
| 4909 |
+
|
| 4910 |
+
/**
|
| 4911 |
+
* Handles raw key down events from the text area.
|
| 4912 |
+
* - Should only be active in insert mode.
|
| 4913 |
+
* - For recording deletes in insert mode.
|
| 4914 |
+
*/
|
| 4915 |
+
function onKeyEventTargetKeyDown(e) {
|
| 4916 |
+
var macroModeState = vimGlobalState.macroModeState;
|
| 4917 |
+
var lastChange = macroModeState.lastInsertModeChanges;
|
| 4918 |
+
var keyName = CodeMirror.keyName(e);
|
| 4919 |
+
if (!keyName) { return; }
|
| 4920 |
+
function onKeyFound() {
|
| 4921 |
+
lastChange.changes.push(new InsertModeKey(keyName));
|
| 4922 |
+
return true;
|
| 4923 |
+
}
|
| 4924 |
+
if (keyName.indexOf('Delete') != -1 || keyName.indexOf('Backspace') != -1) {
|
| 4925 |
+
CodeMirror.lookupKey(keyName, 'vim-insert', onKeyFound);
|
| 4926 |
+
}
|
| 4927 |
+
}
|
| 4928 |
+
|
| 4929 |
+
/**
|
| 4930 |
+
* Repeats the last edit, which includes exactly 1 command and at most 1
|
| 4931 |
+
* insert. Operator and motion commands are read from lastEditInputState,
|
| 4932 |
+
* while action commands are read from lastEditActionCommand.
|
| 4933 |
+
*
|
| 4934 |
+
* If repeatForInsert is true, then the function was called by
|
| 4935 |
+
* exitInsertMode to repeat the insert mode changes the user just made. The
|
| 4936 |
+
* corresponding enterInsertMode call was made with a count.
|
| 4937 |
+
*/
|
| 4938 |
+
function repeatLastEdit(cm, vim, repeat, repeatForInsert) {
|
| 4939 |
+
var macroModeState = vimGlobalState.macroModeState;
|
| 4940 |
+
macroModeState.isPlaying = true;
|
| 4941 |
+
var isAction = !!vim.lastEditActionCommand;
|
| 4942 |
+
var cachedInputState = vim.inputState;
|
| 4943 |
+
function repeatCommand() {
|
| 4944 |
+
if (isAction) {
|
| 4945 |
+
commandDispatcher.processAction(cm, vim, vim.lastEditActionCommand);
|
| 4946 |
+
} else {
|
| 4947 |
+
commandDispatcher.evalInput(cm, vim);
|
| 4948 |
+
}
|
| 4949 |
+
}
|
| 4950 |
+
function repeatInsert(repeat) {
|
| 4951 |
+
if (macroModeState.lastInsertModeChanges.changes.length > 0) {
|
| 4952 |
+
// For some reason, repeat cw in desktop VIM does not repeat
|
| 4953 |
+
// insert mode changes. Will conform to that behavior.
|
| 4954 |
+
repeat = !vim.lastEditActionCommand ? 1 : repeat;
|
| 4955 |
+
var changeObject = macroModeState.lastInsertModeChanges;
|
| 4956 |
+
repeatInsertModeChanges(cm, changeObject.changes, repeat);
|
| 4957 |
+
}
|
| 4958 |
+
}
|
| 4959 |
+
vim.inputState = vim.lastEditInputState;
|
| 4960 |
+
if (isAction && vim.lastEditActionCommand.interlaceInsertRepeat) {
|
| 4961 |
+
// o and O repeat have to be interlaced with insert repeats so that the
|
| 4962 |
+
// insertions appear on separate lines instead of the last line.
|
| 4963 |
+
for (var i = 0; i < repeat; i++) {
|
| 4964 |
+
repeatCommand();
|
| 4965 |
+
repeatInsert(1);
|
| 4966 |
+
}
|
| 4967 |
+
} else {
|
| 4968 |
+
if (!repeatForInsert) {
|
| 4969 |
+
// Hack to get the cursor to end up at the right place. If I is
|
| 4970 |
+
// repeated in insert mode repeat, cursor will be 1 insert
|
| 4971 |
+
// change set left of where it should be.
|
| 4972 |
+
repeatCommand();
|
| 4973 |
+
}
|
| 4974 |
+
repeatInsert(repeat);
|
| 4975 |
+
}
|
| 4976 |
+
vim.inputState = cachedInputState;
|
| 4977 |
+
if (vim.insertMode && !repeatForInsert) {
|
| 4978 |
+
// Don't exit insert mode twice. If repeatForInsert is set, then we
|
| 4979 |
+
// were called by an exitInsertMode call lower on the stack.
|
| 4980 |
+
exitInsertMode(cm);
|
| 4981 |
+
}
|
| 4982 |
+
macroModeState.isPlaying = false;
|
| 4983 |
+
};
|
| 4984 |
+
|
| 4985 |
+
function repeatInsertModeChanges(cm, changes, repeat) {
|
| 4986 |
+
function keyHandler(binding) {
|
| 4987 |
+
if (typeof binding == 'string') {
|
| 4988 |
+
CodeMirror.commands[binding](cm);
|
| 4989 |
+
} else {
|
| 4990 |
+
binding(cm);
|
| 4991 |
+
}
|
| 4992 |
+
return true;
|
| 4993 |
+
}
|
| 4994 |
+
var head = cm.getCursor('head');
|
| 4995 |
+
var inVisualBlock = vimGlobalState.macroModeState.lastInsertModeChanges.inVisualBlock;
|
| 4996 |
+
if (inVisualBlock) {
|
| 4997 |
+
// Set up block selection again for repeating the changes.
|
| 4998 |
+
var vim = cm.state.vim;
|
| 4999 |
+
var lastSel = vim.lastSelection;
|
| 5000 |
+
var offset = getOffset(lastSel.anchor, lastSel.head);
|
| 5001 |
+
selectForInsert(cm, head, offset.line + 1);
|
| 5002 |
+
repeat = cm.listSelections().length;
|
| 5003 |
+
cm.setCursor(head);
|
| 5004 |
+
}
|
| 5005 |
+
for (var i = 0; i < repeat; i++) {
|
| 5006 |
+
if (inVisualBlock) {
|
| 5007 |
+
cm.setCursor(offsetCursor(head, i, 0));
|
| 5008 |
+
}
|
| 5009 |
+
for (var j = 0; j < changes.length; j++) {
|
| 5010 |
+
var change = changes[j];
|
| 5011 |
+
if (change instanceof InsertModeKey) {
|
| 5012 |
+
CodeMirror.lookupKey(change.keyName, 'vim-insert', keyHandler);
|
| 5013 |
+
} else {
|
| 5014 |
+
var cur = cm.getCursor();
|
| 5015 |
+
cm.replaceRange(change, cur, cur);
|
| 5016 |
+
}
|
| 5017 |
+
}
|
| 5018 |
+
}
|
| 5019 |
+
if (inVisualBlock) {
|
| 5020 |
+
cm.setCursor(offsetCursor(head, 0, 1));
|
| 5021 |
+
}
|
| 5022 |
+
}
|
| 5023 |
+
|
| 5024 |
+
resetVimGlobalState();
|
| 5025 |
+
return vimApi;
|
| 5026 |
+
};
|
| 5027 |
+
// Initialize Vim and make it available as an API.
|
| 5028 |
+
CodeMirror.Vim = Vim();
|
| 5029 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/lib/codemirror.css
ADDED
|
@@ -0,0 +1,325 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* BASICS */
|
| 2 |
+
|
| 3 |
+
.CodeMirror {
|
| 4 |
+
/* Set height, width, borders, and global font properties here */
|
| 5 |
+
font-family: monospace;
|
| 6 |
+
height: 300px;
|
| 7 |
+
color: black;
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
/* PADDING */
|
| 11 |
+
|
| 12 |
+
.CodeMirror-lines {
|
| 13 |
+
padding: 4px 0; /* Vertical padding around content */
|
| 14 |
+
}
|
| 15 |
+
.CodeMirror pre {
|
| 16 |
+
padding: 0 4px; /* Horizontal padding of content */
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
.CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
|
| 20 |
+
background-color: white; /* The little square between H and V scrollbars */
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
/* GUTTER */
|
| 24 |
+
|
| 25 |
+
.CodeMirror-gutters {
|
| 26 |
+
border-right: 1px solid #ddd;
|
| 27 |
+
background-color: #f7f7f7;
|
| 28 |
+
white-space: nowrap;
|
| 29 |
+
}
|
| 30 |
+
.CodeMirror-linenumbers {}
|
| 31 |
+
.CodeMirror-linenumber {
|
| 32 |
+
padding: 0 3px 0 5px;
|
| 33 |
+
min-width: 20px;
|
| 34 |
+
text-align: right;
|
| 35 |
+
color: #999;
|
| 36 |
+
white-space: nowrap;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
.CodeMirror-guttermarker { color: black; }
|
| 40 |
+
.CodeMirror-guttermarker-subtle { color: #999; }
|
| 41 |
+
|
| 42 |
+
/* CURSOR */
|
| 43 |
+
|
| 44 |
+
.CodeMirror div.CodeMirror-cursor {
|
| 45 |
+
border-left: 1px solid black;
|
| 46 |
+
}
|
| 47 |
+
/* Shown when moving in bi-directional text */
|
| 48 |
+
.CodeMirror div.CodeMirror-secondarycursor {
|
| 49 |
+
border-left: 1px solid silver;
|
| 50 |
+
}
|
| 51 |
+
.CodeMirror.cm-fat-cursor div.CodeMirror-cursor {
|
| 52 |
+
width: auto;
|
| 53 |
+
border: 0;
|
| 54 |
+
background: #7e7;
|
| 55 |
+
}
|
| 56 |
+
.CodeMirror.cm-fat-cursor div.CodeMirror-cursors {
|
| 57 |
+
z-index: 1;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
.cm-animate-fat-cursor {
|
| 61 |
+
width: auto;
|
| 62 |
+
border: 0;
|
| 63 |
+
-webkit-animation: blink 1.06s steps(1) infinite;
|
| 64 |
+
-moz-animation: blink 1.06s steps(1) infinite;
|
| 65 |
+
animation: blink 1.06s steps(1) infinite;
|
| 66 |
+
}
|
| 67 |
+
@-moz-keyframes blink {
|
| 68 |
+
0% { background: #7e7; }
|
| 69 |
+
50% { background: none; }
|
| 70 |
+
100% { background: #7e7; }
|
| 71 |
+
}
|
| 72 |
+
@-webkit-keyframes blink {
|
| 73 |
+
0% { background: #7e7; }
|
| 74 |
+
50% { background: none; }
|
| 75 |
+
100% { background: #7e7; }
|
| 76 |
+
}
|
| 77 |
+
@keyframes blink {
|
| 78 |
+
0% { background: #7e7; }
|
| 79 |
+
50% { background: none; }
|
| 80 |
+
100% { background: #7e7; }
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
/* Can style cursor different in overwrite (non-insert) mode */
|
| 84 |
+
div.CodeMirror-overwrite div.CodeMirror-cursor {}
|
| 85 |
+
|
| 86 |
+
.cm-tab { display: inline-block; text-decoration: inherit; }
|
| 87 |
+
|
| 88 |
+
.CodeMirror-ruler {
|
| 89 |
+
border-left: 1px solid #ccc;
|
| 90 |
+
position: absolute;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
/* DEFAULT THEME */
|
| 94 |
+
|
| 95 |
+
.cm-s-default .cm-keyword {color: #708;}
|
| 96 |
+
.cm-s-default .cm-atom {color: #219;}
|
| 97 |
+
.cm-s-default .cm-number {color: #164;}
|
| 98 |
+
.cm-s-default .cm-def {color: #00f;}
|
| 99 |
+
.cm-s-default .cm-variable,
|
| 100 |
+
.cm-s-default .cm-punctuation,
|
| 101 |
+
.cm-s-default .cm-property,
|
| 102 |
+
.cm-s-default .cm-operator {}
|
| 103 |
+
.cm-s-default .cm-variable-2 {color: #05a;}
|
| 104 |
+
.cm-s-default .cm-variable-3 {color: #085;}
|
| 105 |
+
.cm-s-default .cm-comment {color: #a50;}
|
| 106 |
+
.cm-s-default .cm-string {color: #a11;}
|
| 107 |
+
.cm-s-default .cm-string-2 {color: #f50;}
|
| 108 |
+
.cm-s-default .cm-meta {color: #555;}
|
| 109 |
+
.cm-s-default .cm-qualifier {color: #555;}
|
| 110 |
+
.cm-s-default .cm-builtin {color: #30a;}
|
| 111 |
+
.cm-s-default .cm-bracket {color: #997;}
|
| 112 |
+
.cm-s-default .cm-tag {color: #170;}
|
| 113 |
+
.cm-s-default .cm-attribute {color: #00c;}
|
| 114 |
+
.cm-s-default .cm-header {color: blue;}
|
| 115 |
+
.cm-s-default .cm-quote {color: #090;}
|
| 116 |
+
.cm-s-default .cm-hr {color: #999;}
|
| 117 |
+
.cm-s-default .cm-link {color: #00c;}
|
| 118 |
+
|
| 119 |
+
.cm-negative {color: #d44;}
|
| 120 |
+
.cm-positive {color: #292;}
|
| 121 |
+
.cm-header, .cm-strong {font-weight: bold;}
|
| 122 |
+
.cm-em {font-style: italic;}
|
| 123 |
+
.cm-link {text-decoration: underline;}
|
| 124 |
+
.cm-strikethrough {text-decoration: line-through;}
|
| 125 |
+
|
| 126 |
+
.cm-s-default .cm-error {color: #f00;}
|
| 127 |
+
.cm-invalidchar {color: #f00;}
|
| 128 |
+
|
| 129 |
+
.CodeMirror-composing { border-bottom: 2px solid; }
|
| 130 |
+
|
| 131 |
+
/* Default styles for common addons */
|
| 132 |
+
|
| 133 |
+
div.CodeMirror span.CodeMirror-matchingbracket {color: #0f0;}
|
| 134 |
+
div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
|
| 135 |
+
.CodeMirror-matchingtag { background: rgba(255, 150, 0, .3); }
|
| 136 |
+
.CodeMirror-activeline-background {background: #e8f2ff;}
|
| 137 |
+
|
| 138 |
+
/* STOP */
|
| 139 |
+
|
| 140 |
+
/* The rest of this file contains styles related to the mechanics of
|
| 141 |
+
the editor. You probably shouldn't touch them. */
|
| 142 |
+
|
| 143 |
+
.CodeMirror {
|
| 144 |
+
position: relative;
|
| 145 |
+
overflow: hidden;
|
| 146 |
+
background: white;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
.CodeMirror-scroll {
|
| 150 |
+
overflow: scroll !important; /* Things will break if this is overridden */
|
| 151 |
+
/* 30px is the magic margin used to hide the element's real scrollbars */
|
| 152 |
+
/* See overflow: hidden in .CodeMirror */
|
| 153 |
+
margin-bottom: -30px; margin-right: -30px;
|
| 154 |
+
padding-bottom: 30px;
|
| 155 |
+
height: 100%;
|
| 156 |
+
outline: none; /* Prevent dragging from highlighting the element */
|
| 157 |
+
position: relative;
|
| 158 |
+
}
|
| 159 |
+
.CodeMirror-sizer {
|
| 160 |
+
position: relative;
|
| 161 |
+
border-right: 30px solid transparent;
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
/* The fake, visible scrollbars. Used to force redraw during scrolling
|
| 165 |
+
before actuall scrolling happens, thus preventing shaking and
|
| 166 |
+
flickering artifacts. */
|
| 167 |
+
.CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
|
| 168 |
+
position: absolute;
|
| 169 |
+
z-index: 6;
|
| 170 |
+
display: none;
|
| 171 |
+
}
|
| 172 |
+
.CodeMirror-vscrollbar {
|
| 173 |
+
right: 0; top: 0;
|
| 174 |
+
overflow-x: hidden;
|
| 175 |
+
overflow-y: scroll;
|
| 176 |
+
}
|
| 177 |
+
.CodeMirror-hscrollbar {
|
| 178 |
+
bottom: 0; left: 0;
|
| 179 |
+
overflow-y: hidden;
|
| 180 |
+
overflow-x: scroll;
|
| 181 |
+
}
|
| 182 |
+
.CodeMirror-scrollbar-filler {
|
| 183 |
+
right: 0; bottom: 0;
|
| 184 |
+
}
|
| 185 |
+
.CodeMirror-gutter-filler {
|
| 186 |
+
left: 0; bottom: 0;
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
.CodeMirror-gutters {
|
| 190 |
+
position: absolute; left: 0; top: 0;
|
| 191 |
+
z-index: 3;
|
| 192 |
+
}
|
| 193 |
+
.CodeMirror-gutter {
|
| 194 |
+
white-space: normal;
|
| 195 |
+
height: 100%;
|
| 196 |
+
display: inline-block;
|
| 197 |
+
margin-bottom: -30px;
|
| 198 |
+
/* Hack to make IE7 behave */
|
| 199 |
+
*zoom:1;
|
| 200 |
+
*display:inline;
|
| 201 |
+
}
|
| 202 |
+
.CodeMirror-gutter-wrapper {
|
| 203 |
+
position: absolute;
|
| 204 |
+
z-index: 4;
|
| 205 |
+
height: 100%;
|
| 206 |
+
}
|
| 207 |
+
.CodeMirror-gutter-elt {
|
| 208 |
+
position: absolute;
|
| 209 |
+
cursor: default;
|
| 210 |
+
z-index: 4;
|
| 211 |
+
}
|
| 212 |
+
.CodeMirror-gutter-wrapper {
|
| 213 |
+
-webkit-user-select: none;
|
| 214 |
+
-moz-user-select: none;
|
| 215 |
+
user-select: none;
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
.CodeMirror-lines {
|
| 219 |
+
cursor: text;
|
| 220 |
+
min-height: 1px; /* prevents collapsing before first draw */
|
| 221 |
+
}
|
| 222 |
+
.CodeMirror pre {
|
| 223 |
+
/* Reset some styles that the rest of the page might have set */
|
| 224 |
+
-moz-border-radius: 0; -webkit-border-radius: 0; border-radius: 0;
|
| 225 |
+
border-width: 0;
|
| 226 |
+
background: transparent;
|
| 227 |
+
font-family: inherit;
|
| 228 |
+
font-size: inherit;
|
| 229 |
+
margin: 0;
|
| 230 |
+
white-space: pre;
|
| 231 |
+
word-wrap: normal;
|
| 232 |
+
line-height: inherit;
|
| 233 |
+
color: inherit;
|
| 234 |
+
z-index: 2;
|
| 235 |
+
position: relative;
|
| 236 |
+
overflow: visible;
|
| 237 |
+
-webkit-tap-highlight-color: transparent;
|
| 238 |
+
}
|
| 239 |
+
.CodeMirror-wrap pre {
|
| 240 |
+
word-wrap: break-word;
|
| 241 |
+
white-space: pre-wrap;
|
| 242 |
+
word-break: normal;
|
| 243 |
+
}
|
| 244 |
+
|
| 245 |
+
.CodeMirror-linebackground {
|
| 246 |
+
position: absolute;
|
| 247 |
+
left: 0; right: 0; top: 0; bottom: 0;
|
| 248 |
+
z-index: 0;
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
.CodeMirror-linewidget {
|
| 252 |
+
position: relative;
|
| 253 |
+
z-index: 2;
|
| 254 |
+
overflow: auto;
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
.CodeMirror-widget {}
|
| 258 |
+
|
| 259 |
+
.CodeMirror-code {
|
| 260 |
+
outline: none;
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
/* Force content-box sizing for the elements where we expect it */
|
| 264 |
+
.CodeMirror-scroll,
|
| 265 |
+
.CodeMirror-sizer,
|
| 266 |
+
.CodeMirror-gutter,
|
| 267 |
+
.CodeMirror-gutters,
|
| 268 |
+
.CodeMirror-linenumber {
|
| 269 |
+
-moz-box-sizing: content-box;
|
| 270 |
+
box-sizing: content-box;
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
.CodeMirror-measure {
|
| 274 |
+
position: absolute;
|
| 275 |
+
width: 100%;
|
| 276 |
+
height: 0;
|
| 277 |
+
overflow: hidden;
|
| 278 |
+
visibility: hidden;
|
| 279 |
+
}
|
| 280 |
+
.CodeMirror-measure pre { position: static; }
|
| 281 |
+
|
| 282 |
+
.CodeMirror div.CodeMirror-cursor {
|
| 283 |
+
position: absolute;
|
| 284 |
+
border-right: none;
|
| 285 |
+
width: 0;
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
div.CodeMirror-cursors {
|
| 289 |
+
visibility: hidden;
|
| 290 |
+
position: relative;
|
| 291 |
+
z-index: 3;
|
| 292 |
+
}
|
| 293 |
+
.CodeMirror-focused div.CodeMirror-cursors {
|
| 294 |
+
visibility: visible;
|
| 295 |
+
}
|
| 296 |
+
|
| 297 |
+
.CodeMirror-selected { background: #d9d9d9; }
|
| 298 |
+
.CodeMirror-focused .CodeMirror-selected { background: #d7d4f0; }
|
| 299 |
+
.CodeMirror-crosshair { cursor: crosshair; }
|
| 300 |
+
.CodeMirror ::selection { background: #d7d4f0; }
|
| 301 |
+
.CodeMirror ::-moz-selection { background: #d7d4f0; }
|
| 302 |
+
|
| 303 |
+
.cm-searching {
|
| 304 |
+
background: #ffa;
|
| 305 |
+
background: rgba(255, 255, 0, .4);
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
/* IE7 hack to prevent it from returning funny offsetTops on the spans */
|
| 309 |
+
.CodeMirror span { *vertical-align: text-bottom; }
|
| 310 |
+
|
| 311 |
+
/* Used to force a border model for a node */
|
| 312 |
+
.cm-force-border { padding-right: .1px; }
|
| 313 |
+
|
| 314 |
+
@media print {
|
| 315 |
+
/* Hide the cursor when printing */
|
| 316 |
+
.CodeMirror div.CodeMirror-cursors {
|
| 317 |
+
visibility: hidden;
|
| 318 |
+
}
|
| 319 |
+
}
|
| 320 |
+
|
| 321 |
+
/* See issue #2901 */
|
| 322 |
+
.cm-tab-wrap-hack:after { content: ''; }
|
| 323 |
+
|
| 324 |
+
/* Help users use markselection to safely style text background */
|
| 325 |
+
span.CodeMirror-selectedtext { background: none; }
|
js/tiny_mce/plugins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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
// This is CodeMirror (http://codemirror.net), a code editor
|
| 5 |
+
// implemented in JavaScript on top of the browser's DOM.
|
| 6 |
+
//
|
| 7 |
+
// You can find some technical background for some of the code below
|
| 8 |
+
// at http://marijnhaverbeke.nl/blog/#cm-internals .
|
| 9 |
+
|
| 10 |
+
(function(mod) {
|
| 11 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 12 |
+
module.exports = mod();
|
| 13 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 14 |
+
return define([], mod);
|
| 15 |
+
else // Plain browser env
|
| 16 |
+
this.CodeMirror = mod();
|
| 17 |
+
})(function() {
|
| 18 |
+
"use strict";
|
| 19 |
+
|
| 20 |
+
// BROWSER SNIFFING
|
| 21 |
+
|
| 22 |
+
// Kludges for bugs and behavior differences that can't be feature
|
| 23 |
+
// detected are enabled based on userAgent etc sniffing.
|
| 24 |
+
|
| 25 |
+
var gecko = /gecko\/\d/i.test(navigator.userAgent);
|
| 26 |
+
var ie_upto10 = /MSIE \d/.test(navigator.userAgent);
|
| 27 |
+
var ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);
|
| 28 |
+
var ie = ie_upto10 || ie_11up;
|
| 29 |
+
var ie_version = ie && (ie_upto10 ? document.documentMode || 6 : ie_11up[1]);
|
| 30 |
+
var webkit = /WebKit\//.test(navigator.userAgent);
|
| 31 |
+
var qtwebkit = webkit && /Qt\/\d+\.\d+/.test(navigator.userAgent);
|
| 32 |
+
var chrome = /Chrome\//.test(navigator.userAgent);
|
| 33 |
+
var presto = /Opera\//.test(navigator.userAgent);
|
| 34 |
+
var safari = /Apple Computer/.test(navigator.vendor);
|
| 35 |
+
var mac_geMountainLion = /Mac OS X 1\d\D([8-9]|\d\d)\D/.test(navigator.userAgent);
|
| 36 |
+
var phantom = /PhantomJS/.test(navigator.userAgent);
|
| 37 |
+
|
| 38 |
+
var ios = /AppleWebKit/.test(navigator.userAgent) && /Mobile\/\w+/.test(navigator.userAgent);
|
| 39 |
+
// This is woefully incomplete. Suggestions for alternative methods welcome.
|
| 40 |
+
var mobile = ios || /Android|webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(navigator.userAgent);
|
| 41 |
+
var mac = ios || /Mac/.test(navigator.platform);
|
| 42 |
+
var windows = /win/i.test(navigator.platform);
|
| 43 |
+
|
| 44 |
+
var presto_version = presto && navigator.userAgent.match(/Version\/(\d*\.\d*)/);
|
| 45 |
+
if (presto_version) presto_version = Number(presto_version[1]);
|
| 46 |
+
if (presto_version && presto_version >= 15) { presto = false; webkit = true; }
|
| 47 |
+
// Some browsers use the wrong event properties to signal cmd/ctrl on OS X
|
| 48 |
+
var flipCtrlCmd = mac && (qtwebkit || presto && (presto_version == null || presto_version < 12.11));
|
| 49 |
+
var captureRightClick = gecko || (ie && ie_version >= 9);
|
| 50 |
+
|
| 51 |
+
// Optimize some code when these features are not used.
|
| 52 |
+
var sawReadOnlySpans = false, sawCollapsedSpans = false;
|
| 53 |
+
|
| 54 |
+
// EDITOR CONSTRUCTOR
|
| 55 |
+
|
| 56 |
+
// A CodeMirror instance represents an editor. This is the object
|
| 57 |
+
// that user code is usually dealing with.
|
| 58 |
+
|
| 59 |
+
function CodeMirror(place, options) {
|
| 60 |
+
if (!(this instanceof CodeMirror)) return new CodeMirror(place, options);
|
| 61 |
+
|
| 62 |
+
this.options = options = options ? copyObj(options) : {};
|
| 63 |
+
// Determine effective options based on given values and defaults.
|
| 64 |
+
copyObj(defaults, options, false);
|
| 65 |
+
setGuttersForLineNumbers(options);
|
| 66 |
+
|
| 67 |
+
var doc = options.value;
|
| 68 |
+
if (typeof doc == "string") doc = new Doc(doc, options.mode);
|
| 69 |
+
this.doc = doc;
|
| 70 |
+
|
| 71 |
+
var input = new CodeMirror.inputStyles[options.inputStyle](this);
|
| 72 |
+
var display = this.display = new Display(place, doc, input);
|
| 73 |
+
display.wrapper.CodeMirror = this;
|
| 74 |
+
updateGutters(this);
|
| 75 |
+
themeChanged(this);
|
| 76 |
+
if (options.lineWrapping)
|
| 77 |
+
this.display.wrapper.className += " CodeMirror-wrap";
|
| 78 |
+
if (options.autofocus && !mobile) display.input.focus();
|
| 79 |
+
initScrollbars(this);
|
| 80 |
+
|
| 81 |
+
this.state = {
|
| 82 |
+
keyMaps: [], // stores maps added by addKeyMap
|
| 83 |
+
overlays: [], // highlighting overlays, as added by addOverlay
|
| 84 |
+
modeGen: 0, // bumped when mode/overlay changes, used to invalidate highlighting info
|
| 85 |
+
overwrite: false,
|
| 86 |
+
delayingBlurEvent: false,
|
| 87 |
+
focused: false,
|
| 88 |
+
suppressEdits: false, // used to disable editing during key handlers when in readOnly mode
|
| 89 |
+
pasteIncoming: false, cutIncoming: false, // help recognize paste/cut edits in input.poll
|
| 90 |
+
draggingText: false,
|
| 91 |
+
highlight: new Delayed(), // stores highlight worker timeout
|
| 92 |
+
keySeq: null, // Unfinished key sequence
|
| 93 |
+
specialChars: null
|
| 94 |
+
};
|
| 95 |
+
|
| 96 |
+
var cm = this;
|
| 97 |
+
|
| 98 |
+
// Override magic textarea content restore that IE sometimes does
|
| 99 |
+
// on our hidden textarea on reload
|
| 100 |
+
if (ie && ie_version < 11) setTimeout(function() { cm.display.input.reset(true); }, 20);
|
| 101 |
+
|
| 102 |
+
registerEventHandlers(this);
|
| 103 |
+
ensureGlobalHandlers();
|
| 104 |
+
|
| 105 |
+
startOperation(this);
|
| 106 |
+
this.curOp.forceUpdate = true;
|
| 107 |
+
attachDoc(this, doc);
|
| 108 |
+
|
| 109 |
+
if ((options.autofocus && !mobile) || cm.hasFocus())
|
| 110 |
+
setTimeout(bind(onFocus, this), 20);
|
| 111 |
+
else
|
| 112 |
+
onBlur(this);
|
| 113 |
+
|
| 114 |
+
for (var opt in optionHandlers) if (optionHandlers.hasOwnProperty(opt))
|
| 115 |
+
optionHandlers[opt](this, options[opt], Init);
|
| 116 |
+
maybeUpdateLineNumberWidth(this);
|
| 117 |
+
if (options.finishInit) options.finishInit(this);
|
| 118 |
+
for (var i = 0; i < initHooks.length; ++i) initHooks[i](this);
|
| 119 |
+
endOperation(this);
|
| 120 |
+
// Suppress optimizelegibility in Webkit, since it breaks text
|
| 121 |
+
// measuring on line wrapping boundaries.
|
| 122 |
+
if (webkit && options.lineWrapping &&
|
| 123 |
+
getComputedStyle(display.lineDiv).textRendering == "optimizelegibility")
|
| 124 |
+
display.lineDiv.style.textRendering = "auto";
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
// DISPLAY CONSTRUCTOR
|
| 128 |
+
|
| 129 |
+
// The display handles the DOM integration, both for input reading
|
| 130 |
+
// and content drawing. It holds references to DOM nodes and
|
| 131 |
+
// display-related state.
|
| 132 |
+
|
| 133 |
+
function Display(place, doc, input) {
|
| 134 |
+
var d = this;
|
| 135 |
+
this.input = input;
|
| 136 |
+
|
| 137 |
+
// Covers bottom-right square when both scrollbars are present.
|
| 138 |
+
d.scrollbarFiller = elt("div", null, "CodeMirror-scrollbar-filler");
|
| 139 |
+
d.scrollbarFiller.setAttribute("cm-not-content", "true");
|
| 140 |
+
// Covers bottom of gutter when coverGutterNextToScrollbar is on
|
| 141 |
+
// and h scrollbar is present.
|
| 142 |
+
d.gutterFiller = elt("div", null, "CodeMirror-gutter-filler");
|
| 143 |
+
d.gutterFiller.setAttribute("cm-not-content", "true");
|
| 144 |
+
// Will contain the actual code, positioned to cover the viewport.
|
| 145 |
+
d.lineDiv = elt("div", null, "CodeMirror-code");
|
| 146 |
+
// Elements are added to these to represent selection and cursors.
|
| 147 |
+
d.selectionDiv = elt("div", null, null, "position: relative; z-index: 1");
|
| 148 |
+
d.cursorDiv = elt("div", null, "CodeMirror-cursors");
|
| 149 |
+
// A visibility: hidden element used to find the size of things.
|
| 150 |
+
d.measure = elt("div", null, "CodeMirror-measure");
|
| 151 |
+
// When lines outside of the viewport are measured, they are drawn in this.
|
| 152 |
+
d.lineMeasure = elt("div", null, "CodeMirror-measure");
|
| 153 |
+
// Wraps everything that needs to exist inside the vertically-padded coordinate system
|
| 154 |
+
d.lineSpace = elt("div", [d.measure, d.lineMeasure, d.selectionDiv, d.cursorDiv, d.lineDiv],
|
| 155 |
+
null, "position: relative; outline: none");
|
| 156 |
+
// Moved around its parent to cover visible view.
|
| 157 |
+
d.mover = elt("div", [elt("div", [d.lineSpace], "CodeMirror-lines")], null, "position: relative");
|
| 158 |
+
// Set to the height of the document, allowing scrolling.
|
| 159 |
+
d.sizer = elt("div", [d.mover], "CodeMirror-sizer");
|
| 160 |
+
d.sizerWidth = null;
|
| 161 |
+
// Behavior of elts with overflow: auto and padding is
|
| 162 |
+
// inconsistent across browsers. This is used to ensure the
|
| 163 |
+
// scrollable area is big enough.
|
| 164 |
+
d.heightForcer = elt("div", null, null, "position: absolute; height: " + scrollerGap + "px; width: 1px;");
|
| 165 |
+
// Will contain the gutters, if any.
|
| 166 |
+
d.gutters = elt("div", null, "CodeMirror-gutters");
|
| 167 |
+
d.lineGutter = null;
|
| 168 |
+
// Actual scrollable element.
|
| 169 |
+
d.scroller = elt("div", [d.sizer, d.heightForcer, d.gutters], "CodeMirror-scroll");
|
| 170 |
+
d.scroller.setAttribute("tabIndex", "-1");
|
| 171 |
+
// The element in which the editor lives.
|
| 172 |
+
d.wrapper = elt("div", [d.scrollbarFiller, d.gutterFiller, d.scroller], "CodeMirror");
|
| 173 |
+
|
| 174 |
+
// Work around IE7 z-index bug (not perfect, hence IE7 not really being supported)
|
| 175 |
+
if (ie && ie_version < 8) { d.gutters.style.zIndex = -1; d.scroller.style.paddingRight = 0; }
|
| 176 |
+
if (!webkit && !(gecko && mobile)) d.scroller.draggable = true;
|
| 177 |
+
|
| 178 |
+
if (place) {
|
| 179 |
+
if (place.appendChild) place.appendChild(d.wrapper);
|
| 180 |
+
else place(d.wrapper);
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
// Current rendered range (may be bigger than the view window).
|
| 184 |
+
d.viewFrom = d.viewTo = doc.first;
|
| 185 |
+
d.reportedViewFrom = d.reportedViewTo = doc.first;
|
| 186 |
+
// Information about the rendered lines.
|
| 187 |
+
d.view = [];
|
| 188 |
+
d.renderedView = null;
|
| 189 |
+
// Holds info about a single rendered line when it was rendered
|
| 190 |
+
// for measurement, while not in view.
|
| 191 |
+
d.externalMeasured = null;
|
| 192 |
+
// Empty space (in pixels) above the view
|
| 193 |
+
d.viewOffset = 0;
|
| 194 |
+
d.lastWrapHeight = d.lastWrapWidth = 0;
|
| 195 |
+
d.updateLineNumbers = null;
|
| 196 |
+
|
| 197 |
+
d.nativeBarWidth = d.barHeight = d.barWidth = 0;
|
| 198 |
+
d.scrollbarsClipped = false;
|
| 199 |
+
|
| 200 |
+
// Used to only resize the line number gutter when necessary (when
|
| 201 |
+
// the amount of lines crosses a boundary that makes its width change)
|
| 202 |
+
d.lineNumWidth = d.lineNumInnerWidth = d.lineNumChars = null;
|
| 203 |
+
// Set to true when a non-horizontal-scrolling line widget is
|
| 204 |
+
// added. As an optimization, line widget aligning is skipped when
|
| 205 |
+
// this is false.
|
| 206 |
+
d.alignWidgets = false;
|
| 207 |
+
|
| 208 |
+
d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null;
|
| 209 |
+
|
| 210 |
+
// Tracks the maximum line length so that the horizontal scrollbar
|
| 211 |
+
// can be kept static when scrolling.
|
| 212 |
+
d.maxLine = null;
|
| 213 |
+
d.maxLineLength = 0;
|
| 214 |
+
d.maxLineChanged = false;
|
| 215 |
+
|
| 216 |
+
// Used for measuring wheel scrolling granularity
|
| 217 |
+
d.wheelDX = d.wheelDY = d.wheelStartX = d.wheelStartY = null;
|
| 218 |
+
|
| 219 |
+
// True when shift is held down.
|
| 220 |
+
d.shift = false;
|
| 221 |
+
|
| 222 |
+
// Used to track whether anything happened since the context menu
|
| 223 |
+
// was opened.
|
| 224 |
+
d.selForContextMenu = null;
|
| 225 |
+
|
| 226 |
+
d.activeTouch = null;
|
| 227 |
+
|
| 228 |
+
input.init(d);
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
// STATE UPDATES
|
| 232 |
+
|
| 233 |
+
// Used to get the editor into a consistent state again when options change.
|
| 234 |
+
|
| 235 |
+
function loadMode(cm) {
|
| 236 |
+
cm.doc.mode = CodeMirror.getMode(cm.options, cm.doc.modeOption);
|
| 237 |
+
resetModeState(cm);
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
function resetModeState(cm) {
|
| 241 |
+
cm.doc.iter(function(line) {
|
| 242 |
+
if (line.stateAfter) line.stateAfter = null;
|
| 243 |
+
if (line.styles) line.styles = null;
|
| 244 |
+
});
|
| 245 |
+
cm.doc.frontier = cm.doc.first;
|
| 246 |
+
startWorker(cm, 100);
|
| 247 |
+
cm.state.modeGen++;
|
| 248 |
+
if (cm.curOp) regChange(cm);
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
function wrappingChanged(cm) {
|
| 252 |
+
if (cm.options.lineWrapping) {
|
| 253 |
+
addClass(cm.display.wrapper, "CodeMirror-wrap");
|
| 254 |
+
cm.display.sizer.style.minWidth = "";
|
| 255 |
+
cm.display.sizerWidth = null;
|
| 256 |
+
} else {
|
| 257 |
+
rmClass(cm.display.wrapper, "CodeMirror-wrap");
|
| 258 |
+
findMaxLine(cm);
|
| 259 |
+
}
|
| 260 |
+
estimateLineHeights(cm);
|
| 261 |
+
regChange(cm);
|
| 262 |
+
clearCaches(cm);
|
| 263 |
+
setTimeout(function(){updateScrollbars(cm);}, 100);
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
// Returns a function that estimates the height of a line, to use as
|
| 267 |
+
// first approximation until the line becomes visible (and is thus
|
| 268 |
+
// properly measurable).
|
| 269 |
+
function estimateHeight(cm) {
|
| 270 |
+
var th = textHeight(cm.display), wrapping = cm.options.lineWrapping;
|
| 271 |
+
var perLine = wrapping && Math.max(5, cm.display.scroller.clientWidth / charWidth(cm.display) - 3);
|
| 272 |
+
return function(line) {
|
| 273 |
+
if (lineIsHidden(cm.doc, line)) return 0;
|
| 274 |
+
|
| 275 |
+
var widgetsHeight = 0;
|
| 276 |
+
if (line.widgets) for (var i = 0; i < line.widgets.length; i++) {
|
| 277 |
+
if (line.widgets[i].height) widgetsHeight += line.widgets[i].height;
|
| 278 |
+
}
|
| 279 |
+
|
| 280 |
+
if (wrapping)
|
| 281 |
+
return widgetsHeight + (Math.ceil(line.text.length / perLine) || 1) * th;
|
| 282 |
+
else
|
| 283 |
+
return widgetsHeight + th;
|
| 284 |
+
};
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
function estimateLineHeights(cm) {
|
| 288 |
+
var doc = cm.doc, est = estimateHeight(cm);
|
| 289 |
+
doc.iter(function(line) {
|
| 290 |
+
var estHeight = est(line);
|
| 291 |
+
if (estHeight != line.height) updateLineHeight(line, estHeight);
|
| 292 |
+
});
|
| 293 |
+
}
|
| 294 |
+
|
| 295 |
+
function themeChanged(cm) {
|
| 296 |
+
cm.display.wrapper.className = cm.display.wrapper.className.replace(/\s*cm-s-\S+/g, "") +
|
| 297 |
+
cm.options.theme.replace(/(^|\s)\s*/g, " cm-s-");
|
| 298 |
+
clearCaches(cm);
|
| 299 |
+
}
|
| 300 |
+
|
| 301 |
+
function guttersChanged(cm) {
|
| 302 |
+
updateGutters(cm);
|
| 303 |
+
regChange(cm);
|
| 304 |
+
setTimeout(function(){alignHorizontally(cm);}, 20);
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
// Rebuild the gutter elements, ensure the margin to the left of the
|
| 308 |
+
// code matches their width.
|
| 309 |
+
function updateGutters(cm) {
|
| 310 |
+
var gutters = cm.display.gutters, specs = cm.options.gutters;
|
| 311 |
+
removeChildren(gutters);
|
| 312 |
+
for (var i = 0; i < specs.length; ++i) {
|
| 313 |
+
var gutterClass = specs[i];
|
| 314 |
+
var gElt = gutters.appendChild(elt("div", null, "CodeMirror-gutter " + gutterClass));
|
| 315 |
+
if (gutterClass == "CodeMirror-linenumbers") {
|
| 316 |
+
cm.display.lineGutter = gElt;
|
| 317 |
+
gElt.style.width = (cm.display.lineNumWidth || 1) + "px";
|
| 318 |
+
}
|
| 319 |
+
}
|
| 320 |
+
gutters.style.display = i ? "" : "none";
|
| 321 |
+
updateGutterSpace(cm);
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
function updateGutterSpace(cm) {
|
| 325 |
+
var width = cm.display.gutters.offsetWidth;
|
| 326 |
+
cm.display.sizer.style.marginLeft = width + "px";
|
| 327 |
+
}
|
| 328 |
+
|
| 329 |
+
// Compute the character length of a line, taking into account
|
| 330 |
+
// collapsed ranges (see markText) that might hide parts, and join
|
| 331 |
+
// other lines onto it.
|
| 332 |
+
function lineLength(line) {
|
| 333 |
+
if (line.height == 0) return 0;
|
| 334 |
+
var len = line.text.length, merged, cur = line;
|
| 335 |
+
while (merged = collapsedSpanAtStart(cur)) {
|
| 336 |
+
var found = merged.find(0, true);
|
| 337 |
+
cur = found.from.line;
|
| 338 |
+
len += found.from.ch - found.to.ch;
|
| 339 |
+
}
|
| 340 |
+
cur = line;
|
| 341 |
+
while (merged = collapsedSpanAtEnd(cur)) {
|
| 342 |
+
var found = merged.find(0, true);
|
| 343 |
+
len -= cur.text.length - found.from.ch;
|
| 344 |
+
cur = found.to.line;
|
| 345 |
+
len += cur.text.length - found.to.ch;
|
| 346 |
+
}
|
| 347 |
+
return len;
|
| 348 |
+
}
|
| 349 |
+
|
| 350 |
+
// Find the longest line in the document.
|
| 351 |
+
function findMaxLine(cm) {
|
| 352 |
+
var d = cm.display, doc = cm.doc;
|
| 353 |
+
d.maxLine = getLine(doc, doc.first);
|
| 354 |
+
d.maxLineLength = lineLength(d.maxLine);
|
| 355 |
+
d.maxLineChanged = true;
|
| 356 |
+
doc.iter(function(line) {
|
| 357 |
+
var len = lineLength(line);
|
| 358 |
+
if (len > d.maxLineLength) {
|
| 359 |
+
d.maxLineLength = len;
|
| 360 |
+
d.maxLine = line;
|
| 361 |
+
}
|
| 362 |
+
});
|
| 363 |
+
}
|
| 364 |
+
|
| 365 |
+
// Make sure the gutters options contains the element
|
| 366 |
+
// "CodeMirror-linenumbers" when the lineNumbers option is true.
|
| 367 |
+
function setGuttersForLineNumbers(options) {
|
| 368 |
+
var found = indexOf(options.gutters, "CodeMirror-linenumbers");
|
| 369 |
+
if (found == -1 && options.lineNumbers) {
|
| 370 |
+
options.gutters = options.gutters.concat(["CodeMirror-linenumbers"]);
|
| 371 |
+
} else if (found > -1 && !options.lineNumbers) {
|
| 372 |
+
options.gutters = options.gutters.slice(0);
|
| 373 |
+
options.gutters.splice(found, 1);
|
| 374 |
+
}
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
// SCROLLBARS
|
| 378 |
+
|
| 379 |
+
// Prepare DOM reads needed to update the scrollbars. Done in one
|
| 380 |
+
// shot to minimize update/measure roundtrips.
|
| 381 |
+
function measureForScrollbars(cm) {
|
| 382 |
+
var d = cm.display, gutterW = d.gutters.offsetWidth;
|
| 383 |
+
var docH = Math.round(cm.doc.height + paddingVert(cm.display));
|
| 384 |
+
return {
|
| 385 |
+
clientHeight: d.scroller.clientHeight,
|
| 386 |
+
viewHeight: d.wrapper.clientHeight,
|
| 387 |
+
scrollWidth: d.scroller.scrollWidth, clientWidth: d.scroller.clientWidth,
|
| 388 |
+
viewWidth: d.wrapper.clientWidth,
|
| 389 |
+
barLeft: cm.options.fixedGutter ? gutterW : 0,
|
| 390 |
+
docHeight: docH,
|
| 391 |
+
scrollHeight: docH + scrollGap(cm) + d.barHeight,
|
| 392 |
+
nativeBarWidth: d.nativeBarWidth,
|
| 393 |
+
gutterWidth: gutterW
|
| 394 |
+
};
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
function NativeScrollbars(place, scroll, cm) {
|
| 398 |
+
this.cm = cm;
|
| 399 |
+
var vert = this.vert = elt("div", [elt("div", null, null, "min-width: 1px")], "CodeMirror-vscrollbar");
|
| 400 |
+
var horiz = this.horiz = elt("div", [elt("div", null, null, "height: 100%; min-height: 1px")], "CodeMirror-hscrollbar");
|
| 401 |
+
place(vert); place(horiz);
|
| 402 |
+
|
| 403 |
+
on(vert, "scroll", function() {
|
| 404 |
+
if (vert.clientHeight) scroll(vert.scrollTop, "vertical");
|
| 405 |
+
});
|
| 406 |
+
on(horiz, "scroll", function() {
|
| 407 |
+
if (horiz.clientWidth) scroll(horiz.scrollLeft, "horizontal");
|
| 408 |
+
});
|
| 409 |
+
|
| 410 |
+
this.checkedOverlay = false;
|
| 411 |
+
// Need to set a minimum width to see the scrollbar on IE7 (but must not set it on IE8).
|
| 412 |
+
if (ie && ie_version < 8) this.horiz.style.minHeight = this.vert.style.minWidth = "18px";
|
| 413 |
+
}
|
| 414 |
+
|
| 415 |
+
NativeScrollbars.prototype = copyObj({
|
| 416 |
+
update: function(measure) {
|
| 417 |
+
var needsH = measure.scrollWidth > measure.clientWidth + 1;
|
| 418 |
+
var needsV = measure.scrollHeight > measure.clientHeight + 1;
|
| 419 |
+
var sWidth = measure.nativeBarWidth;
|
| 420 |
+
|
| 421 |
+
if (needsV) {
|
| 422 |
+
this.vert.style.display = "block";
|
| 423 |
+
this.vert.style.bottom = needsH ? sWidth + "px" : "0";
|
| 424 |
+
var totalHeight = measure.viewHeight - (needsH ? sWidth : 0);
|
| 425 |
+
// A bug in IE8 can cause this value to be negative, so guard it.
|
| 426 |
+
this.vert.firstChild.style.height =
|
| 427 |
+
Math.max(0, measure.scrollHeight - measure.clientHeight + totalHeight) + "px";
|
| 428 |
+
} else {
|
| 429 |
+
this.vert.style.display = "";
|
| 430 |
+
this.vert.firstChild.style.height = "0";
|
| 431 |
+
}
|
| 432 |
+
|
| 433 |
+
if (needsH) {
|
| 434 |
+
this.horiz.style.display = "block";
|
| 435 |
+
this.horiz.style.right = needsV ? sWidth + "px" : "0";
|
| 436 |
+
this.horiz.style.left = measure.barLeft + "px";
|
| 437 |
+
var totalWidth = measure.viewWidth - measure.barLeft - (needsV ? sWidth : 0);
|
| 438 |
+
this.horiz.firstChild.style.width =
|
| 439 |
+
(measure.scrollWidth - measure.clientWidth + totalWidth) + "px";
|
| 440 |
+
} else {
|
| 441 |
+
this.horiz.style.display = "";
|
| 442 |
+
this.horiz.firstChild.style.width = "0";
|
| 443 |
+
}
|
| 444 |
+
|
| 445 |
+
if (!this.checkedOverlay && measure.clientHeight > 0) {
|
| 446 |
+
if (sWidth == 0) this.overlayHack();
|
| 447 |
+
this.checkedOverlay = true;
|
| 448 |
+
}
|
| 449 |
+
|
| 450 |
+
return {right: needsV ? sWidth : 0, bottom: needsH ? sWidth : 0};
|
| 451 |
+
},
|
| 452 |
+
setScrollLeft: function(pos) {
|
| 453 |
+
if (this.horiz.scrollLeft != pos) this.horiz.scrollLeft = pos;
|
| 454 |
+
},
|
| 455 |
+
setScrollTop: function(pos) {
|
| 456 |
+
if (this.vert.scrollTop != pos) this.vert.scrollTop = pos;
|
| 457 |
+
},
|
| 458 |
+
overlayHack: function() {
|
| 459 |
+
var w = mac && !mac_geMountainLion ? "12px" : "18px";
|
| 460 |
+
this.horiz.style.minHeight = this.vert.style.minWidth = w;
|
| 461 |
+
var self = this;
|
| 462 |
+
var barMouseDown = function(e) {
|
| 463 |
+
if (e_target(e) != self.vert && e_target(e) != self.horiz)
|
| 464 |
+
operation(self.cm, onMouseDown)(e);
|
| 465 |
+
};
|
| 466 |
+
on(this.vert, "mousedown", barMouseDown);
|
| 467 |
+
on(this.horiz, "mousedown", barMouseDown);
|
| 468 |
+
},
|
| 469 |
+
clear: function() {
|
| 470 |
+
var parent = this.horiz.parentNode;
|
| 471 |
+
parent.removeChild(this.horiz);
|
| 472 |
+
parent.removeChild(this.vert);
|
| 473 |
+
}
|
| 474 |
+
}, NativeScrollbars.prototype);
|
| 475 |
+
|
| 476 |
+
function NullScrollbars() {}
|
| 477 |
+
|
| 478 |
+
NullScrollbars.prototype = copyObj({
|
| 479 |
+
update: function() { return {bottom: 0, right: 0}; },
|
| 480 |
+
setScrollLeft: function() {},
|
| 481 |
+
setScrollTop: function() {},
|
| 482 |
+
clear: function() {}
|
| 483 |
+
}, NullScrollbars.prototype);
|
| 484 |
+
|
| 485 |
+
CodeMirror.scrollbarModel = {"native": NativeScrollbars, "null": NullScrollbars};
|
| 486 |
+
|
| 487 |
+
function initScrollbars(cm) {
|
| 488 |
+
if (cm.display.scrollbars) {
|
| 489 |
+
cm.display.scrollbars.clear();
|
| 490 |
+
if (cm.display.scrollbars.addClass)
|
| 491 |
+
rmClass(cm.display.wrapper, cm.display.scrollbars.addClass);
|
| 492 |
+
}
|
| 493 |
+
|
| 494 |
+
cm.display.scrollbars = new CodeMirror.scrollbarModel[cm.options.scrollbarStyle](function(node) {
|
| 495 |
+
cm.display.wrapper.insertBefore(node, cm.display.scrollbarFiller);
|
| 496 |
+
// Prevent clicks in the scrollbars from killing focus
|
| 497 |
+
on(node, "mousedown", function() {
|
| 498 |
+
if (cm.state.focused) setTimeout(function() { cm.display.input.focus(); }, 0);
|
| 499 |
+
});
|
| 500 |
+
node.setAttribute("cm-not-content", "true");
|
| 501 |
+
}, function(pos, axis) {
|
| 502 |
+
if (axis == "horizontal") setScrollLeft(cm, pos);
|
| 503 |
+
else setScrollTop(cm, pos);
|
| 504 |
+
}, cm);
|
| 505 |
+
if (cm.display.scrollbars.addClass)
|
| 506 |
+
addClass(cm.display.wrapper, cm.display.scrollbars.addClass);
|
| 507 |
+
}
|
| 508 |
+
|
| 509 |
+
function updateScrollbars(cm, measure) {
|
| 510 |
+
if (!measure) measure = measureForScrollbars(cm);
|
| 511 |
+
var startWidth = cm.display.barWidth, startHeight = cm.display.barHeight;
|
| 512 |
+
updateScrollbarsInner(cm, measure);
|
| 513 |
+
for (var i = 0; i < 4 && startWidth != cm.display.barWidth || startHeight != cm.display.barHeight; i++) {
|
| 514 |
+
if (startWidth != cm.display.barWidth && cm.options.lineWrapping)
|
| 515 |
+
updateHeightsInViewport(cm);
|
| 516 |
+
updateScrollbarsInner(cm, measureForScrollbars(cm));
|
| 517 |
+
startWidth = cm.display.barWidth; startHeight = cm.display.barHeight;
|
| 518 |
+
}
|
| 519 |
+
}
|
| 520 |
+
|
| 521 |
+
// Re-synchronize the fake scrollbars with the actual size of the
|
| 522 |
+
// content.
|
| 523 |
+
function updateScrollbarsInner(cm, measure) {
|
| 524 |
+
var d = cm.display;
|
| 525 |
+
var sizes = d.scrollbars.update(measure);
|
| 526 |
+
|
| 527 |
+
d.sizer.style.paddingRight = (d.barWidth = sizes.right) + "px";
|
| 528 |
+
d.sizer.style.paddingBottom = (d.barHeight = sizes.bottom) + "px";
|
| 529 |
+
|
| 530 |
+
if (sizes.right && sizes.bottom) {
|
| 531 |
+
d.scrollbarFiller.style.display = "block";
|
| 532 |
+
d.scrollbarFiller.style.height = sizes.bottom + "px";
|
| 533 |
+
d.scrollbarFiller.style.width = sizes.right + "px";
|
| 534 |
+
} else d.scrollbarFiller.style.display = "";
|
| 535 |
+
if (sizes.bottom && cm.options.coverGutterNextToScrollbar && cm.options.fixedGutter) {
|
| 536 |
+
d.gutterFiller.style.display = "block";
|
| 537 |
+
d.gutterFiller.style.height = sizes.bottom + "px";
|
| 538 |
+
d.gutterFiller.style.width = measure.gutterWidth + "px";
|
| 539 |
+
} else d.gutterFiller.style.display = "";
|
| 540 |
+
}
|
| 541 |
+
|
| 542 |
+
// Compute the lines that are visible in a given viewport (defaults
|
| 543 |
+
// the the current scroll position). viewport may contain top,
|
| 544 |
+
// height, and ensure (see op.scrollToPos) properties.
|
| 545 |
+
function visibleLines(display, doc, viewport) {
|
| 546 |
+
var top = viewport && viewport.top != null ? Math.max(0, viewport.top) : display.scroller.scrollTop;
|
| 547 |
+
top = Math.floor(top - paddingTop(display));
|
| 548 |
+
var bottom = viewport && viewport.bottom != null ? viewport.bottom : top + display.wrapper.clientHeight;
|
| 549 |
+
|
| 550 |
+
var from = lineAtHeight(doc, top), to = lineAtHeight(doc, bottom);
|
| 551 |
+
// Ensure is a {from: {line, ch}, to: {line, ch}} object, and
|
| 552 |
+
// forces those lines into the viewport (if possible).
|
| 553 |
+
if (viewport && viewport.ensure) {
|
| 554 |
+
var ensureFrom = viewport.ensure.from.line, ensureTo = viewport.ensure.to.line;
|
| 555 |
+
if (ensureFrom < from) {
|
| 556 |
+
from = ensureFrom;
|
| 557 |
+
to = lineAtHeight(doc, heightAtLine(getLine(doc, ensureFrom)) + display.wrapper.clientHeight);
|
| 558 |
+
} else if (Math.min(ensureTo, doc.lastLine()) >= to) {
|
| 559 |
+
from = lineAtHeight(doc, heightAtLine(getLine(doc, ensureTo)) - display.wrapper.clientHeight);
|
| 560 |
+
to = ensureTo;
|
| 561 |
+
}
|
| 562 |
+
}
|
| 563 |
+
return {from: from, to: Math.max(to, from + 1)};
|
| 564 |
+
}
|
| 565 |
+
|
| 566 |
+
// LINE NUMBERS
|
| 567 |
+
|
| 568 |
+
// Re-align line numbers and gutter marks to compensate for
|
| 569 |
+
// horizontal scrolling.
|
| 570 |
+
function alignHorizontally(cm) {
|
| 571 |
+
var display = cm.display, view = display.view;
|
| 572 |
+
if (!display.alignWidgets && (!display.gutters.firstChild || !cm.options.fixedGutter)) return;
|
| 573 |
+
var comp = compensateForHScroll(display) - display.scroller.scrollLeft + cm.doc.scrollLeft;
|
| 574 |
+
var gutterW = display.gutters.offsetWidth, left = comp + "px";
|
| 575 |
+
for (var i = 0; i < view.length; i++) if (!view[i].hidden) {
|
| 576 |
+
if (cm.options.fixedGutter && view[i].gutter)
|
| 577 |
+
view[i].gutter.style.left = left;
|
| 578 |
+
var align = view[i].alignable;
|
| 579 |
+
if (align) for (var j = 0; j < align.length; j++)
|
| 580 |
+
align[j].style.left = left;
|
| 581 |
+
}
|
| 582 |
+
if (cm.options.fixedGutter)
|
| 583 |
+
display.gutters.style.left = (comp + gutterW) + "px";
|
| 584 |
+
}
|
| 585 |
+
|
| 586 |
+
// Used to ensure that the line number gutter is still the right
|
| 587 |
+
// size for the current document size. Returns true when an update
|
| 588 |
+
// is needed.
|
| 589 |
+
function maybeUpdateLineNumberWidth(cm) {
|
| 590 |
+
if (!cm.options.lineNumbers) return false;
|
| 591 |
+
var doc = cm.doc, last = lineNumberFor(cm.options, doc.first + doc.size - 1), display = cm.display;
|
| 592 |
+
if (last.length != display.lineNumChars) {
|
| 593 |
+
var test = display.measure.appendChild(elt("div", [elt("div", last)],
|
| 594 |
+
"CodeMirror-linenumber CodeMirror-gutter-elt"));
|
| 595 |
+
var innerW = test.firstChild.offsetWidth, padding = test.offsetWidth - innerW;
|
| 596 |
+
display.lineGutter.style.width = "";
|
| 597 |
+
display.lineNumInnerWidth = Math.max(innerW, display.lineGutter.offsetWidth - padding) + 1;
|
| 598 |
+
display.lineNumWidth = display.lineNumInnerWidth + padding;
|
| 599 |
+
display.lineNumChars = display.lineNumInnerWidth ? last.length : -1;
|
| 600 |
+
display.lineGutter.style.width = display.lineNumWidth + "px";
|
| 601 |
+
updateGutterSpace(cm);
|
| 602 |
+
return true;
|
| 603 |
+
}
|
| 604 |
+
return false;
|
| 605 |
+
}
|
| 606 |
+
|
| 607 |
+
function lineNumberFor(options, i) {
|
| 608 |
+
return String(options.lineNumberFormatter(i + options.firstLineNumber));
|
| 609 |
+
}
|
| 610 |
+
|
| 611 |
+
// Computes display.scroller.scrollLeft + display.gutters.offsetWidth,
|
| 612 |
+
// but using getBoundingClientRect to get a sub-pixel-accurate
|
| 613 |
+
// result.
|
| 614 |
+
function compensateForHScroll(display) {
|
| 615 |
+
return display.scroller.getBoundingClientRect().left - display.sizer.getBoundingClientRect().left;
|
| 616 |
+
}
|
| 617 |
+
|
| 618 |
+
// DISPLAY DRAWING
|
| 619 |
+
|
| 620 |
+
function DisplayUpdate(cm, viewport, force) {
|
| 621 |
+
var display = cm.display;
|
| 622 |
+
|
| 623 |
+
this.viewport = viewport;
|
| 624 |
+
// Store some values that we'll need later (but don't want to force a relayout for)
|
| 625 |
+
this.visible = visibleLines(display, cm.doc, viewport);
|
| 626 |
+
this.editorIsHidden = !display.wrapper.offsetWidth;
|
| 627 |
+
this.wrapperHeight = display.wrapper.clientHeight;
|
| 628 |
+
this.wrapperWidth = display.wrapper.clientWidth;
|
| 629 |
+
this.oldDisplayWidth = displayWidth(cm);
|
| 630 |
+
this.force = force;
|
| 631 |
+
this.dims = getDimensions(cm);
|
| 632 |
+
this.events = [];
|
| 633 |
+
}
|
| 634 |
+
|
| 635 |
+
DisplayUpdate.prototype.signal = function(emitter, type) {
|
| 636 |
+
if (hasHandler(emitter, type))
|
| 637 |
+
this.events.push(arguments);
|
| 638 |
+
};
|
| 639 |
+
DisplayUpdate.prototype.finish = function() {
|
| 640 |
+
for (var i = 0; i < this.events.length; i++)
|
| 641 |
+
signal.apply(null, this.events[i]);
|
| 642 |
+
};
|
| 643 |
+
|
| 644 |
+
function maybeClipScrollbars(cm) {
|
| 645 |
+
var display = cm.display;
|
| 646 |
+
if (!display.scrollbarsClipped && display.scroller.offsetWidth) {
|
| 647 |
+
display.nativeBarWidth = display.scroller.offsetWidth - display.scroller.clientWidth;
|
| 648 |
+
display.heightForcer.style.height = scrollGap(cm) + "px";
|
| 649 |
+
display.sizer.style.marginBottom = -display.nativeBarWidth + "px";
|
| 650 |
+
display.sizer.style.borderRightWidth = scrollGap(cm) + "px";
|
| 651 |
+
display.scrollbarsClipped = true;
|
| 652 |
+
}
|
| 653 |
+
}
|
| 654 |
+
|
| 655 |
+
// Does the actual updating of the line display. Bails out
|
| 656 |
+
// (returning false) when there is nothing to be done and forced is
|
| 657 |
+
// false.
|
| 658 |
+
function updateDisplayIfNeeded(cm, update) {
|
| 659 |
+
var display = cm.display, doc = cm.doc;
|
| 660 |
+
|
| 661 |
+
if (update.editorIsHidden) {
|
| 662 |
+
resetView(cm);
|
| 663 |
+
return false;
|
| 664 |
+
}
|
| 665 |
+
|
| 666 |
+
// Bail out if the visible area is already rendered and nothing changed.
|
| 667 |
+
if (!update.force &&
|
| 668 |
+
update.visible.from >= display.viewFrom && update.visible.to <= display.viewTo &&
|
| 669 |
+
(display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo) &&
|
| 670 |
+
display.renderedView == display.view && countDirtyView(cm) == 0)
|
| 671 |
+
return false;
|
| 672 |
+
|
| 673 |
+
if (maybeUpdateLineNumberWidth(cm)) {
|
| 674 |
+
resetView(cm);
|
| 675 |
+
update.dims = getDimensions(cm);
|
| 676 |
+
}
|
| 677 |
+
|
| 678 |
+
// Compute a suitable new viewport (from & to)
|
| 679 |
+
var end = doc.first + doc.size;
|
| 680 |
+
var from = Math.max(update.visible.from - cm.options.viewportMargin, doc.first);
|
| 681 |
+
var to = Math.min(end, update.visible.to + cm.options.viewportMargin);
|
| 682 |
+
if (display.viewFrom < from && from - display.viewFrom < 20) from = Math.max(doc.first, display.viewFrom);
|
| 683 |
+
if (display.viewTo > to && display.viewTo - to < 20) to = Math.min(end, display.viewTo);
|
| 684 |
+
if (sawCollapsedSpans) {
|
| 685 |
+
from = visualLineNo(cm.doc, from);
|
| 686 |
+
to = visualLineEndNo(cm.doc, to);
|
| 687 |
+
}
|
| 688 |
+
|
| 689 |
+
var different = from != display.viewFrom || to != display.viewTo ||
|
| 690 |
+
display.lastWrapHeight != update.wrapperHeight || display.lastWrapWidth != update.wrapperWidth;
|
| 691 |
+
adjustView(cm, from, to);
|
| 692 |
+
|
| 693 |
+
display.viewOffset = heightAtLine(getLine(cm.doc, display.viewFrom));
|
| 694 |
+
// Position the mover div to align with the current scroll position
|
| 695 |
+
cm.display.mover.style.top = display.viewOffset + "px";
|
| 696 |
+
|
| 697 |
+
var toUpdate = countDirtyView(cm);
|
| 698 |
+
if (!different && toUpdate == 0 && !update.force && display.renderedView == display.view &&
|
| 699 |
+
(display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo))
|
| 700 |
+
return false;
|
| 701 |
+
|
| 702 |
+
// For big changes, we hide the enclosing element during the
|
| 703 |
+
// update, since that speeds up the operations on most browsers.
|
| 704 |
+
var focused = activeElt();
|
| 705 |
+
if (toUpdate > 4) display.lineDiv.style.display = "none";
|
| 706 |
+
patchDisplay(cm, display.updateLineNumbers, update.dims);
|
| 707 |
+
if (toUpdate > 4) display.lineDiv.style.display = "";
|
| 708 |
+
display.renderedView = display.view;
|
| 709 |
+
// There might have been a widget with a focused element that got
|
| 710 |
+
// hidden or updated, if so re-focus it.
|
| 711 |
+
if (focused && activeElt() != focused && focused.offsetHeight) focused.focus();
|
| 712 |
+
|
| 713 |
+
// Prevent selection and cursors from interfering with the scroll
|
| 714 |
+
// width and height.
|
| 715 |
+
removeChildren(display.cursorDiv);
|
| 716 |
+
removeChildren(display.selectionDiv);
|
| 717 |
+
display.gutters.style.height = 0;
|
| 718 |
+
|
| 719 |
+
if (different) {
|
| 720 |
+
display.lastWrapHeight = update.wrapperHeight;
|
| 721 |
+
display.lastWrapWidth = update.wrapperWidth;
|
| 722 |
+
startWorker(cm, 400);
|
| 723 |
+
}
|
| 724 |
+
|
| 725 |
+
display.updateLineNumbers = null;
|
| 726 |
+
|
| 727 |
+
return true;
|
| 728 |
+
}
|
| 729 |
+
|
| 730 |
+
function postUpdateDisplay(cm, update) {
|
| 731 |
+
var viewport = update.viewport;
|
| 732 |
+
for (var first = true;; first = false) {
|
| 733 |
+
if (!first || !cm.options.lineWrapping || update.oldDisplayWidth == displayWidth(cm)) {
|
| 734 |
+
// Clip forced viewport to actual scrollable area.
|
| 735 |
+
if (viewport && viewport.top != null)
|
| 736 |
+
viewport = {top: Math.min(cm.doc.height + paddingVert(cm.display) - displayHeight(cm), viewport.top)};
|
| 737 |
+
// Updated line heights might result in the drawn area not
|
| 738 |
+
// actually covering the viewport. Keep looping until it does.
|
| 739 |
+
update.visible = visibleLines(cm.display, cm.doc, viewport);
|
| 740 |
+
if (update.visible.from >= cm.display.viewFrom && update.visible.to <= cm.display.viewTo)
|
| 741 |
+
break;
|
| 742 |
+
}
|
| 743 |
+
if (!updateDisplayIfNeeded(cm, update)) break;
|
| 744 |
+
updateHeightsInViewport(cm);
|
| 745 |
+
var barMeasure = measureForScrollbars(cm);
|
| 746 |
+
updateSelection(cm);
|
| 747 |
+
setDocumentHeight(cm, barMeasure);
|
| 748 |
+
updateScrollbars(cm, barMeasure);
|
| 749 |
+
}
|
| 750 |
+
|
| 751 |
+
update.signal(cm, "update", cm);
|
| 752 |
+
if (cm.display.viewFrom != cm.display.reportedViewFrom || cm.display.viewTo != cm.display.reportedViewTo) {
|
| 753 |
+
update.signal(cm, "viewportChange", cm, cm.display.viewFrom, cm.display.viewTo);
|
| 754 |
+
cm.display.reportedViewFrom = cm.display.viewFrom; cm.display.reportedViewTo = cm.display.viewTo;
|
| 755 |
+
}
|
| 756 |
+
}
|
| 757 |
+
|
| 758 |
+
function updateDisplaySimple(cm, viewport) {
|
| 759 |
+
var update = new DisplayUpdate(cm, viewport);
|
| 760 |
+
if (updateDisplayIfNeeded(cm, update)) {
|
| 761 |
+
updateHeightsInViewport(cm);
|
| 762 |
+
postUpdateDisplay(cm, update);
|
| 763 |
+
var barMeasure = measureForScrollbars(cm);
|
| 764 |
+
updateSelection(cm);
|
| 765 |
+
setDocumentHeight(cm, barMeasure);
|
| 766 |
+
updateScrollbars(cm, barMeasure);
|
| 767 |
+
update.finish();
|
| 768 |
+
}
|
| 769 |
+
}
|
| 770 |
+
|
| 771 |
+
function setDocumentHeight(cm, measure) {
|
| 772 |
+
cm.display.sizer.style.minHeight = measure.docHeight + "px";
|
| 773 |
+
var total = measure.docHeight + cm.display.barHeight;
|
| 774 |
+
cm.display.heightForcer.style.top = total + "px";
|
| 775 |
+
cm.display.gutters.style.height = Math.max(total + scrollGap(cm), measure.clientHeight) + "px";
|
| 776 |
+
}
|
| 777 |
+
|
| 778 |
+
// Read the actual heights of the rendered lines, and update their
|
| 779 |
+
// stored heights to match.
|
| 780 |
+
function updateHeightsInViewport(cm) {
|
| 781 |
+
var display = cm.display;
|
| 782 |
+
var prevBottom = display.lineDiv.offsetTop;
|
| 783 |
+
for (var i = 0; i < display.view.length; i++) {
|
| 784 |
+
var cur = display.view[i], height;
|
| 785 |
+
if (cur.hidden) continue;
|
| 786 |
+
if (ie && ie_version < 8) {
|
| 787 |
+
var bot = cur.node.offsetTop + cur.node.offsetHeight;
|
| 788 |
+
height = bot - prevBottom;
|
| 789 |
+
prevBottom = bot;
|
| 790 |
+
} else {
|
| 791 |
+
var box = cur.node.getBoundingClientRect();
|
| 792 |
+
height = box.bottom - box.top;
|
| 793 |
+
}
|
| 794 |
+
var diff = cur.line.height - height;
|
| 795 |
+
if (height < 2) height = textHeight(display);
|
| 796 |
+
if (diff > .001 || diff < -.001) {
|
| 797 |
+
updateLineHeight(cur.line, height);
|
| 798 |
+
updateWidgetHeight(cur.line);
|
| 799 |
+
if (cur.rest) for (var j = 0; j < cur.rest.length; j++)
|
| 800 |
+
updateWidgetHeight(cur.rest[j]);
|
| 801 |
+
}
|
| 802 |
+
}
|
| 803 |
+
}
|
| 804 |
+
|
| 805 |
+
// Read and store the height of line widgets associated with the
|
| 806 |
+
// given line.
|
| 807 |
+
function updateWidgetHeight(line) {
|
| 808 |
+
if (line.widgets) for (var i = 0; i < line.widgets.length; ++i)
|
| 809 |
+
line.widgets[i].height = line.widgets[i].node.offsetHeight;
|
| 810 |
+
}
|
| 811 |
+
|
| 812 |
+
// Do a bulk-read of the DOM positions and sizes needed to draw the
|
| 813 |
+
// view, so that we don't interleave reading and writing to the DOM.
|
| 814 |
+
function getDimensions(cm) {
|
| 815 |
+
var d = cm.display, left = {}, width = {};
|
| 816 |
+
var gutterLeft = d.gutters.clientLeft;
|
| 817 |
+
for (var n = d.gutters.firstChild, i = 0; n; n = n.nextSibling, ++i) {
|
| 818 |
+
left[cm.options.gutters[i]] = n.offsetLeft + n.clientLeft + gutterLeft;
|
| 819 |
+
width[cm.options.gutters[i]] = n.clientWidth;
|
| 820 |
+
}
|
| 821 |
+
return {fixedPos: compensateForHScroll(d),
|
| 822 |
+
gutterTotalWidth: d.gutters.offsetWidth,
|
| 823 |
+
gutterLeft: left,
|
| 824 |
+
gutterWidth: width,
|
| 825 |
+
wrapperWidth: d.wrapper.clientWidth};
|
| 826 |
+
}
|
| 827 |
+
|
| 828 |
+
// Sync the actual display DOM structure with display.view, removing
|
| 829 |
+
// nodes for lines that are no longer in view, and creating the ones
|
| 830 |
+
// that are not there yet, and updating the ones that are out of
|
| 831 |
+
// date.
|
| 832 |
+
function patchDisplay(cm, updateNumbersFrom, dims) {
|
| 833 |
+
var display = cm.display, lineNumbers = cm.options.lineNumbers;
|
| 834 |
+
var container = display.lineDiv, cur = container.firstChild;
|
| 835 |
+
|
| 836 |
+
function rm(node) {
|
| 837 |
+
var next = node.nextSibling;
|
| 838 |
+
// Works around a throw-scroll bug in OS X Webkit
|
| 839 |
+
if (webkit && mac && cm.display.currentWheelTarget == node)
|
| 840 |
+
node.style.display = "none";
|
| 841 |
+
else
|
| 842 |
+
node.parentNode.removeChild(node);
|
| 843 |
+
return next;
|
| 844 |
+
}
|
| 845 |
+
|
| 846 |
+
var view = display.view, lineN = display.viewFrom;
|
| 847 |
+
// Loop over the elements in the view, syncing cur (the DOM nodes
|
| 848 |
+
// in display.lineDiv) with the view as we go.
|
| 849 |
+
for (var i = 0; i < view.length; i++) {
|
| 850 |
+
var lineView = view[i];
|
| 851 |
+
if (lineView.hidden) {
|
| 852 |
+
} else if (!lineView.node || lineView.node.parentNode != container) { // Not drawn yet
|
| 853 |
+
var node = buildLineElement(cm, lineView, lineN, dims);
|
| 854 |
+
container.insertBefore(node, cur);
|
| 855 |
+
} else { // Already drawn
|
| 856 |
+
while (cur != lineView.node) cur = rm(cur);
|
| 857 |
+
var updateNumber = lineNumbers && updateNumbersFrom != null &&
|
| 858 |
+
updateNumbersFrom <= lineN && lineView.lineNumber;
|
| 859 |
+
if (lineView.changes) {
|
| 860 |
+
if (indexOf(lineView.changes, "gutter") > -1) updateNumber = false;
|
| 861 |
+
updateLineForChanges(cm, lineView, lineN, dims);
|
| 862 |
+
}
|
| 863 |
+
if (updateNumber) {
|
| 864 |
+
removeChildren(lineView.lineNumber);
|
| 865 |
+
lineView.lineNumber.appendChild(document.createTextNode(lineNumberFor(cm.options, lineN)));
|
| 866 |
+
}
|
| 867 |
+
cur = lineView.node.nextSibling;
|
| 868 |
+
}
|
| 869 |
+
lineN += lineView.size;
|
| 870 |
+
}
|
| 871 |
+
while (cur) cur = rm(cur);
|
| 872 |
+
}
|
| 873 |
+
|
| 874 |
+
// When an aspect of a line changes, a string is added to
|
| 875 |
+
// lineView.changes. This updates the relevant part of the line's
|
| 876 |
+
// DOM structure.
|
| 877 |
+
function updateLineForChanges(cm, lineView, lineN, dims) {
|
| 878 |
+
for (var j = 0; j < lineView.changes.length; j++) {
|
| 879 |
+
var type = lineView.changes[j];
|
| 880 |
+
if (type == "text") updateLineText(cm, lineView);
|
| 881 |
+
else if (type == "gutter") updateLineGutter(cm, lineView, lineN, dims);
|
| 882 |
+
else if (type == "class") updateLineClasses(lineView);
|
| 883 |
+
else if (type == "widget") updateLineWidgets(cm, lineView, dims);
|
| 884 |
+
}
|
| 885 |
+
lineView.changes = null;
|
| 886 |
+
}
|
| 887 |
+
|
| 888 |
+
// Lines with gutter elements, widgets or a background class need to
|
| 889 |
+
// be wrapped, and have the extra elements added to the wrapper div
|
| 890 |
+
function ensureLineWrapped(lineView) {
|
| 891 |
+
if (lineView.node == lineView.text) {
|
| 892 |
+
lineView.node = elt("div", null, null, "position: relative");
|
| 893 |
+
if (lineView.text.parentNode)
|
| 894 |
+
lineView.text.parentNode.replaceChild(lineView.node, lineView.text);
|
| 895 |
+
lineView.node.appendChild(lineView.text);
|
| 896 |
+
if (ie && ie_version < 8) lineView.node.style.zIndex = 2;
|
| 897 |
+
}
|
| 898 |
+
return lineView.node;
|
| 899 |
+
}
|
| 900 |
+
|
| 901 |
+
function updateLineBackground(lineView) {
|
| 902 |
+
var cls = lineView.bgClass ? lineView.bgClass + " " + (lineView.line.bgClass || "") : lineView.line.bgClass;
|
| 903 |
+
if (cls) cls += " CodeMirror-linebackground";
|
| 904 |
+
if (lineView.background) {
|
| 905 |
+
if (cls) lineView.background.className = cls;
|
| 906 |
+
else { lineView.background.parentNode.removeChild(lineView.background); lineView.background = null; }
|
| 907 |
+
} else if (cls) {
|
| 908 |
+
var wrap = ensureLineWrapped(lineView);
|
| 909 |
+
lineView.background = wrap.insertBefore(elt("div", null, cls), wrap.firstChild);
|
| 910 |
+
}
|
| 911 |
+
}
|
| 912 |
+
|
| 913 |
+
// Wrapper around buildLineContent which will reuse the structure
|
| 914 |
+
// in display.externalMeasured when possible.
|
| 915 |
+
function getLineContent(cm, lineView) {
|
| 916 |
+
var ext = cm.display.externalMeasured;
|
| 917 |
+
if (ext && ext.line == lineView.line) {
|
| 918 |
+
cm.display.externalMeasured = null;
|
| 919 |
+
lineView.measure = ext.measure;
|
| 920 |
+
return ext.built;
|
| 921 |
+
}
|
| 922 |
+
return buildLineContent(cm, lineView);
|
| 923 |
+
}
|
| 924 |
+
|
| 925 |
+
// Redraw the line's text. Interacts with the background and text
|
| 926 |
+
// classes because the mode may output tokens that influence these
|
| 927 |
+
// classes.
|
| 928 |
+
function updateLineText(cm, lineView) {
|
| 929 |
+
var cls = lineView.text.className;
|
| 930 |
+
var built = getLineContent(cm, lineView);
|
| 931 |
+
if (lineView.text == lineView.node) lineView.node = built.pre;
|
| 932 |
+
lineView.text.parentNode.replaceChild(built.pre, lineView.text);
|
| 933 |
+
lineView.text = built.pre;
|
| 934 |
+
if (built.bgClass != lineView.bgClass || built.textClass != lineView.textClass) {
|
| 935 |
+
lineView.bgClass = built.bgClass;
|
| 936 |
+
lineView.textClass = built.textClass;
|
| 937 |
+
updateLineClasses(lineView);
|
| 938 |
+
} else if (cls) {
|
| 939 |
+
lineView.text.className = cls;
|
| 940 |
+
}
|
| 941 |
+
}
|
| 942 |
+
|
| 943 |
+
function updateLineClasses(lineView) {
|
| 944 |
+
updateLineBackground(lineView);
|
| 945 |
+
if (lineView.line.wrapClass)
|
| 946 |
+
ensureLineWrapped(lineView).className = lineView.line.wrapClass;
|
| 947 |
+
else if (lineView.node != lineView.text)
|
| 948 |
+
lineView.node.className = "";
|
| 949 |
+
var textClass = lineView.textClass ? lineView.textClass + " " + (lineView.line.textClass || "") : lineView.line.textClass;
|
| 950 |
+
lineView.text.className = textClass || "";
|
| 951 |
+
}
|
| 952 |
+
|
| 953 |
+
function updateLineGutter(cm, lineView, lineN, dims) {
|
| 954 |
+
if (lineView.gutter) {
|
| 955 |
+
lineView.node.removeChild(lineView.gutter);
|
| 956 |
+
lineView.gutter = null;
|
| 957 |
+
}
|
| 958 |
+
var markers = lineView.line.gutterMarkers;
|
| 959 |
+
if (cm.options.lineNumbers || markers) {
|
| 960 |
+
var wrap = ensureLineWrapped(lineView);
|
| 961 |
+
var gutterWrap = lineView.gutter = elt("div", null, "CodeMirror-gutter-wrapper", "left: " +
|
| 962 |
+
(cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) +
|
| 963 |
+
"px; width: " + dims.gutterTotalWidth + "px");
|
| 964 |
+
cm.display.input.setUneditable(gutterWrap);
|
| 965 |
+
wrap.insertBefore(gutterWrap, lineView.text);
|
| 966 |
+
if (lineView.line.gutterClass)
|
| 967 |
+
gutterWrap.className += " " + lineView.line.gutterClass;
|
| 968 |
+
if (cm.options.lineNumbers && (!markers || !markers["CodeMirror-linenumbers"]))
|
| 969 |
+
lineView.lineNumber = gutterWrap.appendChild(
|
| 970 |
+
elt("div", lineNumberFor(cm.options, lineN),
|
| 971 |
+
"CodeMirror-linenumber CodeMirror-gutter-elt",
|
| 972 |
+
"left: " + dims.gutterLeft["CodeMirror-linenumbers"] + "px; width: "
|
| 973 |
+
+ cm.display.lineNumInnerWidth + "px"));
|
| 974 |
+
if (markers) for (var k = 0; k < cm.options.gutters.length; ++k) {
|
| 975 |
+
var id = cm.options.gutters[k], found = markers.hasOwnProperty(id) && markers[id];
|
| 976 |
+
if (found)
|
| 977 |
+
gutterWrap.appendChild(elt("div", [found], "CodeMirror-gutter-elt", "left: " +
|
| 978 |
+
dims.gutterLeft[id] + "px; width: " + dims.gutterWidth[id] + "px"));
|
| 979 |
+
}
|
| 980 |
+
}
|
| 981 |
+
}
|
| 982 |
+
|
| 983 |
+
function updateLineWidgets(cm, lineView, dims) {
|
| 984 |
+
if (lineView.alignable) lineView.alignable = null;
|
| 985 |
+
for (var node = lineView.node.firstChild, next; node; node = next) {
|
| 986 |
+
var next = node.nextSibling;
|
| 987 |
+
if (node.className == "CodeMirror-linewidget")
|
| 988 |
+
lineView.node.removeChild(node);
|
| 989 |
+
}
|
| 990 |
+
insertLineWidgets(cm, lineView, dims);
|
| 991 |
+
}
|
| 992 |
+
|
| 993 |
+
// Build a line's DOM representation from scratch
|
| 994 |
+
function buildLineElement(cm, lineView, lineN, dims) {
|
| 995 |
+
var built = getLineContent(cm, lineView);
|
| 996 |
+
lineView.text = lineView.node = built.pre;
|
| 997 |
+
if (built.bgClass) lineView.bgClass = built.bgClass;
|
| 998 |
+
if (built.textClass) lineView.textClass = built.textClass;
|
| 999 |
+
|
| 1000 |
+
updateLineClasses(lineView);
|
| 1001 |
+
updateLineGutter(cm, lineView, lineN, dims);
|
| 1002 |
+
insertLineWidgets(cm, lineView, dims);
|
| 1003 |
+
return lineView.node;
|
| 1004 |
+
}
|
| 1005 |
+
|
| 1006 |
+
// A lineView may contain multiple logical lines (when merged by
|
| 1007 |
+
// collapsed spans). The widgets for all of them need to be drawn.
|
| 1008 |
+
function insertLineWidgets(cm, lineView, dims) {
|
| 1009 |
+
insertLineWidgetsFor(cm, lineView.line, lineView, dims, true);
|
| 1010 |
+
if (lineView.rest) for (var i = 0; i < lineView.rest.length; i++)
|
| 1011 |
+
insertLineWidgetsFor(cm, lineView.rest[i], lineView, dims, false);
|
| 1012 |
+
}
|
| 1013 |
+
|
| 1014 |
+
function insertLineWidgetsFor(cm, line, lineView, dims, allowAbove) {
|
| 1015 |
+
if (!line.widgets) return;
|
| 1016 |
+
var wrap = ensureLineWrapped(lineView);
|
| 1017 |
+
for (var i = 0, ws = line.widgets; i < ws.length; ++i) {
|
| 1018 |
+
var widget = ws[i], node = elt("div", [widget.node], "CodeMirror-linewidget");
|
| 1019 |
+
if (!widget.handleMouseEvents) node.setAttribute("cm-ignore-events", "true");
|
| 1020 |
+
positionLineWidget(widget, node, lineView, dims);
|
| 1021 |
+
cm.display.input.setUneditable(node);
|
| 1022 |
+
if (allowAbove && widget.above)
|
| 1023 |
+
wrap.insertBefore(node, lineView.gutter || lineView.text);
|
| 1024 |
+
else
|
| 1025 |
+
wrap.appendChild(node);
|
| 1026 |
+
signalLater(widget, "redraw");
|
| 1027 |
+
}
|
| 1028 |
+
}
|
| 1029 |
+
|
| 1030 |
+
function positionLineWidget(widget, node, lineView, dims) {
|
| 1031 |
+
if (widget.noHScroll) {
|
| 1032 |
+
(lineView.alignable || (lineView.alignable = [])).push(node);
|
| 1033 |
+
var width = dims.wrapperWidth;
|
| 1034 |
+
node.style.left = dims.fixedPos + "px";
|
| 1035 |
+
if (!widget.coverGutter) {
|
| 1036 |
+
width -= dims.gutterTotalWidth;
|
| 1037 |
+
node.style.paddingLeft = dims.gutterTotalWidth + "px";
|
| 1038 |
+
}
|
| 1039 |
+
node.style.width = width + "px";
|
| 1040 |
+
}
|
| 1041 |
+
if (widget.coverGutter) {
|
| 1042 |
+
node.style.zIndex = 5;
|
| 1043 |
+
node.style.position = "relative";
|
| 1044 |
+
if (!widget.noHScroll) node.style.marginLeft = -dims.gutterTotalWidth + "px";
|
| 1045 |
+
}
|
| 1046 |
+
}
|
| 1047 |
+
|
| 1048 |
+
// POSITION OBJECT
|
| 1049 |
+
|
| 1050 |
+
// A Pos instance represents a position within the text.
|
| 1051 |
+
var Pos = CodeMirror.Pos = function(line, ch) {
|
| 1052 |
+
if (!(this instanceof Pos)) return new Pos(line, ch);
|
| 1053 |
+
this.line = line; this.ch = ch;
|
| 1054 |
+
};
|
| 1055 |
+
|
| 1056 |
+
// Compare two positions, return 0 if they are the same, a negative
|
| 1057 |
+
// number when a is less, and a positive number otherwise.
|
| 1058 |
+
var cmp = CodeMirror.cmpPos = function(a, b) { return a.line - b.line || a.ch - b.ch; };
|
| 1059 |
+
|
| 1060 |
+
function copyPos(x) {return Pos(x.line, x.ch);}
|
| 1061 |
+
function maxPos(a, b) { return cmp(a, b) < 0 ? b : a; }
|
| 1062 |
+
function minPos(a, b) { return cmp(a, b) < 0 ? a : b; }
|
| 1063 |
+
|
| 1064 |
+
// INPUT HANDLING
|
| 1065 |
+
|
| 1066 |
+
function ensureFocus(cm) {
|
| 1067 |
+
if (!cm.state.focused) { cm.display.input.focus(); onFocus(cm); }
|
| 1068 |
+
}
|
| 1069 |
+
|
| 1070 |
+
function isReadOnly(cm) {
|
| 1071 |
+
return cm.options.readOnly || cm.doc.cantEdit;
|
| 1072 |
+
}
|
| 1073 |
+
|
| 1074 |
+
// This will be set to an array of strings when copying, so that,
|
| 1075 |
+
// when pasting, we know what kind of selections the copied text
|
| 1076 |
+
// was made out of.
|
| 1077 |
+
var lastCopied = null;
|
| 1078 |
+
|
| 1079 |
+
function applyTextInput(cm, inserted, deleted, sel, origin) {
|
| 1080 |
+
var doc = cm.doc;
|
| 1081 |
+
cm.display.shift = false;
|
| 1082 |
+
if (!sel) sel = doc.sel;
|
| 1083 |
+
|
| 1084 |
+
var textLines = splitLines(inserted), multiPaste = null;
|
| 1085 |
+
// When pasing N lines into N selections, insert one line per selection
|
| 1086 |
+
if (cm.state.pasteIncoming && sel.ranges.length > 1) {
|
| 1087 |
+
if (lastCopied && lastCopied.join("\n") == inserted)
|
| 1088 |
+
multiPaste = sel.ranges.length % lastCopied.length == 0 && map(lastCopied, splitLines);
|
| 1089 |
+
else if (textLines.length == sel.ranges.length)
|
| 1090 |
+
multiPaste = map(textLines, function(l) { return [l]; });
|
| 1091 |
+
}
|
| 1092 |
+
|
| 1093 |
+
// Normal behavior is to insert the new text into every selection
|
| 1094 |
+
for (var i = sel.ranges.length - 1; i >= 0; i--) {
|
| 1095 |
+
var range = sel.ranges[i];
|
| 1096 |
+
var from = range.from(), to = range.to();
|
| 1097 |
+
if (range.empty()) {
|
| 1098 |
+
if (deleted && deleted > 0) // Handle deletion
|
| 1099 |
+
from = Pos(from.line, from.ch - deleted);
|
| 1100 |
+
else if (cm.state.overwrite && !cm.state.pasteIncoming) // Handle overwrite
|
| 1101 |
+
to = Pos(to.line, Math.min(getLine(doc, to.line).text.length, to.ch + lst(textLines).length));
|
| 1102 |
+
}
|
| 1103 |
+
var updateInput = cm.curOp.updateInput;
|
| 1104 |
+
var changeEvent = {from: from, to: to, text: multiPaste ? multiPaste[i % multiPaste.length] : textLines,
|
| 1105 |
+
origin: origin || (cm.state.pasteIncoming ? "paste" : cm.state.cutIncoming ? "cut" : "+input")};
|
| 1106 |
+
makeChange(cm.doc, changeEvent);
|
| 1107 |
+
signalLater(cm, "inputRead", cm, changeEvent);
|
| 1108 |
+
}
|
| 1109 |
+
if (inserted && !cm.state.pasteIncoming)
|
| 1110 |
+
triggerElectric(cm, inserted);
|
| 1111 |
+
|
| 1112 |
+
ensureCursorVisible(cm);
|
| 1113 |
+
cm.curOp.updateInput = updateInput;
|
| 1114 |
+
cm.curOp.typing = true;
|
| 1115 |
+
cm.state.pasteIncoming = cm.state.cutIncoming = false;
|
| 1116 |
+
}
|
| 1117 |
+
|
| 1118 |
+
function triggerElectric(cm, inserted) {
|
| 1119 |
+
// When an 'electric' character is inserted, immediately trigger a reindent
|
| 1120 |
+
if (!cm.options.electricChars || !cm.options.smartIndent) return;
|
| 1121 |
+
var sel = cm.doc.sel;
|
| 1122 |
+
|
| 1123 |
+
for (var i = sel.ranges.length - 1; i >= 0; i--) {
|
| 1124 |
+
var range = sel.ranges[i];
|
| 1125 |
+
if (range.head.ch > 100 || (i && sel.ranges[i - 1].head.line == range.head.line)) continue;
|
| 1126 |
+
var mode = cm.getModeAt(range.head);
|
| 1127 |
+
var indented = false;
|
| 1128 |
+
if (mode.electricChars) {
|
| 1129 |
+
for (var j = 0; j < mode.electricChars.length; j++)
|
| 1130 |
+
if (inserted.indexOf(mode.electricChars.charAt(j)) > -1) {
|
| 1131 |
+
indented = indentLine(cm, range.head.line, "smart");
|
| 1132 |
+
break;
|
| 1133 |
+
}
|
| 1134 |
+
} else if (mode.electricInput) {
|
| 1135 |
+
if (mode.electricInput.test(getLine(cm.doc, range.head.line).text.slice(0, range.head.ch)))
|
| 1136 |
+
indented = indentLine(cm, range.head.line, "smart");
|
| 1137 |
+
}
|
| 1138 |
+
if (indented) signalLater(cm, "electricInput", cm, range.head.line);
|
| 1139 |
+
}
|
| 1140 |
+
}
|
| 1141 |
+
|
| 1142 |
+
function copyableRanges(cm) {
|
| 1143 |
+
var text = [], ranges = [];
|
| 1144 |
+
for (var i = 0; i < cm.doc.sel.ranges.length; i++) {
|
| 1145 |
+
var line = cm.doc.sel.ranges[i].head.line;
|
| 1146 |
+
var lineRange = {anchor: Pos(line, 0), head: Pos(line + 1, 0)};
|
| 1147 |
+
ranges.push(lineRange);
|
| 1148 |
+
text.push(cm.getRange(lineRange.anchor, lineRange.head));
|
| 1149 |
+
}
|
| 1150 |
+
return {text: text, ranges: ranges};
|
| 1151 |
+
}
|
| 1152 |
+
|
| 1153 |
+
function disableBrowserMagic(field) {
|
| 1154 |
+
field.setAttribute("autocorrect", "off");
|
| 1155 |
+
field.setAttribute("autocapitalize", "off");
|
| 1156 |
+
field.setAttribute("spellcheck", "false");
|
| 1157 |
+
}
|
| 1158 |
+
|
| 1159 |
+
// TEXTAREA INPUT STYLE
|
| 1160 |
+
|
| 1161 |
+
function TextareaInput(cm) {
|
| 1162 |
+
this.cm = cm;
|
| 1163 |
+
// See input.poll and input.reset
|
| 1164 |
+
this.prevInput = "";
|
| 1165 |
+
|
| 1166 |
+
// Flag that indicates whether we expect input to appear real soon
|
| 1167 |
+
// now (after some event like 'keypress' or 'input') and are
|
| 1168 |
+
// polling intensively.
|
| 1169 |
+
this.pollingFast = false;
|
| 1170 |
+
// Self-resetting timeout for the poller
|
| 1171 |
+
this.polling = new Delayed();
|
| 1172 |
+
// Tracks when input.reset has punted to just putting a short
|
| 1173 |
+
// string into the textarea instead of the full selection.
|
| 1174 |
+
this.inaccurateSelection = false;
|
| 1175 |
+
// Used to work around IE issue with selection being forgotten when focus moves away from textarea
|
| 1176 |
+
this.hasSelection = false;
|
| 1177 |
+
this.composing = null;
|
| 1178 |
+
};
|
| 1179 |
+
|
| 1180 |
+
function hiddenTextarea() {
|
| 1181 |
+
var te = elt("textarea", null, null, "position: absolute; padding: 0; width: 1px; height: 1em; outline: none");
|
| 1182 |
+
var div = elt("div", [te], null, "overflow: hidden; position: relative; width: 3px; height: 0px;");
|
| 1183 |
+
// The textarea is kept positioned near the cursor to prevent the
|
| 1184 |
+
// fact that it'll be scrolled into view on input from scrolling
|
| 1185 |
+
// our fake cursor out of view. On webkit, when wrap=off, paste is
|
| 1186 |
+
// very slow. So make the area wide instead.
|
| 1187 |
+
if (webkit) te.style.width = "1000px";
|
| 1188 |
+
else te.setAttribute("wrap", "off");
|
| 1189 |
+
// If border: 0; -- iOS fails to open keyboard (issue #1287)
|
| 1190 |
+
if (ios) te.style.border = "1px solid black";
|
| 1191 |
+
disableBrowserMagic(te);
|
| 1192 |
+
return div;
|
| 1193 |
+
}
|
| 1194 |
+
|
| 1195 |
+
TextareaInput.prototype = copyObj({
|
| 1196 |
+
init: function(display) {
|
| 1197 |
+
var input = this, cm = this.cm;
|
| 1198 |
+
|
| 1199 |
+
// Wraps and hides input textarea
|
| 1200 |
+
var div = this.wrapper = hiddenTextarea();
|
| 1201 |
+
// The semihidden textarea that is focused when the editor is
|
| 1202 |
+
// focused, and receives input.
|
| 1203 |
+
var te = this.textarea = div.firstChild;
|
| 1204 |
+
display.wrapper.insertBefore(div, display.wrapper.firstChild);
|
| 1205 |
+
|
| 1206 |
+
// Needed to hide big blue blinking cursor on Mobile Safari (doesn't seem to work in iOS 8 anymore)
|
| 1207 |
+
if (ios) te.style.width = "0px";
|
| 1208 |
+
|
| 1209 |
+
on(te, "input", function() {
|
| 1210 |
+
if (ie && ie_version >= 9 && input.hasSelection) input.hasSelection = null;
|
| 1211 |
+
input.poll();
|
| 1212 |
+
});
|
| 1213 |
+
|
| 1214 |
+
on(te, "paste", function() {
|
| 1215 |
+
// Workaround for webkit bug https://bugs.webkit.org/show_bug.cgi?id=90206
|
| 1216 |
+
// Add a char to the end of textarea before paste occur so that
|
| 1217 |
+
// selection doesn't span to the end of textarea.
|
| 1218 |
+
if (webkit && !cm.state.fakedLastChar && !(new Date - cm.state.lastMiddleDown < 200)) {
|
| 1219 |
+
var start = te.selectionStart, end = te.selectionEnd;
|
| 1220 |
+
te.value += "$";
|
| 1221 |
+
// The selection end needs to be set before the start, otherwise there
|
| 1222 |
+
// can be an intermediate non-empty selection between the two, which
|
| 1223 |
+
// can override the middle-click paste buffer on linux and cause the
|
| 1224 |
+
// wrong thing to get pasted.
|
| 1225 |
+
te.selectionEnd = end;
|
| 1226 |
+
te.selectionStart = start;
|
| 1227 |
+
cm.state.fakedLastChar = true;
|
| 1228 |
+
}
|
| 1229 |
+
cm.state.pasteIncoming = true;
|
| 1230 |
+
input.fastPoll();
|
| 1231 |
+
});
|
| 1232 |
+
|
| 1233 |
+
function prepareCopyCut(e) {
|
| 1234 |
+
if (cm.somethingSelected()) {
|
| 1235 |
+
lastCopied = cm.getSelections();
|
| 1236 |
+
if (input.inaccurateSelection) {
|
| 1237 |
+
input.prevInput = "";
|
| 1238 |
+
input.inaccurateSelection = false;
|
| 1239 |
+
te.value = lastCopied.join("\n");
|
| 1240 |
+
selectInput(te);
|
| 1241 |
+
}
|
| 1242 |
+
} else if (!cm.options.lineWiseCopyCut) {
|
| 1243 |
+
return;
|
| 1244 |
+
} else {
|
| 1245 |
+
var ranges = copyableRanges(cm);
|
| 1246 |
+
lastCopied = ranges.text;
|
| 1247 |
+
if (e.type == "cut") {
|
| 1248 |
+
cm.setSelections(ranges.ranges, null, sel_dontScroll);
|
| 1249 |
+
} else {
|
| 1250 |
+
input.prevInput = "";
|
| 1251 |
+
te.value = ranges.text.join("\n");
|
| 1252 |
+
selectInput(te);
|
| 1253 |
+
}
|
| 1254 |
+
}
|
| 1255 |
+
if (e.type == "cut") cm.state.cutIncoming = true;
|
| 1256 |
+
}
|
| 1257 |
+
on(te, "cut", prepareCopyCut);
|
| 1258 |
+
on(te, "copy", prepareCopyCut);
|
| 1259 |
+
|
| 1260 |
+
on(display.scroller, "paste", function(e) {
|
| 1261 |
+
if (eventInWidget(display, e)) return;
|
| 1262 |
+
cm.state.pasteIncoming = true;
|
| 1263 |
+
input.focus();
|
| 1264 |
+
});
|
| 1265 |
+
|
| 1266 |
+
// Prevent normal selection in the editor (we handle our own)
|
| 1267 |
+
on(display.lineSpace, "selectstart", function(e) {
|
| 1268 |
+
if (!eventInWidget(display, e)) e_preventDefault(e);
|
| 1269 |
+
});
|
| 1270 |
+
|
| 1271 |
+
on(te, "compositionstart", function() {
|
| 1272 |
+
var start = cm.getCursor("from");
|
| 1273 |
+
input.composing = {
|
| 1274 |
+
start: start,
|
| 1275 |
+
range: cm.markText(start, cm.getCursor("to"), {className: "CodeMirror-composing"})
|
| 1276 |
+
};
|
| 1277 |
+
});
|
| 1278 |
+
on(te, "compositionend", function() {
|
| 1279 |
+
if (input.composing) {
|
| 1280 |
+
input.poll();
|
| 1281 |
+
input.composing.range.clear();
|
| 1282 |
+
input.composing = null;
|
| 1283 |
+
}
|
| 1284 |
+
});
|
| 1285 |
+
},
|
| 1286 |
+
|
| 1287 |
+
prepareSelection: function() {
|
| 1288 |
+
// Redraw the selection and/or cursor
|
| 1289 |
+
var cm = this.cm, display = cm.display, doc = cm.doc;
|
| 1290 |
+
var result = prepareSelection(cm);
|
| 1291 |
+
|
| 1292 |
+
// Move the hidden textarea near the cursor to prevent scrolling artifacts
|
| 1293 |
+
if (cm.options.moveInputWithCursor) {
|
| 1294 |
+
var headPos = cursorCoords(cm, doc.sel.primary().head, "div");
|
| 1295 |
+
var wrapOff = display.wrapper.getBoundingClientRect(), lineOff = display.lineDiv.getBoundingClientRect();
|
| 1296 |
+
result.teTop = Math.max(0, Math.min(display.wrapper.clientHeight - 10,
|
| 1297 |
+
headPos.top + lineOff.top - wrapOff.top));
|
| 1298 |
+
result.teLeft = Math.max(0, Math.min(display.wrapper.clientWidth - 10,
|
| 1299 |
+
headPos.left + lineOff.left - wrapOff.left));
|
| 1300 |
+
}
|
| 1301 |
+
|
| 1302 |
+
return result;
|
| 1303 |
+
},
|
| 1304 |
+
|
| 1305 |
+
showSelection: function(drawn) {
|
| 1306 |
+
var cm = this.cm, display = cm.display;
|
| 1307 |
+
removeChildrenAndAdd(display.cursorDiv, drawn.cursors);
|
| 1308 |
+
removeChildrenAndAdd(display.selectionDiv, drawn.selection);
|
| 1309 |
+
if (drawn.teTop != null) {
|
| 1310 |
+
this.wrapper.style.top = drawn.teTop + "px";
|
| 1311 |
+
this.wrapper.style.left = drawn.teLeft + "px";
|
| 1312 |
+
}
|
| 1313 |
+
},
|
| 1314 |
+
|
| 1315 |
+
// Reset the input to correspond to the selection (or to be empty,
|
| 1316 |
+
// when not typing and nothing is selected)
|
| 1317 |
+
reset: function(typing) {
|
| 1318 |
+
if (this.contextMenuPending) return;
|
| 1319 |
+
var minimal, selected, cm = this.cm, doc = cm.doc;
|
| 1320 |
+
if (cm.somethingSelected()) {
|
| 1321 |
+
this.prevInput = "";
|
| 1322 |
+
var range = doc.sel.primary();
|
| 1323 |
+
minimal = hasCopyEvent &&
|
| 1324 |
+
(range.to().line - range.from().line > 100 || (selected = cm.getSelection()).length > 1000);
|
| 1325 |
+
var content = minimal ? "-" : selected || cm.getSelection();
|
| 1326 |
+
this.textarea.value = content;
|
| 1327 |
+
if (cm.state.focused) selectInput(this.textarea);
|
| 1328 |
+
if (ie && ie_version >= 9) this.hasSelection = content;
|
| 1329 |
+
} else if (!typing) {
|
| 1330 |
+
this.prevInput = this.textarea.value = "";
|
| 1331 |
+
if (ie && ie_version >= 9) this.hasSelection = null;
|
| 1332 |
+
}
|
| 1333 |
+
this.inaccurateSelection = minimal;
|
| 1334 |
+
},
|
| 1335 |
+
|
| 1336 |
+
getField: function() { return this.textarea; },
|
| 1337 |
+
|
| 1338 |
+
supportsTouch: function() { return false; },
|
| 1339 |
+
|
| 1340 |
+
focus: function() {
|
| 1341 |
+
if (this.cm.options.readOnly != "nocursor" && (!mobile || activeElt() != this.textarea)) {
|
| 1342 |
+
try { this.textarea.focus(); }
|
| 1343 |
+
catch (e) {} // IE8 will throw if the textarea is display: none or not in DOM
|
| 1344 |
+
}
|
| 1345 |
+
},
|
| 1346 |
+
|
| 1347 |
+
blur: function() { this.textarea.blur(); },
|
| 1348 |
+
|
| 1349 |
+
resetPosition: function() {
|
| 1350 |
+
this.wrapper.style.top = this.wrapper.style.left = 0;
|
| 1351 |
+
},
|
| 1352 |
+
|
| 1353 |
+
receivedFocus: function() { this.slowPoll(); },
|
| 1354 |
+
|
| 1355 |
+
// Poll for input changes, using the normal rate of polling. This
|
| 1356 |
+
// runs as long as the editor is focused.
|
| 1357 |
+
slowPoll: function() {
|
| 1358 |
+
var input = this;
|
| 1359 |
+
if (input.pollingFast) return;
|
| 1360 |
+
input.polling.set(this.cm.options.pollInterval, function() {
|
| 1361 |
+
input.poll();
|
| 1362 |
+
if (input.cm.state.focused) input.slowPoll();
|
| 1363 |
+
});
|
| 1364 |
+
},
|
| 1365 |
+
|
| 1366 |
+
// When an event has just come in that is likely to add or change
|
| 1367 |
+
// something in the input textarea, we poll faster, to ensure that
|
| 1368 |
+
// the change appears on the screen quickly.
|
| 1369 |
+
fastPoll: function() {
|
| 1370 |
+
var missed = false, input = this;
|
| 1371 |
+
input.pollingFast = true;
|
| 1372 |
+
function p() {
|
| 1373 |
+
var changed = input.poll();
|
| 1374 |
+
if (!changed && !missed) {missed = true; input.polling.set(60, p);}
|
| 1375 |
+
else {input.pollingFast = false; input.slowPoll();}
|
| 1376 |
+
}
|
| 1377 |
+
input.polling.set(20, p);
|
| 1378 |
+
},
|
| 1379 |
+
|
| 1380 |
+
// Read input from the textarea, and update the document to match.
|
| 1381 |
+
// When something is selected, it is present in the textarea, and
|
| 1382 |
+
// selected (unless it is huge, in which case a placeholder is
|
| 1383 |
+
// used). When nothing is selected, the cursor sits after previously
|
| 1384 |
+
// seen text (can be empty), which is stored in prevInput (we must
|
| 1385 |
+
// not reset the textarea when typing, because that breaks IME).
|
| 1386 |
+
poll: function() {
|
| 1387 |
+
var cm = this.cm, input = this.textarea, prevInput = this.prevInput;
|
| 1388 |
+
// Since this is called a *lot*, try to bail out as cheaply as
|
| 1389 |
+
// possible when it is clear that nothing happened. hasSelection
|
| 1390 |
+
// will be the case when there is a lot of text in the textarea,
|
| 1391 |
+
// in which case reading its value would be expensive.
|
| 1392 |
+
if (this.contextMenuPending || !cm.state.focused ||
|
| 1393 |
+
(hasSelection(input) && !prevInput) ||
|
| 1394 |
+
isReadOnly(cm) || cm.options.disableInput || cm.state.keySeq)
|
| 1395 |
+
return false;
|
| 1396 |
+
|
| 1397 |
+
// See paste handler for more on the fakedLastChar kludge
|
| 1398 |
+
if (cm.state.pasteIncoming && cm.state.fakedLastChar) {
|
| 1399 |
+
input.value = input.value.substring(0, input.value.length - 1);
|
| 1400 |
+
cm.state.fakedLastChar = false;
|
| 1401 |
+
}
|
| 1402 |
+
var text = input.value;
|
| 1403 |
+
// If nothing changed, bail.
|
| 1404 |
+
if (text == prevInput && !cm.somethingSelected()) return false;
|
| 1405 |
+
// Work around nonsensical selection resetting in IE9/10, and
|
| 1406 |
+
// inexplicable appearance of private area unicode characters on
|
| 1407 |
+
// some key combos in Mac (#2689).
|
| 1408 |
+
if (ie && ie_version >= 9 && this.hasSelection === text ||
|
| 1409 |
+
mac && /[\uf700-\uf7ff]/.test(text)) {
|
| 1410 |
+
cm.display.input.reset();
|
| 1411 |
+
return false;
|
| 1412 |
+
}
|
| 1413 |
+
|
| 1414 |
+
if (cm.doc.sel == cm.display.selForContextMenu) {
|
| 1415 |
+
var first = text.charCodeAt(0);
|
| 1416 |
+
if (first == 0x200b && !prevInput) prevInput = "\u200b";
|
| 1417 |
+
if (first == 0x21da) { this.reset(); return this.cm.execCommand("undo"); }
|
| 1418 |
+
}
|
| 1419 |
+
// Find the part of the input that is actually new
|
| 1420 |
+
var same = 0, l = Math.min(prevInput.length, text.length);
|
| 1421 |
+
while (same < l && prevInput.charCodeAt(same) == text.charCodeAt(same)) ++same;
|
| 1422 |
+
|
| 1423 |
+
var self = this;
|
| 1424 |
+
runInOp(cm, function() {
|
| 1425 |
+
applyTextInput(cm, text.slice(same), prevInput.length - same,
|
| 1426 |
+
null, self.composing ? "*compose" : null);
|
| 1427 |
+
|
| 1428 |
+
// Don't leave long text in the textarea, since it makes further polling slow
|
| 1429 |
+
if (text.length > 1000 || text.indexOf("\n") > -1) input.value = self.prevInput = "";
|
| 1430 |
+
else self.prevInput = text;
|
| 1431 |
+
|
| 1432 |
+
if (self.composing) {
|
| 1433 |
+
self.composing.range.clear();
|
| 1434 |
+
self.composing.range = cm.markText(self.composing.start, cm.getCursor("to"),
|
| 1435 |
+
{className: "CodeMirror-composing"});
|
| 1436 |
+
}
|
| 1437 |
+
});
|
| 1438 |
+
return true;
|
| 1439 |
+
},
|
| 1440 |
+
|
| 1441 |
+
ensurePolled: function() {
|
| 1442 |
+
if (this.pollingFast && this.poll()) this.pollingFast = false;
|
| 1443 |
+
},
|
| 1444 |
+
|
| 1445 |
+
onKeyPress: function() {
|
| 1446 |
+
if (ie && ie_version >= 9) this.hasSelection = null;
|
| 1447 |
+
this.fastPoll();
|
| 1448 |
+
},
|
| 1449 |
+
|
| 1450 |
+
onContextMenu: function(e) {
|
| 1451 |
+
var input = this, cm = input.cm, display = cm.display, te = input.textarea;
|
| 1452 |
+
var pos = posFromMouse(cm, e), scrollPos = display.scroller.scrollTop;
|
| 1453 |
+
if (!pos || presto) return; // Opera is difficult.
|
| 1454 |
+
|
| 1455 |
+
// Reset the current text selection only if the click is done outside of the selection
|
| 1456 |
+
// and 'resetSelectionOnContextMenu' option is true.
|
| 1457 |
+
var reset = cm.options.resetSelectionOnContextMenu;
|
| 1458 |
+
if (reset && cm.doc.sel.contains(pos) == -1)
|
| 1459 |
+
operation(cm, setSelection)(cm.doc, simpleSelection(pos), sel_dontScroll);
|
| 1460 |
+
|
| 1461 |
+
var oldCSS = te.style.cssText;
|
| 1462 |
+
input.wrapper.style.position = "absolute";
|
| 1463 |
+
te.style.cssText = "position: fixed; width: 30px; height: 30px; top: " + (e.clientY - 5) +
|
| 1464 |
+
"px; left: " + (e.clientX - 5) + "px; z-index: 1000; background: " +
|
| 1465 |
+
(ie ? "rgba(255, 255, 255, .05)" : "transparent") +
|
| 1466 |
+
"; outline: none; border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);";
|
| 1467 |
+
if (webkit) var oldScrollY = window.scrollY; // Work around Chrome issue (#2712)
|
| 1468 |
+
display.input.focus();
|
| 1469 |
+
if (webkit) window.scrollTo(null, oldScrollY);
|
| 1470 |
+
display.input.reset();
|
| 1471 |
+
// Adds "Select all" to context menu in FF
|
| 1472 |
+
if (!cm.somethingSelected()) te.value = input.prevInput = " ";
|
| 1473 |
+
input.contextMenuPending = true;
|
| 1474 |
+
display.selForContextMenu = cm.doc.sel;
|
| 1475 |
+
clearTimeout(display.detectingSelectAll);
|
| 1476 |
+
|
| 1477 |
+
// Select-all will be greyed out if there's nothing to select, so
|
| 1478 |
+
// this adds a zero-width space so that we can later check whether
|
| 1479 |
+
// it got selected.
|
| 1480 |
+
function prepareSelectAllHack() {
|
| 1481 |
+
if (te.selectionStart != null) {
|
| 1482 |
+
var selected = cm.somethingSelected();
|
| 1483 |
+
var extval = "\u200b" + (selected ? te.value : "");
|
| 1484 |
+
te.value = "\u21da"; // Used to catch context-menu undo
|
| 1485 |
+
te.value = extval;
|
| 1486 |
+
input.prevInput = selected ? "" : "\u200b";
|
| 1487 |
+
te.selectionStart = 1; te.selectionEnd = extval.length;
|
| 1488 |
+
// Re-set this, in case some other handler touched the
|
| 1489 |
+
// selection in the meantime.
|
| 1490 |
+
display.selForContextMenu = cm.doc.sel;
|
| 1491 |
+
}
|
| 1492 |
+
}
|
| 1493 |
+
function rehide() {
|
| 1494 |
+
input.contextMenuPending = false;
|
| 1495 |
+
input.wrapper.style.position = "relative";
|
| 1496 |
+
te.style.cssText = oldCSS;
|
| 1497 |
+
if (ie && ie_version < 9) display.scrollbars.setScrollTop(display.scroller.scrollTop = scrollPos);
|
| 1498 |
+
|
| 1499 |
+
// Try to detect the user choosing select-all
|
| 1500 |
+
if (te.selectionStart != null) {
|
| 1501 |
+
if (!ie || (ie && ie_version < 9)) prepareSelectAllHack();
|
| 1502 |
+
var i = 0, poll = function() {
|
| 1503 |
+
if (display.selForContextMenu == cm.doc.sel && te.selectionStart == 0 &&
|
| 1504 |
+
te.selectionEnd > 0 && input.prevInput == "\u200b")
|
| 1505 |
+
operation(cm, commands.selectAll)(cm);
|
| 1506 |
+
else if (i++ < 10) display.detectingSelectAll = setTimeout(poll, 500);
|
| 1507 |
+
else display.input.reset();
|
| 1508 |
+
};
|
| 1509 |
+
display.detectingSelectAll = setTimeout(poll, 200);
|
| 1510 |
+
}
|
| 1511 |
+
}
|
| 1512 |
+
|
| 1513 |
+
if (ie && ie_version >= 9) prepareSelectAllHack();
|
| 1514 |
+
if (captureRightClick) {
|
| 1515 |
+
e_stop(e);
|
| 1516 |
+
var mouseup = function() {
|
| 1517 |
+
off(window, "mouseup", mouseup);
|
| 1518 |
+
setTimeout(rehide, 20);
|
| 1519 |
+
};
|
| 1520 |
+
on(window, "mouseup", mouseup);
|
| 1521 |
+
} else {
|
| 1522 |
+
setTimeout(rehide, 50);
|
| 1523 |
+
}
|
| 1524 |
+
},
|
| 1525 |
+
|
| 1526 |
+
setUneditable: nothing,
|
| 1527 |
+
|
| 1528 |
+
needsContentAttribute: false
|
| 1529 |
+
}, TextareaInput.prototype);
|
| 1530 |
+
|
| 1531 |
+
// CONTENTEDITABLE INPUT STYLE
|
| 1532 |
+
|
| 1533 |
+
function ContentEditableInput(cm) {
|
| 1534 |
+
this.cm = cm;
|
| 1535 |
+
this.lastAnchorNode = this.lastAnchorOffset = this.lastFocusNode = this.lastFocusOffset = null;
|
| 1536 |
+
this.polling = new Delayed();
|
| 1537 |
+
this.gracePeriod = false;
|
| 1538 |
+
}
|
| 1539 |
+
|
| 1540 |
+
ContentEditableInput.prototype = copyObj({
|
| 1541 |
+
init: function(display) {
|
| 1542 |
+
var input = this, cm = input.cm;
|
| 1543 |
+
var div = input.div = display.lineDiv;
|
| 1544 |
+
div.contentEditable = "true";
|
| 1545 |
+
disableBrowserMagic(div);
|
| 1546 |
+
|
| 1547 |
+
on(div, "paste", function(e) {
|
| 1548 |
+
var pasted = e.clipboardData && e.clipboardData.getData("text/plain");
|
| 1549 |
+
if (pasted) {
|
| 1550 |
+
e.preventDefault();
|
| 1551 |
+
cm.replaceSelection(pasted, null, "paste");
|
| 1552 |
+
}
|
| 1553 |
+
});
|
| 1554 |
+
|
| 1555 |
+
on(div, "compositionstart", function(e) {
|
| 1556 |
+
var data = e.data;
|
| 1557 |
+
input.composing = {sel: cm.doc.sel, data: data, startData: data};
|
| 1558 |
+
if (!data) return;
|
| 1559 |
+
var prim = cm.doc.sel.primary();
|
| 1560 |
+
var line = cm.getLine(prim.head.line);
|
| 1561 |
+
var found = line.indexOf(data, Math.max(0, prim.head.ch - data.length));
|
| 1562 |
+
if (found > -1 && found <= prim.head.ch)
|
| 1563 |
+
input.composing.sel = simpleSelection(Pos(prim.head.line, found),
|
| 1564 |
+
Pos(prim.head.line, found + data.length));
|
| 1565 |
+
});
|
| 1566 |
+
on(div, "compositionupdate", function(e) {
|
| 1567 |
+
input.composing.data = e.data;
|
| 1568 |
+
});
|
| 1569 |
+
on(div, "compositionend", function(e) {
|
| 1570 |
+
var ours = input.composing;
|
| 1571 |
+
if (!ours) return;
|
| 1572 |
+
if (e.data != ours.startData && !/\u200b/.test(e.data))
|
| 1573 |
+
ours.data = e.data;
|
| 1574 |
+
// Need a small delay to prevent other code (input event,
|
| 1575 |
+
// selection polling) from doing damage when fired right after
|
| 1576 |
+
// compositionend.
|
| 1577 |
+
setTimeout(function() {
|
| 1578 |
+
if (!ours.handled)
|
| 1579 |
+
input.applyComposition(ours);
|
| 1580 |
+
if (input.composing == ours)
|
| 1581 |
+
input.composing = null;
|
| 1582 |
+
}, 50);
|
| 1583 |
+
});
|
| 1584 |
+
|
| 1585 |
+
on(div, "touchstart", function() {
|
| 1586 |
+
input.forceCompositionEnd();
|
| 1587 |
+
});
|
| 1588 |
+
|
| 1589 |
+
on(div, "input", function() {
|
| 1590 |
+
if (input.composing) return;
|
| 1591 |
+
if (!input.pollContent())
|
| 1592 |
+
runInOp(input.cm, function() {regChange(cm);});
|
| 1593 |
+
});
|
| 1594 |
+
|
| 1595 |
+
function onCopyCut(e) {
|
| 1596 |
+
if (cm.somethingSelected()) {
|
| 1597 |
+
lastCopied = cm.getSelections();
|
| 1598 |
+
if (e.type == "cut") cm.replaceSelection("", null, "cut");
|
| 1599 |
+
} else if (!cm.options.lineWiseCopyCut) {
|
| 1600 |
+
return;
|
| 1601 |
+
} else {
|
| 1602 |
+
var ranges = copyableRanges(cm);
|
| 1603 |
+
lastCopied = ranges.text;
|
| 1604 |
+
if (e.type == "cut") {
|
| 1605 |
+
cm.operation(function() {
|
| 1606 |
+
cm.setSelections(ranges.ranges, 0, sel_dontScroll);
|
| 1607 |
+
cm.replaceSelection("", null, "cut");
|
| 1608 |
+
});
|
| 1609 |
+
}
|
| 1610 |
+
}
|
| 1611 |
+
// iOS exposes the clipboard API, but seems to discard content inserted into it
|
| 1612 |
+
if (e.clipboardData && !ios) {
|
| 1613 |
+
e.preventDefault();
|
| 1614 |
+
e.clipboardData.clearData();
|
| 1615 |
+
e.clipboardData.setData("text/plain", lastCopied.join("\n"));
|
| 1616 |
+
} else {
|
| 1617 |
+
// Old-fashioned briefly-focus-a-textarea hack
|
| 1618 |
+
var kludge = hiddenTextarea(), te = kludge.firstChild;
|
| 1619 |
+
cm.display.lineSpace.insertBefore(kludge, cm.display.lineSpace.firstChild);
|
| 1620 |
+
te.value = lastCopied.join("\n");
|
| 1621 |
+
var hadFocus = document.activeElement;
|
| 1622 |
+
selectInput(te);
|
| 1623 |
+
setTimeout(function() {
|
| 1624 |
+
cm.display.lineSpace.removeChild(kludge);
|
| 1625 |
+
hadFocus.focus();
|
| 1626 |
+
}, 50);
|
| 1627 |
+
}
|
| 1628 |
+
}
|
| 1629 |
+
on(div, "copy", onCopyCut);
|
| 1630 |
+
on(div, "cut", onCopyCut);
|
| 1631 |
+
},
|
| 1632 |
+
|
| 1633 |
+
prepareSelection: function() {
|
| 1634 |
+
var result = prepareSelection(this.cm, false);
|
| 1635 |
+
result.focus = this.cm.state.focused;
|
| 1636 |
+
return result;
|
| 1637 |
+
},
|
| 1638 |
+
|
| 1639 |
+
showSelection: function(info) {
|
| 1640 |
+
if (!info || !this.cm.display.view.length) return;
|
| 1641 |
+
if (info.focus) this.showPrimarySelection();
|
| 1642 |
+
this.showMultipleSelections(info);
|
| 1643 |
+
},
|
| 1644 |
+
|
| 1645 |
+
showPrimarySelection: function() {
|
| 1646 |
+
var sel = window.getSelection(), prim = this.cm.doc.sel.primary();
|
| 1647 |
+
var curAnchor = domToPos(this.cm, sel.anchorNode, sel.anchorOffset);
|
| 1648 |
+
var curFocus = domToPos(this.cm, sel.focusNode, sel.focusOffset);
|
| 1649 |
+
if (curAnchor && !curAnchor.bad && curFocus && !curFocus.bad &&
|
| 1650 |
+
cmp(minPos(curAnchor, curFocus), prim.from()) == 0 &&
|
| 1651 |
+
cmp(maxPos(curAnchor, curFocus), prim.to()) == 0)
|
| 1652 |
+
return;
|
| 1653 |
+
|
| 1654 |
+
var start = posToDOM(this.cm, prim.from());
|
| 1655 |
+
var end = posToDOM(this.cm, prim.to());
|
| 1656 |
+
if (!start && !end) return;
|
| 1657 |
+
|
| 1658 |
+
var view = this.cm.display.view;
|
| 1659 |
+
var old = sel.rangeCount && sel.getRangeAt(0);
|
| 1660 |
+
if (!start) {
|
| 1661 |
+
start = {node: view[0].measure.map[2], offset: 0};
|
| 1662 |
+
} else if (!end) { // FIXME dangerously hacky
|
| 1663 |
+
var measure = view[view.length - 1].measure;
|
| 1664 |
+
var map = measure.maps ? measure.maps[measure.maps.length - 1] : measure.map;
|
| 1665 |
+
end = {node: map[map.length - 1], offset: map[map.length - 2] - map[map.length - 3]};
|
| 1666 |
+
}
|
| 1667 |
+
|
| 1668 |
+
try { var rng = range(start.node, start.offset, end.offset, end.node); }
|
| 1669 |
+
catch(e) {} // Our model of the DOM might be outdated, in which case the range we try to set can be impossible
|
| 1670 |
+
if (rng) {
|
| 1671 |
+
sel.removeAllRanges();
|
| 1672 |
+
sel.addRange(rng);
|
| 1673 |
+
if (old && sel.anchorNode == null) sel.addRange(old);
|
| 1674 |
+
else if (gecko) this.startGracePeriod();
|
| 1675 |
+
}
|
| 1676 |
+
this.rememberSelection();
|
| 1677 |
+
},
|
| 1678 |
+
|
| 1679 |
+
startGracePeriod: function() {
|
| 1680 |
+
var input = this;
|
| 1681 |
+
clearTimeout(this.gracePeriod);
|
| 1682 |
+
this.gracePeriod = setTimeout(function() {
|
| 1683 |
+
input.gracePeriod = false;
|
| 1684 |
+
if (input.selectionChanged())
|
| 1685 |
+
input.cm.operation(function() { input.cm.curOp.selectionChanged = true; });
|
| 1686 |
+
}, 20);
|
| 1687 |
+
},
|
| 1688 |
+
|
| 1689 |
+
showMultipleSelections: function(info) {
|
| 1690 |
+
removeChildrenAndAdd(this.cm.display.cursorDiv, info.cursors);
|
| 1691 |
+
removeChildrenAndAdd(this.cm.display.selectionDiv, info.selection);
|
| 1692 |
+
},
|
| 1693 |
+
|
| 1694 |
+
rememberSelection: function() {
|
| 1695 |
+
var sel = window.getSelection();
|
| 1696 |
+
this.lastAnchorNode = sel.anchorNode; this.lastAnchorOffset = sel.anchorOffset;
|
| 1697 |
+
this.lastFocusNode = sel.focusNode; this.lastFocusOffset = sel.focusOffset;
|
| 1698 |
+
},
|
| 1699 |
+
|
| 1700 |
+
selectionInEditor: function() {
|
| 1701 |
+
var sel = window.getSelection();
|
| 1702 |
+
if (!sel.rangeCount) return false;
|
| 1703 |
+
var node = sel.getRangeAt(0).commonAncestorContainer;
|
| 1704 |
+
return contains(this.div, node);
|
| 1705 |
+
},
|
| 1706 |
+
|
| 1707 |
+
focus: function() {
|
| 1708 |
+
if (this.cm.options.readOnly != "nocursor") this.div.focus();
|
| 1709 |
+
},
|
| 1710 |
+
blur: function() { this.div.blur(); },
|
| 1711 |
+
getField: function() { return this.div; },
|
| 1712 |
+
|
| 1713 |
+
supportsTouch: function() { return true; },
|
| 1714 |
+
|
| 1715 |
+
receivedFocus: function() {
|
| 1716 |
+
var input = this;
|
| 1717 |
+
if (this.selectionInEditor())
|
| 1718 |
+
this.pollSelection();
|
| 1719 |
+
else
|
| 1720 |
+
runInOp(this.cm, function() { input.cm.curOp.selectionChanged = true; });
|
| 1721 |
+
|
| 1722 |
+
function poll() {
|
| 1723 |
+
if (input.cm.state.focused) {
|
| 1724 |
+
input.pollSelection();
|
| 1725 |
+
input.polling.set(input.cm.options.pollInterval, poll);
|
| 1726 |
+
}
|
| 1727 |
+
}
|
| 1728 |
+
this.polling.set(this.cm.options.pollInterval, poll);
|
| 1729 |
+
},
|
| 1730 |
+
|
| 1731 |
+
selectionChanged: function() {
|
| 1732 |
+
var sel = window.getSelection();
|
| 1733 |
+
return sel.anchorNode != this.lastAnchorNode || sel.anchorOffset != this.lastAnchorOffset ||
|
| 1734 |
+
sel.focusNode != this.lastFocusNode || sel.focusOffset != this.lastFocusOffset;
|
| 1735 |
+
},
|
| 1736 |
+
|
| 1737 |
+
pollSelection: function() {
|
| 1738 |
+
if (!this.composing && !this.gracePeriod && this.selectionChanged()) {
|
| 1739 |
+
var sel = window.getSelection(), cm = this.cm;
|
| 1740 |
+
this.rememberSelection();
|
| 1741 |
+
var anchor = domToPos(cm, sel.anchorNode, sel.anchorOffset);
|
| 1742 |
+
var head = domToPos(cm, sel.focusNode, sel.focusOffset);
|
| 1743 |
+
if (anchor && head) runInOp(cm, function() {
|
| 1744 |
+
setSelection(cm.doc, simpleSelection(anchor, head), sel_dontScroll);
|
| 1745 |
+
if (anchor.bad || head.bad) cm.curOp.selectionChanged = true;
|
| 1746 |
+
});
|
| 1747 |
+
}
|
| 1748 |
+
},
|
| 1749 |
+
|
| 1750 |
+
pollContent: function() {
|
| 1751 |
+
var cm = this.cm, display = cm.display, sel = cm.doc.sel.primary();
|
| 1752 |
+
var from = sel.from(), to = sel.to();
|
| 1753 |
+
if (from.line < display.viewFrom || to.line > display.viewTo - 1) return false;
|
| 1754 |
+
|
| 1755 |
+
var fromIndex;
|
| 1756 |
+
if (from.line == display.viewFrom || (fromIndex = findViewIndex(cm, from.line)) == 0) {
|
| 1757 |
+
var fromLine = lineNo(display.view[0].line);
|
| 1758 |
+
var fromNode = display.view[0].node;
|
| 1759 |
+
} else {
|
| 1760 |
+
var fromLine = lineNo(display.view[fromIndex].line);
|
| 1761 |
+
var fromNode = display.view[fromIndex - 1].node.nextSibling;
|
| 1762 |
+
}
|
| 1763 |
+
var toIndex = findViewIndex(cm, to.line);
|
| 1764 |
+
if (toIndex == display.view.length - 1) {
|
| 1765 |
+
var toLine = display.viewTo - 1;
|
| 1766 |
+
var toNode = display.view[toIndex].node;
|
| 1767 |
+
} else {
|
| 1768 |
+
var toLine = lineNo(display.view[toIndex + 1].line) - 1;
|
| 1769 |
+
var toNode = display.view[toIndex + 1].node.previousSibling;
|
| 1770 |
+
}
|
| 1771 |
+
|
| 1772 |
+
var newText = splitLines(domTextBetween(cm, fromNode, toNode, fromLine, toLine));
|
| 1773 |
+
var oldText = getBetween(cm.doc, Pos(fromLine, 0), Pos(toLine, getLine(cm.doc, toLine).text.length));
|
| 1774 |
+
while (newText.length > 1 && oldText.length > 1) {
|
| 1775 |
+
if (lst(newText) == lst(oldText)) { newText.pop(); oldText.pop(); toLine--; }
|
| 1776 |
+
else if (newText[0] == oldText[0]) { newText.shift(); oldText.shift(); fromLine++; }
|
| 1777 |
+
else break;
|
| 1778 |
+
}
|
| 1779 |
+
|
| 1780 |
+
var cutFront = 0, cutEnd = 0;
|
| 1781 |
+
var newTop = newText[0], oldTop = oldText[0], maxCutFront = Math.min(newTop.length, oldTop.length);
|
| 1782 |
+
while (cutFront < maxCutFront && newTop.charCodeAt(cutFront) == oldTop.charCodeAt(cutFront))
|
| 1783 |
+
++cutFront;
|
| 1784 |
+
var newBot = lst(newText), oldBot = lst(oldText);
|
| 1785 |
+
var maxCutEnd = Math.min(newBot.length - (newText.length == 1 ? cutFront : 0),
|
| 1786 |
+
oldBot.length - (oldText.length == 1 ? cutFront : 0));
|
| 1787 |
+
while (cutEnd < maxCutEnd &&
|
| 1788 |
+
newBot.charCodeAt(newBot.length - cutEnd - 1) == oldBot.charCodeAt(oldBot.length - cutEnd - 1))
|
| 1789 |
+
++cutEnd;
|
| 1790 |
+
|
| 1791 |
+
newText[newText.length - 1] = newBot.slice(0, newBot.length - cutEnd);
|
| 1792 |
+
newText[0] = newText[0].slice(cutFront);
|
| 1793 |
+
|
| 1794 |
+
var chFrom = Pos(fromLine, cutFront);
|
| 1795 |
+
var chTo = Pos(toLine, oldText.length ? lst(oldText).length - cutEnd : 0);
|
| 1796 |
+
if (newText.length > 1 || newText[0] || cmp(chFrom, chTo)) {
|
| 1797 |
+
replaceRange(cm.doc, newText, chFrom, chTo, "+input");
|
| 1798 |
+
return true;
|
| 1799 |
+
}
|
| 1800 |
+
},
|
| 1801 |
+
|
| 1802 |
+
ensurePolled: function() {
|
| 1803 |
+
this.forceCompositionEnd();
|
| 1804 |
+
},
|
| 1805 |
+
reset: function() {
|
| 1806 |
+
this.forceCompositionEnd();
|
| 1807 |
+
},
|
| 1808 |
+
forceCompositionEnd: function() {
|
| 1809 |
+
if (!this.composing || this.composing.handled) return;
|
| 1810 |
+
this.applyComposition(this.composing);
|
| 1811 |
+
this.composing.handled = true;
|
| 1812 |
+
this.div.blur();
|
| 1813 |
+
this.div.focus();
|
| 1814 |
+
},
|
| 1815 |
+
applyComposition: function(composing) {
|
| 1816 |
+
if (composing.data && composing.data != composing.startData)
|
| 1817 |
+
operation(this.cm, applyTextInput)(this.cm, composing.data, 0, composing.sel);
|
| 1818 |
+
},
|
| 1819 |
+
|
| 1820 |
+
setUneditable: function(node) {
|
| 1821 |
+
node.setAttribute("contenteditable", "false");
|
| 1822 |
+
},
|
| 1823 |
+
|
| 1824 |
+
onKeyPress: function(e) {
|
| 1825 |
+
e.preventDefault();
|
| 1826 |
+
operation(this.cm, applyTextInput)(this.cm, String.fromCharCode(e.charCode == null ? e.keyCode : e.charCode), 0);
|
| 1827 |
+
},
|
| 1828 |
+
|
| 1829 |
+
onContextMenu: nothing,
|
| 1830 |
+
resetPosition: nothing,
|
| 1831 |
+
|
| 1832 |
+
needsContentAttribute: true
|
| 1833 |
+
}, ContentEditableInput.prototype);
|
| 1834 |
+
|
| 1835 |
+
function posToDOM(cm, pos) {
|
| 1836 |
+
var view = findViewForLine(cm, pos.line);
|
| 1837 |
+
if (!view || view.hidden) return null;
|
| 1838 |
+
var line = getLine(cm.doc, pos.line);
|
| 1839 |
+
var info = mapFromLineView(view, line, pos.line);
|
| 1840 |
+
|
| 1841 |
+
var order = getOrder(line), side = "left";
|
| 1842 |
+
if (order) {
|
| 1843 |
+
var partPos = getBidiPartAt(order, pos.ch);
|
| 1844 |
+
side = partPos % 2 ? "right" : "left";
|
| 1845 |
+
}
|
| 1846 |
+
var result = nodeAndOffsetInLineMap(info.map, pos.ch, side);
|
| 1847 |
+
result.offset = result.collapse == "right" ? result.end : result.start;
|
| 1848 |
+
return result;
|
| 1849 |
+
}
|
| 1850 |
+
|
| 1851 |
+
function badPos(pos, bad) { if (bad) pos.bad = true; return pos; }
|
| 1852 |
+
|
| 1853 |
+
function domToPos(cm, node, offset) {
|
| 1854 |
+
var lineNode;
|
| 1855 |
+
if (node == cm.display.lineDiv) {
|
| 1856 |
+
lineNode = cm.display.lineDiv.childNodes[offset];
|
| 1857 |
+
if (!lineNode) return badPos(cm.clipPos(Pos(cm.display.viewTo - 1)), true);
|
| 1858 |
+
node = null; offset = 0;
|
| 1859 |
+
} else {
|
| 1860 |
+
for (lineNode = node;; lineNode = lineNode.parentNode) {
|
| 1861 |
+
if (!lineNode || lineNode == cm.display.lineDiv) return null;
|
| 1862 |
+
if (lineNode.parentNode && lineNode.parentNode == cm.display.lineDiv) break;
|
| 1863 |
+
}
|
| 1864 |
+
}
|
| 1865 |
+
for (var i = 0; i < cm.display.view.length; i++) {
|
| 1866 |
+
var lineView = cm.display.view[i];
|
| 1867 |
+
if (lineView.node == lineNode)
|
| 1868 |
+
return locateNodeInLineView(lineView, node, offset);
|
| 1869 |
+
}
|
| 1870 |
+
}
|
| 1871 |
+
|
| 1872 |
+
function locateNodeInLineView(lineView, node, offset) {
|
| 1873 |
+
var wrapper = lineView.text.firstChild, bad = false;
|
| 1874 |
+
if (!node || !contains(wrapper, node)) return badPos(Pos(lineNo(lineView.line), 0), true);
|
| 1875 |
+
if (node == wrapper) {
|
| 1876 |
+
bad = true;
|
| 1877 |
+
node = wrapper.childNodes[offset];
|
| 1878 |
+
offset = 0;
|
| 1879 |
+
if (!node) {
|
| 1880 |
+
var line = lineView.rest ? lst(lineView.rest) : lineView.line;
|
| 1881 |
+
return badPos(Pos(lineNo(line), line.text.length), bad);
|
| 1882 |
+
}
|
| 1883 |
+
}
|
| 1884 |
+
|
| 1885 |
+
var textNode = node.nodeType == 3 ? node : null, topNode = node;
|
| 1886 |
+
if (!textNode && node.childNodes.length == 1 && node.firstChild.nodeType == 3) {
|
| 1887 |
+
textNode = node.firstChild;
|
| 1888 |
+
if (offset) offset = textNode.nodeValue.length;
|
| 1889 |
+
}
|
| 1890 |
+
while (topNode.parentNode != wrapper) topNode = topNode.parentNode;
|
| 1891 |
+
var measure = lineView.measure, maps = measure.maps;
|
| 1892 |
+
|
| 1893 |
+
function find(textNode, topNode, offset) {
|
| 1894 |
+
for (var i = -1; i < (maps ? maps.length : 0); i++) {
|
| 1895 |
+
var map = i < 0 ? measure.map : maps[i];
|
| 1896 |
+
for (var j = 0; j < map.length; j += 3) {
|
| 1897 |
+
var curNode = map[j + 2];
|
| 1898 |
+
if (curNode == textNode || curNode == topNode) {
|
| 1899 |
+
var line = lineNo(i < 0 ? lineView.line : lineView.rest[i]);
|
| 1900 |
+
var ch = map[j] + offset;
|
| 1901 |
+
if (offset < 0 || curNode != textNode) ch = map[j + (offset ? 1 : 0)];
|
| 1902 |
+
return Pos(line, ch);
|
| 1903 |
+
}
|
| 1904 |
+
}
|
| 1905 |
+
}
|
| 1906 |
+
}
|
| 1907 |
+
var found = find(textNode, topNode, offset);
|
| 1908 |
+
if (found) return badPos(found, bad);
|
| 1909 |
+
|
| 1910 |
+
// FIXME this is all really shaky. might handle the few cases it needs to handle, but likely to cause problems
|
| 1911 |
+
for (var after = topNode.nextSibling, dist = textNode ? textNode.nodeValue.length - offset : 0; after; after = after.nextSibling) {
|
| 1912 |
+
found = find(after, after.firstChild, 0);
|
| 1913 |
+
if (found)
|
| 1914 |
+
return badPos(Pos(found.line, found.ch - dist), bad);
|
| 1915 |
+
else
|
| 1916 |
+
dist += after.textContent.length;
|
| 1917 |
+
}
|
| 1918 |
+
for (var before = topNode.previousSibling, dist = offset; before; before = before.previousSibling) {
|
| 1919 |
+
found = find(before, before.firstChild, -1);
|
| 1920 |
+
if (found)
|
| 1921 |
+
return badPos(Pos(found.line, found.ch + dist), bad);
|
| 1922 |
+
else
|
| 1923 |
+
dist += after.textContent.length;
|
| 1924 |
+
}
|
| 1925 |
+
}
|
| 1926 |
+
|
| 1927 |
+
function domTextBetween(cm, from, to, fromLine, toLine) {
|
| 1928 |
+
var text = "", closing = false;
|
| 1929 |
+
function recognizeMarker(id) { return function(marker) { return marker.id == id; }; }
|
| 1930 |
+
function walk(node) {
|
| 1931 |
+
if (node.nodeType == 1) {
|
| 1932 |
+
var cmText = node.getAttribute("cm-text");
|
| 1933 |
+
if (cmText != null) {
|
| 1934 |
+
if (cmText == "") cmText = node.textContent.replace(/\u200b/g, "");
|
| 1935 |
+
text += cmText;
|
| 1936 |
+
return;
|
| 1937 |
+
}
|
| 1938 |
+
var markerID = node.getAttribute("cm-marker"), range;
|
| 1939 |
+
if (markerID) {
|
| 1940 |
+
var found = cm.findMarks(Pos(fromLine, 0), Pos(toLine + 1, 0), recognizeMarker(+markerID));
|
| 1941 |
+
if (found.length && (range = found[0].find()))
|
| 1942 |
+
text += getBetween(cm.doc, range.from, range.to).join("\n");
|
| 1943 |
+
return;
|
| 1944 |
+
}
|
| 1945 |
+
if (node.getAttribute("contenteditable") == "false") return;
|
| 1946 |
+
for (var i = 0; i < node.childNodes.length; i++)
|
| 1947 |
+
walk(node.childNodes[i]);
|
| 1948 |
+
if (/^(pre|div|p)$/i.test(node.nodeName))
|
| 1949 |
+
closing = true;
|
| 1950 |
+
} else if (node.nodeType == 3) {
|
| 1951 |
+
var val = node.nodeValue;
|
| 1952 |
+
if (!val) return;
|
| 1953 |
+
if (closing) {
|
| 1954 |
+
text += "\n";
|
| 1955 |
+
closing = false;
|
| 1956 |
+
}
|
| 1957 |
+
text += val;
|
| 1958 |
+
}
|
| 1959 |
+
}
|
| 1960 |
+
for (;;) {
|
| 1961 |
+
walk(from);
|
| 1962 |
+
if (from == to) break;
|
| 1963 |
+
from = from.nextSibling;
|
| 1964 |
+
}
|
| 1965 |
+
return text;
|
| 1966 |
+
}
|
| 1967 |
+
|
| 1968 |
+
CodeMirror.inputStyles = {"textarea": TextareaInput, "contenteditable": ContentEditableInput};
|
| 1969 |
+
|
| 1970 |
+
// SELECTION / CURSOR
|
| 1971 |
+
|
| 1972 |
+
// Selection objects are immutable. A new one is created every time
|
| 1973 |
+
// the selection changes. A selection is one or more non-overlapping
|
| 1974 |
+
// (and non-touching) ranges, sorted, and an integer that indicates
|
| 1975 |
+
// which one is the primary selection (the one that's scrolled into
|
| 1976 |
+
// view, that getCursor returns, etc).
|
| 1977 |
+
function Selection(ranges, primIndex) {
|
| 1978 |
+
this.ranges = ranges;
|
| 1979 |
+
this.primIndex = primIndex;
|
| 1980 |
+
}
|
| 1981 |
+
|
| 1982 |
+
Selection.prototype = {
|
| 1983 |
+
primary: function() { return this.ranges[this.primIndex]; },
|
| 1984 |
+
equals: function(other) {
|
| 1985 |
+
if (other == this) return true;
|
| 1986 |
+
if (other.primIndex != this.primIndex || other.ranges.length != this.ranges.length) return false;
|
| 1987 |
+
for (var i = 0; i < this.ranges.length; i++) {
|
| 1988 |
+
var here = this.ranges[i], there = other.ranges[i];
|
| 1989 |
+
if (cmp(here.anchor, there.anchor) != 0 || cmp(here.head, there.head) != 0) return false;
|
| 1990 |
+
}
|
| 1991 |
+
return true;
|
| 1992 |
+
},
|
| 1993 |
+
deepCopy: function() {
|
| 1994 |
+
for (var out = [], i = 0; i < this.ranges.length; i++)
|
| 1995 |
+
out[i] = new Range(copyPos(this.ranges[i].anchor), copyPos(this.ranges[i].head));
|
| 1996 |
+
return new Selection(out, this.primIndex);
|
| 1997 |
+
},
|
| 1998 |
+
somethingSelected: function() {
|
| 1999 |
+
for (var i = 0; i < this.ranges.length; i++)
|
| 2000 |
+
if (!this.ranges[i].empty()) return true;
|
| 2001 |
+
return false;
|
| 2002 |
+
},
|
| 2003 |
+
contains: function(pos, end) {
|
| 2004 |
+
if (!end) end = pos;
|
| 2005 |
+
for (var i = 0; i < this.ranges.length; i++) {
|
| 2006 |
+
var range = this.ranges[i];
|
| 2007 |
+
if (cmp(end, range.from()) >= 0 && cmp(pos, range.to()) <= 0)
|
| 2008 |
+
return i;
|
| 2009 |
+
}
|
| 2010 |
+
return -1;
|
| 2011 |
+
}
|
| 2012 |
+
};
|
| 2013 |
+
|
| 2014 |
+
function Range(anchor, head) {
|
| 2015 |
+
this.anchor = anchor; this.head = head;
|
| 2016 |
+
}
|
| 2017 |
+
|
| 2018 |
+
Range.prototype = {
|
| 2019 |
+
from: function() { return minPos(this.anchor, this.head); },
|
| 2020 |
+
to: function() { return maxPos(this.anchor, this.head); },
|
| 2021 |
+
empty: function() {
|
| 2022 |
+
return this.head.line == this.anchor.line && this.head.ch == this.anchor.ch;
|
| 2023 |
+
}
|
| 2024 |
+
};
|
| 2025 |
+
|
| 2026 |
+
// Take an unsorted, potentially overlapping set of ranges, and
|
| 2027 |
+
// build a selection out of it. 'Consumes' ranges array (modifying
|
| 2028 |
+
// it).
|
| 2029 |
+
function normalizeSelection(ranges, primIndex) {
|
| 2030 |
+
var prim = ranges[primIndex];
|
| 2031 |
+
ranges.sort(function(a, b) { return cmp(a.from(), b.from()); });
|
| 2032 |
+
primIndex = indexOf(ranges, prim);
|
| 2033 |
+
for (var i = 1; i < ranges.length; i++) {
|
| 2034 |
+
var cur = ranges[i], prev = ranges[i - 1];
|
| 2035 |
+
if (cmp(prev.to(), cur.from()) >= 0) {
|
| 2036 |
+
var from = minPos(prev.from(), cur.from()), to = maxPos(prev.to(), cur.to());
|
| 2037 |
+
var inv = prev.empty() ? cur.from() == cur.head : prev.from() == prev.head;
|
| 2038 |
+
if (i <= primIndex) --primIndex;
|
| 2039 |
+
ranges.splice(--i, 2, new Range(inv ? to : from, inv ? from : to));
|
| 2040 |
+
}
|
| 2041 |
+
}
|
| 2042 |
+
return new Selection(ranges, primIndex);
|
| 2043 |
+
}
|
| 2044 |
+
|
| 2045 |
+
function simpleSelection(anchor, head) {
|
| 2046 |
+
return new Selection([new Range(anchor, head || anchor)], 0);
|
| 2047 |
+
}
|
| 2048 |
+
|
| 2049 |
+
// Most of the external API clips given positions to make sure they
|
| 2050 |
+
// actually exist within the document.
|
| 2051 |
+
function clipLine(doc, n) {return Math.max(doc.first, Math.min(n, doc.first + doc.size - 1));}
|
| 2052 |
+
function clipPos(doc, pos) {
|
| 2053 |
+
if (pos.line < doc.first) return Pos(doc.first, 0);
|
| 2054 |
+
var last = doc.first + doc.size - 1;
|
| 2055 |
+
if (pos.line > last) return Pos(last, getLine(doc, last).text.length);
|
| 2056 |
+
return clipToLen(pos, getLine(doc, pos.line).text.length);
|
| 2057 |
+
}
|
| 2058 |
+
function clipToLen(pos, linelen) {
|
| 2059 |
+
var ch = pos.ch;
|
| 2060 |
+
if (ch == null || ch > linelen) return Pos(pos.line, linelen);
|
| 2061 |
+
else if (ch < 0) return Pos(pos.line, 0);
|
| 2062 |
+
else return pos;
|
| 2063 |
+
}
|
| 2064 |
+
function isLine(doc, l) {return l >= doc.first && l < doc.first + doc.size;}
|
| 2065 |
+
function clipPosArray(doc, array) {
|
| 2066 |
+
for (var out = [], i = 0; i < array.length; i++) out[i] = clipPos(doc, array[i]);
|
| 2067 |
+
return out;
|
| 2068 |
+
}
|
| 2069 |
+
|
| 2070 |
+
// SELECTION UPDATES
|
| 2071 |
+
|
| 2072 |
+
// The 'scroll' parameter given to many of these indicated whether
|
| 2073 |
+
// the new cursor position should be scrolled into view after
|
| 2074 |
+
// modifying the selection.
|
| 2075 |
+
|
| 2076 |
+
// If shift is held or the extend flag is set, extends a range to
|
| 2077 |
+
// include a given position (and optionally a second position).
|
| 2078 |
+
// Otherwise, simply returns the range between the given positions.
|
| 2079 |
+
// Used for cursor motion and such.
|
| 2080 |
+
function extendRange(doc, range, head, other) {
|
| 2081 |
+
if (doc.cm && doc.cm.display.shift || doc.extend) {
|
| 2082 |
+
var anchor = range.anchor;
|
| 2083 |
+
if (other) {
|
| 2084 |
+
var posBefore = cmp(head, anchor) < 0;
|
| 2085 |
+
if (posBefore != (cmp(other, anchor) < 0)) {
|
| 2086 |
+
anchor = head;
|
| 2087 |
+
head = other;
|
| 2088 |
+
} else if (posBefore != (cmp(head, other) < 0)) {
|
| 2089 |
+
head = other;
|
| 2090 |
+
}
|
| 2091 |
+
}
|
| 2092 |
+
return new Range(anchor, head);
|
| 2093 |
+
} else {
|
| 2094 |
+
return new Range(other || head, head);
|
| 2095 |
+
}
|
| 2096 |
+
}
|
| 2097 |
+
|
| 2098 |
+
// Extend the primary selection range, discard the rest.
|
| 2099 |
+
function extendSelection(doc, head, other, options) {
|
| 2100 |
+
setSelection(doc, new Selection([extendRange(doc, doc.sel.primary(), head, other)], 0), options);
|
| 2101 |
+
}
|
| 2102 |
+
|
| 2103 |
+
// Extend all selections (pos is an array of selections with length
|
| 2104 |
+
// equal the number of selections)
|
| 2105 |
+
function extendSelections(doc, heads, options) {
|
| 2106 |
+
for (var out = [], i = 0; i < doc.sel.ranges.length; i++)
|
| 2107 |
+
out[i] = extendRange(doc, doc.sel.ranges[i], heads[i], null);
|
| 2108 |
+
var newSel = normalizeSelection(out, doc.sel.primIndex);
|
| 2109 |
+
setSelection(doc, newSel, options);
|
| 2110 |
+
}
|
| 2111 |
+
|
| 2112 |
+
// Updates a single range in the selection.
|
| 2113 |
+
function replaceOneSelection(doc, i, range, options) {
|
| 2114 |
+
var ranges = doc.sel.ranges.slice(0);
|
| 2115 |
+
ranges[i] = range;
|
| 2116 |
+
setSelection(doc, normalizeSelection(ranges, doc.sel.primIndex), options);
|
| 2117 |
+
}
|
| 2118 |
+
|
| 2119 |
+
// Reset the selection to a single range.
|
| 2120 |
+
function setSimpleSelection(doc, anchor, head, options) {
|
| 2121 |
+
setSelection(doc, simpleSelection(anchor, head), options);
|
| 2122 |
+
}
|
| 2123 |
+
|
| 2124 |
+
// Give beforeSelectionChange handlers a change to influence a
|
| 2125 |
+
// selection update.
|
| 2126 |
+
function filterSelectionChange(doc, sel) {
|
| 2127 |
+
var obj = {
|
| 2128 |
+
ranges: sel.ranges,
|
| 2129 |
+
update: function(ranges) {
|
| 2130 |
+
this.ranges = [];
|
| 2131 |
+
for (var i = 0; i < ranges.length; i++)
|
| 2132 |
+
this.ranges[i] = new Range(clipPos(doc, ranges[i].anchor),
|
| 2133 |
+
clipPos(doc, ranges[i].head));
|
| 2134 |
+
}
|
| 2135 |
+
};
|
| 2136 |
+
signal(doc, "beforeSelectionChange", doc, obj);
|
| 2137 |
+
if (doc.cm) signal(doc.cm, "beforeSelectionChange", doc.cm, obj);
|
| 2138 |
+
if (obj.ranges != sel.ranges) return normalizeSelection(obj.ranges, obj.ranges.length - 1);
|
| 2139 |
+
else return sel;
|
| 2140 |
+
}
|
| 2141 |
+
|
| 2142 |
+
function setSelectionReplaceHistory(doc, sel, options) {
|
| 2143 |
+
var done = doc.history.done, last = lst(done);
|
| 2144 |
+
if (last && last.ranges) {
|
| 2145 |
+
done[done.length - 1] = sel;
|
| 2146 |
+
setSelectionNoUndo(doc, sel, options);
|
| 2147 |
+
} else {
|
| 2148 |
+
setSelection(doc, sel, options);
|
| 2149 |
+
}
|
| 2150 |
+
}
|
| 2151 |
+
|
| 2152 |
+
// Set a new selection.
|
| 2153 |
+
function setSelection(doc, sel, options) {
|
| 2154 |
+
setSelectionNoUndo(doc, sel, options);
|
| 2155 |
+
addSelectionToHistory(doc, doc.sel, doc.cm ? doc.cm.curOp.id : NaN, options);
|
| 2156 |
+
}
|
| 2157 |
+
|
| 2158 |
+
function setSelectionNoUndo(doc, sel, options) {
|
| 2159 |
+
if (hasHandler(doc, "beforeSelectionChange") || doc.cm && hasHandler(doc.cm, "beforeSelectionChange"))
|
| 2160 |
+
sel = filterSelectionChange(doc, sel);
|
| 2161 |
+
|
| 2162 |
+
var bias = options && options.bias ||
|
| 2163 |
+
(cmp(sel.primary().head, doc.sel.primary().head) < 0 ? -1 : 1);
|
| 2164 |
+
setSelectionInner(doc, skipAtomicInSelection(doc, sel, bias, true));
|
| 2165 |
+
|
| 2166 |
+
if (!(options && options.scroll === false) && doc.cm)
|
| 2167 |
+
ensureCursorVisible(doc.cm);
|
| 2168 |
+
}
|
| 2169 |
+
|
| 2170 |
+
function setSelectionInner(doc, sel) {
|
| 2171 |
+
if (sel.equals(doc.sel)) return;
|
| 2172 |
+
|
| 2173 |
+
doc.sel = sel;
|
| 2174 |
+
|
| 2175 |
+
if (doc.cm) {
|
| 2176 |
+
doc.cm.curOp.updateInput = doc.cm.curOp.selectionChanged = true;
|
| 2177 |
+
signalCursorActivity(doc.cm);
|
| 2178 |
+
}
|
| 2179 |
+
signalLater(doc, "cursorActivity", doc);
|
| 2180 |
+
}
|
| 2181 |
+
|
| 2182 |
+
// Verify that the selection does not partially select any atomic
|
| 2183 |
+
// marked ranges.
|
| 2184 |
+
function reCheckSelection(doc) {
|
| 2185 |
+
setSelectionInner(doc, skipAtomicInSelection(doc, doc.sel, null, false), sel_dontScroll);
|
| 2186 |
+
}
|
| 2187 |
+
|
| 2188 |
+
// Return a selection that does not partially select any atomic
|
| 2189 |
+
// ranges.
|
| 2190 |
+
function skipAtomicInSelection(doc, sel, bias, mayClear) {
|
| 2191 |
+
var out;
|
| 2192 |
+
for (var i = 0; i < sel.ranges.length; i++) {
|
| 2193 |
+
var range = sel.ranges[i];
|
| 2194 |
+
var newAnchor = skipAtomic(doc, range.anchor, bias, mayClear);
|
| 2195 |
+
var newHead = skipAtomic(doc, range.head, bias, mayClear);
|
| 2196 |
+
if (out || newAnchor != range.anchor || newHead != range.head) {
|
| 2197 |
+
if (!out) out = sel.ranges.slice(0, i);
|
| 2198 |
+
out[i] = new Range(newAnchor, newHead);
|
| 2199 |
+
}
|
| 2200 |
+
}
|
| 2201 |
+
return out ? normalizeSelection(out, sel.primIndex) : sel;
|
| 2202 |
+
}
|
| 2203 |
+
|
| 2204 |
+
// Ensure a given position is not inside an atomic range.
|
| 2205 |
+
function skipAtomic(doc, pos, bias, mayClear) {
|
| 2206 |
+
var flipped = false, curPos = pos;
|
| 2207 |
+
var dir = bias || 1;
|
| 2208 |
+
doc.cantEdit = false;
|
| 2209 |
+
search: for (;;) {
|
| 2210 |
+
var line = getLine(doc, curPos.line);
|
| 2211 |
+
if (line.markedSpans) {
|
| 2212 |
+
for (var i = 0; i < line.markedSpans.length; ++i) {
|
| 2213 |
+
var sp = line.markedSpans[i], m = sp.marker;
|
| 2214 |
+
if ((sp.from == null || (m.inclusiveLeft ? sp.from <= curPos.ch : sp.from < curPos.ch)) &&
|
| 2215 |
+
(sp.to == null || (m.inclusiveRight ? sp.to >= curPos.ch : sp.to > curPos.ch))) {
|
| 2216 |
+
if (mayClear) {
|
| 2217 |
+
signal(m, "beforeCursorEnter");
|
| 2218 |
+
if (m.explicitlyCleared) {
|
| 2219 |
+
if (!line.markedSpans) break;
|
| 2220 |
+
else {--i; continue;}
|
| 2221 |
+
}
|
| 2222 |
+
}
|
| 2223 |
+
if (!m.atomic) continue;
|
| 2224 |
+
var newPos = m.find(dir < 0 ? -1 : 1);
|
| 2225 |
+
if (cmp(newPos, curPos) == 0) {
|
| 2226 |
+
newPos.ch += dir;
|
| 2227 |
+
if (newPos.ch < 0) {
|
| 2228 |
+
if (newPos.line > doc.first) newPos = clipPos(doc, Pos(newPos.line - 1));
|
| 2229 |
+
else newPos = null;
|
| 2230 |
+
} else if (newPos.ch > line.text.length) {
|
| 2231 |
+
if (newPos.line < doc.first + doc.size - 1) newPos = Pos(newPos.line + 1, 0);
|
| 2232 |
+
else newPos = null;
|
| 2233 |
+
}
|
| 2234 |
+
if (!newPos) {
|
| 2235 |
+
if (flipped) {
|
| 2236 |
+
// Driven in a corner -- no valid cursor position found at all
|
| 2237 |
+
// -- try again *with* clearing, if we didn't already
|
| 2238 |
+
if (!mayClear) return skipAtomic(doc, pos, bias, true);
|
| 2239 |
+
// Otherwise, turn off editing until further notice, and return the start of the doc
|
| 2240 |
+
doc.cantEdit = true;
|
| 2241 |
+
return Pos(doc.first, 0);
|
| 2242 |
+
}
|
| 2243 |
+
flipped = true; newPos = pos; dir = -dir;
|
| 2244 |
+
}
|
| 2245 |
+
}
|
| 2246 |
+
curPos = newPos;
|
| 2247 |
+
continue search;
|
| 2248 |
+
}
|
| 2249 |
+
}
|
| 2250 |
+
}
|
| 2251 |
+
return curPos;
|
| 2252 |
+
}
|
| 2253 |
+
}
|
| 2254 |
+
|
| 2255 |
+
// SELECTION DRAWING
|
| 2256 |
+
|
| 2257 |
+
function updateSelection(cm) {
|
| 2258 |
+
cm.display.input.showSelection(cm.display.input.prepareSelection());
|
| 2259 |
+
}
|
| 2260 |
+
|
| 2261 |
+
function prepareSelection(cm, primary) {
|
| 2262 |
+
var doc = cm.doc, result = {};
|
| 2263 |
+
var curFragment = result.cursors = document.createDocumentFragment();
|
| 2264 |
+
var selFragment = result.selection = document.createDocumentFragment();
|
| 2265 |
+
|
| 2266 |
+
for (var i = 0; i < doc.sel.ranges.length; i++) {
|
| 2267 |
+
if (primary === false && i == doc.sel.primIndex) continue;
|
| 2268 |
+
var range = doc.sel.ranges[i];
|
| 2269 |
+
var collapsed = range.empty();
|
| 2270 |
+
if (collapsed || cm.options.showCursorWhenSelecting)
|
| 2271 |
+
drawSelectionCursor(cm, range, curFragment);
|
| 2272 |
+
if (!collapsed)
|
| 2273 |
+
drawSelectionRange(cm, range, selFragment);
|
| 2274 |
+
}
|
| 2275 |
+
return result;
|
| 2276 |
+
}
|
| 2277 |
+
|
| 2278 |
+
// Draws a cursor for the given range
|
| 2279 |
+
function drawSelectionCursor(cm, range, output) {
|
| 2280 |
+
var pos = cursorCoords(cm, range.head, "div", null, null, !cm.options.singleCursorHeightPerLine);
|
| 2281 |
+
|
| 2282 |
+
var cursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor"));
|
| 2283 |
+
cursor.style.left = pos.left + "px";
|
| 2284 |
+
cursor.style.top = pos.top + "px";
|
| 2285 |
+
cursor.style.height = Math.max(0, pos.bottom - pos.top) * cm.options.cursorHeight + "px";
|
| 2286 |
+
|
| 2287 |
+
if (pos.other) {
|
| 2288 |
+
// Secondary cursor, shown when on a 'jump' in bi-directional text
|
| 2289 |
+
var otherCursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor CodeMirror-secondarycursor"));
|
| 2290 |
+
otherCursor.style.display = "";
|
| 2291 |
+
otherCursor.style.left = pos.other.left + "px";
|
| 2292 |
+
otherCursor.style.top = pos.other.top + "px";
|
| 2293 |
+
otherCursor.style.height = (pos.other.bottom - pos.other.top) * .85 + "px";
|
| 2294 |
+
}
|
| 2295 |
+
}
|
| 2296 |
+
|
| 2297 |
+
// Draws the given range as a highlighted selection
|
| 2298 |
+
function drawSelectionRange(cm, range, output) {
|
| 2299 |
+
var display = cm.display, doc = cm.doc;
|
| 2300 |
+
var fragment = document.createDocumentFragment();
|
| 2301 |
+
var padding = paddingH(cm.display), leftSide = padding.left;
|
| 2302 |
+
var rightSide = Math.max(display.sizerWidth, displayWidth(cm) - display.sizer.offsetLeft) - padding.right;
|
| 2303 |
+
|
| 2304 |
+
function add(left, top, width, bottom) {
|
| 2305 |
+
if (top < 0) top = 0;
|
| 2306 |
+
top = Math.round(top);
|
| 2307 |
+
bottom = Math.round(bottom);
|
| 2308 |
+
fragment.appendChild(elt("div", null, "CodeMirror-selected", "position: absolute; left: " + left +
|
| 2309 |
+
"px; top: " + top + "px; width: " + (width == null ? rightSide - left : width) +
|
| 2310 |
+
"px; height: " + (bottom - top) + "px"));
|
| 2311 |
+
}
|
| 2312 |
+
|
| 2313 |
+
function drawForLine(line, fromArg, toArg) {
|
| 2314 |
+
var lineObj = getLine(doc, line);
|
| 2315 |
+
var lineLen = lineObj.text.length;
|
| 2316 |
+
var start, end;
|
| 2317 |
+
function coords(ch, bias) {
|
| 2318 |
+
return charCoords(cm, Pos(line, ch), "div", lineObj, bias);
|
| 2319 |
+
}
|
| 2320 |
+
|
| 2321 |
+
iterateBidiSections(getOrder(lineObj), fromArg || 0, toArg == null ? lineLen : toArg, function(from, to, dir) {
|
| 2322 |
+
var leftPos = coords(from, "left"), rightPos, left, right;
|
| 2323 |
+
if (from == to) {
|
| 2324 |
+
rightPos = leftPos;
|
| 2325 |
+
left = right = leftPos.left;
|
| 2326 |
+
} else {
|
| 2327 |
+
rightPos = coords(to - 1, "right");
|
| 2328 |
+
if (dir == "rtl") { var tmp = leftPos; leftPos = rightPos; rightPos = tmp; }
|
| 2329 |
+
left = leftPos.left;
|
| 2330 |
+
right = rightPos.right;
|
| 2331 |
+
}
|
| 2332 |
+
if (fromArg == null && from == 0) left = leftSide;
|
| 2333 |
+
if (rightPos.top - leftPos.top > 3) { // Different lines, draw top part
|
| 2334 |
+
add(left, leftPos.top, null, leftPos.bottom);
|
| 2335 |
+
left = leftSide;
|
| 2336 |
+
if (leftPos.bottom < rightPos.top) add(left, leftPos.bottom, null, rightPos.top);
|
| 2337 |
+
}
|
| 2338 |
+
if (toArg == null && to == lineLen) right = rightSide;
|
| 2339 |
+
if (!start || leftPos.top < start.top || leftPos.top == start.top && leftPos.left < start.left)
|
| 2340 |
+
start = leftPos;
|
| 2341 |
+
if (!end || rightPos.bottom > end.bottom || rightPos.bottom == end.bottom && rightPos.right > end.right)
|
| 2342 |
+
end = rightPos;
|
| 2343 |
+
if (left < leftSide + 1) left = leftSide;
|
| 2344 |
+
add(left, rightPos.top, right - left, rightPos.bottom);
|
| 2345 |
+
});
|
| 2346 |
+
return {start: start, end: end};
|
| 2347 |
+
}
|
| 2348 |
+
|
| 2349 |
+
var sFrom = range.from(), sTo = range.to();
|
| 2350 |
+
if (sFrom.line == sTo.line) {
|
| 2351 |
+
drawForLine(sFrom.line, sFrom.ch, sTo.ch);
|
| 2352 |
+
} else {
|
| 2353 |
+
var fromLine = getLine(doc, sFrom.line), toLine = getLine(doc, sTo.line);
|
| 2354 |
+
var singleVLine = visualLine(fromLine) == visualLine(toLine);
|
| 2355 |
+
var leftEnd = drawForLine(sFrom.line, sFrom.ch, singleVLine ? fromLine.text.length + 1 : null).end;
|
| 2356 |
+
var rightStart = drawForLine(sTo.line, singleVLine ? 0 : null, sTo.ch).start;
|
| 2357 |
+
if (singleVLine) {
|
| 2358 |
+
if (leftEnd.top < rightStart.top - 2) {
|
| 2359 |
+
add(leftEnd.right, leftEnd.top, null, leftEnd.bottom);
|
| 2360 |
+
add(leftSide, rightStart.top, rightStart.left, rightStart.bottom);
|
| 2361 |
+
} else {
|
| 2362 |
+
add(leftEnd.right, leftEnd.top, rightStart.left - leftEnd.right, leftEnd.bottom);
|
| 2363 |
+
}
|
| 2364 |
+
}
|
| 2365 |
+
if (leftEnd.bottom < rightStart.top)
|
| 2366 |
+
add(leftSide, leftEnd.bottom, null, rightStart.top);
|
| 2367 |
+
}
|
| 2368 |
+
|
| 2369 |
+
output.appendChild(fragment);
|
| 2370 |
+
}
|
| 2371 |
+
|
| 2372 |
+
// Cursor-blinking
|
| 2373 |
+
function restartBlink(cm) {
|
| 2374 |
+
if (!cm.state.focused) return;
|
| 2375 |
+
var display = cm.display;
|
| 2376 |
+
clearInterval(display.blinker);
|
| 2377 |
+
var on = true;
|
| 2378 |
+
display.cursorDiv.style.visibility = "";
|
| 2379 |
+
if (cm.options.cursorBlinkRate > 0)
|
| 2380 |
+
display.blinker = setInterval(function() {
|
| 2381 |
+
display.cursorDiv.style.visibility = (on = !on) ? "" : "hidden";
|
| 2382 |
+
}, cm.options.cursorBlinkRate);
|
| 2383 |
+
else if (cm.options.cursorBlinkRate < 0)
|
| 2384 |
+
display.cursorDiv.style.visibility = "hidden";
|
| 2385 |
+
}
|
| 2386 |
+
|
| 2387 |
+
// HIGHLIGHT WORKER
|
| 2388 |
+
|
| 2389 |
+
function startWorker(cm, time) {
|
| 2390 |
+
if (cm.doc.mode.startState && cm.doc.frontier < cm.display.viewTo)
|
| 2391 |
+
cm.state.highlight.set(time, bind(highlightWorker, cm));
|
| 2392 |
+
}
|
| 2393 |
+
|
| 2394 |
+
function highlightWorker(cm) {
|
| 2395 |
+
var doc = cm.doc;
|
| 2396 |
+
if (doc.frontier < doc.first) doc.frontier = doc.first;
|
| 2397 |
+
if (doc.frontier >= cm.display.viewTo) return;
|
| 2398 |
+
var end = +new Date + cm.options.workTime;
|
| 2399 |
+
var state = copyState(doc.mode, getStateBefore(cm, doc.frontier));
|
| 2400 |
+
var changedLines = [];
|
| 2401 |
+
|
| 2402 |
+
doc.iter(doc.frontier, Math.min(doc.first + doc.size, cm.display.viewTo + 500), function(line) {
|
| 2403 |
+
if (doc.frontier >= cm.display.viewFrom) { // Visible
|
| 2404 |
+
var oldStyles = line.styles;
|
| 2405 |
+
var highlighted = highlightLine(cm, line, state, true);
|
| 2406 |
+
line.styles = highlighted.styles;
|
| 2407 |
+
var oldCls = line.styleClasses, newCls = highlighted.classes;
|
| 2408 |
+
if (newCls) line.styleClasses = newCls;
|
| 2409 |
+
else if (oldCls) line.styleClasses = null;
|
| 2410 |
+
var ischange = !oldStyles || oldStyles.length != line.styles.length ||
|
| 2411 |
+
oldCls != newCls && (!oldCls || !newCls || oldCls.bgClass != newCls.bgClass || oldCls.textClass != newCls.textClass);
|
| 2412 |
+
for (var i = 0; !ischange && i < oldStyles.length; ++i) ischange = oldStyles[i] != line.styles[i];
|
| 2413 |
+
if (ischange) changedLines.push(doc.frontier);
|
| 2414 |
+
line.stateAfter = copyState(doc.mode, state);
|
| 2415 |
+
} else {
|
| 2416 |
+
processLine(cm, line.text, state);
|
| 2417 |
+
line.stateAfter = doc.frontier % 5 == 0 ? copyState(doc.mode, state) : null;
|
| 2418 |
+
}
|
| 2419 |
+
++doc.frontier;
|
| 2420 |
+
if (+new Date > end) {
|
| 2421 |
+
startWorker(cm, cm.options.workDelay);
|
| 2422 |
+
return true;
|
| 2423 |
+
}
|
| 2424 |
+
});
|
| 2425 |
+
if (changedLines.length) runInOp(cm, function() {
|
| 2426 |
+
for (var i = 0; i < changedLines.length; i++)
|
| 2427 |
+
regLineChange(cm, changedLines[i], "text");
|
| 2428 |
+
});
|
| 2429 |
+
}
|
| 2430 |
+
|
| 2431 |
+
// Finds the line to start with when starting a parse. Tries to
|
| 2432 |
+
// find a line with a stateAfter, so that it can start with a
|
| 2433 |
+
// valid state. If that fails, it returns the line with the
|
| 2434 |
+
// smallest indentation, which tends to need the least context to
|
| 2435 |
+
// parse correctly.
|
| 2436 |
+
function findStartLine(cm, n, precise) {
|
| 2437 |
+
var minindent, minline, doc = cm.doc;
|
| 2438 |
+
var lim = precise ? -1 : n - (cm.doc.mode.innerMode ? 1000 : 100);
|
| 2439 |
+
for (var search = n; search > lim; --search) {
|
| 2440 |
+
if (search <= doc.first) return doc.first;
|
| 2441 |
+
var line = getLine(doc, search - 1);
|
| 2442 |
+
if (line.stateAfter && (!precise || search <= doc.frontier)) return search;
|
| 2443 |
+
var indented = countColumn(line.text, null, cm.options.tabSize);
|
| 2444 |
+
if (minline == null || minindent > indented) {
|
| 2445 |
+
minline = search - 1;
|
| 2446 |
+
minindent = indented;
|
| 2447 |
+
}
|
| 2448 |
+
}
|
| 2449 |
+
return minline;
|
| 2450 |
+
}
|
| 2451 |
+
|
| 2452 |
+
function getStateBefore(cm, n, precise) {
|
| 2453 |
+
var doc = cm.doc, display = cm.display;
|
| 2454 |
+
if (!doc.mode.startState) return true;
|
| 2455 |
+
var pos = findStartLine(cm, n, precise), state = pos > doc.first && getLine(doc, pos-1).stateAfter;
|
| 2456 |
+
if (!state) state = startState(doc.mode);
|
| 2457 |
+
else state = copyState(doc.mode, state);
|
| 2458 |
+
doc.iter(pos, n, function(line) {
|
| 2459 |
+
processLine(cm, line.text, state);
|
| 2460 |
+
var save = pos == n - 1 || pos % 5 == 0 || pos >= display.viewFrom && pos < display.viewTo;
|
| 2461 |
+
line.stateAfter = save ? copyState(doc.mode, state) : null;
|
| 2462 |
+
++pos;
|
| 2463 |
+
});
|
| 2464 |
+
if (precise) doc.frontier = pos;
|
| 2465 |
+
return state;
|
| 2466 |
+
}
|
| 2467 |
+
|
| 2468 |
+
// POSITION MEASUREMENT
|
| 2469 |
+
|
| 2470 |
+
function paddingTop(display) {return display.lineSpace.offsetTop;}
|
| 2471 |
+
function paddingVert(display) {return display.mover.offsetHeight - display.lineSpace.offsetHeight;}
|
| 2472 |
+
function paddingH(display) {
|
| 2473 |
+
if (display.cachedPaddingH) return display.cachedPaddingH;
|
| 2474 |
+
var e = removeChildrenAndAdd(display.measure, elt("pre", "x"));
|
| 2475 |
+
var style = window.getComputedStyle ? window.getComputedStyle(e) : e.currentStyle;
|
| 2476 |
+
var data = {left: parseInt(style.paddingLeft), right: parseInt(style.paddingRight)};
|
| 2477 |
+
if (!isNaN(data.left) && !isNaN(data.right)) display.cachedPaddingH = data;
|
| 2478 |
+
return data;
|
| 2479 |
+
}
|
| 2480 |
+
|
| 2481 |
+
function scrollGap(cm) { return scrollerGap - cm.display.nativeBarWidth; }
|
| 2482 |
+
function displayWidth(cm) {
|
| 2483 |
+
return cm.display.scroller.clientWidth - scrollGap(cm) - cm.display.barWidth;
|
| 2484 |
+
}
|
| 2485 |
+
function displayHeight(cm) {
|
| 2486 |
+
return cm.display.scroller.clientHeight - scrollGap(cm) - cm.display.barHeight;
|
| 2487 |
+
}
|
| 2488 |
+
|
| 2489 |
+
// Ensure the lineView.wrapping.heights array is populated. This is
|
| 2490 |
+
// an array of bottom offsets for the lines that make up a drawn
|
| 2491 |
+
// line. When lineWrapping is on, there might be more than one
|
| 2492 |
+
// height.
|
| 2493 |
+
function ensureLineHeights(cm, lineView, rect) {
|
| 2494 |
+
var wrapping = cm.options.lineWrapping;
|
| 2495 |
+
var curWidth = wrapping && displayWidth(cm);
|
| 2496 |
+
if (!lineView.measure.heights || wrapping && lineView.measure.width != curWidth) {
|
| 2497 |
+
var heights = lineView.measure.heights = [];
|
| 2498 |
+
if (wrapping) {
|
| 2499 |
+
lineView.measure.width = curWidth;
|
| 2500 |
+
var rects = lineView.text.firstChild.getClientRects();
|
| 2501 |
+
for (var i = 0; i < rects.length - 1; i++) {
|
| 2502 |
+
var cur = rects[i], next = rects[i + 1];
|
| 2503 |
+
if (Math.abs(cur.bottom - next.bottom) > 2)
|
| 2504 |
+
heights.push((cur.bottom + next.top) / 2 - rect.top);
|
| 2505 |
+
}
|
| 2506 |
+
}
|
| 2507 |
+
heights.push(rect.bottom - rect.top);
|
| 2508 |
+
}
|
| 2509 |
+
}
|
| 2510 |
+
|
| 2511 |
+
// Find a line map (mapping character offsets to text nodes) and a
|
| 2512 |
+
// measurement cache for the given line number. (A line view might
|
| 2513 |
+
// contain multiple lines when collapsed ranges are present.)
|
| 2514 |
+
function mapFromLineView(lineView, line, lineN) {
|
| 2515 |
+
if (lineView.line == line)
|
| 2516 |
+
return {map: lineView.measure.map, cache: lineView.measure.cache};
|
| 2517 |
+
for (var i = 0; i < lineView.rest.length; i++)
|
| 2518 |
+
if (lineView.rest[i] == line)
|
| 2519 |
+
return {map: lineView.measure.maps[i], cache: lineView.measure.caches[i]};
|
| 2520 |
+
for (var i = 0; i < lineView.rest.length; i++)
|
| 2521 |
+
if (lineNo(lineView.rest[i]) > lineN)
|
| 2522 |
+
return {map: lineView.measure.maps[i], cache: lineView.measure.caches[i], before: true};
|
| 2523 |
+
}
|
| 2524 |
+
|
| 2525 |
+
// Render a line into the hidden node display.externalMeasured. Used
|
| 2526 |
+
// when measurement is needed for a line that's not in the viewport.
|
| 2527 |
+
function updateExternalMeasurement(cm, line) {
|
| 2528 |
+
line = visualLine(line);
|
| 2529 |
+
var lineN = lineNo(line);
|
| 2530 |
+
var view = cm.display.externalMeasured = new LineView(cm.doc, line, lineN);
|
| 2531 |
+
view.lineN = lineN;
|
| 2532 |
+
var built = view.built = buildLineContent(cm, view);
|
| 2533 |
+
view.text = built.pre;
|
| 2534 |
+
removeChildrenAndAdd(cm.display.lineMeasure, built.pre);
|
| 2535 |
+
return view;
|
| 2536 |
+
}
|
| 2537 |
+
|
| 2538 |
+
// Get a {top, bottom, left, right} box (in line-local coordinates)
|
| 2539 |
+
// for a given character.
|
| 2540 |
+
function measureChar(cm, line, ch, bias) {
|
| 2541 |
+
return measureCharPrepared(cm, prepareMeasureForLine(cm, line), ch, bias);
|
| 2542 |
+
}
|
| 2543 |
+
|
| 2544 |
+
// Find a line view that corresponds to the given line number.
|
| 2545 |
+
function findViewForLine(cm, lineN) {
|
| 2546 |
+
if (lineN >= cm.display.viewFrom && lineN < cm.display.viewTo)
|
| 2547 |
+
return cm.display.view[findViewIndex(cm, lineN)];
|
| 2548 |
+
var ext = cm.display.externalMeasured;
|
| 2549 |
+
if (ext && lineN >= ext.lineN && lineN < ext.lineN + ext.size)
|
| 2550 |
+
return ext;
|
| 2551 |
+
}
|
| 2552 |
+
|
| 2553 |
+
// Measurement can be split in two steps, the set-up work that
|
| 2554 |
+
// applies to the whole line, and the measurement of the actual
|
| 2555 |
+
// character. Functions like coordsChar, that need to do a lot of
|
| 2556 |
+
// measurements in a row, can thus ensure that the set-up work is
|
| 2557 |
+
// only done once.
|
| 2558 |
+
function prepareMeasureForLine(cm, line) {
|
| 2559 |
+
var lineN = lineNo(line);
|
| 2560 |
+
var view = findViewForLine(cm, lineN);
|
| 2561 |
+
if (view && !view.text)
|
| 2562 |
+
view = null;
|
| 2563 |
+
else if (view && view.changes)
|
| 2564 |
+
updateLineForChanges(cm, view, lineN, getDimensions(cm));
|
| 2565 |
+
if (!view)
|
| 2566 |
+
view = updateExternalMeasurement(cm, line);
|
| 2567 |
+
|
| 2568 |
+
var info = mapFromLineView(view, line, lineN);
|
| 2569 |
+
return {
|
| 2570 |
+
line: line, view: view, rect: null,
|
| 2571 |
+
map: info.map, cache: info.cache, before: info.before,
|
| 2572 |
+
hasHeights: false
|
| 2573 |
+
};
|
| 2574 |
+
}
|
| 2575 |
+
|
| 2576 |
+
// Given a prepared measurement object, measures the position of an
|
| 2577 |
+
// actual character (or fetches it from the cache).
|
| 2578 |
+
function measureCharPrepared(cm, prepared, ch, bias, varHeight) {
|
| 2579 |
+
if (prepared.before) ch = -1;
|
| 2580 |
+
var key = ch + (bias || ""), found;
|
| 2581 |
+
if (prepared.cache.hasOwnProperty(key)) {
|
| 2582 |
+
found = prepared.cache[key];
|
| 2583 |
+
} else {
|
| 2584 |
+
if (!prepared.rect)
|
| 2585 |
+
prepared.rect = prepared.view.text.getBoundingClientRect();
|
| 2586 |
+
if (!prepared.hasHeights) {
|
| 2587 |
+
ensureLineHeights(cm, prepared.view, prepared.rect);
|
| 2588 |
+
prepared.hasHeights = true;
|
| 2589 |
+
}
|
| 2590 |
+
found = measureCharInner(cm, prepared, ch, bias);
|
| 2591 |
+
if (!found.bogus) prepared.cache[key] = found;
|
| 2592 |
+
}
|
| 2593 |
+
return {left: found.left, right: found.right,
|
| 2594 |
+
top: varHeight ? found.rtop : found.top,
|
| 2595 |
+
bottom: varHeight ? found.rbottom : found.bottom};
|
| 2596 |
+
}
|
| 2597 |
+
|
| 2598 |
+
var nullRect = {left: 0, right: 0, top: 0, bottom: 0};
|
| 2599 |
+
|
| 2600 |
+
function nodeAndOffsetInLineMap(map, ch, bias) {
|
| 2601 |
+
var node, start, end, collapse;
|
| 2602 |
+
// First, search the line map for the text node corresponding to,
|
| 2603 |
+
// or closest to, the target character.
|
| 2604 |
+
for (var i = 0; i < map.length; i += 3) {
|
| 2605 |
+
var mStart = map[i], mEnd = map[i + 1];
|
| 2606 |
+
if (ch < mStart) {
|
| 2607 |
+
start = 0; end = 1;
|
| 2608 |
+
collapse = "left";
|
| 2609 |
+
} else if (ch < mEnd) {
|
| 2610 |
+
start = ch - mStart;
|
| 2611 |
+
end = start + 1;
|
| 2612 |
+
} else if (i == map.length - 3 || ch == mEnd && map[i + 3] > ch) {
|
| 2613 |
+
end = mEnd - mStart;
|
| 2614 |
+
start = end - 1;
|
| 2615 |
+
if (ch >= mEnd) collapse = "right";
|
| 2616 |
+
}
|
| 2617 |
+
if (start != null) {
|
| 2618 |
+
node = map[i + 2];
|
| 2619 |
+
if (mStart == mEnd && bias == (node.insertLeft ? "left" : "right"))
|
| 2620 |
+
collapse = bias;
|
| 2621 |
+
if (bias == "left" && start == 0)
|
| 2622 |
+
while (i && map[i - 2] == map[i - 3] && map[i - 1].insertLeft) {
|
| 2623 |
+
node = map[(i -= 3) + 2];
|
| 2624 |
+
collapse = "left";
|
| 2625 |
+
}
|
| 2626 |
+
if (bias == "right" && start == mEnd - mStart)
|
| 2627 |
+
while (i < map.length - 3 && map[i + 3] == map[i + 4] && !map[i + 5].insertLeft) {
|
| 2628 |
+
node = map[(i += 3) + 2];
|
| 2629 |
+
collapse = "right";
|
| 2630 |
+
}
|
| 2631 |
+
break;
|
| 2632 |
+
}
|
| 2633 |
+
}
|
| 2634 |
+
return {node: node, start: start, end: end, collapse: collapse, coverStart: mStart, coverEnd: mEnd};
|
| 2635 |
+
}
|
| 2636 |
+
|
| 2637 |
+
function measureCharInner(cm, prepared, ch, bias) {
|
| 2638 |
+
var place = nodeAndOffsetInLineMap(prepared.map, ch, bias);
|
| 2639 |
+
var node = place.node, start = place.start, end = place.end, collapse = place.collapse;
|
| 2640 |
+
|
| 2641 |
+
var rect;
|
| 2642 |
+
if (node.nodeType == 3) { // If it is a text node, use a range to retrieve the coordinates.
|
| 2643 |
+
for (var i = 0; i < 4; i++) { // Retry a maximum of 4 times when nonsense rectangles are returned
|
| 2644 |
+
while (start && isExtendingChar(prepared.line.text.charAt(place.coverStart + start))) --start;
|
| 2645 |
+
while (place.coverStart + end < place.coverEnd && isExtendingChar(prepared.line.text.charAt(place.coverStart + end))) ++end;
|
| 2646 |
+
if (ie && ie_version < 9 && start == 0 && end == place.coverEnd - place.coverStart) {
|
| 2647 |
+
rect = node.parentNode.getBoundingClientRect();
|
| 2648 |
+
} else if (ie && cm.options.lineWrapping) {
|
| 2649 |
+
var rects = range(node, start, end).getClientRects();
|
| 2650 |
+
if (rects.length)
|
| 2651 |
+
rect = rects[bias == "right" ? rects.length - 1 : 0];
|
| 2652 |
+
else
|
| 2653 |
+
rect = nullRect;
|
| 2654 |
+
} else {
|
| 2655 |
+
rect = range(node, start, end).getBoundingClientRect() || nullRect;
|
| 2656 |
+
}
|
| 2657 |
+
if (rect.left || rect.right || start == 0) break;
|
| 2658 |
+
end = start;
|
| 2659 |
+
start = start - 1;
|
| 2660 |
+
collapse = "right";
|
| 2661 |
+
}
|
| 2662 |
+
if (ie && ie_version < 11) rect = maybeUpdateRectForZooming(cm.display.measure, rect);
|
| 2663 |
+
} else { // If it is a widget, simply get the box for the whole widget.
|
| 2664 |
+
if (start > 0) collapse = bias = "right";
|
| 2665 |
+
var rects;
|
| 2666 |
+
if (cm.options.lineWrapping && (rects = node.getClientRects()).length > 1)
|
| 2667 |
+
rect = rects[bias == "right" ? rects.length - 1 : 0];
|
| 2668 |
+
else
|
| 2669 |
+
rect = node.getBoundingClientRect();
|
| 2670 |
+
}
|
| 2671 |
+
if (ie && ie_version < 9 && !start && (!rect || !rect.left && !rect.right)) {
|
| 2672 |
+
var rSpan = node.parentNode.getClientRects()[0];
|
| 2673 |
+
if (rSpan)
|
| 2674 |
+
rect = {left: rSpan.left, right: rSpan.left + charWidth(cm.display), top: rSpan.top, bottom: rSpan.bottom};
|
| 2675 |
+
else
|
| 2676 |
+
rect = nullRect;
|
| 2677 |
+
}
|
| 2678 |
+
|
| 2679 |
+
var rtop = rect.top - prepared.rect.top, rbot = rect.bottom - prepared.rect.top;
|
| 2680 |
+
var mid = (rtop + rbot) / 2;
|
| 2681 |
+
var heights = prepared.view.measure.heights;
|
| 2682 |
+
for (var i = 0; i < heights.length - 1; i++)
|
| 2683 |
+
if (mid < heights[i]) break;
|
| 2684 |
+
var top = i ? heights[i - 1] : 0, bot = heights[i];
|
| 2685 |
+
var result = {left: (collapse == "right" ? rect.right : rect.left) - prepared.rect.left,
|
| 2686 |
+
right: (collapse == "left" ? rect.left : rect.right) - prepared.rect.left,
|
| 2687 |
+
top: top, bottom: bot};
|
| 2688 |
+
if (!rect.left && !rect.right) result.bogus = true;
|
| 2689 |
+
if (!cm.options.singleCursorHeightPerLine) { result.rtop = rtop; result.rbottom = rbot; }
|
| 2690 |
+
|
| 2691 |
+
return result;
|
| 2692 |
+
}
|
| 2693 |
+
|
| 2694 |
+
// Work around problem with bounding client rects on ranges being
|
| 2695 |
+
// returned incorrectly when zoomed on IE10 and below.
|
| 2696 |
+
function maybeUpdateRectForZooming(measure, rect) {
|
| 2697 |
+
if (!window.screen || screen.logicalXDPI == null ||
|
| 2698 |
+
screen.logicalXDPI == screen.deviceXDPI || !hasBadZoomedRects(measure))
|
| 2699 |
+
return rect;
|
| 2700 |
+
var scaleX = screen.logicalXDPI / screen.deviceXDPI;
|
| 2701 |
+
var scaleY = screen.logicalYDPI / screen.deviceYDPI;
|
| 2702 |
+
return {left: rect.left * scaleX, right: rect.right * scaleX,
|
| 2703 |
+
top: rect.top * scaleY, bottom: rect.bottom * scaleY};
|
| 2704 |
+
}
|
| 2705 |
+
|
| 2706 |
+
function clearLineMeasurementCacheFor(lineView) {
|
| 2707 |
+
if (lineView.measure) {
|
| 2708 |
+
lineView.measure.cache = {};
|
| 2709 |
+
lineView.measure.heights = null;
|
| 2710 |
+
if (lineView.rest) for (var i = 0; i < lineView.rest.length; i++)
|
| 2711 |
+
lineView.measure.caches[i] = {};
|
| 2712 |
+
}
|
| 2713 |
+
}
|
| 2714 |
+
|
| 2715 |
+
function clearLineMeasurementCache(cm) {
|
| 2716 |
+
cm.display.externalMeasure = null;
|
| 2717 |
+
removeChildren(cm.display.lineMeasure);
|
| 2718 |
+
for (var i = 0; i < cm.display.view.length; i++)
|
| 2719 |
+
clearLineMeasurementCacheFor(cm.display.view[i]);
|
| 2720 |
+
}
|
| 2721 |
+
|
| 2722 |
+
function clearCaches(cm) {
|
| 2723 |
+
clearLineMeasurementCache(cm);
|
| 2724 |
+
cm.display.cachedCharWidth = cm.display.cachedTextHeight = cm.display.cachedPaddingH = null;
|
| 2725 |
+
if (!cm.options.lineWrapping) cm.display.maxLineChanged = true;
|
| 2726 |
+
cm.display.lineNumChars = null;
|
| 2727 |
+
}
|
| 2728 |
+
|
| 2729 |
+
function pageScrollX() { return window.pageXOffset || (document.documentElement || document.body).scrollLeft; }
|
| 2730 |
+
function pageScrollY() { return window.pageYOffset || (document.documentElement || document.body).scrollTop; }
|
| 2731 |
+
|
| 2732 |
+
// Converts a {top, bottom, left, right} box from line-local
|
| 2733 |
+
// coordinates into another coordinate system. Context may be one of
|
| 2734 |
+
// "line", "div" (display.lineDiv), "local"/null (editor), "window",
|
| 2735 |
+
// or "page".
|
| 2736 |
+
function intoCoordSystem(cm, lineObj, rect, context) {
|
| 2737 |
+
if (lineObj.widgets) for (var i = 0; i < lineObj.widgets.length; ++i) if (lineObj.widgets[i].above) {
|
| 2738 |
+
var size = widgetHeight(lineObj.widgets[i]);
|
| 2739 |
+
rect.top += size; rect.bottom += size;
|
| 2740 |
+
}
|
| 2741 |
+
if (context == "line") return rect;
|
| 2742 |
+
if (!context) context = "local";
|
| 2743 |
+
var yOff = heightAtLine(lineObj);
|
| 2744 |
+
if (context == "local") yOff += paddingTop(cm.display);
|
| 2745 |
+
else yOff -= cm.display.viewOffset;
|
| 2746 |
+
if (context == "page" || context == "window") {
|
| 2747 |
+
var lOff = cm.display.lineSpace.getBoundingClientRect();
|
| 2748 |
+
yOff += lOff.top + (context == "window" ? 0 : pageScrollY());
|
| 2749 |
+
var xOff = lOff.left + (context == "window" ? 0 : pageScrollX());
|
| 2750 |
+
rect.left += xOff; rect.right += xOff;
|
| 2751 |
+
}
|
| 2752 |
+
rect.top += yOff; rect.bottom += yOff;
|
| 2753 |
+
return rect;
|
| 2754 |
+
}
|
| 2755 |
+
|
| 2756 |
+
// Coverts a box from "div" coords to another coordinate system.
|
| 2757 |
+
// Context may be "window", "page", "div", or "local"/null.
|
| 2758 |
+
function fromCoordSystem(cm, coords, context) {
|
| 2759 |
+
if (context == "div") return coords;
|
| 2760 |
+
var left = coords.left, top = coords.top;
|
| 2761 |
+
// First move into "page" coordinate system
|
| 2762 |
+
if (context == "page") {
|
| 2763 |
+
left -= pageScrollX();
|
| 2764 |
+
top -= pageScrollY();
|
| 2765 |
+
} else if (context == "local" || !context) {
|
| 2766 |
+
var localBox = cm.display.sizer.getBoundingClientRect();
|
| 2767 |
+
left += localBox.left;
|
| 2768 |
+
top += localBox.top;
|
| 2769 |
+
}
|
| 2770 |
+
|
| 2771 |
+
var lineSpaceBox = cm.display.lineSpace.getBoundingClientRect();
|
| 2772 |
+
return {left: left - lineSpaceBox.left, top: top - lineSpaceBox.top};
|
| 2773 |
+
}
|
| 2774 |
+
|
| 2775 |
+
function charCoords(cm, pos, context, lineObj, bias) {
|
| 2776 |
+
if (!lineObj) lineObj = getLine(cm.doc, pos.line);
|
| 2777 |
+
return intoCoordSystem(cm, lineObj, measureChar(cm, lineObj, pos.ch, bias), context);
|
| 2778 |
+
}
|
| 2779 |
+
|
| 2780 |
+
// Returns a box for a given cursor position, which may have an
|
| 2781 |
+
// 'other' property containing the position of the secondary cursor
|
| 2782 |
+
// on a bidi boundary.
|
| 2783 |
+
function cursorCoords(cm, pos, context, lineObj, preparedMeasure, varHeight) {
|
| 2784 |
+
lineObj = lineObj || getLine(cm.doc, pos.line);
|
| 2785 |
+
if (!preparedMeasure) preparedMeasure = prepareMeasureForLine(cm, lineObj);
|
| 2786 |
+
function get(ch, right) {
|
| 2787 |
+
var m = measureCharPrepared(cm, preparedMeasure, ch, right ? "right" : "left", varHeight);
|
| 2788 |
+
if (right) m.left = m.right; else m.right = m.left;
|
| 2789 |
+
return intoCoordSystem(cm, lineObj, m, context);
|
| 2790 |
+
}
|
| 2791 |
+
function getBidi(ch, partPos) {
|
| 2792 |
+
var part = order[partPos], right = part.level % 2;
|
| 2793 |
+
if (ch == bidiLeft(part) && partPos && part.level < order[partPos - 1].level) {
|
| 2794 |
+
part = order[--partPos];
|
| 2795 |
+
ch = bidiRight(part) - (part.level % 2 ? 0 : 1);
|
| 2796 |
+
right = true;
|
| 2797 |
+
} else if (ch == bidiRight(part) && partPos < order.length - 1 && part.level < order[partPos + 1].level) {
|
| 2798 |
+
part = order[++partPos];
|
| 2799 |
+
ch = bidiLeft(part) - part.level % 2;
|
| 2800 |
+
right = false;
|
| 2801 |
+
}
|
| 2802 |
+
if (right && ch == part.to && ch > part.from) return get(ch - 1);
|
| 2803 |
+
return get(ch, right);
|
| 2804 |
+
}
|
| 2805 |
+
var order = getOrder(lineObj), ch = pos.ch;
|
| 2806 |
+
if (!order) return get(ch);
|
| 2807 |
+
var partPos = getBidiPartAt(order, ch);
|
| 2808 |
+
var val = getBidi(ch, partPos);
|
| 2809 |
+
if (bidiOther != null) val.other = getBidi(ch, bidiOther);
|
| 2810 |
+
return val;
|
| 2811 |
+
}
|
| 2812 |
+
|
| 2813 |
+
// Used to cheaply estimate the coordinates for a position. Used for
|
| 2814 |
+
// intermediate scroll updates.
|
| 2815 |
+
function estimateCoords(cm, pos) {
|
| 2816 |
+
var left = 0, pos = clipPos(cm.doc, pos);
|
| 2817 |
+
if (!cm.options.lineWrapping) left = charWidth(cm.display) * pos.ch;
|
| 2818 |
+
var lineObj = getLine(cm.doc, pos.line);
|
| 2819 |
+
var top = heightAtLine(lineObj) + paddingTop(cm.display);
|
| 2820 |
+
return {left: left, right: left, top: top, bottom: top + lineObj.height};
|
| 2821 |
+
}
|
| 2822 |
+
|
| 2823 |
+
// Positions returned by coordsChar contain some extra information.
|
| 2824 |
+
// xRel is the relative x position of the input coordinates compared
|
| 2825 |
+
// to the found position (so xRel > 0 means the coordinates are to
|
| 2826 |
+
// the right of the character position, for example). When outside
|
| 2827 |
+
// is true, that means the coordinates lie outside the line's
|
| 2828 |
+
// vertical range.
|
| 2829 |
+
function PosWithInfo(line, ch, outside, xRel) {
|
| 2830 |
+
var pos = Pos(line, ch);
|
| 2831 |
+
pos.xRel = xRel;
|
| 2832 |
+
if (outside) pos.outside = true;
|
| 2833 |
+
return pos;
|
| 2834 |
+
}
|
| 2835 |
+
|
| 2836 |
+
// Compute the character position closest to the given coordinates.
|
| 2837 |
+
// Input must be lineSpace-local ("div" coordinate system).
|
| 2838 |
+
function coordsChar(cm, x, y) {
|
| 2839 |
+
var doc = cm.doc;
|
| 2840 |
+
y += cm.display.viewOffset;
|
| 2841 |
+
if (y < 0) return PosWithInfo(doc.first, 0, true, -1);
|
| 2842 |
+
var lineN = lineAtHeight(doc, y), last = doc.first + doc.size - 1;
|
| 2843 |
+
if (lineN > last)
|
| 2844 |
+
return PosWithInfo(doc.first + doc.size - 1, getLine(doc, last).text.length, true, 1);
|
| 2845 |
+
if (x < 0) x = 0;
|
| 2846 |
+
|
| 2847 |
+
var lineObj = getLine(doc, lineN);
|
| 2848 |
+
for (;;) {
|
| 2849 |
+
var found = coordsCharInner(cm, lineObj, lineN, x, y);
|
| 2850 |
+
var merged = collapsedSpanAtEnd(lineObj);
|
| 2851 |
+
var mergedPos = merged && merged.find(0, true);
|
| 2852 |
+
if (merged && (found.ch > mergedPos.from.ch || found.ch == mergedPos.from.ch && found.xRel > 0))
|
| 2853 |
+
lineN = lineNo(lineObj = mergedPos.to.line);
|
| 2854 |
+
else
|
| 2855 |
+
return found;
|
| 2856 |
+
}
|
| 2857 |
+
}
|
| 2858 |
+
|
| 2859 |
+
function coordsCharInner(cm, lineObj, lineNo, x, y) {
|
| 2860 |
+
var innerOff = y - heightAtLine(lineObj);
|
| 2861 |
+
var wrongLine = false, adjust = 2 * cm.display.wrapper.clientWidth;
|
| 2862 |
+
var preparedMeasure = prepareMeasureForLine(cm, lineObj);
|
| 2863 |
+
|
| 2864 |
+
function getX(ch) {
|
| 2865 |
+
var sp = cursorCoords(cm, Pos(lineNo, ch), "line", lineObj, preparedMeasure);
|
| 2866 |
+
wrongLine = true;
|
| 2867 |
+
if (innerOff > sp.bottom) return sp.left - adjust;
|
| 2868 |
+
else if (innerOff < sp.top) return sp.left + adjust;
|
| 2869 |
+
else wrongLine = false;
|
| 2870 |
+
return sp.left;
|
| 2871 |
+
}
|
| 2872 |
+
|
| 2873 |
+
var bidi = getOrder(lineObj), dist = lineObj.text.length;
|
| 2874 |
+
var from = lineLeft(lineObj), to = lineRight(lineObj);
|
| 2875 |
+
var fromX = getX(from), fromOutside = wrongLine, toX = getX(to), toOutside = wrongLine;
|
| 2876 |
+
|
| 2877 |
+
if (x > toX) return PosWithInfo(lineNo, to, toOutside, 1);
|
| 2878 |
+
// Do a binary search between these bounds.
|
| 2879 |
+
for (;;) {
|
| 2880 |
+
if (bidi ? to == from || to == moveVisually(lineObj, from, 1) : to - from <= 1) {
|
| 2881 |
+
var ch = x < fromX || x - fromX <= toX - x ? from : to;
|
| 2882 |
+
var xDiff = x - (ch == from ? fromX : toX);
|
| 2883 |
+
while (isExtendingChar(lineObj.text.charAt(ch))) ++ch;
|
| 2884 |
+
var pos = PosWithInfo(lineNo, ch, ch == from ? fromOutside : toOutside,
|
| 2885 |
+
xDiff < -1 ? -1 : xDiff > 1 ? 1 : 0);
|
| 2886 |
+
return pos;
|
| 2887 |
+
}
|
| 2888 |
+
var step = Math.ceil(dist / 2), middle = from + step;
|
| 2889 |
+
if (bidi) {
|
| 2890 |
+
middle = from;
|
| 2891 |
+
for (var i = 0; i < step; ++i) middle = moveVisually(lineObj, middle, 1);
|
| 2892 |
+
}
|
| 2893 |
+
var middleX = getX(middle);
|
| 2894 |
+
if (middleX > x) {to = middle; toX = middleX; if (toOutside = wrongLine) toX += 1000; dist = step;}
|
| 2895 |
+
else {from = middle; fromX = middleX; fromOutside = wrongLine; dist -= step;}
|
| 2896 |
+
}
|
| 2897 |
+
}
|
| 2898 |
+
|
| 2899 |
+
var measureText;
|
| 2900 |
+
// Compute the default text height.
|
| 2901 |
+
function textHeight(display) {
|
| 2902 |
+
if (display.cachedTextHeight != null) return display.cachedTextHeight;
|
| 2903 |
+
if (measureText == null) {
|
| 2904 |
+
measureText = elt("pre");
|
| 2905 |
+
// Measure a bunch of lines, for browsers that compute
|
| 2906 |
+
// fractional heights.
|
| 2907 |
+
for (var i = 0; i < 49; ++i) {
|
| 2908 |
+
measureText.appendChild(document.createTextNode("x"));
|
| 2909 |
+
measureText.appendChild(elt("br"));
|
| 2910 |
+
}
|
| 2911 |
+
measureText.appendChild(document.createTextNode("x"));
|
| 2912 |
+
}
|
| 2913 |
+
removeChildrenAndAdd(display.measure, measureText);
|
| 2914 |
+
var height = measureText.offsetHeight / 50;
|
| 2915 |
+
if (height > 3) display.cachedTextHeight = height;
|
| 2916 |
+
removeChildren(display.measure);
|
| 2917 |
+
return height || 1;
|
| 2918 |
+
}
|
| 2919 |
+
|
| 2920 |
+
// Compute the default character width.
|
| 2921 |
+
function charWidth(display) {
|
| 2922 |
+
if (display.cachedCharWidth != null) return display.cachedCharWidth;
|
| 2923 |
+
var anchor = elt("span", "xxxxxxxxxx");
|
| 2924 |
+
var pre = elt("pre", [anchor]);
|
| 2925 |
+
removeChildrenAndAdd(display.measure, pre);
|
| 2926 |
+
var rect = anchor.getBoundingClientRect(), width = (rect.right - rect.left) / 10;
|
| 2927 |
+
if (width > 2) display.cachedCharWidth = width;
|
| 2928 |
+
return width || 10;
|
| 2929 |
+
}
|
| 2930 |
+
|
| 2931 |
+
// OPERATIONS
|
| 2932 |
+
|
| 2933 |
+
// Operations are used to wrap a series of changes to the editor
|
| 2934 |
+
// state in such a way that each change won't have to update the
|
| 2935 |
+
// cursor and display (which would be awkward, slow, and
|
| 2936 |
+
// error-prone). Instead, display updates are batched and then all
|
| 2937 |
+
// combined and executed at once.
|
| 2938 |
+
|
| 2939 |
+
var operationGroup = null;
|
| 2940 |
+
|
| 2941 |
+
var nextOpId = 0;
|
| 2942 |
+
// Start a new operation.
|
| 2943 |
+
function startOperation(cm) {
|
| 2944 |
+
cm.curOp = {
|
| 2945 |
+
cm: cm,
|
| 2946 |
+
viewChanged: false, // Flag that indicates that lines might need to be redrawn
|
| 2947 |
+
startHeight: cm.doc.height, // Used to detect need to update scrollbar
|
| 2948 |
+
forceUpdate: false, // Used to force a redraw
|
| 2949 |
+
updateInput: null, // Whether to reset the input textarea
|
| 2950 |
+
typing: false, // Whether this reset should be careful to leave existing text (for compositing)
|
| 2951 |
+
changeObjs: null, // Accumulated changes, for firing change events
|
| 2952 |
+
cursorActivityHandlers: null, // Set of handlers to fire cursorActivity on
|
| 2953 |
+
cursorActivityCalled: 0, // Tracks which cursorActivity handlers have been called already
|
| 2954 |
+
selectionChanged: false, // Whether the selection needs to be redrawn
|
| 2955 |
+
updateMaxLine: false, // Set when the widest line needs to be determined anew
|
| 2956 |
+
scrollLeft: null, scrollTop: null, // Intermediate scroll position, not pushed to DOM yet
|
| 2957 |
+
scrollToPos: null, // Used to scroll to a specific position
|
| 2958 |
+
focus: false,
|
| 2959 |
+
id: ++nextOpId // Unique ID
|
| 2960 |
+
};
|
| 2961 |
+
if (operationGroup) {
|
| 2962 |
+
operationGroup.ops.push(cm.curOp);
|
| 2963 |
+
} else {
|
| 2964 |
+
cm.curOp.ownsGroup = operationGroup = {
|
| 2965 |
+
ops: [cm.curOp],
|
| 2966 |
+
delayedCallbacks: []
|
| 2967 |
+
};
|
| 2968 |
+
}
|
| 2969 |
+
}
|
| 2970 |
+
|
| 2971 |
+
function fireCallbacksForOps(group) {
|
| 2972 |
+
// Calls delayed callbacks and cursorActivity handlers until no
|
| 2973 |
+
// new ones appear
|
| 2974 |
+
var callbacks = group.delayedCallbacks, i = 0;
|
| 2975 |
+
do {
|
| 2976 |
+
for (; i < callbacks.length; i++)
|
| 2977 |
+
callbacks[i]();
|
| 2978 |
+
for (var j = 0; j < group.ops.length; j++) {
|
| 2979 |
+
var op = group.ops[j];
|
| 2980 |
+
if (op.cursorActivityHandlers)
|
| 2981 |
+
while (op.cursorActivityCalled < op.cursorActivityHandlers.length)
|
| 2982 |
+
op.cursorActivityHandlers[op.cursorActivityCalled++](op.cm);
|
| 2983 |
+
}
|
| 2984 |
+
} while (i < callbacks.length);
|
| 2985 |
+
}
|
| 2986 |
+
|
| 2987 |
+
// Finish an operation, updating the display and signalling delayed events
|
| 2988 |
+
function endOperation(cm) {
|
| 2989 |
+
var op = cm.curOp, group = op.ownsGroup;
|
| 2990 |
+
if (!group) return;
|
| 2991 |
+
|
| 2992 |
+
try { fireCallbacksForOps(group); }
|
| 2993 |
+
finally {
|
| 2994 |
+
operationGroup = null;
|
| 2995 |
+
for (var i = 0; i < group.ops.length; i++)
|
| 2996 |
+
group.ops[i].cm.curOp = null;
|
| 2997 |
+
endOperations(group);
|
| 2998 |
+
}
|
| 2999 |
+
}
|
| 3000 |
+
|
| 3001 |
+
// The DOM updates done when an operation finishes are batched so
|
| 3002 |
+
// that the minimum number of relayouts are required.
|
| 3003 |
+
function endOperations(group) {
|
| 3004 |
+
var ops = group.ops;
|
| 3005 |
+
for (var i = 0; i < ops.length; i++) // Read DOM
|
| 3006 |
+
endOperation_R1(ops[i]);
|
| 3007 |
+
for (var i = 0; i < ops.length; i++) // Write DOM (maybe)
|
| 3008 |
+
endOperation_W1(ops[i]);
|
| 3009 |
+
for (var i = 0; i < ops.length; i++) // Read DOM
|
| 3010 |
+
endOperation_R2(ops[i]);
|
| 3011 |
+
for (var i = 0; i < ops.length; i++) // Write DOM (maybe)
|
| 3012 |
+
endOperation_W2(ops[i]);
|
| 3013 |
+
for (var i = 0; i < ops.length; i++) // Read DOM
|
| 3014 |
+
endOperation_finish(ops[i]);
|
| 3015 |
+
}
|
| 3016 |
+
|
| 3017 |
+
function endOperation_R1(op) {
|
| 3018 |
+
var cm = op.cm, display = cm.display;
|
| 3019 |
+
maybeClipScrollbars(cm);
|
| 3020 |
+
if (op.updateMaxLine) findMaxLine(cm);
|
| 3021 |
+
|
| 3022 |
+
op.mustUpdate = op.viewChanged || op.forceUpdate || op.scrollTop != null ||
|
| 3023 |
+
op.scrollToPos && (op.scrollToPos.from.line < display.viewFrom ||
|
| 3024 |
+
op.scrollToPos.to.line >= display.viewTo) ||
|
| 3025 |
+
display.maxLineChanged && cm.options.lineWrapping;
|
| 3026 |
+
op.update = op.mustUpdate &&
|
| 3027 |
+
new DisplayUpdate(cm, op.mustUpdate && {top: op.scrollTop, ensure: op.scrollToPos}, op.forceUpdate);
|
| 3028 |
+
}
|
| 3029 |
+
|
| 3030 |
+
function endOperation_W1(op) {
|
| 3031 |
+
op.updatedDisplay = op.mustUpdate && updateDisplayIfNeeded(op.cm, op.update);
|
| 3032 |
+
}
|
| 3033 |
+
|
| 3034 |
+
function endOperation_R2(op) {
|
| 3035 |
+
var cm = op.cm, display = cm.display;
|
| 3036 |
+
if (op.updatedDisplay) updateHeightsInViewport(cm);
|
| 3037 |
+
|
| 3038 |
+
op.barMeasure = measureForScrollbars(cm);
|
| 3039 |
+
|
| 3040 |
+
// If the max line changed since it was last measured, measure it,
|
| 3041 |
+
// and ensure the document's width matches it.
|
| 3042 |
+
// updateDisplay_W2 will use these properties to do the actual resizing
|
| 3043 |
+
if (display.maxLineChanged && !cm.options.lineWrapping) {
|
| 3044 |
+
op.adjustWidthTo = measureChar(cm, display.maxLine, display.maxLine.text.length).left + 3;
|
| 3045 |
+
cm.display.sizerWidth = op.adjustWidthTo;
|
| 3046 |
+
op.barMeasure.scrollWidth =
|
| 3047 |
+
Math.max(display.scroller.clientWidth, display.sizer.offsetLeft + op.adjustWidthTo + scrollGap(cm) + cm.display.barWidth);
|
| 3048 |
+
op.maxScrollLeft = Math.max(0, display.sizer.offsetLeft + op.adjustWidthTo - displayWidth(cm));
|
| 3049 |
+
}
|
| 3050 |
+
|
| 3051 |
+
if (op.updatedDisplay || op.selectionChanged)
|
| 3052 |
+
op.preparedSelection = display.input.prepareSelection();
|
| 3053 |
+
}
|
| 3054 |
+
|
| 3055 |
+
function endOperation_W2(op) {
|
| 3056 |
+
var cm = op.cm;
|
| 3057 |
+
|
| 3058 |
+
if (op.adjustWidthTo != null) {
|
| 3059 |
+
cm.display.sizer.style.minWidth = op.adjustWidthTo + "px";
|
| 3060 |
+
if (op.maxScrollLeft < cm.doc.scrollLeft)
|
| 3061 |
+
setScrollLeft(cm, Math.min(cm.display.scroller.scrollLeft, op.maxScrollLeft), true);
|
| 3062 |
+
cm.display.maxLineChanged = false;
|
| 3063 |
+
}
|
| 3064 |
+
|
| 3065 |
+
if (op.preparedSelection)
|
| 3066 |
+
cm.display.input.showSelection(op.preparedSelection);
|
| 3067 |
+
if (op.updatedDisplay)
|
| 3068 |
+
setDocumentHeight(cm, op.barMeasure);
|
| 3069 |
+
if (op.updatedDisplay || op.startHeight != cm.doc.height)
|
| 3070 |
+
updateScrollbars(cm, op.barMeasure);
|
| 3071 |
+
|
| 3072 |
+
if (op.selectionChanged) restartBlink(cm);
|
| 3073 |
+
|
| 3074 |
+
if (cm.state.focused && op.updateInput)
|
| 3075 |
+
cm.display.input.reset(op.typing);
|
| 3076 |
+
if (op.focus && op.focus == activeElt()) ensureFocus(op.cm);
|
| 3077 |
+
}
|
| 3078 |
+
|
| 3079 |
+
function endOperation_finish(op) {
|
| 3080 |
+
var cm = op.cm, display = cm.display, doc = cm.doc;
|
| 3081 |
+
|
| 3082 |
+
if (op.updatedDisplay) postUpdateDisplay(cm, op.update);
|
| 3083 |
+
|
| 3084 |
+
// Abort mouse wheel delta measurement, when scrolling explicitly
|
| 3085 |
+
if (display.wheelStartX != null && (op.scrollTop != null || op.scrollLeft != null || op.scrollToPos))
|
| 3086 |
+
display.wheelStartX = display.wheelStartY = null;
|
| 3087 |
+
|
| 3088 |
+
// Propagate the scroll position to the actual DOM scroller
|
| 3089 |
+
if (op.scrollTop != null && (display.scroller.scrollTop != op.scrollTop || op.forceScroll)) {
|
| 3090 |
+
doc.scrollTop = Math.max(0, Math.min(display.scroller.scrollHeight - display.scroller.clientHeight, op.scrollTop));
|
| 3091 |
+
display.scrollbars.setScrollTop(doc.scrollTop);
|
| 3092 |
+
display.scroller.scrollTop = doc.scrollTop;
|
| 3093 |
+
}
|
| 3094 |
+
if (op.scrollLeft != null && (display.scroller.scrollLeft != op.scrollLeft || op.forceScroll)) {
|
| 3095 |
+
doc.scrollLeft = Math.max(0, Math.min(display.scroller.scrollWidth - displayWidth(cm), op.scrollLeft));
|
| 3096 |
+
display.scrollbars.setScrollLeft(doc.scrollLeft);
|
| 3097 |
+
display.scroller.scrollLeft = doc.scrollLeft;
|
| 3098 |
+
alignHorizontally(cm);
|
| 3099 |
+
}
|
| 3100 |
+
// If we need to scroll a specific position into view, do so.
|
| 3101 |
+
if (op.scrollToPos) {
|
| 3102 |
+
var coords = scrollPosIntoView(cm, clipPos(doc, op.scrollToPos.from),
|
| 3103 |
+
clipPos(doc, op.scrollToPos.to), op.scrollToPos.margin);
|
| 3104 |
+
if (op.scrollToPos.isCursor && cm.state.focused) maybeScrollWindow(cm, coords);
|
| 3105 |
+
}
|
| 3106 |
+
|
| 3107 |
+
// Fire events for markers that are hidden/unidden by editing or
|
| 3108 |
+
// undoing
|
| 3109 |
+
var hidden = op.maybeHiddenMarkers, unhidden = op.maybeUnhiddenMarkers;
|
| 3110 |
+
if (hidden) for (var i = 0; i < hidden.length; ++i)
|
| 3111 |
+
if (!hidden[i].lines.length) signal(hidden[i], "hide");
|
| 3112 |
+
if (unhidden) for (var i = 0; i < unhidden.length; ++i)
|
| 3113 |
+
if (unhidden[i].lines.length) signal(unhidden[i], "unhide");
|
| 3114 |
+
|
| 3115 |
+
if (display.wrapper.offsetHeight)
|
| 3116 |
+
doc.scrollTop = cm.display.scroller.scrollTop;
|
| 3117 |
+
|
| 3118 |
+
// Fire change events, and delayed event handlers
|
| 3119 |
+
if (op.changeObjs)
|
| 3120 |
+
signal(cm, "changes", cm, op.changeObjs);
|
| 3121 |
+
if (op.update)
|
| 3122 |
+
op.update.finish();
|
| 3123 |
+
}
|
| 3124 |
+
|
| 3125 |
+
// Run the given function in an operation
|
| 3126 |
+
function runInOp(cm, f) {
|
| 3127 |
+
if (cm.curOp) return f();
|
| 3128 |
+
startOperation(cm);
|
| 3129 |
+
try { return f(); }
|
| 3130 |
+
finally { endOperation(cm); }
|
| 3131 |
+
}
|
| 3132 |
+
// Wraps a function in an operation. Returns the wrapped function.
|
| 3133 |
+
function operation(cm, f) {
|
| 3134 |
+
return function() {
|
| 3135 |
+
if (cm.curOp) return f.apply(cm, arguments);
|
| 3136 |
+
startOperation(cm);
|
| 3137 |
+
try { return f.apply(cm, arguments); }
|
| 3138 |
+
finally { endOperation(cm); }
|
| 3139 |
+
};
|
| 3140 |
+
}
|
| 3141 |
+
// Used to add methods to editor and doc instances, wrapping them in
|
| 3142 |
+
// operations.
|
| 3143 |
+
function methodOp(f) {
|
| 3144 |
+
return function() {
|
| 3145 |
+
if (this.curOp) return f.apply(this, arguments);
|
| 3146 |
+
startOperation(this);
|
| 3147 |
+
try { return f.apply(this, arguments); }
|
| 3148 |
+
finally { endOperation(this); }
|
| 3149 |
+
};
|
| 3150 |
+
}
|
| 3151 |
+
function docMethodOp(f) {
|
| 3152 |
+
return function() {
|
| 3153 |
+
var cm = this.cm;
|
| 3154 |
+
if (!cm || cm.curOp) return f.apply(this, arguments);
|
| 3155 |
+
startOperation(cm);
|
| 3156 |
+
try { return f.apply(this, arguments); }
|
| 3157 |
+
finally { endOperation(cm); }
|
| 3158 |
+
};
|
| 3159 |
+
}
|
| 3160 |
+
|
| 3161 |
+
// VIEW TRACKING
|
| 3162 |
+
|
| 3163 |
+
// These objects are used to represent the visible (currently drawn)
|
| 3164 |
+
// part of the document. A LineView may correspond to multiple
|
| 3165 |
+
// logical lines, if those are connected by collapsed ranges.
|
| 3166 |
+
function LineView(doc, line, lineN) {
|
| 3167 |
+
// The starting line
|
| 3168 |
+
this.line = line;
|
| 3169 |
+
// Continuing lines, if any
|
| 3170 |
+
this.rest = visualLineContinued(line);
|
| 3171 |
+
// Number of logical lines in this visual line
|
| 3172 |
+
this.size = this.rest ? lineNo(lst(this.rest)) - lineN + 1 : 1;
|
| 3173 |
+
this.node = this.text = null;
|
| 3174 |
+
this.hidden = lineIsHidden(doc, line);
|
| 3175 |
+
}
|
| 3176 |
+
|
| 3177 |
+
// Create a range of LineView objects for the given lines.
|
| 3178 |
+
function buildViewArray(cm, from, to) {
|
| 3179 |
+
var array = [], nextPos;
|
| 3180 |
+
for (var pos = from; pos < to; pos = nextPos) {
|
| 3181 |
+
var view = new LineView(cm.doc, getLine(cm.doc, pos), pos);
|
| 3182 |
+
nextPos = pos + view.size;
|
| 3183 |
+
array.push(view);
|
| 3184 |
+
}
|
| 3185 |
+
return array;
|
| 3186 |
+
}
|
| 3187 |
+
|
| 3188 |
+
// Updates the display.view data structure for a given change to the
|
| 3189 |
+
// document. From and to are in pre-change coordinates. Lendiff is
|
| 3190 |
+
// the amount of lines added or subtracted by the change. This is
|
| 3191 |
+
// used for changes that span multiple lines, or change the way
|
| 3192 |
+
// lines are divided into visual lines. regLineChange (below)
|
| 3193 |
+
// registers single-line changes.
|
| 3194 |
+
function regChange(cm, from, to, lendiff) {
|
| 3195 |
+
if (from == null) from = cm.doc.first;
|
| 3196 |
+
if (to == null) to = cm.doc.first + cm.doc.size;
|
| 3197 |
+
if (!lendiff) lendiff = 0;
|
| 3198 |
+
|
| 3199 |
+
var display = cm.display;
|
| 3200 |
+
if (lendiff && to < display.viewTo &&
|
| 3201 |
+
(display.updateLineNumbers == null || display.updateLineNumbers > from))
|
| 3202 |
+
display.updateLineNumbers = from;
|
| 3203 |
+
|
| 3204 |
+
cm.curOp.viewChanged = true;
|
| 3205 |
+
|
| 3206 |
+
if (from >= display.viewTo) { // Change after
|
| 3207 |
+
if (sawCollapsedSpans && visualLineNo(cm.doc, from) < display.viewTo)
|
| 3208 |
+
resetView(cm);
|
| 3209 |
+
} else if (to <= display.viewFrom) { // Change before
|
| 3210 |
+
if (sawCollapsedSpans && visualLineEndNo(cm.doc, to + lendiff) > display.viewFrom) {
|
| 3211 |
+
resetView(cm);
|
| 3212 |
+
} else {
|
| 3213 |
+
display.viewFrom += lendiff;
|
| 3214 |
+
display.viewTo += lendiff;
|
| 3215 |
+
}
|
| 3216 |
+
} else if (from <= display.viewFrom && to >= display.viewTo) { // Full overlap
|
| 3217 |
+
resetView(cm);
|
| 3218 |
+
} else if (from <= display.viewFrom) { // Top overlap
|
| 3219 |
+
var cut = viewCuttingPoint(cm, to, to + lendiff, 1);
|
| 3220 |
+
if (cut) {
|
| 3221 |
+
display.view = display.view.slice(cut.index);
|
| 3222 |
+
display.viewFrom = cut.lineN;
|
| 3223 |
+
display.viewTo += lendiff;
|
| 3224 |
+
} else {
|
| 3225 |
+
resetView(cm);
|
| 3226 |
+
}
|
| 3227 |
+
} else if (to >= display.viewTo) { // Bottom overlap
|
| 3228 |
+
var cut = viewCuttingPoint(cm, from, from, -1);
|
| 3229 |
+
if (cut) {
|
| 3230 |
+
display.view = display.view.slice(0, cut.index);
|
| 3231 |
+
display.viewTo = cut.lineN;
|
| 3232 |
+
} else {
|
| 3233 |
+
resetView(cm);
|
| 3234 |
+
}
|
| 3235 |
+
} else { // Gap in the middle
|
| 3236 |
+
var cutTop = viewCuttingPoint(cm, from, from, -1);
|
| 3237 |
+
var cutBot = viewCuttingPoint(cm, to, to + lendiff, 1);
|
| 3238 |
+
if (cutTop && cutBot) {
|
| 3239 |
+
display.view = display.view.slice(0, cutTop.index)
|
| 3240 |
+
.concat(buildViewArray(cm, cutTop.lineN, cutBot.lineN))
|
| 3241 |
+
.concat(display.view.slice(cutBot.index));
|
| 3242 |
+
display.viewTo += lendiff;
|
| 3243 |
+
} else {
|
| 3244 |
+
resetView(cm);
|
| 3245 |
+
}
|
| 3246 |
+
}
|
| 3247 |
+
|
| 3248 |
+
var ext = display.externalMeasured;
|
| 3249 |
+
if (ext) {
|
| 3250 |
+
if (to < ext.lineN)
|
| 3251 |
+
ext.lineN += lendiff;
|
| 3252 |
+
else if (from < ext.lineN + ext.size)
|
| 3253 |
+
display.externalMeasured = null;
|
| 3254 |
+
}
|
| 3255 |
+
}
|
| 3256 |
+
|
| 3257 |
+
// Register a change to a single line. Type must be one of "text",
|
| 3258 |
+
// "gutter", "class", "widget"
|
| 3259 |
+
function regLineChange(cm, line, type) {
|
| 3260 |
+
cm.curOp.viewChanged = true;
|
| 3261 |
+
var display = cm.display, ext = cm.display.externalMeasured;
|
| 3262 |
+
if (ext && line >= ext.lineN && line < ext.lineN + ext.size)
|
| 3263 |
+
display.externalMeasured = null;
|
| 3264 |
+
|
| 3265 |
+
if (line < display.viewFrom || line >= display.viewTo) return;
|
| 3266 |
+
var lineView = display.view[findViewIndex(cm, line)];
|
| 3267 |
+
if (lineView.node == null) return;
|
| 3268 |
+
var arr = lineView.changes || (lineView.changes = []);
|
| 3269 |
+
if (indexOf(arr, type) == -1) arr.push(type);
|
| 3270 |
+
}
|
| 3271 |
+
|
| 3272 |
+
// Clear the view.
|
| 3273 |
+
function resetView(cm) {
|
| 3274 |
+
cm.display.viewFrom = cm.display.viewTo = cm.doc.first;
|
| 3275 |
+
cm.display.view = [];
|
| 3276 |
+
cm.display.viewOffset = 0;
|
| 3277 |
+
}
|
| 3278 |
+
|
| 3279 |
+
// Find the view element corresponding to a given line. Return null
|
| 3280 |
+
// when the line isn't visible.
|
| 3281 |
+
function findViewIndex(cm, n) {
|
| 3282 |
+
if (n >= cm.display.viewTo) return null;
|
| 3283 |
+
n -= cm.display.viewFrom;
|
| 3284 |
+
if (n < 0) return null;
|
| 3285 |
+
var view = cm.display.view;
|
| 3286 |
+
for (var i = 0; i < view.length; i++) {
|
| 3287 |
+
n -= view[i].size;
|
| 3288 |
+
if (n < 0) return i;
|
| 3289 |
+
}
|
| 3290 |
+
}
|
| 3291 |
+
|
| 3292 |
+
function viewCuttingPoint(cm, oldN, newN, dir) {
|
| 3293 |
+
var index = findViewIndex(cm, oldN), diff, view = cm.display.view;
|
| 3294 |
+
if (!sawCollapsedSpans || newN == cm.doc.first + cm.doc.size)
|
| 3295 |
+
return {index: index, lineN: newN};
|
| 3296 |
+
for (var i = 0, n = cm.display.viewFrom; i < index; i++)
|
| 3297 |
+
n += view[i].size;
|
| 3298 |
+
if (n != oldN) {
|
| 3299 |
+
if (dir > 0) {
|
| 3300 |
+
if (index == view.length - 1) return null;
|
| 3301 |
+
diff = (n + view[index].size) - oldN;
|
| 3302 |
+
index++;
|
| 3303 |
+
} else {
|
| 3304 |
+
diff = n - oldN;
|
| 3305 |
+
}
|
| 3306 |
+
oldN += diff; newN += diff;
|
| 3307 |
+
}
|
| 3308 |
+
while (visualLineNo(cm.doc, newN) != newN) {
|
| 3309 |
+
if (index == (dir < 0 ? 0 : view.length - 1)) return null;
|
| 3310 |
+
newN += dir * view[index - (dir < 0 ? 1 : 0)].size;
|
| 3311 |
+
index += dir;
|
| 3312 |
+
}
|
| 3313 |
+
return {index: index, lineN: newN};
|
| 3314 |
+
}
|
| 3315 |
+
|
| 3316 |
+
// Force the view to cover a given range, adding empty view element
|
| 3317 |
+
// or clipping off existing ones as needed.
|
| 3318 |
+
function adjustView(cm, from, to) {
|
| 3319 |
+
var display = cm.display, view = display.view;
|
| 3320 |
+
if (view.length == 0 || from >= display.viewTo || to <= display.viewFrom) {
|
| 3321 |
+
display.view = buildViewArray(cm, from, to);
|
| 3322 |
+
display.viewFrom = from;
|
| 3323 |
+
} else {
|
| 3324 |
+
if (display.viewFrom > from)
|
| 3325 |
+
display.view = buildViewArray(cm, from, display.viewFrom).concat(display.view);
|
| 3326 |
+
else if (display.viewFrom < from)
|
| 3327 |
+
display.view = display.view.slice(findViewIndex(cm, from));
|
| 3328 |
+
display.viewFrom = from;
|
| 3329 |
+
if (display.viewTo < to)
|
| 3330 |
+
display.view = display.view.concat(buildViewArray(cm, display.viewTo, to));
|
| 3331 |
+
else if (display.viewTo > to)
|
| 3332 |
+
display.view = display.view.slice(0, findViewIndex(cm, to));
|
| 3333 |
+
}
|
| 3334 |
+
display.viewTo = to;
|
| 3335 |
+
}
|
| 3336 |
+
|
| 3337 |
+
// Count the number of lines in the view whose DOM representation is
|
| 3338 |
+
// out of date (or nonexistent).
|
| 3339 |
+
function countDirtyView(cm) {
|
| 3340 |
+
var view = cm.display.view, dirty = 0;
|
| 3341 |
+
for (var i = 0; i < view.length; i++) {
|
| 3342 |
+
var lineView = view[i];
|
| 3343 |
+
if (!lineView.hidden && (!lineView.node || lineView.changes)) ++dirty;
|
| 3344 |
+
}
|
| 3345 |
+
return dirty;
|
| 3346 |
+
}
|
| 3347 |
+
|
| 3348 |
+
// EVENT HANDLERS
|
| 3349 |
+
|
| 3350 |
+
// Attach the necessary event handlers when initializing the editor
|
| 3351 |
+
function registerEventHandlers(cm) {
|
| 3352 |
+
var d = cm.display;
|
| 3353 |
+
on(d.scroller, "mousedown", operation(cm, onMouseDown));
|
| 3354 |
+
// Older IE's will not fire a second mousedown for a double click
|
| 3355 |
+
if (ie && ie_version < 11)
|
| 3356 |
+
on(d.scroller, "dblclick", operation(cm, function(e) {
|
| 3357 |
+
if (signalDOMEvent(cm, e)) return;
|
| 3358 |
+
var pos = posFromMouse(cm, e);
|
| 3359 |
+
if (!pos || clickInGutter(cm, e) || eventInWidget(cm.display, e)) return;
|
| 3360 |
+
e_preventDefault(e);
|
| 3361 |
+
var word = cm.findWordAt(pos);
|
| 3362 |
+
extendSelection(cm.doc, word.anchor, word.head);
|
| 3363 |
+
}));
|
| 3364 |
+
else
|
| 3365 |
+
on(d.scroller, "dblclick", function(e) { signalDOMEvent(cm, e) || e_preventDefault(e); });
|
| 3366 |
+
// Some browsers fire contextmenu *after* opening the menu, at
|
| 3367 |
+
// which point we can't mess with it anymore. Context menu is
|
| 3368 |
+
// handled in onMouseDown for these browsers.
|
| 3369 |
+
if (!captureRightClick) on(d.scroller, "contextmenu", function(e) {onContextMenu(cm, e);});
|
| 3370 |
+
|
| 3371 |
+
// Used to suppress mouse event handling when a touch happens
|
| 3372 |
+
var touchFinished, prevTouch = {end: 0};
|
| 3373 |
+
function finishTouch() {
|
| 3374 |
+
if (d.activeTouch) {
|
| 3375 |
+
touchFinished = setTimeout(function() {d.activeTouch = null;}, 1000);
|
| 3376 |
+
prevTouch = d.activeTouch;
|
| 3377 |
+
prevTouch.end = +new Date;
|
| 3378 |
+
}
|
| 3379 |
+
};
|
| 3380 |
+
function isMouseLikeTouchEvent(e) {
|
| 3381 |
+
if (e.touches.length != 1) return false;
|
| 3382 |
+
var touch = e.touches[0];
|
| 3383 |
+
return touch.radiusX <= 1 && touch.radiusY <= 1;
|
| 3384 |
+
}
|
| 3385 |
+
function farAway(touch, other) {
|
| 3386 |
+
if (other.left == null) return true;
|
| 3387 |
+
var dx = other.left - touch.left, dy = other.top - touch.top;
|
| 3388 |
+
return dx * dx + dy * dy > 20 * 20;
|
| 3389 |
+
}
|
| 3390 |
+
on(d.scroller, "touchstart", function(e) {
|
| 3391 |
+
if (!isMouseLikeTouchEvent(e)) {
|
| 3392 |
+
clearTimeout(touchFinished);
|
| 3393 |
+
var now = +new Date;
|
| 3394 |
+
d.activeTouch = {start: now, moved: false,
|
| 3395 |
+
prev: now - prevTouch.end <= 300 ? prevTouch : null};
|
| 3396 |
+
if (e.touches.length == 1) {
|
| 3397 |
+
d.activeTouch.left = e.touches[0].pageX;
|
| 3398 |
+
d.activeTouch.top = e.touches[0].pageY;
|
| 3399 |
+
}
|
| 3400 |
+
}
|
| 3401 |
+
});
|
| 3402 |
+
on(d.scroller, "touchmove", function() {
|
| 3403 |
+
if (d.activeTouch) d.activeTouch.moved = true;
|
| 3404 |
+
});
|
| 3405 |
+
on(d.scroller, "touchend", function(e) {
|
| 3406 |
+
var touch = d.activeTouch;
|
| 3407 |
+
if (touch && !eventInWidget(d, e) && touch.left != null &&
|
| 3408 |
+
!touch.moved && new Date - touch.start < 300) {
|
| 3409 |
+
var pos = cm.coordsChar(d.activeTouch, "page"), range;
|
| 3410 |
+
if (!touch.prev || farAway(touch, touch.prev)) // Single tap
|
| 3411 |
+
range = new Range(pos, pos);
|
| 3412 |
+
else if (!touch.prev.prev || farAway(touch, touch.prev.prev)) // Double tap
|
| 3413 |
+
range = cm.findWordAt(pos);
|
| 3414 |
+
else // Triple tap
|
| 3415 |
+
range = new Range(Pos(pos.line, 0), clipPos(cm.doc, Pos(pos.line + 1, 0)));
|
| 3416 |
+
cm.setSelection(range.anchor, range.head);
|
| 3417 |
+
cm.focus();
|
| 3418 |
+
e_preventDefault(e);
|
| 3419 |
+
}
|
| 3420 |
+
finishTouch();
|
| 3421 |
+
});
|
| 3422 |
+
on(d.scroller, "touchcancel", finishTouch);
|
| 3423 |
+
|
| 3424 |
+
// Sync scrolling between fake scrollbars and real scrollable
|
| 3425 |
+
// area, ensure viewport is updated when scrolling.
|
| 3426 |
+
on(d.scroller, "scroll", function() {
|
| 3427 |
+
if (d.scroller.clientHeight) {
|
| 3428 |
+
setScrollTop(cm, d.scroller.scrollTop);
|
| 3429 |
+
setScrollLeft(cm, d.scroller.scrollLeft, true);
|
| 3430 |
+
signal(cm, "scroll", cm);
|
| 3431 |
+
}
|
| 3432 |
+
});
|
| 3433 |
+
|
| 3434 |
+
// Listen to wheel events in order to try and update the viewport on time.
|
| 3435 |
+
on(d.scroller, "mousewheel", function(e){onScrollWheel(cm, e);});
|
| 3436 |
+
on(d.scroller, "DOMMouseScroll", function(e){onScrollWheel(cm, e);});
|
| 3437 |
+
|
| 3438 |
+
// Prevent wrapper from ever scrolling
|
| 3439 |
+
on(d.wrapper, "scroll", function() { d.wrapper.scrollTop = d.wrapper.scrollLeft = 0; });
|
| 3440 |
+
|
| 3441 |
+
d.dragFunctions = {
|
| 3442 |
+
simple: function(e) {if (!signalDOMEvent(cm, e)) e_stop(e);},
|
| 3443 |
+
start: function(e){onDragStart(cm, e);},
|
| 3444 |
+
drop: operation(cm, onDrop)
|
| 3445 |
+
};
|
| 3446 |
+
|
| 3447 |
+
var inp = d.input.getField();
|
| 3448 |
+
on(inp, "keyup", function(e) { onKeyUp.call(cm, e); });
|
| 3449 |
+
on(inp, "keydown", operation(cm, onKeyDown));
|
| 3450 |
+
on(inp, "keypress", operation(cm, onKeyPress));
|
| 3451 |
+
on(inp, "focus", bind(onFocus, cm));
|
| 3452 |
+
on(inp, "blur", bind(onBlur, cm));
|
| 3453 |
+
}
|
| 3454 |
+
|
| 3455 |
+
function dragDropChanged(cm, value, old) {
|
| 3456 |
+
var wasOn = old && old != CodeMirror.Init;
|
| 3457 |
+
if (!value != !wasOn) {
|
| 3458 |
+
var funcs = cm.display.dragFunctions;
|
| 3459 |
+
var toggle = value ? on : off;
|
| 3460 |
+
toggle(cm.display.scroller, "dragstart", funcs.start);
|
| 3461 |
+
toggle(cm.display.scroller, "dragenter", funcs.simple);
|
| 3462 |
+
toggle(cm.display.scroller, "dragover", funcs.simple);
|
| 3463 |
+
toggle(cm.display.scroller, "drop", funcs.drop);
|
| 3464 |
+
}
|
| 3465 |
+
}
|
| 3466 |
+
|
| 3467 |
+
// Called when the window resizes
|
| 3468 |
+
function onResize(cm) {
|
| 3469 |
+
var d = cm.display;
|
| 3470 |
+
if (d.lastWrapHeight == d.wrapper.clientHeight && d.lastWrapWidth == d.wrapper.clientWidth)
|
| 3471 |
+
return;
|
| 3472 |
+
// Might be a text scaling operation, clear size caches.
|
| 3473 |
+
d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null;
|
| 3474 |
+
d.scrollbarsClipped = false;
|
| 3475 |
+
cm.setSize();
|
| 3476 |
+
}
|
| 3477 |
+
|
| 3478 |
+
// MOUSE EVENTS
|
| 3479 |
+
|
| 3480 |
+
// Return true when the given mouse event happened in a widget
|
| 3481 |
+
function eventInWidget(display, e) {
|
| 3482 |
+
for (var n = e_target(e); n != display.wrapper; n = n.parentNode) {
|
| 3483 |
+
if (!n || (n.nodeType == 1 && n.getAttribute("cm-ignore-events") == "true") ||
|
| 3484 |
+
(n.parentNode == display.sizer && n != display.mover))
|
| 3485 |
+
return true;
|
| 3486 |
+
}
|
| 3487 |
+
}
|
| 3488 |
+
|
| 3489 |
+
// Given a mouse event, find the corresponding position. If liberal
|
| 3490 |
+
// is false, it checks whether a gutter or scrollbar was clicked,
|
| 3491 |
+
// and returns null if it was. forRect is used by rectangular
|
| 3492 |
+
// selections, and tries to estimate a character position even for
|
| 3493 |
+
// coordinates beyond the right of the text.
|
| 3494 |
+
function posFromMouse(cm, e, liberal, forRect) {
|
| 3495 |
+
var display = cm.display;
|
| 3496 |
+
if (!liberal && e_target(e).getAttribute("cm-not-content") == "true") return null;
|
| 3497 |
+
|
| 3498 |
+
var x, y, space = display.lineSpace.getBoundingClientRect();
|
| 3499 |
+
// Fails unpredictably on IE[67] when mouse is dragged around quickly.
|
| 3500 |
+
try { x = e.clientX - space.left; y = e.clientY - space.top; }
|
| 3501 |
+
catch (e) { return null; }
|
| 3502 |
+
var coords = coordsChar(cm, x, y), line;
|
| 3503 |
+
if (forRect && coords.xRel == 1 && (line = getLine(cm.doc, coords.line).text).length == coords.ch) {
|
| 3504 |
+
var colDiff = countColumn(line, line.length, cm.options.tabSize) - line.length;
|
| 3505 |
+
coords = Pos(coords.line, Math.max(0, Math.round((x - paddingH(cm.display).left) / charWidth(cm.display)) - colDiff));
|
| 3506 |
+
}
|
| 3507 |
+
return coords;
|
| 3508 |
+
}
|
| 3509 |
+
|
| 3510 |
+
// A mouse down can be a single click, double click, triple click,
|
| 3511 |
+
// start of selection drag, start of text drag, new cursor
|
| 3512 |
+
// (ctrl-click), rectangle drag (alt-drag), or xwin
|
| 3513 |
+
// middle-click-paste. Or it might be a click on something we should
|
| 3514 |
+
// not interfere with, such as a scrollbar or widget.
|
| 3515 |
+
function onMouseDown(e) {
|
| 3516 |
+
var cm = this, display = cm.display;
|
| 3517 |
+
if (display.activeTouch && display.input.supportsTouch() || signalDOMEvent(cm, e)) return;
|
| 3518 |
+
display.shift = e.shiftKey;
|
| 3519 |
+
|
| 3520 |
+
if (eventInWidget(display, e)) {
|
| 3521 |
+
if (!webkit) {
|
| 3522 |
+
// Briefly turn off draggability, to allow widgets to do
|
| 3523 |
+
// normal dragging things.
|
| 3524 |
+
display.scroller.draggable = false;
|
| 3525 |
+
setTimeout(function(){display.scroller.draggable = true;}, 100);
|
| 3526 |
+
}
|
| 3527 |
+
return;
|
| 3528 |
+
}
|
| 3529 |
+
if (clickInGutter(cm, e)) return;
|
| 3530 |
+
var start = posFromMouse(cm, e);
|
| 3531 |
+
window.focus();
|
| 3532 |
+
|
| 3533 |
+
switch (e_button(e)) {
|
| 3534 |
+
case 1:
|
| 3535 |
+
if (start)
|
| 3536 |
+
leftButtonDown(cm, e, start);
|
| 3537 |
+
else if (e_target(e) == display.scroller)
|
| 3538 |
+
e_preventDefault(e);
|
| 3539 |
+
break;
|
| 3540 |
+
case 2:
|
| 3541 |
+
if (webkit) cm.state.lastMiddleDown = +new Date;
|
| 3542 |
+
if (start) extendSelection(cm.doc, start);
|
| 3543 |
+
setTimeout(function() {display.input.focus();}, 20);
|
| 3544 |
+
e_preventDefault(e);
|
| 3545 |
+
break;
|
| 3546 |
+
case 3:
|
| 3547 |
+
if (captureRightClick) onContextMenu(cm, e);
|
| 3548 |
+
else delayBlurEvent(cm);
|
| 3549 |
+
break;
|
| 3550 |
+
}
|
| 3551 |
+
}
|
| 3552 |
+
|
| 3553 |
+
var lastClick, lastDoubleClick;
|
| 3554 |
+
function leftButtonDown(cm, e, start) {
|
| 3555 |
+
if (ie) setTimeout(bind(ensureFocus, cm), 0);
|
| 3556 |
+
else cm.curOp.focus = activeElt();
|
| 3557 |
+
|
| 3558 |
+
var now = +new Date, type;
|
| 3559 |
+
if (lastDoubleClick && lastDoubleClick.time > now - 400 && cmp(lastDoubleClick.pos, start) == 0) {
|
| 3560 |
+
type = "triple";
|
| 3561 |
+
} else if (lastClick && lastClick.time > now - 400 && cmp(lastClick.pos, start) == 0) {
|
| 3562 |
+
type = "double";
|
| 3563 |
+
lastDoubleClick = {time: now, pos: start};
|
| 3564 |
+
} else {
|
| 3565 |
+
type = "single";
|
| 3566 |
+
lastClick = {time: now, pos: start};
|
| 3567 |
+
}
|
| 3568 |
+
|
| 3569 |
+
var sel = cm.doc.sel, modifier = mac ? e.metaKey : e.ctrlKey, contained;
|
| 3570 |
+
if (cm.options.dragDrop && dragAndDrop && !isReadOnly(cm) &&
|
| 3571 |
+
type == "single" && (contained = sel.contains(start)) > -1 &&
|
| 3572 |
+
!sel.ranges[contained].empty())
|
| 3573 |
+
leftButtonStartDrag(cm, e, start, modifier);
|
| 3574 |
+
else
|
| 3575 |
+
leftButtonSelect(cm, e, start, type, modifier);
|
| 3576 |
+
}
|
| 3577 |
+
|
| 3578 |
+
// Start a text drag. When it ends, see if any dragging actually
|
| 3579 |
+
// happen, and treat as a click if it didn't.
|
| 3580 |
+
function leftButtonStartDrag(cm, e, start, modifier) {
|
| 3581 |
+
var display = cm.display, startTime = +new Date;
|
| 3582 |
+
var dragEnd = operation(cm, function(e2) {
|
| 3583 |
+
if (webkit) display.scroller.draggable = false;
|
| 3584 |
+
cm.state.draggingText = false;
|
| 3585 |
+
off(document, "mouseup", dragEnd);
|
| 3586 |
+
off(display.scroller, "drop", dragEnd);
|
| 3587 |
+
if (Math.abs(e.clientX - e2.clientX) + Math.abs(e.clientY - e2.clientY) < 10) {
|
| 3588 |
+
e_preventDefault(e2);
|
| 3589 |
+
if (!modifier && +new Date - 200 < startTime)
|
| 3590 |
+
extendSelection(cm.doc, start);
|
| 3591 |
+
// Work around unexplainable focus problem in IE9 (#2127) and Chrome (#3081)
|
| 3592 |
+
if (webkit || ie && ie_version == 9)
|
| 3593 |
+
setTimeout(function() {document.body.focus(); display.input.focus();}, 20);
|
| 3594 |
+
else
|
| 3595 |
+
display.input.focus();
|
| 3596 |
+
}
|
| 3597 |
+
});
|
| 3598 |
+
// Let the drag handler handle this.
|
| 3599 |
+
if (webkit) display.scroller.draggable = true;
|
| 3600 |
+
cm.state.draggingText = dragEnd;
|
| 3601 |
+
// IE's approach to draggable
|
| 3602 |
+
if (display.scroller.dragDrop) display.scroller.dragDrop();
|
| 3603 |
+
on(document, "mouseup", dragEnd);
|
| 3604 |
+
on(display.scroller, "drop", dragEnd);
|
| 3605 |
+
}
|
| 3606 |
+
|
| 3607 |
+
// Normal selection, as opposed to text dragging.
|
| 3608 |
+
function leftButtonSelect(cm, e, start, type, addNew) {
|
| 3609 |
+
var display = cm.display, doc = cm.doc;
|
| 3610 |
+
e_preventDefault(e);
|
| 3611 |
+
|
| 3612 |
+
var ourRange, ourIndex, startSel = doc.sel, ranges = startSel.ranges;
|
| 3613 |
+
if (addNew && !e.shiftKey) {
|
| 3614 |
+
ourIndex = doc.sel.contains(start);
|
| 3615 |
+
if (ourIndex > -1)
|
| 3616 |
+
ourRange = ranges[ourIndex];
|
| 3617 |
+
else
|
| 3618 |
+
ourRange = new Range(start, start);
|
| 3619 |
+
} else {
|
| 3620 |
+
ourRange = doc.sel.primary();
|
| 3621 |
+
ourIndex = doc.sel.primIndex;
|
| 3622 |
+
}
|
| 3623 |
+
|
| 3624 |
+
if (e.altKey) {
|
| 3625 |
+
type = "rect";
|
| 3626 |
+
if (!addNew) ourRange = new Range(start, start);
|
| 3627 |
+
start = posFromMouse(cm, e, true, true);
|
| 3628 |
+
ourIndex = -1;
|
| 3629 |
+
} else if (type == "double") {
|
| 3630 |
+
var word = cm.findWordAt(start);
|
| 3631 |
+
if (cm.display.shift || doc.extend)
|
| 3632 |
+
ourRange = extendRange(doc, ourRange, word.anchor, word.head);
|
| 3633 |
+
else
|
| 3634 |
+
ourRange = word;
|
| 3635 |
+
} else if (type == "triple") {
|
| 3636 |
+
var line = new Range(Pos(start.line, 0), clipPos(doc, Pos(start.line + 1, 0)));
|
| 3637 |
+
if (cm.display.shift || doc.extend)
|
| 3638 |
+
ourRange = extendRange(doc, ourRange, line.anchor, line.head);
|
| 3639 |
+
else
|
| 3640 |
+
ourRange = line;
|
| 3641 |
+
} else {
|
| 3642 |
+
ourRange = extendRange(doc, ourRange, start);
|
| 3643 |
+
}
|
| 3644 |
+
|
| 3645 |
+
if (!addNew) {
|
| 3646 |
+
ourIndex = 0;
|
| 3647 |
+
setSelection(doc, new Selection([ourRange], 0), sel_mouse);
|
| 3648 |
+
startSel = doc.sel;
|
| 3649 |
+
} else if (ourIndex == -1) {
|
| 3650 |
+
ourIndex = ranges.length;
|
| 3651 |
+
setSelection(doc, normalizeSelection(ranges.concat([ourRange]), ourIndex),
|
| 3652 |
+
{scroll: false, origin: "*mouse"});
|
| 3653 |
+
} else if (ranges.length > 1 && ranges[ourIndex].empty() && type == "single" && !e.shiftKey) {
|
| 3654 |
+
setSelection(doc, normalizeSelection(ranges.slice(0, ourIndex).concat(ranges.slice(ourIndex + 1)), 0));
|
| 3655 |
+
startSel = doc.sel;
|
| 3656 |
+
} else {
|
| 3657 |
+
replaceOneSelection(doc, ourIndex, ourRange, sel_mouse);
|
| 3658 |
+
}
|
| 3659 |
+
|
| 3660 |
+
var lastPos = start;
|
| 3661 |
+
function extendTo(pos) {
|
| 3662 |
+
if (cmp(lastPos, pos) == 0) return;
|
| 3663 |
+
lastPos = pos;
|
| 3664 |
+
|
| 3665 |
+
if (type == "rect") {
|
| 3666 |
+
var ranges = [], tabSize = cm.options.tabSize;
|
| 3667 |
+
var startCol = countColumn(getLine(doc, start.line).text, start.ch, tabSize);
|
| 3668 |
+
var posCol = countColumn(getLine(doc, pos.line).text, pos.ch, tabSize);
|
| 3669 |
+
var left = Math.min(startCol, posCol), right = Math.max(startCol, posCol);
|
| 3670 |
+
for (var line = Math.min(start.line, pos.line), end = Math.min(cm.lastLine(), Math.max(start.line, pos.line));
|
| 3671 |
+
line <= end; line++) {
|
| 3672 |
+
var text = getLine(doc, line).text, leftPos = findColumn(text, left, tabSize);
|
| 3673 |
+
if (left == right)
|
| 3674 |
+
ranges.push(new Range(Pos(line, leftPos), Pos(line, leftPos)));
|
| 3675 |
+
else if (text.length > leftPos)
|
| 3676 |
+
ranges.push(new Range(Pos(line, leftPos), Pos(line, findColumn(text, right, tabSize))));
|
| 3677 |
+
}
|
| 3678 |
+
if (!ranges.length) ranges.push(new Range(start, start));
|
| 3679 |
+
setSelection(doc, normalizeSelection(startSel.ranges.slice(0, ourIndex).concat(ranges), ourIndex),
|
| 3680 |
+
{origin: "*mouse", scroll: false});
|
| 3681 |
+
cm.scrollIntoView(pos);
|
| 3682 |
+
} else {
|
| 3683 |
+
var oldRange = ourRange;
|
| 3684 |
+
var anchor = oldRange.anchor, head = pos;
|
| 3685 |
+
if (type != "single") {
|
| 3686 |
+
if (type == "double")
|
| 3687 |
+
var range = cm.findWordAt(pos);
|
| 3688 |
+
else
|
| 3689 |
+
var range = new Range(Pos(pos.line, 0), clipPos(doc, Pos(pos.line + 1, 0)));
|
| 3690 |
+
if (cmp(range.anchor, anchor) > 0) {
|
| 3691 |
+
head = range.head;
|
| 3692 |
+
anchor = minPos(oldRange.from(), range.anchor);
|
| 3693 |
+
} else {
|
| 3694 |
+
head = range.anchor;
|
| 3695 |
+
anchor = maxPos(oldRange.to(), range.head);
|
| 3696 |
+
}
|
| 3697 |
+
}
|
| 3698 |
+
var ranges = startSel.ranges.slice(0);
|
| 3699 |
+
ranges[ourIndex] = new Range(clipPos(doc, anchor), head);
|
| 3700 |
+
setSelection(doc, normalizeSelection(ranges, ourIndex), sel_mouse);
|
| 3701 |
+
}
|
| 3702 |
+
}
|
| 3703 |
+
|
| 3704 |
+
var editorSize = display.wrapper.getBoundingClientRect();
|
| 3705 |
+
// Used to ensure timeout re-tries don't fire when another extend
|
| 3706 |
+
// happened in the meantime (clearTimeout isn't reliable -- at
|
| 3707 |
+
// least on Chrome, the timeouts still happen even when cleared,
|
| 3708 |
+
// if the clear happens after their scheduled firing time).
|
| 3709 |
+
var counter = 0;
|
| 3710 |
+
|
| 3711 |
+
function extend(e) {
|
| 3712 |
+
var curCount = ++counter;
|
| 3713 |
+
var cur = posFromMouse(cm, e, true, type == "rect");
|
| 3714 |
+
if (!cur) return;
|
| 3715 |
+
if (cmp(cur, lastPos) != 0) {
|
| 3716 |
+
cm.curOp.focus = activeElt();
|
| 3717 |
+
extendTo(cur);
|
| 3718 |
+
var visible = visibleLines(display, doc);
|
| 3719 |
+
if (cur.line >= visible.to || cur.line < visible.from)
|
| 3720 |
+
setTimeout(operation(cm, function(){if (counter == curCount) extend(e);}), 150);
|
| 3721 |
+
} else {
|
| 3722 |
+
var outside = e.clientY < editorSize.top ? -20 : e.clientY > editorSize.bottom ? 20 : 0;
|
| 3723 |
+
if (outside) setTimeout(operation(cm, function() {
|
| 3724 |
+
if (counter != curCount) return;
|
| 3725 |
+
display.scroller.scrollTop += outside;
|
| 3726 |
+
extend(e);
|
| 3727 |
+
}), 50);
|
| 3728 |
+
}
|
| 3729 |
+
}
|
| 3730 |
+
|
| 3731 |
+
function done(e) {
|
| 3732 |
+
counter = Infinity;
|
| 3733 |
+
e_preventDefault(e);
|
| 3734 |
+
display.input.focus();
|
| 3735 |
+
off(document, "mousemove", move);
|
| 3736 |
+
off(document, "mouseup", up);
|
| 3737 |
+
doc.history.lastSelOrigin = null;
|
| 3738 |
+
}
|
| 3739 |
+
|
| 3740 |
+
var move = operation(cm, function(e) {
|
| 3741 |
+
if (!e_button(e)) done(e);
|
| 3742 |
+
else extend(e);
|
| 3743 |
+
});
|
| 3744 |
+
var up = operation(cm, done);
|
| 3745 |
+
on(document, "mousemove", move);
|
| 3746 |
+
on(document, "mouseup", up);
|
| 3747 |
+
}
|
| 3748 |
+
|
| 3749 |
+
// Determines whether an event happened in the gutter, and fires the
|
| 3750 |
+
// handlers for the corresponding event.
|
| 3751 |
+
function gutterEvent(cm, e, type, prevent, signalfn) {
|
| 3752 |
+
try { var mX = e.clientX, mY = e.clientY; }
|
| 3753 |
+
catch(e) { return false; }
|
| 3754 |
+
if (mX >= Math.floor(cm.display.gutters.getBoundingClientRect().right)) return false;
|
| 3755 |
+
if (prevent) e_preventDefault(e);
|
| 3756 |
+
|
| 3757 |
+
var display = cm.display;
|
| 3758 |
+
var lineBox = display.lineDiv.getBoundingClientRect();
|
| 3759 |
+
|
| 3760 |
+
if (mY > lineBox.bottom || !hasHandler(cm, type)) return e_defaultPrevented(e);
|
| 3761 |
+
mY -= lineBox.top - display.viewOffset;
|
| 3762 |
+
|
| 3763 |
+
for (var i = 0; i < cm.options.gutters.length; ++i) {
|
| 3764 |
+
var g = display.gutters.childNodes[i];
|
| 3765 |
+
if (g && g.getBoundingClientRect().right >= mX) {
|
| 3766 |
+
var line = lineAtHeight(cm.doc, mY);
|
| 3767 |
+
var gutter = cm.options.gutters[i];
|
| 3768 |
+
signalfn(cm, type, cm, line, gutter, e);
|
| 3769 |
+
return e_defaultPrevented(e);
|
| 3770 |
+
}
|
| 3771 |
+
}
|
| 3772 |
+
}
|
| 3773 |
+
|
| 3774 |
+
function clickInGutter(cm, e) {
|
| 3775 |
+
return gutterEvent(cm, e, "gutterClick", true, signalLater);
|
| 3776 |
+
}
|
| 3777 |
+
|
| 3778 |
+
// Kludge to work around strange IE behavior where it'll sometimes
|
| 3779 |
+
// re-fire a series of drag-related events right after the drop (#1551)
|
| 3780 |
+
var lastDrop = 0;
|
| 3781 |
+
|
| 3782 |
+
function onDrop(e) {
|
| 3783 |
+
var cm = this;
|
| 3784 |
+
if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e))
|
| 3785 |
+
return;
|
| 3786 |
+
e_preventDefault(e);
|
| 3787 |
+
if (ie) lastDrop = +new Date;
|
| 3788 |
+
var pos = posFromMouse(cm, e, true), files = e.dataTransfer.files;
|
| 3789 |
+
if (!pos || isReadOnly(cm)) return;
|
| 3790 |
+
// Might be a file drop, in which case we simply extract the text
|
| 3791 |
+
// and insert it.
|
| 3792 |
+
if (files && files.length && window.FileReader && window.File) {
|
| 3793 |
+
var n = files.length, text = Array(n), read = 0;
|
| 3794 |
+
var loadFile = function(file, i) {
|
| 3795 |
+
var reader = new FileReader;
|
| 3796 |
+
reader.onload = operation(cm, function() {
|
| 3797 |
+
text[i] = reader.result;
|
| 3798 |
+
if (++read == n) {
|
| 3799 |
+
pos = clipPos(cm.doc, pos);
|
| 3800 |
+
var change = {from: pos, to: pos, text: splitLines(text.join("\n")), origin: "paste"};
|
| 3801 |
+
makeChange(cm.doc, change);
|
| 3802 |
+
setSelectionReplaceHistory(cm.doc, simpleSelection(pos, changeEnd(change)));
|
| 3803 |
+
}
|
| 3804 |
+
});
|
| 3805 |
+
reader.readAsText(file);
|
| 3806 |
+
};
|
| 3807 |
+
for (var i = 0; i < n; ++i) loadFile(files[i], i);
|
| 3808 |
+
} else { // Normal drop
|
| 3809 |
+
// Don't do a replace if the drop happened inside of the selected text.
|
| 3810 |
+
if (cm.state.draggingText && cm.doc.sel.contains(pos) > -1) {
|
| 3811 |
+
cm.state.draggingText(e);
|
| 3812 |
+
// Ensure the editor is re-focused
|
| 3813 |
+
setTimeout(function() {cm.display.input.focus();}, 20);
|
| 3814 |
+
return;
|
| 3815 |
+
}
|
| 3816 |
+
try {
|
| 3817 |
+
var text = e.dataTransfer.getData("Text");
|
| 3818 |
+
if (text) {
|
| 3819 |
+
if (cm.state.draggingText && !(mac ? e.altKey : e.ctrlKey))
|
| 3820 |
+
var selected = cm.listSelections();
|
| 3821 |
+
setSelectionNoUndo(cm.doc, simpleSelection(pos, pos));
|
| 3822 |
+
if (selected) for (var i = 0; i < selected.length; ++i)
|
| 3823 |
+
replaceRange(cm.doc, "", selected[i].anchor, selected[i].head, "drag");
|
| 3824 |
+
cm.replaceSelection(text, "around", "paste");
|
| 3825 |
+
cm.display.input.focus();
|
| 3826 |
+
}
|
| 3827 |
+
}
|
| 3828 |
+
catch(e){}
|
| 3829 |
+
}
|
| 3830 |
+
}
|
| 3831 |
+
|
| 3832 |
+
function onDragStart(cm, e) {
|
| 3833 |
+
if (ie && (!cm.state.draggingText || +new Date - lastDrop < 100)) { e_stop(e); return; }
|
| 3834 |
+
if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e)) return;
|
| 3835 |
+
|
| 3836 |
+
e.dataTransfer.setData("Text", cm.getSelection());
|
| 3837 |
+
|
| 3838 |
+
// Use dummy image instead of default browsers image.
|
| 3839 |
+
// Recent Safari (~6.0.2) have a tendency to segfault when this happens, so we don't do it there.
|
| 3840 |
+
if (e.dataTransfer.setDragImage && !safari) {
|
| 3841 |
+
var img = elt("img", null, null, "position: fixed; left: 0; top: 0;");
|
| 3842 |
+
img.src = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
|
| 3843 |
+
if (presto) {
|
| 3844 |
+
img.width = img.height = 1;
|
| 3845 |
+
cm.display.wrapper.appendChild(img);
|
| 3846 |
+
// Force a relayout, or Opera won't use our image for some obscure reason
|
| 3847 |
+
img._top = img.offsetTop;
|
| 3848 |
+
}
|
| 3849 |
+
e.dataTransfer.setDragImage(img, 0, 0);
|
| 3850 |
+
if (presto) img.parentNode.removeChild(img);
|
| 3851 |
+
}
|
| 3852 |
+
}
|
| 3853 |
+
|
| 3854 |
+
// SCROLL EVENTS
|
| 3855 |
+
|
| 3856 |
+
// Sync the scrollable area and scrollbars, ensure the viewport
|
| 3857 |
+
// covers the visible area.
|
| 3858 |
+
function setScrollTop(cm, val) {
|
| 3859 |
+
if (Math.abs(cm.doc.scrollTop - val) < 2) return;
|
| 3860 |
+
cm.doc.scrollTop = val;
|
| 3861 |
+
if (!gecko) updateDisplaySimple(cm, {top: val});
|
| 3862 |
+
if (cm.display.scroller.scrollTop != val) cm.display.scroller.scrollTop = val;
|
| 3863 |
+
cm.display.scrollbars.setScrollTop(val);
|
| 3864 |
+
if (gecko) updateDisplaySimple(cm);
|
| 3865 |
+
startWorker(cm, 100);
|
| 3866 |
+
}
|
| 3867 |
+
// Sync scroller and scrollbar, ensure the gutter elements are
|
| 3868 |
+
// aligned.
|
| 3869 |
+
function setScrollLeft(cm, val, isScroller) {
|
| 3870 |
+
if (isScroller ? val == cm.doc.scrollLeft : Math.abs(cm.doc.scrollLeft - val) < 2) return;
|
| 3871 |
+
val = Math.min(val, cm.display.scroller.scrollWidth - cm.display.scroller.clientWidth);
|
| 3872 |
+
cm.doc.scrollLeft = val;
|
| 3873 |
+
alignHorizontally(cm);
|
| 3874 |
+
if (cm.display.scroller.scrollLeft != val) cm.display.scroller.scrollLeft = val;
|
| 3875 |
+
cm.display.scrollbars.setScrollLeft(val);
|
| 3876 |
+
}
|
| 3877 |
+
|
| 3878 |
+
// Since the delta values reported on mouse wheel events are
|
| 3879 |
+
// unstandardized between browsers and even browser versions, and
|
| 3880 |
+
// generally horribly unpredictable, this code starts by measuring
|
| 3881 |
+
// the scroll effect that the first few mouse wheel events have,
|
| 3882 |
+
// and, from that, detects the way it can convert deltas to pixel
|
| 3883 |
+
// offsets afterwards.
|
| 3884 |
+
//
|
| 3885 |
+
// The reason we want to know the amount a wheel event will scroll
|
| 3886 |
+
// is that it gives us a chance to update the display before the
|
| 3887 |
+
// actual scrolling happens, reducing flickering.
|
| 3888 |
+
|
| 3889 |
+
var wheelSamples = 0, wheelPixelsPerUnit = null;
|
| 3890 |
+
// Fill in a browser-detected starting value on browsers where we
|
| 3891 |
+
// know one. These don't have to be accurate -- the result of them
|
| 3892 |
+
// being wrong would just be a slight flicker on the first wheel
|
| 3893 |
+
// scroll (if it is large enough).
|
| 3894 |
+
if (ie) wheelPixelsPerUnit = -.53;
|
| 3895 |
+
else if (gecko) wheelPixelsPerUnit = 15;
|
| 3896 |
+
else if (chrome) wheelPixelsPerUnit = -.7;
|
| 3897 |
+
else if (safari) wheelPixelsPerUnit = -1/3;
|
| 3898 |
+
|
| 3899 |
+
var wheelEventDelta = function(e) {
|
| 3900 |
+
var dx = e.wheelDeltaX, dy = e.wheelDeltaY;
|
| 3901 |
+
if (dx == null && e.detail && e.axis == e.HORIZONTAL_AXIS) dx = e.detail;
|
| 3902 |
+
if (dy == null && e.detail && e.axis == e.VERTICAL_AXIS) dy = e.detail;
|
| 3903 |
+
else if (dy == null) dy = e.wheelDelta;
|
| 3904 |
+
return {x: dx, y: dy};
|
| 3905 |
+
};
|
| 3906 |
+
CodeMirror.wheelEventPixels = function(e) {
|
| 3907 |
+
var delta = wheelEventDelta(e);
|
| 3908 |
+
delta.x *= wheelPixelsPerUnit;
|
| 3909 |
+
delta.y *= wheelPixelsPerUnit;
|
| 3910 |
+
return delta;
|
| 3911 |
+
};
|
| 3912 |
+
|
| 3913 |
+
function onScrollWheel(cm, e) {
|
| 3914 |
+
var delta = wheelEventDelta(e), dx = delta.x, dy = delta.y;
|
| 3915 |
+
|
| 3916 |
+
var display = cm.display, scroll = display.scroller;
|
| 3917 |
+
// Quit if there's nothing to scroll here
|
| 3918 |
+
if (!(dx && scroll.scrollWidth > scroll.clientWidth ||
|
| 3919 |
+
dy && scroll.scrollHeight > scroll.clientHeight)) return;
|
| 3920 |
+
|
| 3921 |
+
// Webkit browsers on OS X abort momentum scrolls when the target
|
| 3922 |
+
// of the scroll event is removed from the scrollable element.
|
| 3923 |
+
// This hack (see related code in patchDisplay) makes sure the
|
| 3924 |
+
// element is kept around.
|
| 3925 |
+
if (dy && mac && webkit) {
|
| 3926 |
+
outer: for (var cur = e.target, view = display.view; cur != scroll; cur = cur.parentNode) {
|
| 3927 |
+
for (var i = 0; i < view.length; i++) {
|
| 3928 |
+
if (view[i].node == cur) {
|
| 3929 |
+
cm.display.currentWheelTarget = cur;
|
| 3930 |
+
break outer;
|
| 3931 |
+
}
|
| 3932 |
+
}
|
| 3933 |
+
}
|
| 3934 |
+
}
|
| 3935 |
+
|
| 3936 |
+
// On some browsers, horizontal scrolling will cause redraws to
|
| 3937 |
+
// happen before the gutter has been realigned, causing it to
|
| 3938 |
+
// wriggle around in a most unseemly way. When we have an
|
| 3939 |
+
// estimated pixels/delta value, we just handle horizontal
|
| 3940 |
+
// scrolling entirely here. It'll be slightly off from native, but
|
| 3941 |
+
// better than glitching out.
|
| 3942 |
+
if (dx && !gecko && !presto && wheelPixelsPerUnit != null) {
|
| 3943 |
+
if (dy)
|
| 3944 |
+
setScrollTop(cm, Math.max(0, Math.min(scroll.scrollTop + dy * wheelPixelsPerUnit, scroll.scrollHeight - scroll.clientHeight)));
|
| 3945 |
+
setScrollLeft(cm, Math.max(0, Math.min(scroll.scrollLeft + dx * wheelPixelsPerUnit, scroll.scrollWidth - scroll.clientWidth)));
|
| 3946 |
+
e_preventDefault(e);
|
| 3947 |
+
display.wheelStartX = null; // Abort measurement, if in progress
|
| 3948 |
+
return;
|
| 3949 |
+
}
|
| 3950 |
+
|
| 3951 |
+
// 'Project' the visible viewport to cover the area that is being
|
| 3952 |
+
// scrolled into view (if we know enough to estimate it).
|
| 3953 |
+
if (dy && wheelPixelsPerUnit != null) {
|
| 3954 |
+
var pixels = dy * wheelPixelsPerUnit;
|
| 3955 |
+
var top = cm.doc.scrollTop, bot = top + display.wrapper.clientHeight;
|
| 3956 |
+
if (pixels < 0) top = Math.max(0, top + pixels - 50);
|
| 3957 |
+
else bot = Math.min(cm.doc.height, bot + pixels + 50);
|
| 3958 |
+
updateDisplaySimple(cm, {top: top, bottom: bot});
|
| 3959 |
+
}
|
| 3960 |
+
|
| 3961 |
+
if (wheelSamples < 20) {
|
| 3962 |
+
if (display.wheelStartX == null) {
|
| 3963 |
+
display.wheelStartX = scroll.scrollLeft; display.wheelStartY = scroll.scrollTop;
|
| 3964 |
+
display.wheelDX = dx; display.wheelDY = dy;
|
| 3965 |
+
setTimeout(function() {
|
| 3966 |
+
if (display.wheelStartX == null) return;
|
| 3967 |
+
var movedX = scroll.scrollLeft - display.wheelStartX;
|
| 3968 |
+
var movedY = scroll.scrollTop - display.wheelStartY;
|
| 3969 |
+
var sample = (movedY && display.wheelDY && movedY / display.wheelDY) ||
|
| 3970 |
+
(movedX && display.wheelDX && movedX / display.wheelDX);
|
| 3971 |
+
display.wheelStartX = display.wheelStartY = null;
|
| 3972 |
+
if (!sample) return;
|
| 3973 |
+
wheelPixelsPerUnit = (wheelPixelsPerUnit * wheelSamples + sample) / (wheelSamples + 1);
|
| 3974 |
+
++wheelSamples;
|
| 3975 |
+
}, 200);
|
| 3976 |
+
} else {
|
| 3977 |
+
display.wheelDX += dx; display.wheelDY += dy;
|
| 3978 |
+
}
|
| 3979 |
+
}
|
| 3980 |
+
}
|
| 3981 |
+
|
| 3982 |
+
// KEY EVENTS
|
| 3983 |
+
|
| 3984 |
+
// Run a handler that was bound to a key.
|
| 3985 |
+
function doHandleBinding(cm, bound, dropShift) {
|
| 3986 |
+
if (typeof bound == "string") {
|
| 3987 |
+
bound = commands[bound];
|
| 3988 |
+
if (!bound) return false;
|
| 3989 |
+
}
|
| 3990 |
+
// Ensure previous input has been read, so that the handler sees a
|
| 3991 |
+
// consistent view of the document
|
| 3992 |
+
cm.display.input.ensurePolled();
|
| 3993 |
+
var prevShift = cm.display.shift, done = false;
|
| 3994 |
+
try {
|
| 3995 |
+
if (isReadOnly(cm)) cm.state.suppressEdits = true;
|
| 3996 |
+
if (dropShift) cm.display.shift = false;
|
| 3997 |
+
done = bound(cm) != Pass;
|
| 3998 |
+
} finally {
|
| 3999 |
+
cm.display.shift = prevShift;
|
| 4000 |
+
cm.state.suppressEdits = false;
|
| 4001 |
+
}
|
| 4002 |
+
return done;
|
| 4003 |
+
}
|
| 4004 |
+
|
| 4005 |
+
function lookupKeyForEditor(cm, name, handle) {
|
| 4006 |
+
for (var i = 0; i < cm.state.keyMaps.length; i++) {
|
| 4007 |
+
var result = lookupKey(name, cm.state.keyMaps[i], handle, cm);
|
| 4008 |
+
if (result) return result;
|
| 4009 |
+
}
|
| 4010 |
+
return (cm.options.extraKeys && lookupKey(name, cm.options.extraKeys, handle, cm))
|
| 4011 |
+
|| lookupKey(name, cm.options.keyMap, handle, cm);
|
| 4012 |
+
}
|
| 4013 |
+
|
| 4014 |
+
var stopSeq = new Delayed;
|
| 4015 |
+
function dispatchKey(cm, name, e, handle) {
|
| 4016 |
+
var seq = cm.state.keySeq;
|
| 4017 |
+
if (seq) {
|
| 4018 |
+
if (isModifierKey(name)) return "handled";
|
| 4019 |
+
stopSeq.set(50, function() {
|
| 4020 |
+
if (cm.state.keySeq == seq) {
|
| 4021 |
+
cm.state.keySeq = null;
|
| 4022 |
+
cm.display.input.reset();
|
| 4023 |
+
}
|
| 4024 |
+
});
|
| 4025 |
+
name = seq + " " + name;
|
| 4026 |
+
}
|
| 4027 |
+
var result = lookupKeyForEditor(cm, name, handle);
|
| 4028 |
+
|
| 4029 |
+
if (result == "multi")
|
| 4030 |
+
cm.state.keySeq = name;
|
| 4031 |
+
if (result == "handled")
|
| 4032 |
+
signalLater(cm, "keyHandled", cm, name, e);
|
| 4033 |
+
|
| 4034 |
+
if (result == "handled" || result == "multi") {
|
| 4035 |
+
e_preventDefault(e);
|
| 4036 |
+
restartBlink(cm);
|
| 4037 |
+
}
|
| 4038 |
+
|
| 4039 |
+
if (seq && !result && /\'$/.test(name)) {
|
| 4040 |
+
e_preventDefault(e);
|
| 4041 |
+
return true;
|
| 4042 |
+
}
|
| 4043 |
+
return !!result;
|
| 4044 |
+
}
|
| 4045 |
+
|
| 4046 |
+
// Handle a key from the keydown event.
|
| 4047 |
+
function handleKeyBinding(cm, e) {
|
| 4048 |
+
var name = keyName(e, true);
|
| 4049 |
+
if (!name) return false;
|
| 4050 |
+
|
| 4051 |
+
if (e.shiftKey && !cm.state.keySeq) {
|
| 4052 |
+
// First try to resolve full name (including 'Shift-'). Failing
|
| 4053 |
+
// that, see if there is a cursor-motion command (starting with
|
| 4054 |
+
// 'go') bound to the keyname without 'Shift-'.
|
| 4055 |
+
return dispatchKey(cm, "Shift-" + name, e, function(b) {return doHandleBinding(cm, b, true);})
|
| 4056 |
+
|| dispatchKey(cm, name, e, function(b) {
|
| 4057 |
+
if (typeof b == "string" ? /^go[A-Z]/.test(b) : b.motion)
|
| 4058 |
+
return doHandleBinding(cm, b);
|
| 4059 |
+
});
|
| 4060 |
+
} else {
|
| 4061 |
+
return dispatchKey(cm, name, e, function(b) { return doHandleBinding(cm, b); });
|
| 4062 |
+
}
|
| 4063 |
+
}
|
| 4064 |
+
|
| 4065 |
+
// Handle a key from the keypress event
|
| 4066 |
+
function handleCharBinding(cm, e, ch) {
|
| 4067 |
+
return dispatchKey(cm, "'" + ch + "'", e,
|
| 4068 |
+
function(b) { return doHandleBinding(cm, b, true); });
|
| 4069 |
+
}
|
| 4070 |
+
|
| 4071 |
+
var lastStoppedKey = null;
|
| 4072 |
+
function onKeyDown(e) {
|
| 4073 |
+
var cm = this;
|
| 4074 |
+
cm.curOp.focus = activeElt();
|
| 4075 |
+
if (signalDOMEvent(cm, e)) return;
|
| 4076 |
+
// IE does strange things with escape.
|
| 4077 |
+
if (ie && ie_version < 11 && e.keyCode == 27) e.returnValue = false;
|
| 4078 |
+
var code = e.keyCode;
|
| 4079 |
+
cm.display.shift = code == 16 || e.shiftKey;
|
| 4080 |
+
var handled = handleKeyBinding(cm, e);
|
| 4081 |
+
if (presto) {
|
| 4082 |
+
lastStoppedKey = handled ? code : null;
|
| 4083 |
+
// Opera has no cut event... we try to at least catch the key combo
|
| 4084 |
+
if (!handled && code == 88 && !hasCopyEvent && (mac ? e.metaKey : e.ctrlKey))
|
| 4085 |
+
cm.replaceSelection("", null, "cut");
|
| 4086 |
+
}
|
| 4087 |
+
|
| 4088 |
+
// Turn mouse into crosshair when Alt is held on Mac.
|
| 4089 |
+
if (code == 18 && !/\bCodeMirror-crosshair\b/.test(cm.display.lineDiv.className))
|
| 4090 |
+
showCrossHair(cm);
|
| 4091 |
+
}
|
| 4092 |
+
|
| 4093 |
+
function showCrossHair(cm) {
|
| 4094 |
+
var lineDiv = cm.display.lineDiv;
|
| 4095 |
+
addClass(lineDiv, "CodeMirror-crosshair");
|
| 4096 |
+
|
| 4097 |
+
function up(e) {
|
| 4098 |
+
if (e.keyCode == 18 || !e.altKey) {
|
| 4099 |
+
rmClass(lineDiv, "CodeMirror-crosshair");
|
| 4100 |
+
off(document, "keyup", up);
|
| 4101 |
+
off(document, "mouseover", up);
|
| 4102 |
+
}
|
| 4103 |
+
}
|
| 4104 |
+
on(document, "keyup", up);
|
| 4105 |
+
on(document, "mouseover", up);
|
| 4106 |
+
}
|
| 4107 |
+
|
| 4108 |
+
function onKeyUp(e) {
|
| 4109 |
+
if (e.keyCode == 16) this.doc.sel.shift = false;
|
| 4110 |
+
signalDOMEvent(this, e);
|
| 4111 |
+
}
|
| 4112 |
+
|
| 4113 |
+
function onKeyPress(e) {
|
| 4114 |
+
var cm = this;
|
| 4115 |
+
if (eventInWidget(cm.display, e) || signalDOMEvent(cm, e) || e.ctrlKey && !e.altKey || mac && e.metaKey) return;
|
| 4116 |
+
var keyCode = e.keyCode, charCode = e.charCode;
|
| 4117 |
+
if (presto && keyCode == lastStoppedKey) {lastStoppedKey = null; e_preventDefault(e); return;}
|
| 4118 |
+
if ((presto && (!e.which || e.which < 10)) && handleKeyBinding(cm, e)) return;
|
| 4119 |
+
var ch = String.fromCharCode(charCode == null ? keyCode : charCode);
|
| 4120 |
+
if (handleCharBinding(cm, e, ch)) return;
|
| 4121 |
+
cm.display.input.onKeyPress(e);
|
| 4122 |
+
}
|
| 4123 |
+
|
| 4124 |
+
// FOCUS/BLUR EVENTS
|
| 4125 |
+
|
| 4126 |
+
function delayBlurEvent(cm) {
|
| 4127 |
+
cm.state.delayingBlurEvent = true;
|
| 4128 |
+
setTimeout(function() {
|
| 4129 |
+
if (cm.state.delayingBlurEvent) {
|
| 4130 |
+
cm.state.delayingBlurEvent = false;
|
| 4131 |
+
onBlur(cm);
|
| 4132 |
+
}
|
| 4133 |
+
}, 100);
|
| 4134 |
+
}
|
| 4135 |
+
|
| 4136 |
+
function onFocus(cm) {
|
| 4137 |
+
if (cm.state.delayingBlurEvent) cm.state.delayingBlurEvent = false;
|
| 4138 |
+
|
| 4139 |
+
if (cm.options.readOnly == "nocursor") return;
|
| 4140 |
+
if (!cm.state.focused) {
|
| 4141 |
+
signal(cm, "focus", cm);
|
| 4142 |
+
cm.state.focused = true;
|
| 4143 |
+
addClass(cm.display.wrapper, "CodeMirror-focused");
|
| 4144 |
+
// This test prevents this from firing when a context
|
| 4145 |
+
// menu is closed (since the input reset would kill the
|
| 4146 |
+
// select-all detection hack)
|
| 4147 |
+
if (!cm.curOp && cm.display.selForContextMenu != cm.doc.sel) {
|
| 4148 |
+
cm.display.input.reset();
|
| 4149 |
+
if (webkit) setTimeout(function() { cm.display.input.reset(true); }, 20); // Issue #1730
|
| 4150 |
+
}
|
| 4151 |
+
cm.display.input.receivedFocus();
|
| 4152 |
+
}
|
| 4153 |
+
restartBlink(cm);
|
| 4154 |
+
}
|
| 4155 |
+
function onBlur(cm) {
|
| 4156 |
+
if (cm.state.delayingBlurEvent) return;
|
| 4157 |
+
|
| 4158 |
+
if (cm.state.focused) {
|
| 4159 |
+
signal(cm, "blur", cm);
|
| 4160 |
+
cm.state.focused = false;
|
| 4161 |
+
rmClass(cm.display.wrapper, "CodeMirror-focused");
|
| 4162 |
+
}
|
| 4163 |
+
clearInterval(cm.display.blinker);
|
| 4164 |
+
setTimeout(function() {if (!cm.state.focused) cm.display.shift = false;}, 150);
|
| 4165 |
+
}
|
| 4166 |
+
|
| 4167 |
+
// CONTEXT MENU HANDLING
|
| 4168 |
+
|
| 4169 |
+
// To make the context menu work, we need to briefly unhide the
|
| 4170 |
+
// textarea (making it as unobtrusive as possible) to let the
|
| 4171 |
+
// right-click take effect on it.
|
| 4172 |
+
function onContextMenu(cm, e) {
|
| 4173 |
+
if (eventInWidget(cm.display, e) || contextMenuInGutter(cm, e)) return;
|
| 4174 |
+
cm.display.input.onContextMenu(e);
|
| 4175 |
+
}
|
| 4176 |
+
|
| 4177 |
+
function contextMenuInGutter(cm, e) {
|
| 4178 |
+
if (!hasHandler(cm, "gutterContextMenu")) return false;
|
| 4179 |
+
return gutterEvent(cm, e, "gutterContextMenu", false, signal);
|
| 4180 |
+
}
|
| 4181 |
+
|
| 4182 |
+
// UPDATING
|
| 4183 |
+
|
| 4184 |
+
// Compute the position of the end of a change (its 'to' property
|
| 4185 |
+
// refers to the pre-change end).
|
| 4186 |
+
var changeEnd = CodeMirror.changeEnd = function(change) {
|
| 4187 |
+
if (!change.text) return change.to;
|
| 4188 |
+
return Pos(change.from.line + change.text.length - 1,
|
| 4189 |
+
lst(change.text).length + (change.text.length == 1 ? change.from.ch : 0));
|
| 4190 |
+
};
|
| 4191 |
+
|
| 4192 |
+
// Adjust a position to refer to the post-change position of the
|
| 4193 |
+
// same text, or the end of the change if the change covers it.
|
| 4194 |
+
function adjustForChange(pos, change) {
|
| 4195 |
+
if (cmp(pos, change.from) < 0) return pos;
|
| 4196 |
+
if (cmp(pos, change.to) <= 0) return changeEnd(change);
|
| 4197 |
+
|
| 4198 |
+
var line = pos.line + change.text.length - (change.to.line - change.from.line) - 1, ch = pos.ch;
|
| 4199 |
+
if (pos.line == change.to.line) ch += changeEnd(change).ch - change.to.ch;
|
| 4200 |
+
return Pos(line, ch);
|
| 4201 |
+
}
|
| 4202 |
+
|
| 4203 |
+
function computeSelAfterChange(doc, change) {
|
| 4204 |
+
var out = [];
|
| 4205 |
+
for (var i = 0; i < doc.sel.ranges.length; i++) {
|
| 4206 |
+
var range = doc.sel.ranges[i];
|
| 4207 |
+
out.push(new Range(adjustForChange(range.anchor, change),
|
| 4208 |
+
adjustForChange(range.head, change)));
|
| 4209 |
+
}
|
| 4210 |
+
return normalizeSelection(out, doc.sel.primIndex);
|
| 4211 |
+
}
|
| 4212 |
+
|
| 4213 |
+
function offsetPos(pos, old, nw) {
|
| 4214 |
+
if (pos.line == old.line)
|
| 4215 |
+
return Pos(nw.line, pos.ch - old.ch + nw.ch);
|
| 4216 |
+
else
|
| 4217 |
+
return Pos(nw.line + (pos.line - old.line), pos.ch);
|
| 4218 |
+
}
|
| 4219 |
+
|
| 4220 |
+
// Used by replaceSelections to allow moving the selection to the
|
| 4221 |
+
// start or around the replaced test. Hint may be "start" or "around".
|
| 4222 |
+
function computeReplacedSel(doc, changes, hint) {
|
| 4223 |
+
var out = [];
|
| 4224 |
+
var oldPrev = Pos(doc.first, 0), newPrev = oldPrev;
|
| 4225 |
+
for (var i = 0; i < changes.length; i++) {
|
| 4226 |
+
var change = changes[i];
|
| 4227 |
+
var from = offsetPos(change.from, oldPrev, newPrev);
|
| 4228 |
+
var to = offsetPos(changeEnd(change), oldPrev, newPrev);
|
| 4229 |
+
oldPrev = change.to;
|
| 4230 |
+
newPrev = to;
|
| 4231 |
+
if (hint == "around") {
|
| 4232 |
+
var range = doc.sel.ranges[i], inv = cmp(range.head, range.anchor) < 0;
|
| 4233 |
+
out[i] = new Range(inv ? to : from, inv ? from : to);
|
| 4234 |
+
} else {
|
| 4235 |
+
out[i] = new Range(from, from);
|
| 4236 |
+
}
|
| 4237 |
+
}
|
| 4238 |
+
return new Selection(out, doc.sel.primIndex);
|
| 4239 |
+
}
|
| 4240 |
+
|
| 4241 |
+
// Allow "beforeChange" event handlers to influence a change
|
| 4242 |
+
function filterChange(doc, change, update) {
|
| 4243 |
+
var obj = {
|
| 4244 |
+
canceled: false,
|
| 4245 |
+
from: change.from,
|
| 4246 |
+
to: change.to,
|
| 4247 |
+
text: change.text,
|
| 4248 |
+
origin: change.origin,
|
| 4249 |
+
cancel: function() { this.canceled = true; }
|
| 4250 |
+
};
|
| 4251 |
+
if (update) obj.update = function(from, to, text, origin) {
|
| 4252 |
+
if (from) this.from = clipPos(doc, from);
|
| 4253 |
+
if (to) this.to = clipPos(doc, to);
|
| 4254 |
+
if (text) this.text = text;
|
| 4255 |
+
if (origin !== undefined) this.origin = origin;
|
| 4256 |
+
};
|
| 4257 |
+
signal(doc, "beforeChange", doc, obj);
|
| 4258 |
+
if (doc.cm) signal(doc.cm, "beforeChange", doc.cm, obj);
|
| 4259 |
+
|
| 4260 |
+
if (obj.canceled) return null;
|
| 4261 |
+
return {from: obj.from, to: obj.to, text: obj.text, origin: obj.origin};
|
| 4262 |
+
}
|
| 4263 |
+
|
| 4264 |
+
// Apply a change to a document, and add it to the document's
|
| 4265 |
+
// history, and propagating it to all linked documents.
|
| 4266 |
+
function makeChange(doc, change, ignoreReadOnly) {
|
| 4267 |
+
if (doc.cm) {
|
| 4268 |
+
if (!doc.cm.curOp) return operation(doc.cm, makeChange)(doc, change, ignoreReadOnly);
|
| 4269 |
+
if (doc.cm.state.suppressEdits) return;
|
| 4270 |
+
}
|
| 4271 |
+
|
| 4272 |
+
if (hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange")) {
|
| 4273 |
+
change = filterChange(doc, change, true);
|
| 4274 |
+
if (!change) return;
|
| 4275 |
+
}
|
| 4276 |
+
|
| 4277 |
+
// Possibly split or suppress the update based on the presence
|
| 4278 |
+
// of read-only spans in its range.
|
| 4279 |
+
var split = sawReadOnlySpans && !ignoreReadOnly && removeReadOnlyRanges(doc, change.from, change.to);
|
| 4280 |
+
if (split) {
|
| 4281 |
+
for (var i = split.length - 1; i >= 0; --i)
|
| 4282 |
+
makeChangeInner(doc, {from: split[i].from, to: split[i].to, text: i ? [""] : change.text});
|
| 4283 |
+
} else {
|
| 4284 |
+
makeChangeInner(doc, change);
|
| 4285 |
+
}
|
| 4286 |
+
}
|
| 4287 |
+
|
| 4288 |
+
function makeChangeInner(doc, change) {
|
| 4289 |
+
if (change.text.length == 1 && change.text[0] == "" && cmp(change.from, change.to) == 0) return;
|
| 4290 |
+
var selAfter = computeSelAfterChange(doc, change);
|
| 4291 |
+
addChangeToHistory(doc, change, selAfter, doc.cm ? doc.cm.curOp.id : NaN);
|
| 4292 |
+
|
| 4293 |
+
makeChangeSingleDoc(doc, change, selAfter, stretchSpansOverChange(doc, change));
|
| 4294 |
+
var rebased = [];
|
| 4295 |
+
|
| 4296 |
+
linkedDocs(doc, function(doc, sharedHist) {
|
| 4297 |
+
if (!sharedHist && indexOf(rebased, doc.history) == -1) {
|
| 4298 |
+
rebaseHist(doc.history, change);
|
| 4299 |
+
rebased.push(doc.history);
|
| 4300 |
+
}
|
| 4301 |
+
makeChangeSingleDoc(doc, change, null, stretchSpansOverChange(doc, change));
|
| 4302 |
+
});
|
| 4303 |
+
}
|
| 4304 |
+
|
| 4305 |
+
// Revert a change stored in a document's history.
|
| 4306 |
+
function makeChangeFromHistory(doc, type, allowSelectionOnly) {
|
| 4307 |
+
if (doc.cm && doc.cm.state.suppressEdits) return;
|
| 4308 |
+
|
| 4309 |
+
var hist = doc.history, event, selAfter = doc.sel;
|
| 4310 |
+
var source = type == "undo" ? hist.done : hist.undone, dest = type == "undo" ? hist.undone : hist.done;
|
| 4311 |
+
|
| 4312 |
+
// Verify that there is a useable event (so that ctrl-z won't
|
| 4313 |
+
// needlessly clear selection events)
|
| 4314 |
+
for (var i = 0; i < source.length; i++) {
|
| 4315 |
+
event = source[i];
|
| 4316 |
+
if (allowSelectionOnly ? event.ranges && !event.equals(doc.sel) : !event.ranges)
|
| 4317 |
+
break;
|
| 4318 |
+
}
|
| 4319 |
+
if (i == source.length) return;
|
| 4320 |
+
hist.lastOrigin = hist.lastSelOrigin = null;
|
| 4321 |
+
|
| 4322 |
+
for (;;) {
|
| 4323 |
+
event = source.pop();
|
| 4324 |
+
if (event.ranges) {
|
| 4325 |
+
pushSelectionToHistory(event, dest);
|
| 4326 |
+
if (allowSelectionOnly && !event.equals(doc.sel)) {
|
| 4327 |
+
setSelection(doc, event, {clearRedo: false});
|
| 4328 |
+
return;
|
| 4329 |
+
}
|
| 4330 |
+
selAfter = event;
|
| 4331 |
+
}
|
| 4332 |
+
else break;
|
| 4333 |
+
}
|
| 4334 |
+
|
| 4335 |
+
// Build up a reverse change object to add to the opposite history
|
| 4336 |
+
// stack (redo when undoing, and vice versa).
|
| 4337 |
+
var antiChanges = [];
|
| 4338 |
+
pushSelectionToHistory(selAfter, dest);
|
| 4339 |
+
dest.push({changes: antiChanges, generation: hist.generation});
|
| 4340 |
+
hist.generation = event.generation || ++hist.maxGeneration;
|
| 4341 |
+
|
| 4342 |
+
var filter = hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange");
|
| 4343 |
+
|
| 4344 |
+
for (var i = event.changes.length - 1; i >= 0; --i) {
|
| 4345 |
+
var change = event.changes[i];
|
| 4346 |
+
change.origin = type;
|
| 4347 |
+
if (filter && !filterChange(doc, change, false)) {
|
| 4348 |
+
source.length = 0;
|
| 4349 |
+
return;
|
| 4350 |
+
}
|
| 4351 |
+
|
| 4352 |
+
antiChanges.push(historyChangeFromChange(doc, change));
|
| 4353 |
+
|
| 4354 |
+
var after = i ? computeSelAfterChange(doc, change) : lst(source);
|
| 4355 |
+
makeChangeSingleDoc(doc, change, after, mergeOldSpans(doc, change));
|
| 4356 |
+
if (!i && doc.cm) doc.cm.scrollIntoView({from: change.from, to: changeEnd(change)});
|
| 4357 |
+
var rebased = [];
|
| 4358 |
+
|
| 4359 |
+
// Propagate to the linked documents
|
| 4360 |
+
linkedDocs(doc, function(doc, sharedHist) {
|
| 4361 |
+
if (!sharedHist && indexOf(rebased, doc.history) == -1) {
|
| 4362 |
+
rebaseHist(doc.history, change);
|
| 4363 |
+
rebased.push(doc.history);
|
| 4364 |
+
}
|
| 4365 |
+
makeChangeSingleDoc(doc, change, null, mergeOldSpans(doc, change));
|
| 4366 |
+
});
|
| 4367 |
+
}
|
| 4368 |
+
}
|
| 4369 |
+
|
| 4370 |
+
// Sub-views need their line numbers shifted when text is added
|
| 4371 |
+
// above or below them in the parent document.
|
| 4372 |
+
function shiftDoc(doc, distance) {
|
| 4373 |
+
if (distance == 0) return;
|
| 4374 |
+
doc.first += distance;
|
| 4375 |
+
doc.sel = new Selection(map(doc.sel.ranges, function(range) {
|
| 4376 |
+
return new Range(Pos(range.anchor.line + distance, range.anchor.ch),
|
| 4377 |
+
Pos(range.head.line + distance, range.head.ch));
|
| 4378 |
+
}), doc.sel.primIndex);
|
| 4379 |
+
if (doc.cm) {
|
| 4380 |
+
regChange(doc.cm, doc.first, doc.first - distance, distance);
|
| 4381 |
+
for (var d = doc.cm.display, l = d.viewFrom; l < d.viewTo; l++)
|
| 4382 |
+
regLineChange(doc.cm, l, "gutter");
|
| 4383 |
+
}
|
| 4384 |
+
}
|
| 4385 |
+
|
| 4386 |
+
// More lower-level change function, handling only a single document
|
| 4387 |
+
// (not linked ones).
|
| 4388 |
+
function makeChangeSingleDoc(doc, change, selAfter, spans) {
|
| 4389 |
+
if (doc.cm && !doc.cm.curOp)
|
| 4390 |
+
return operation(doc.cm, makeChangeSingleDoc)(doc, change, selAfter, spans);
|
| 4391 |
+
|
| 4392 |
+
if (change.to.line < doc.first) {
|
| 4393 |
+
shiftDoc(doc, change.text.length - 1 - (change.to.line - change.from.line));
|
| 4394 |
+
return;
|
| 4395 |
+
}
|
| 4396 |
+
if (change.from.line > doc.lastLine()) return;
|
| 4397 |
+
|
| 4398 |
+
// Clip the change to the size of this doc
|
| 4399 |
+
if (change.from.line < doc.first) {
|
| 4400 |
+
var shift = change.text.length - 1 - (doc.first - change.from.line);
|
| 4401 |
+
shiftDoc(doc, shift);
|
| 4402 |
+
change = {from: Pos(doc.first, 0), to: Pos(change.to.line + shift, change.to.ch),
|
| 4403 |
+
text: [lst(change.text)], origin: change.origin};
|
| 4404 |
+
}
|
| 4405 |
+
var last = doc.lastLine();
|
| 4406 |
+
if (change.to.line > last) {
|
| 4407 |
+
change = {from: change.from, to: Pos(last, getLine(doc, last).text.length),
|
| 4408 |
+
text: [change.text[0]], origin: change.origin};
|
| 4409 |
+
}
|
| 4410 |
+
|
| 4411 |
+
change.removed = getBetween(doc, change.from, change.to);
|
| 4412 |
+
|
| 4413 |
+
if (!selAfter) selAfter = computeSelAfterChange(doc, change);
|
| 4414 |
+
if (doc.cm) makeChangeSingleDocInEditor(doc.cm, change, spans);
|
| 4415 |
+
else updateDoc(doc, change, spans);
|
| 4416 |
+
setSelectionNoUndo(doc, selAfter, sel_dontScroll);
|
| 4417 |
+
}
|
| 4418 |
+
|
| 4419 |
+
// Handle the interaction of a change to a document with the editor
|
| 4420 |
+
// that this document is part of.
|
| 4421 |
+
function makeChangeSingleDocInEditor(cm, change, spans) {
|
| 4422 |
+
var doc = cm.doc, display = cm.display, from = change.from, to = change.to;
|
| 4423 |
+
|
| 4424 |
+
var recomputeMaxLength = false, checkWidthStart = from.line;
|
| 4425 |
+
if (!cm.options.lineWrapping) {
|
| 4426 |
+
checkWidthStart = lineNo(visualLine(getLine(doc, from.line)));
|
| 4427 |
+
doc.iter(checkWidthStart, to.line + 1, function(line) {
|
| 4428 |
+
if (line == display.maxLine) {
|
| 4429 |
+
recomputeMaxLength = true;
|
| 4430 |
+
return true;
|
| 4431 |
+
}
|
| 4432 |
+
});
|
| 4433 |
+
}
|
| 4434 |
+
|
| 4435 |
+
if (doc.sel.contains(change.from, change.to) > -1)
|
| 4436 |
+
signalCursorActivity(cm);
|
| 4437 |
+
|
| 4438 |
+
updateDoc(doc, change, spans, estimateHeight(cm));
|
| 4439 |
+
|
| 4440 |
+
if (!cm.options.lineWrapping) {
|
| 4441 |
+
doc.iter(checkWidthStart, from.line + change.text.length, function(line) {
|
| 4442 |
+
var len = lineLength(line);
|
| 4443 |
+
if (len > display.maxLineLength) {
|
| 4444 |
+
display.maxLine = line;
|
| 4445 |
+
display.maxLineLength = len;
|
| 4446 |
+
display.maxLineChanged = true;
|
| 4447 |
+
recomputeMaxLength = false;
|
| 4448 |
+
}
|
| 4449 |
+
});
|
| 4450 |
+
if (recomputeMaxLength) cm.curOp.updateMaxLine = true;
|
| 4451 |
+
}
|
| 4452 |
+
|
| 4453 |
+
// Adjust frontier, schedule worker
|
| 4454 |
+
doc.frontier = Math.min(doc.frontier, from.line);
|
| 4455 |
+
startWorker(cm, 400);
|
| 4456 |
+
|
| 4457 |
+
var lendiff = change.text.length - (to.line - from.line) - 1;
|
| 4458 |
+
// Remember that these lines changed, for updating the display
|
| 4459 |
+
if (change.full)
|
| 4460 |
+
regChange(cm);
|
| 4461 |
+
else if (from.line == to.line && change.text.length == 1 && !isWholeLineUpdate(cm.doc, change))
|
| 4462 |
+
regLineChange(cm, from.line, "text");
|
| 4463 |
+
else
|
| 4464 |
+
regChange(cm, from.line, to.line + 1, lendiff);
|
| 4465 |
+
|
| 4466 |
+
var changesHandler = hasHandler(cm, "changes"), changeHandler = hasHandler(cm, "change");
|
| 4467 |
+
if (changeHandler || changesHandler) {
|
| 4468 |
+
var obj = {
|
| 4469 |
+
from: from, to: to,
|
| 4470 |
+
text: change.text,
|
| 4471 |
+
removed: change.removed,
|
| 4472 |
+
origin: change.origin
|
| 4473 |
+
};
|
| 4474 |
+
if (changeHandler) signalLater(cm, "change", cm, obj);
|
| 4475 |
+
if (changesHandler) (cm.curOp.changeObjs || (cm.curOp.changeObjs = [])).push(obj);
|
| 4476 |
+
}
|
| 4477 |
+
cm.display.selForContextMenu = null;
|
| 4478 |
+
}
|
| 4479 |
+
|
| 4480 |
+
function replaceRange(doc, code, from, to, origin) {
|
| 4481 |
+
if (!to) to = from;
|
| 4482 |
+
if (cmp(to, from) < 0) { var tmp = to; to = from; from = tmp; }
|
| 4483 |
+
if (typeof code == "string") code = splitLines(code);
|
| 4484 |
+
makeChange(doc, {from: from, to: to, text: code, origin: origin});
|
| 4485 |
+
}
|
| 4486 |
+
|
| 4487 |
+
// SCROLLING THINGS INTO VIEW
|
| 4488 |
+
|
| 4489 |
+
// If an editor sits on the top or bottom of the window, partially
|
| 4490 |
+
// scrolled out of view, this ensures that the cursor is visible.
|
| 4491 |
+
function maybeScrollWindow(cm, coords) {
|
| 4492 |
+
if (signalDOMEvent(cm, "scrollCursorIntoView")) return;
|
| 4493 |
+
|
| 4494 |
+
var display = cm.display, box = display.sizer.getBoundingClientRect(), doScroll = null;
|
| 4495 |
+
if (coords.top + box.top < 0) doScroll = true;
|
| 4496 |
+
else if (coords.bottom + box.top > (window.innerHeight || document.documentElement.clientHeight)) doScroll = false;
|
| 4497 |
+
if (doScroll != null && !phantom) {
|
| 4498 |
+
var scrollNode = elt("div", "\u200b", null, "position: absolute; top: " +
|
| 4499 |
+
(coords.top - display.viewOffset - paddingTop(cm.display)) + "px; height: " +
|
| 4500 |
+
(coords.bottom - coords.top + scrollGap(cm) + display.barHeight) + "px; left: " +
|
| 4501 |
+
coords.left + "px; width: 2px;");
|
| 4502 |
+
cm.display.lineSpace.appendChild(scrollNode);
|
| 4503 |
+
scrollNode.scrollIntoView(doScroll);
|
| 4504 |
+
cm.display.lineSpace.removeChild(scrollNode);
|
| 4505 |
+
}
|
| 4506 |
+
}
|
| 4507 |
+
|
| 4508 |
+
// Scroll a given position into view (immediately), verifying that
|
| 4509 |
+
// it actually became visible (as line heights are accurately
|
| 4510 |
+
// measured, the position of something may 'drift' during drawing).
|
| 4511 |
+
function scrollPosIntoView(cm, pos, end, margin) {
|
| 4512 |
+
if (margin == null) margin = 0;
|
| 4513 |
+
for (var limit = 0; limit < 5; limit++) {
|
| 4514 |
+
var changed = false, coords = cursorCoords(cm, pos);
|
| 4515 |
+
var endCoords = !end || end == pos ? coords : cursorCoords(cm, end);
|
| 4516 |
+
var scrollPos = calculateScrollPos(cm, Math.min(coords.left, endCoords.left),
|
| 4517 |
+
Math.min(coords.top, endCoords.top) - margin,
|
| 4518 |
+
Math.max(coords.left, endCoords.left),
|
| 4519 |
+
Math.max(coords.bottom, endCoords.bottom) + margin);
|
| 4520 |
+
var startTop = cm.doc.scrollTop, startLeft = cm.doc.scrollLeft;
|
| 4521 |
+
if (scrollPos.scrollTop != null) {
|
| 4522 |
+
setScrollTop(cm, scrollPos.scrollTop);
|
| 4523 |
+
if (Math.abs(cm.doc.scrollTop - startTop) > 1) changed = true;
|
| 4524 |
+
}
|
| 4525 |
+
if (scrollPos.scrollLeft != null) {
|
| 4526 |
+
setScrollLeft(cm, scrollPos.scrollLeft);
|
| 4527 |
+
if (Math.abs(cm.doc.scrollLeft - startLeft) > 1) changed = true;
|
| 4528 |
+
}
|
| 4529 |
+
if (!changed) break;
|
| 4530 |
+
}
|
| 4531 |
+
return coords;
|
| 4532 |
+
}
|
| 4533 |
+
|
| 4534 |
+
// Scroll a given set of coordinates into view (immediately).
|
| 4535 |
+
function scrollIntoView(cm, x1, y1, x2, y2) {
|
| 4536 |
+
var scrollPos = calculateScrollPos(cm, x1, y1, x2, y2);
|
| 4537 |
+
if (scrollPos.scrollTop != null) setScrollTop(cm, scrollPos.scrollTop);
|
| 4538 |
+
if (scrollPos.scrollLeft != null) setScrollLeft(cm, scrollPos.scrollLeft);
|
| 4539 |
+
}
|
| 4540 |
+
|
| 4541 |
+
// Calculate a new scroll position needed to scroll the given
|
| 4542 |
+
// rectangle into view. Returns an object with scrollTop and
|
| 4543 |
+
// scrollLeft properties. When these are undefined, the
|
| 4544 |
+
// vertical/horizontal position does not need to be adjusted.
|
| 4545 |
+
function calculateScrollPos(cm, x1, y1, x2, y2) {
|
| 4546 |
+
var display = cm.display, snapMargin = textHeight(cm.display);
|
| 4547 |
+
if (y1 < 0) y1 = 0;
|
| 4548 |
+
var screentop = cm.curOp && cm.curOp.scrollTop != null ? cm.curOp.scrollTop : display.scroller.scrollTop;
|
| 4549 |
+
var screen = displayHeight(cm), result = {};
|
| 4550 |
+
if (y2 - y1 > screen) y2 = y1 + screen;
|
| 4551 |
+
var docBottom = cm.doc.height + paddingVert(display);
|
| 4552 |
+
var atTop = y1 < snapMargin, atBottom = y2 > docBottom - snapMargin;
|
| 4553 |
+
if (y1 < screentop) {
|
| 4554 |
+
result.scrollTop = atTop ? 0 : y1;
|
| 4555 |
+
} else if (y2 > screentop + screen) {
|
| 4556 |
+
var newTop = Math.min(y1, (atBottom ? docBottom : y2) - screen);
|
| 4557 |
+
if (newTop != screentop) result.scrollTop = newTop;
|
| 4558 |
+
}
|
| 4559 |
+
|
| 4560 |
+
var screenleft = cm.curOp && cm.curOp.scrollLeft != null ? cm.curOp.scrollLeft : display.scroller.scrollLeft;
|
| 4561 |
+
var screenw = displayWidth(cm) - (cm.options.fixedGutter ? display.gutters.offsetWidth : 0);
|
| 4562 |
+
var tooWide = x2 - x1 > screenw;
|
| 4563 |
+
if (tooWide) x2 = x1 + screenw;
|
| 4564 |
+
if (x1 < 10)
|
| 4565 |
+
result.scrollLeft = 0;
|
| 4566 |
+
else if (x1 < screenleft)
|
| 4567 |
+
result.scrollLeft = Math.max(0, x1 - (tooWide ? 0 : 10));
|
| 4568 |
+
else if (x2 > screenw + screenleft - 3)
|
| 4569 |
+
result.scrollLeft = x2 + (tooWide ? 0 : 10) - screenw;
|
| 4570 |
+
return result;
|
| 4571 |
+
}
|
| 4572 |
+
|
| 4573 |
+
// Store a relative adjustment to the scroll position in the current
|
| 4574 |
+
// operation (to be applied when the operation finishes).
|
| 4575 |
+
function addToScrollPos(cm, left, top) {
|
| 4576 |
+
if (left != null || top != null) resolveScrollToPos(cm);
|
| 4577 |
+
if (left != null)
|
| 4578 |
+
cm.curOp.scrollLeft = (cm.curOp.scrollLeft == null ? cm.doc.scrollLeft : cm.curOp.scrollLeft) + left;
|
| 4579 |
+
if (top != null)
|
| 4580 |
+
cm.curOp.scrollTop = (cm.curOp.scrollTop == null ? cm.doc.scrollTop : cm.curOp.scrollTop) + top;
|
| 4581 |
+
}
|
| 4582 |
+
|
| 4583 |
+
// Make sure that at the end of the operation the current cursor is
|
| 4584 |
+
// shown.
|
| 4585 |
+
function ensureCursorVisible(cm) {
|
| 4586 |
+
resolveScrollToPos(cm);
|
| 4587 |
+
var cur = cm.getCursor(), from = cur, to = cur;
|
| 4588 |
+
if (!cm.options.lineWrapping) {
|
| 4589 |
+
from = cur.ch ? Pos(cur.line, cur.ch - 1) : cur;
|
| 4590 |
+
to = Pos(cur.line, cur.ch + 1);
|
| 4591 |
+
}
|
| 4592 |
+
cm.curOp.scrollToPos = {from: from, to: to, margin: cm.options.cursorScrollMargin, isCursor: true};
|
| 4593 |
+
}
|
| 4594 |
+
|
| 4595 |
+
// When an operation has its scrollToPos property set, and another
|
| 4596 |
+
// scroll action is applied before the end of the operation, this
|
| 4597 |
+
// 'simulates' scrolling that position into view in a cheap way, so
|
| 4598 |
+
// that the effect of intermediate scroll commands is not ignored.
|
| 4599 |
+
function resolveScrollToPos(cm) {
|
| 4600 |
+
var range = cm.curOp.scrollToPos;
|
| 4601 |
+
if (range) {
|
| 4602 |
+
cm.curOp.scrollToPos = null;
|
| 4603 |
+
var from = estimateCoords(cm, range.from), to = estimateCoords(cm, range.to);
|
| 4604 |
+
var sPos = calculateScrollPos(cm, Math.min(from.left, to.left),
|
| 4605 |
+
Math.min(from.top, to.top) - range.margin,
|
| 4606 |
+
Math.max(from.right, to.right),
|
| 4607 |
+
Math.max(from.bottom, to.bottom) + range.margin);
|
| 4608 |
+
cm.scrollTo(sPos.scrollLeft, sPos.scrollTop);
|
| 4609 |
+
}
|
| 4610 |
+
}
|
| 4611 |
+
|
| 4612 |
+
// API UTILITIES
|
| 4613 |
+
|
| 4614 |
+
// Indent the given line. The how parameter can be "smart",
|
| 4615 |
+
// "add"/null, "subtract", or "prev". When aggressive is false
|
| 4616 |
+
// (typically set to true for forced single-line indents), empty
|
| 4617 |
+
// lines are not indented, and places where the mode returns Pass
|
| 4618 |
+
// are left alone.
|
| 4619 |
+
function indentLine(cm, n, how, aggressive) {
|
| 4620 |
+
var doc = cm.doc, state;
|
| 4621 |
+
if (how == null) how = "add";
|
| 4622 |
+
if (how == "smart") {
|
| 4623 |
+
// Fall back to "prev" when the mode doesn't have an indentation
|
| 4624 |
+
// method.
|
| 4625 |
+
if (!doc.mode.indent) how = "prev";
|
| 4626 |
+
else state = getStateBefore(cm, n);
|
| 4627 |
+
}
|
| 4628 |
+
|
| 4629 |
+
var tabSize = cm.options.tabSize;
|
| 4630 |
+
var line = getLine(doc, n), curSpace = countColumn(line.text, null, tabSize);
|
| 4631 |
+
if (line.stateAfter) line.stateAfter = null;
|
| 4632 |
+
var curSpaceString = line.text.match(/^\s*/)[0], indentation;
|
| 4633 |
+
if (!aggressive && !/\S/.test(line.text)) {
|
| 4634 |
+
indentation = 0;
|
| 4635 |
+
how = "not";
|
| 4636 |
+
} else if (how == "smart") {
|
| 4637 |
+
indentation = doc.mode.indent(state, line.text.slice(curSpaceString.length), line.text);
|
| 4638 |
+
if (indentation == Pass || indentation > 150) {
|
| 4639 |
+
if (!aggressive) return;
|
| 4640 |
+
how = "prev";
|
| 4641 |
+
}
|
| 4642 |
+
}
|
| 4643 |
+
if (how == "prev") {
|
| 4644 |
+
if (n > doc.first) indentation = countColumn(getLine(doc, n-1).text, null, tabSize);
|
| 4645 |
+
else indentation = 0;
|
| 4646 |
+
} else if (how == "add") {
|
| 4647 |
+
indentation = curSpace + cm.options.indentUnit;
|
| 4648 |
+
} else if (how == "subtract") {
|
| 4649 |
+
indentation = curSpace - cm.options.indentUnit;
|
| 4650 |
+
} else if (typeof how == "number") {
|
| 4651 |
+
indentation = curSpace + how;
|
| 4652 |
+
}
|
| 4653 |
+
indentation = Math.max(0, indentation);
|
| 4654 |
+
|
| 4655 |
+
var indentString = "", pos = 0;
|
| 4656 |
+
if (cm.options.indentWithTabs)
|
| 4657 |
+
for (var i = Math.floor(indentation / tabSize); i; --i) {pos += tabSize; indentString += "\t";}
|
| 4658 |
+
if (pos < indentation) indentString += spaceStr(indentation - pos);
|
| 4659 |
+
|
| 4660 |
+
if (indentString != curSpaceString) {
|
| 4661 |
+
replaceRange(doc, indentString, Pos(n, 0), Pos(n, curSpaceString.length), "+input");
|
| 4662 |
+
line.stateAfter = null;
|
| 4663 |
+
return true;
|
| 4664 |
+
} else {
|
| 4665 |
+
// Ensure that, if the cursor was in the whitespace at the start
|
| 4666 |
+
// of the line, it is moved to the end of that space.
|
| 4667 |
+
for (var i = 0; i < doc.sel.ranges.length; i++) {
|
| 4668 |
+
var range = doc.sel.ranges[i];
|
| 4669 |
+
if (range.head.line == n && range.head.ch < curSpaceString.length) {
|
| 4670 |
+
var pos = Pos(n, curSpaceString.length);
|
| 4671 |
+
replaceOneSelection(doc, i, new Range(pos, pos));
|
| 4672 |
+
break;
|
| 4673 |
+
}
|
| 4674 |
+
}
|
| 4675 |
+
}
|
| 4676 |
+
}
|
| 4677 |
+
|
| 4678 |
+
// Utility for applying a change to a line by handle or number,
|
| 4679 |
+
// returning the number and optionally registering the line as
|
| 4680 |
+
// changed.
|
| 4681 |
+
function changeLine(doc, handle, changeType, op) {
|
| 4682 |
+
var no = handle, line = handle;
|
| 4683 |
+
if (typeof handle == "number") line = getLine(doc, clipLine(doc, handle));
|
| 4684 |
+
else no = lineNo(handle);
|
| 4685 |
+
if (no == null) return null;
|
| 4686 |
+
if (op(line, no) && doc.cm) regLineChange(doc.cm, no, changeType);
|
| 4687 |
+
return line;
|
| 4688 |
+
}
|
| 4689 |
+
|
| 4690 |
+
// Helper for deleting text near the selection(s), used to implement
|
| 4691 |
+
// backspace, delete, and similar functionality.
|
| 4692 |
+
function deleteNearSelection(cm, compute) {
|
| 4693 |
+
var ranges = cm.doc.sel.ranges, kill = [];
|
| 4694 |
+
// Build up a set of ranges to kill first, merging overlapping
|
| 4695 |
+
// ranges.
|
| 4696 |
+
for (var i = 0; i < ranges.length; i++) {
|
| 4697 |
+
var toKill = compute(ranges[i]);
|
| 4698 |
+
while (kill.length && cmp(toKill.from, lst(kill).to) <= 0) {
|
| 4699 |
+
var replaced = kill.pop();
|
| 4700 |
+
if (cmp(replaced.from, toKill.from) < 0) {
|
| 4701 |
+
toKill.from = replaced.from;
|
| 4702 |
+
break;
|
| 4703 |
+
}
|
| 4704 |
+
}
|
| 4705 |
+
kill.push(toKill);
|
| 4706 |
+
}
|
| 4707 |
+
// Next, remove those actual ranges.
|
| 4708 |
+
runInOp(cm, function() {
|
| 4709 |
+
for (var i = kill.length - 1; i >= 0; i--)
|
| 4710 |
+
replaceRange(cm.doc, "", kill[i].from, kill[i].to, "+delete");
|
| 4711 |
+
ensureCursorVisible(cm);
|
| 4712 |
+
});
|
| 4713 |
+
}
|
| 4714 |
+
|
| 4715 |
+
// Used for horizontal relative motion. Dir is -1 or 1 (left or
|
| 4716 |
+
// right), unit can be "char", "column" (like char, but doesn't
|
| 4717 |
+
// cross line boundaries), "word" (across next word), or "group" (to
|
| 4718 |
+
// the start of next group of word or non-word-non-whitespace
|
| 4719 |
+
// chars). The visually param controls whether, in right-to-left
|
| 4720 |
+
// text, direction 1 means to move towards the next index in the
|
| 4721 |
+
// string, or towards the character to the right of the current
|
| 4722 |
+
// position. The resulting position will have a hitSide=true
|
| 4723 |
+
// property if it reached the end of the document.
|
| 4724 |
+
function findPosH(doc, pos, dir, unit, visually) {
|
| 4725 |
+
var line = pos.line, ch = pos.ch, origDir = dir;
|
| 4726 |
+
var lineObj = getLine(doc, line);
|
| 4727 |
+
var possible = true;
|
| 4728 |
+
function findNextLine() {
|
| 4729 |
+
var l = line + dir;
|
| 4730 |
+
if (l < doc.first || l >= doc.first + doc.size) return (possible = false);
|
| 4731 |
+
line = l;
|
| 4732 |
+
return lineObj = getLine(doc, l);
|
| 4733 |
+
}
|
| 4734 |
+
function moveOnce(boundToLine) {
|
| 4735 |
+
var next = (visually ? moveVisually : moveLogically)(lineObj, ch, dir, true);
|
| 4736 |
+
if (next == null) {
|
| 4737 |
+
if (!boundToLine && findNextLine()) {
|
| 4738 |
+
if (visually) ch = (dir < 0 ? lineRight : lineLeft)(lineObj);
|
| 4739 |
+
else ch = dir < 0 ? lineObj.text.length : 0;
|
| 4740 |
+
} else return (possible = false);
|
| 4741 |
+
} else ch = next;
|
| 4742 |
+
return true;
|
| 4743 |
+
}
|
| 4744 |
+
|
| 4745 |
+
if (unit == "char") moveOnce();
|
| 4746 |
+
else if (unit == "column") moveOnce(true);
|
| 4747 |
+
else if (unit == "word" || unit == "group") {
|
| 4748 |
+
var sawType = null, group = unit == "group";
|
| 4749 |
+
var helper = doc.cm && doc.cm.getHelper(pos, "wordChars");
|
| 4750 |
+
for (var first = true;; first = false) {
|
| 4751 |
+
if (dir < 0 && !moveOnce(!first)) break;
|
| 4752 |
+
var cur = lineObj.text.charAt(ch) || "\n";
|
| 4753 |
+
var type = isWordChar(cur, helper) ? "w"
|
| 4754 |
+
: group && cur == "\n" ? "n"
|
| 4755 |
+
: !group || /\s/.test(cur) ? null
|
| 4756 |
+
: "p";
|
| 4757 |
+
if (group && !first && !type) type = "s";
|
| 4758 |
+
if (sawType && sawType != type) {
|
| 4759 |
+
if (dir < 0) {dir = 1; moveOnce();}
|
| 4760 |
+
break;
|
| 4761 |
+
}
|
| 4762 |
+
|
| 4763 |
+
if (type) sawType = type;
|
| 4764 |
+
if (dir > 0 && !moveOnce(!first)) break;
|
| 4765 |
+
}
|
| 4766 |
+
}
|
| 4767 |
+
var result = skipAtomic(doc, Pos(line, ch), origDir, true);
|
| 4768 |
+
if (!possible) result.hitSide = true;
|
| 4769 |
+
return result;
|
| 4770 |
+
}
|
| 4771 |
+
|
| 4772 |
+
// For relative vertical movement. Dir may be -1 or 1. Unit can be
|
| 4773 |
+
// "page" or "line". The resulting position will have a hitSide=true
|
| 4774 |
+
// property if it reached the end of the document.
|
| 4775 |
+
function findPosV(cm, pos, dir, unit) {
|
| 4776 |
+
var doc = cm.doc, x = pos.left, y;
|
| 4777 |
+
if (unit == "page") {
|
| 4778 |
+
var pageSize = Math.min(cm.display.wrapper.clientHeight, window.innerHeight || document.documentElement.clientHeight);
|
| 4779 |
+
y = pos.top + dir * (pageSize - (dir < 0 ? 1.5 : .5) * textHeight(cm.display));
|
| 4780 |
+
} else if (unit == "line") {
|
| 4781 |
+
y = dir > 0 ? pos.bottom + 3 : pos.top - 3;
|
| 4782 |
+
}
|
| 4783 |
+
for (;;) {
|
| 4784 |
+
var target = coordsChar(cm, x, y);
|
| 4785 |
+
if (!target.outside) break;
|
| 4786 |
+
if (dir < 0 ? y <= 0 : y >= doc.height) { target.hitSide = true; break; }
|
| 4787 |
+
y += dir * 5;
|
| 4788 |
+
}
|
| 4789 |
+
return target;
|
| 4790 |
+
}
|
| 4791 |
+
|
| 4792 |
+
// EDITOR METHODS
|
| 4793 |
+
|
| 4794 |
+
// The publicly visible API. Note that methodOp(f) means
|
| 4795 |
+
// 'wrap f in an operation, performed on its `this` parameter'.
|
| 4796 |
+
|
| 4797 |
+
// This is not the complete set of editor methods. Most of the
|
| 4798 |
+
// methods defined on the Doc type are also injected into
|
| 4799 |
+
// CodeMirror.prototype, for backwards compatibility and
|
| 4800 |
+
// convenience.
|
| 4801 |
+
|
| 4802 |
+
CodeMirror.prototype = {
|
| 4803 |
+
constructor: CodeMirror,
|
| 4804 |
+
focus: function(){window.focus(); this.display.input.focus();},
|
| 4805 |
+
|
| 4806 |
+
setOption: function(option, value) {
|
| 4807 |
+
var options = this.options, old = options[option];
|
| 4808 |
+
if (options[option] == value && option != "mode") return;
|
| 4809 |
+
options[option] = value;
|
| 4810 |
+
if (optionHandlers.hasOwnProperty(option))
|
| 4811 |
+
operation(this, optionHandlers[option])(this, value, old);
|
| 4812 |
+
},
|
| 4813 |
+
|
| 4814 |
+
getOption: function(option) {return this.options[option];},
|
| 4815 |
+
getDoc: function() {return this.doc;},
|
| 4816 |
+
|
| 4817 |
+
addKeyMap: function(map, bottom) {
|
| 4818 |
+
this.state.keyMaps[bottom ? "push" : "unshift"](getKeyMap(map));
|
| 4819 |
+
},
|
| 4820 |
+
removeKeyMap: function(map) {
|
| 4821 |
+
var maps = this.state.keyMaps;
|
| 4822 |
+
for (var i = 0; i < maps.length; ++i)
|
| 4823 |
+
if (maps[i] == map || maps[i].name == map) {
|
| 4824 |
+
maps.splice(i, 1);
|
| 4825 |
+
return true;
|
| 4826 |
+
}
|
| 4827 |
+
},
|
| 4828 |
+
|
| 4829 |
+
addOverlay: methodOp(function(spec, options) {
|
| 4830 |
+
var mode = spec.token ? spec : CodeMirror.getMode(this.options, spec);
|
| 4831 |
+
if (mode.startState) throw new Error("Overlays may not be stateful.");
|
| 4832 |
+
this.state.overlays.push({mode: mode, modeSpec: spec, opaque: options && options.opaque});
|
| 4833 |
+
this.state.modeGen++;
|
| 4834 |
+
regChange(this);
|
| 4835 |
+
}),
|
| 4836 |
+
removeOverlay: methodOp(function(spec) {
|
| 4837 |
+
var overlays = this.state.overlays;
|
| 4838 |
+
for (var i = 0; i < overlays.length; ++i) {
|
| 4839 |
+
var cur = overlays[i].modeSpec;
|
| 4840 |
+
if (cur == spec || typeof spec == "string" && cur.name == spec) {
|
| 4841 |
+
overlays.splice(i, 1);
|
| 4842 |
+
this.state.modeGen++;
|
| 4843 |
+
regChange(this);
|
| 4844 |
+
return;
|
| 4845 |
+
}
|
| 4846 |
+
}
|
| 4847 |
+
}),
|
| 4848 |
+
|
| 4849 |
+
indentLine: methodOp(function(n, dir, aggressive) {
|
| 4850 |
+
if (typeof dir != "string" && typeof dir != "number") {
|
| 4851 |
+
if (dir == null) dir = this.options.smartIndent ? "smart" : "prev";
|
| 4852 |
+
else dir = dir ? "add" : "subtract";
|
| 4853 |
+
}
|
| 4854 |
+
if (isLine(this.doc, n)) indentLine(this, n, dir, aggressive);
|
| 4855 |
+
}),
|
| 4856 |
+
indentSelection: methodOp(function(how) {
|
| 4857 |
+
var ranges = this.doc.sel.ranges, end = -1;
|
| 4858 |
+
for (var i = 0; i < ranges.length; i++) {
|
| 4859 |
+
var range = ranges[i];
|
| 4860 |
+
if (!range.empty()) {
|
| 4861 |
+
var from = range.from(), to = range.to();
|
| 4862 |
+
var start = Math.max(end, from.line);
|
| 4863 |
+
end = Math.min(this.lastLine(), to.line - (to.ch ? 0 : 1)) + 1;
|
| 4864 |
+
for (var j = start; j < end; ++j)
|
| 4865 |
+
indentLine(this, j, how);
|
| 4866 |
+
var newRanges = this.doc.sel.ranges;
|
| 4867 |
+
if (from.ch == 0 && ranges.length == newRanges.length && newRanges[i].from().ch > 0)
|
| 4868 |
+
replaceOneSelection(this.doc, i, new Range(from, newRanges[i].to()), sel_dontScroll);
|
| 4869 |
+
} else if (range.head.line > end) {
|
| 4870 |
+
indentLine(this, range.head.line, how, true);
|
| 4871 |
+
end = range.head.line;
|
| 4872 |
+
if (i == this.doc.sel.primIndex) ensureCursorVisible(this);
|
| 4873 |
+
}
|
| 4874 |
+
}
|
| 4875 |
+
}),
|
| 4876 |
+
|
| 4877 |
+
// Fetch the parser token for a given character. Useful for hacks
|
| 4878 |
+
// that want to inspect the mode state (say, for completion).
|
| 4879 |
+
getTokenAt: function(pos, precise) {
|
| 4880 |
+
return takeToken(this, pos, precise);
|
| 4881 |
+
},
|
| 4882 |
+
|
| 4883 |
+
getLineTokens: function(line, precise) {
|
| 4884 |
+
return takeToken(this, Pos(line), precise, true);
|
| 4885 |
+
},
|
| 4886 |
+
|
| 4887 |
+
getTokenTypeAt: function(pos) {
|
| 4888 |
+
pos = clipPos(this.doc, pos);
|
| 4889 |
+
var styles = getLineStyles(this, getLine(this.doc, pos.line));
|
| 4890 |
+
var before = 0, after = (styles.length - 1) / 2, ch = pos.ch;
|
| 4891 |
+
var type;
|
| 4892 |
+
if (ch == 0) type = styles[2];
|
| 4893 |
+
else for (;;) {
|
| 4894 |
+
var mid = (before + after) >> 1;
|
| 4895 |
+
if ((mid ? styles[mid * 2 - 1] : 0) >= ch) after = mid;
|
| 4896 |
+
else if (styles[mid * 2 + 1] < ch) before = mid + 1;
|
| 4897 |
+
else { type = styles[mid * 2 + 2]; break; }
|
| 4898 |
+
}
|
| 4899 |
+
var cut = type ? type.indexOf("cm-overlay ") : -1;
|
| 4900 |
+
return cut < 0 ? type : cut == 0 ? null : type.slice(0, cut - 1);
|
| 4901 |
+
},
|
| 4902 |
+
|
| 4903 |
+
getModeAt: function(pos) {
|
| 4904 |
+
var mode = this.doc.mode;
|
| 4905 |
+
if (!mode.innerMode) return mode;
|
| 4906 |
+
return CodeMirror.innerMode(mode, this.getTokenAt(pos).state).mode;
|
| 4907 |
+
},
|
| 4908 |
+
|
| 4909 |
+
getHelper: function(pos, type) {
|
| 4910 |
+
return this.getHelpers(pos, type)[0];
|
| 4911 |
+
},
|
| 4912 |
+
|
| 4913 |
+
getHelpers: function(pos, type) {
|
| 4914 |
+
var found = [];
|
| 4915 |
+
if (!helpers.hasOwnProperty(type)) return found;
|
| 4916 |
+
var help = helpers[type], mode = this.getModeAt(pos);
|
| 4917 |
+
if (typeof mode[type] == "string") {
|
| 4918 |
+
if (help[mode[type]]) found.push(help[mode[type]]);
|
| 4919 |
+
} else if (mode[type]) {
|
| 4920 |
+
for (var i = 0; i < mode[type].length; i++) {
|
| 4921 |
+
var val = help[mode[type][i]];
|
| 4922 |
+
if (val) found.push(val);
|
| 4923 |
+
}
|
| 4924 |
+
} else if (mode.helperType && help[mode.helperType]) {
|
| 4925 |
+
found.push(help[mode.helperType]);
|
| 4926 |
+
} else if (help[mode.name]) {
|
| 4927 |
+
found.push(help[mode.name]);
|
| 4928 |
+
}
|
| 4929 |
+
for (var i = 0; i < help._global.length; i++) {
|
| 4930 |
+
var cur = help._global[i];
|
| 4931 |
+
if (cur.pred(mode, this) && indexOf(found, cur.val) == -1)
|
| 4932 |
+
found.push(cur.val);
|
| 4933 |
+
}
|
| 4934 |
+
return found;
|
| 4935 |
+
},
|
| 4936 |
+
|
| 4937 |
+
getStateAfter: function(line, precise) {
|
| 4938 |
+
var doc = this.doc;
|
| 4939 |
+
line = clipLine(doc, line == null ? doc.first + doc.size - 1: line);
|
| 4940 |
+
return getStateBefore(this, line + 1, precise);
|
| 4941 |
+
},
|
| 4942 |
+
|
| 4943 |
+
cursorCoords: function(start, mode) {
|
| 4944 |
+
var pos, range = this.doc.sel.primary();
|
| 4945 |
+
if (start == null) pos = range.head;
|
| 4946 |
+
else if (typeof start == "object") pos = clipPos(this.doc, start);
|
| 4947 |
+
else pos = start ? range.from() : range.to();
|
| 4948 |
+
return cursorCoords(this, pos, mode || "page");
|
| 4949 |
+
},
|
| 4950 |
+
|
| 4951 |
+
charCoords: function(pos, mode) {
|
| 4952 |
+
return charCoords(this, clipPos(this.doc, pos), mode || "page");
|
| 4953 |
+
},
|
| 4954 |
+
|
| 4955 |
+
coordsChar: function(coords, mode) {
|
| 4956 |
+
coords = fromCoordSystem(this, coords, mode || "page");
|
| 4957 |
+
return coordsChar(this, coords.left, coords.top);
|
| 4958 |
+
},
|
| 4959 |
+
|
| 4960 |
+
lineAtHeight: function(height, mode) {
|
| 4961 |
+
height = fromCoordSystem(this, {top: height, left: 0}, mode || "page").top;
|
| 4962 |
+
return lineAtHeight(this.doc, height + this.display.viewOffset);
|
| 4963 |
+
},
|
| 4964 |
+
heightAtLine: function(line, mode) {
|
| 4965 |
+
var end = false, lineObj;
|
| 4966 |
+
if (typeof line == "number") {
|
| 4967 |
+
var last = this.doc.first + this.doc.size - 1;
|
| 4968 |
+
if (line < this.doc.first) line = this.doc.first;
|
| 4969 |
+
else if (line > last) { line = last; end = true; }
|
| 4970 |
+
lineObj = getLine(this.doc, line);
|
| 4971 |
+
} else {
|
| 4972 |
+
lineObj = line;
|
| 4973 |
+
}
|
| 4974 |
+
return intoCoordSystem(this, lineObj, {top: 0, left: 0}, mode || "page").top +
|
| 4975 |
+
(end ? this.doc.height - heightAtLine(lineObj) : 0);
|
| 4976 |
+
},
|
| 4977 |
+
|
| 4978 |
+
defaultTextHeight: function() { return textHeight(this.display); },
|
| 4979 |
+
defaultCharWidth: function() { return charWidth(this.display); },
|
| 4980 |
+
|
| 4981 |
+
setGutterMarker: methodOp(function(line, gutterID, value) {
|
| 4982 |
+
return changeLine(this.doc, line, "gutter", function(line) {
|
| 4983 |
+
var markers = line.gutterMarkers || (line.gutterMarkers = {});
|
| 4984 |
+
markers[gutterID] = value;
|
| 4985 |
+
if (!value && isEmpty(markers)) line.gutterMarkers = null;
|
| 4986 |
+
return true;
|
| 4987 |
+
});
|
| 4988 |
+
}),
|
| 4989 |
+
|
| 4990 |
+
clearGutter: methodOp(function(gutterID) {
|
| 4991 |
+
var cm = this, doc = cm.doc, i = doc.first;
|
| 4992 |
+
doc.iter(function(line) {
|
| 4993 |
+
if (line.gutterMarkers && line.gutterMarkers[gutterID]) {
|
| 4994 |
+
line.gutterMarkers[gutterID] = null;
|
| 4995 |
+
regLineChange(cm, i, "gutter");
|
| 4996 |
+
if (isEmpty(line.gutterMarkers)) line.gutterMarkers = null;
|
| 4997 |
+
}
|
| 4998 |
+
++i;
|
| 4999 |
+
});
|
| 5000 |
+
}),
|
| 5001 |
+
|
| 5002 |
+
lineInfo: function(line) {
|
| 5003 |
+
if (typeof line == "number") {
|
| 5004 |
+
if (!isLine(this.doc, line)) return null;
|
| 5005 |
+
var n = line;
|
| 5006 |
+
line = getLine(this.doc, line);
|
| 5007 |
+
if (!line) return null;
|
| 5008 |
+
} else {
|
| 5009 |
+
var n = lineNo(line);
|
| 5010 |
+
if (n == null) return null;
|
| 5011 |
+
}
|
| 5012 |
+
return {line: n, handle: line, text: line.text, gutterMarkers: line.gutterMarkers,
|
| 5013 |
+
textClass: line.textClass, bgClass: line.bgClass, wrapClass: line.wrapClass,
|
| 5014 |
+
widgets: line.widgets};
|
| 5015 |
+
},
|
| 5016 |
+
|
| 5017 |
+
getViewport: function() { return {from: this.display.viewFrom, to: this.display.viewTo};},
|
| 5018 |
+
|
| 5019 |
+
addWidget: function(pos, node, scroll, vert, horiz) {
|
| 5020 |
+
var display = this.display;
|
| 5021 |
+
pos = cursorCoords(this, clipPos(this.doc, pos));
|
| 5022 |
+
var top = pos.bottom, left = pos.left;
|
| 5023 |
+
node.style.position = "absolute";
|
| 5024 |
+
node.setAttribute("cm-ignore-events", "true");
|
| 5025 |
+
this.display.input.setUneditable(node);
|
| 5026 |
+
display.sizer.appendChild(node);
|
| 5027 |
+
if (vert == "over") {
|
| 5028 |
+
top = pos.top;
|
| 5029 |
+
} else if (vert == "above" || vert == "near") {
|
| 5030 |
+
var vspace = Math.max(display.wrapper.clientHeight, this.doc.height),
|
| 5031 |
+
hspace = Math.max(display.sizer.clientWidth, display.lineSpace.clientWidth);
|
| 5032 |
+
// Default to positioning above (if specified and possible); otherwise default to positioning below
|
| 5033 |
+
if ((vert == 'above' || pos.bottom + node.offsetHeight > vspace) && pos.top > node.offsetHeight)
|
| 5034 |
+
top = pos.top - node.offsetHeight;
|
| 5035 |
+
else if (pos.bottom + node.offsetHeight <= vspace)
|
| 5036 |
+
top = pos.bottom;
|
| 5037 |
+
if (left + node.offsetWidth > hspace)
|
| 5038 |
+
left = hspace - node.offsetWidth;
|
| 5039 |
+
}
|
| 5040 |
+
node.style.top = top + "px";
|
| 5041 |
+
node.style.left = node.style.right = "";
|
| 5042 |
+
if (horiz == "right") {
|
| 5043 |
+
left = display.sizer.clientWidth - node.offsetWidth;
|
| 5044 |
+
node.style.right = "0px";
|
| 5045 |
+
} else {
|
| 5046 |
+
if (horiz == "left") left = 0;
|
| 5047 |
+
else if (horiz == "middle") left = (display.sizer.clientWidth - node.offsetWidth) / 2;
|
| 5048 |
+
node.style.left = left + "px";
|
| 5049 |
+
}
|
| 5050 |
+
if (scroll)
|
| 5051 |
+
scrollIntoView(this, left, top, left + node.offsetWidth, top + node.offsetHeight);
|
| 5052 |
+
},
|
| 5053 |
+
|
| 5054 |
+
triggerOnKeyDown: methodOp(onKeyDown),
|
| 5055 |
+
triggerOnKeyPress: methodOp(onKeyPress),
|
| 5056 |
+
triggerOnKeyUp: onKeyUp,
|
| 5057 |
+
|
| 5058 |
+
execCommand: function(cmd) {
|
| 5059 |
+
if (commands.hasOwnProperty(cmd))
|
| 5060 |
+
return commands[cmd](this);
|
| 5061 |
+
},
|
| 5062 |
+
|
| 5063 |
+
triggerElectric: methodOp(function(text) { triggerElectric(this, text); }),
|
| 5064 |
+
|
| 5065 |
+
findPosH: function(from, amount, unit, visually) {
|
| 5066 |
+
var dir = 1;
|
| 5067 |
+
if (amount < 0) { dir = -1; amount = -amount; }
|
| 5068 |
+
for (var i = 0, cur = clipPos(this.doc, from); i < amount; ++i) {
|
| 5069 |
+
cur = findPosH(this.doc, cur, dir, unit, visually);
|
| 5070 |
+
if (cur.hitSide) break;
|
| 5071 |
+
}
|
| 5072 |
+
return cur;
|
| 5073 |
+
},
|
| 5074 |
+
|
| 5075 |
+
moveH: methodOp(function(dir, unit) {
|
| 5076 |
+
var cm = this;
|
| 5077 |
+
cm.extendSelectionsBy(function(range) {
|
| 5078 |
+
if (cm.display.shift || cm.doc.extend || range.empty())
|
| 5079 |
+
return findPosH(cm.doc, range.head, dir, unit, cm.options.rtlMoveVisually);
|
| 5080 |
+
else
|
| 5081 |
+
return dir < 0 ? range.from() : range.to();
|
| 5082 |
+
}, sel_move);
|
| 5083 |
+
}),
|
| 5084 |
+
|
| 5085 |
+
deleteH: methodOp(function(dir, unit) {
|
| 5086 |
+
var sel = this.doc.sel, doc = this.doc;
|
| 5087 |
+
if (sel.somethingSelected())
|
| 5088 |
+
doc.replaceSelection("", null, "+delete");
|
| 5089 |
+
else
|
| 5090 |
+
deleteNearSelection(this, function(range) {
|
| 5091 |
+
var other = findPosH(doc, range.head, dir, unit, false);
|
| 5092 |
+
return dir < 0 ? {from: other, to: range.head} : {from: range.head, to: other};
|
| 5093 |
+
});
|
| 5094 |
+
}),
|
| 5095 |
+
|
| 5096 |
+
findPosV: function(from, amount, unit, goalColumn) {
|
| 5097 |
+
var dir = 1, x = goalColumn;
|
| 5098 |
+
if (amount < 0) { dir = -1; amount = -amount; }
|
| 5099 |
+
for (var i = 0, cur = clipPos(this.doc, from); i < amount; ++i) {
|
| 5100 |
+
var coords = cursorCoords(this, cur, "div");
|
| 5101 |
+
if (x == null) x = coords.left;
|
| 5102 |
+
else coords.left = x;
|
| 5103 |
+
cur = findPosV(this, coords, dir, unit);
|
| 5104 |
+
if (cur.hitSide) break;
|
| 5105 |
+
}
|
| 5106 |
+
return cur;
|
| 5107 |
+
},
|
| 5108 |
+
|
| 5109 |
+
moveV: methodOp(function(dir, unit) {
|
| 5110 |
+
var cm = this, doc = this.doc, goals = [];
|
| 5111 |
+
var collapse = !cm.display.shift && !doc.extend && doc.sel.somethingSelected();
|
| 5112 |
+
doc.extendSelectionsBy(function(range) {
|
| 5113 |
+
if (collapse)
|
| 5114 |
+
return dir < 0 ? range.from() : range.to();
|
| 5115 |
+
var headPos = cursorCoords(cm, range.head, "div");
|
| 5116 |
+
if (range.goalColumn != null) headPos.left = range.goalColumn;
|
| 5117 |
+
goals.push(headPos.left);
|
| 5118 |
+
var pos = findPosV(cm, headPos, dir, unit);
|
| 5119 |
+
if (unit == "page" && range == doc.sel.primary())
|
| 5120 |
+
addToScrollPos(cm, null, charCoords(cm, pos, "div").top - headPos.top);
|
| 5121 |
+
return pos;
|
| 5122 |
+
}, sel_move);
|
| 5123 |
+
if (goals.length) for (var i = 0; i < doc.sel.ranges.length; i++)
|
| 5124 |
+
doc.sel.ranges[i].goalColumn = goals[i];
|
| 5125 |
+
}),
|
| 5126 |
+
|
| 5127 |
+
// Find the word at the given position (as returned by coordsChar).
|
| 5128 |
+
findWordAt: function(pos) {
|
| 5129 |
+
var doc = this.doc, line = getLine(doc, pos.line).text;
|
| 5130 |
+
var start = pos.ch, end = pos.ch;
|
| 5131 |
+
if (line) {
|
| 5132 |
+
var helper = this.getHelper(pos, "wordChars");
|
| 5133 |
+
if ((pos.xRel < 0 || end == line.length) && start) --start; else ++end;
|
| 5134 |
+
var startChar = line.charAt(start);
|
| 5135 |
+
var check = isWordChar(startChar, helper)
|
| 5136 |
+
? function(ch) { return isWordChar(ch, helper); }
|
| 5137 |
+
: /\s/.test(startChar) ? function(ch) {return /\s/.test(ch);}
|
| 5138 |
+
: function(ch) {return !/\s/.test(ch) && !isWordChar(ch);};
|
| 5139 |
+
while (start > 0 && check(line.charAt(start - 1))) --start;
|
| 5140 |
+
while (end < line.length && check(line.charAt(end))) ++end;
|
| 5141 |
+
}
|
| 5142 |
+
return new Range(Pos(pos.line, start), Pos(pos.line, end));
|
| 5143 |
+
},
|
| 5144 |
+
|
| 5145 |
+
toggleOverwrite: function(value) {
|
| 5146 |
+
if (value != null && value == this.state.overwrite) return;
|
| 5147 |
+
if (this.state.overwrite = !this.state.overwrite)
|
| 5148 |
+
addClass(this.display.cursorDiv, "CodeMirror-overwrite");
|
| 5149 |
+
else
|
| 5150 |
+
rmClass(this.display.cursorDiv, "CodeMirror-overwrite");
|
| 5151 |
+
|
| 5152 |
+
signal(this, "overwriteToggle", this, this.state.overwrite);
|
| 5153 |
+
},
|
| 5154 |
+
hasFocus: function() { return this.display.input.getField() == activeElt(); },
|
| 5155 |
+
|
| 5156 |
+
scrollTo: methodOp(function(x, y) {
|
| 5157 |
+
if (x != null || y != null) resolveScrollToPos(this);
|
| 5158 |
+
if (x != null) this.curOp.scrollLeft = x;
|
| 5159 |
+
if (y != null) this.curOp.scrollTop = y;
|
| 5160 |
+
}),
|
| 5161 |
+
getScrollInfo: function() {
|
| 5162 |
+
var scroller = this.display.scroller;
|
| 5163 |
+
return {left: scroller.scrollLeft, top: scroller.scrollTop,
|
| 5164 |
+
height: scroller.scrollHeight - scrollGap(this) - this.display.barHeight,
|
| 5165 |
+
width: scroller.scrollWidth - scrollGap(this) - this.display.barWidth,
|
| 5166 |
+
clientHeight: displayHeight(this), clientWidth: displayWidth(this)};
|
| 5167 |
+
},
|
| 5168 |
+
|
| 5169 |
+
scrollIntoView: methodOp(function(range, margin) {
|
| 5170 |
+
if (range == null) {
|
| 5171 |
+
range = {from: this.doc.sel.primary().head, to: null};
|
| 5172 |
+
if (margin == null) margin = this.options.cursorScrollMargin;
|
| 5173 |
+
} else if (typeof range == "number") {
|
| 5174 |
+
range = {from: Pos(range, 0), to: null};
|
| 5175 |
+
} else if (range.from == null) {
|
| 5176 |
+
range = {from: range, to: null};
|
| 5177 |
+
}
|
| 5178 |
+
if (!range.to) range.to = range.from;
|
| 5179 |
+
range.margin = margin || 0;
|
| 5180 |
+
|
| 5181 |
+
if (range.from.line != null) {
|
| 5182 |
+
resolveScrollToPos(this);
|
| 5183 |
+
this.curOp.scrollToPos = range;
|
| 5184 |
+
} else {
|
| 5185 |
+
var sPos = calculateScrollPos(this, Math.min(range.from.left, range.to.left),
|
| 5186 |
+
Math.min(range.from.top, range.to.top) - range.margin,
|
| 5187 |
+
Math.max(range.from.right, range.to.right),
|
| 5188 |
+
Math.max(range.from.bottom, range.to.bottom) + range.margin);
|
| 5189 |
+
this.scrollTo(sPos.scrollLeft, sPos.scrollTop);
|
| 5190 |
+
}
|
| 5191 |
+
}),
|
| 5192 |
+
|
| 5193 |
+
setSize: methodOp(function(width, height) {
|
| 5194 |
+
var cm = this;
|
| 5195 |
+
function interpret(val) {
|
| 5196 |
+
return typeof val == "number" || /^\d+$/.test(String(val)) ? val + "px" : val;
|
| 5197 |
+
}
|
| 5198 |
+
if (width != null) cm.display.wrapper.style.width = interpret(width);
|
| 5199 |
+
if (height != null) cm.display.wrapper.style.height = interpret(height);
|
| 5200 |
+
if (cm.options.lineWrapping) clearLineMeasurementCache(this);
|
| 5201 |
+
var lineNo = cm.display.viewFrom;
|
| 5202 |
+
cm.doc.iter(lineNo, cm.display.viewTo, function(line) {
|
| 5203 |
+
if (line.widgets) for (var i = 0; i < line.widgets.length; i++)
|
| 5204 |
+
if (line.widgets[i].noHScroll) { regLineChange(cm, lineNo, "widget"); break; }
|
| 5205 |
+
++lineNo;
|
| 5206 |
+
});
|
| 5207 |
+
cm.curOp.forceUpdate = true;
|
| 5208 |
+
signal(cm, "refresh", this);
|
| 5209 |
+
}),
|
| 5210 |
+
|
| 5211 |
+
operation: function(f){return runInOp(this, f);},
|
| 5212 |
+
|
| 5213 |
+
refresh: methodOp(function() {
|
| 5214 |
+
var oldHeight = this.display.cachedTextHeight;
|
| 5215 |
+
regChange(this);
|
| 5216 |
+
this.curOp.forceUpdate = true;
|
| 5217 |
+
clearCaches(this);
|
| 5218 |
+
this.scrollTo(this.doc.scrollLeft, this.doc.scrollTop);
|
| 5219 |
+
updateGutterSpace(this);
|
| 5220 |
+
if (oldHeight == null || Math.abs(oldHeight - textHeight(this.display)) > .5)
|
| 5221 |
+
estimateLineHeights(this);
|
| 5222 |
+
signal(this, "refresh", this);
|
| 5223 |
+
}),
|
| 5224 |
+
|
| 5225 |
+
swapDoc: methodOp(function(doc) {
|
| 5226 |
+
var old = this.doc;
|
| 5227 |
+
old.cm = null;
|
| 5228 |
+
attachDoc(this, doc);
|
| 5229 |
+
clearCaches(this);
|
| 5230 |
+
this.display.input.reset();
|
| 5231 |
+
this.scrollTo(doc.scrollLeft, doc.scrollTop);
|
| 5232 |
+
this.curOp.forceScroll = true;
|
| 5233 |
+
signalLater(this, "swapDoc", this, old);
|
| 5234 |
+
return old;
|
| 5235 |
+
}),
|
| 5236 |
+
|
| 5237 |
+
getInputField: function(){return this.display.input.getField();},
|
| 5238 |
+
getWrapperElement: function(){return this.display.wrapper;},
|
| 5239 |
+
getScrollerElement: function(){return this.display.scroller;},
|
| 5240 |
+
getGutterElement: function(){return this.display.gutters;}
|
| 5241 |
+
};
|
| 5242 |
+
eventMixin(CodeMirror);
|
| 5243 |
+
|
| 5244 |
+
// OPTION DEFAULTS
|
| 5245 |
+
|
| 5246 |
+
// The default configuration options.
|
| 5247 |
+
var defaults = CodeMirror.defaults = {};
|
| 5248 |
+
// Functions to run when options are changed.
|
| 5249 |
+
var optionHandlers = CodeMirror.optionHandlers = {};
|
| 5250 |
+
|
| 5251 |
+
function option(name, deflt, handle, notOnInit) {
|
| 5252 |
+
CodeMirror.defaults[name] = deflt;
|
| 5253 |
+
if (handle) optionHandlers[name] =
|
| 5254 |
+
notOnInit ? function(cm, val, old) {if (old != Init) handle(cm, val, old);} : handle;
|
| 5255 |
+
}
|
| 5256 |
+
|
| 5257 |
+
// Passed to option handlers when there is no old value.
|
| 5258 |
+
var Init = CodeMirror.Init = {toString: function(){return "CodeMirror.Init";}};
|
| 5259 |
+
|
| 5260 |
+
// These two are, on init, called from the constructor because they
|
| 5261 |
+
// have to be initialized before the editor can start at all.
|
| 5262 |
+
option("value", "", function(cm, val) {
|
| 5263 |
+
cm.setValue(val);
|
| 5264 |
+
}, true);
|
| 5265 |
+
option("mode", null, function(cm, val) {
|
| 5266 |
+
cm.doc.modeOption = val;
|
| 5267 |
+
loadMode(cm);
|
| 5268 |
+
}, true);
|
| 5269 |
+
|
| 5270 |
+
option("indentUnit", 2, loadMode, true);
|
| 5271 |
+
option("indentWithTabs", false);
|
| 5272 |
+
option("smartIndent", true);
|
| 5273 |
+
option("tabSize", 4, function(cm) {
|
| 5274 |
+
resetModeState(cm);
|
| 5275 |
+
clearCaches(cm);
|
| 5276 |
+
regChange(cm);
|
| 5277 |
+
}, true);
|
| 5278 |
+
option("specialChars", /[\t\u0000-\u0019\u00ad\u200b-\u200f\u2028\u2029\ufeff]/g, function(cm, val, old) {
|
| 5279 |
+
cm.state.specialChars = new RegExp(val.source + (val.test("\t") ? "" : "|\t"), "g");
|
| 5280 |
+
if (old != CodeMirror.Init) cm.refresh();
|
| 5281 |
+
});
|
| 5282 |
+
option("specialCharPlaceholder", defaultSpecialCharPlaceholder, function(cm) {cm.refresh();}, true);
|
| 5283 |
+
option("electricChars", true);
|
| 5284 |
+
option("inputStyle", mobile ? "contenteditable" : "textarea", function() {
|
| 5285 |
+
throw new Error("inputStyle can not (yet) be changed in a running editor"); // FIXME
|
| 5286 |
+
}, true);
|
| 5287 |
+
option("rtlMoveVisually", !windows);
|
| 5288 |
+
option("wholeLineUpdateBefore", true);
|
| 5289 |
+
|
| 5290 |
+
option("theme", "default", function(cm) {
|
| 5291 |
+
themeChanged(cm);
|
| 5292 |
+
guttersChanged(cm);
|
| 5293 |
+
}, true);
|
| 5294 |
+
option("keyMap", "default", function(cm, val, old) {
|
| 5295 |
+
var next = getKeyMap(val);
|
| 5296 |
+
var prev = old != CodeMirror.Init && getKeyMap(old);
|
| 5297 |
+
if (prev && prev.detach) prev.detach(cm, next);
|
| 5298 |
+
if (next.attach) next.attach(cm, prev || null);
|
| 5299 |
+
});
|
| 5300 |
+
option("extraKeys", null);
|
| 5301 |
+
|
| 5302 |
+
option("lineWrapping", false, wrappingChanged, true);
|
| 5303 |
+
option("gutters", [], function(cm) {
|
| 5304 |
+
setGuttersForLineNumbers(cm.options);
|
| 5305 |
+
guttersChanged(cm);
|
| 5306 |
+
}, true);
|
| 5307 |
+
option("fixedGutter", true, function(cm, val) {
|
| 5308 |
+
cm.display.gutters.style.left = val ? compensateForHScroll(cm.display) + "px" : "0";
|
| 5309 |
+
cm.refresh();
|
| 5310 |
+
}, true);
|
| 5311 |
+
option("coverGutterNextToScrollbar", false, function(cm) {updateScrollbars(cm);}, true);
|
| 5312 |
+
option("scrollbarStyle", "native", function(cm) {
|
| 5313 |
+
initScrollbars(cm);
|
| 5314 |
+
updateScrollbars(cm);
|
| 5315 |
+
cm.display.scrollbars.setScrollTop(cm.doc.scrollTop);
|
| 5316 |
+
cm.display.scrollbars.setScrollLeft(cm.doc.scrollLeft);
|
| 5317 |
+
}, true);
|
| 5318 |
+
option("lineNumbers", false, function(cm) {
|
| 5319 |
+
setGuttersForLineNumbers(cm.options);
|
| 5320 |
+
guttersChanged(cm);
|
| 5321 |
+
}, true);
|
| 5322 |
+
option("firstLineNumber", 1, guttersChanged, true);
|
| 5323 |
+
option("lineNumberFormatter", function(integer) {return integer;}, guttersChanged, true);
|
| 5324 |
+
option("showCursorWhenSelecting", false, updateSelection, true);
|
| 5325 |
+
|
| 5326 |
+
option("resetSelectionOnContextMenu", true);
|
| 5327 |
+
option("lineWiseCopyCut", true);
|
| 5328 |
+
|
| 5329 |
+
option("readOnly", false, function(cm, val) {
|
| 5330 |
+
if (val == "nocursor") {
|
| 5331 |
+
onBlur(cm);
|
| 5332 |
+
cm.display.input.blur();
|
| 5333 |
+
cm.display.disabled = true;
|
| 5334 |
+
} else {
|
| 5335 |
+
cm.display.disabled = false;
|
| 5336 |
+
if (!val) cm.display.input.reset();
|
| 5337 |
+
}
|
| 5338 |
+
});
|
| 5339 |
+
option("disableInput", false, function(cm, val) {if (!val) cm.display.input.reset();}, true);
|
| 5340 |
+
option("dragDrop", true, dragDropChanged);
|
| 5341 |
+
|
| 5342 |
+
option("cursorBlinkRate", 530);
|
| 5343 |
+
option("cursorScrollMargin", 0);
|
| 5344 |
+
option("cursorHeight", 1, updateSelection, true);
|
| 5345 |
+
option("singleCursorHeightPerLine", true, updateSelection, true);
|
| 5346 |
+
option("workTime", 100);
|
| 5347 |
+
option("workDelay", 100);
|
| 5348 |
+
option("flattenSpans", true, resetModeState, true);
|
| 5349 |
+
option("addModeClass", false, resetModeState, true);
|
| 5350 |
+
option("pollInterval", 100);
|
| 5351 |
+
option("undoDepth", 200, function(cm, val){cm.doc.history.undoDepth = val;});
|
| 5352 |
+
option("historyEventDelay", 1250);
|
| 5353 |
+
option("viewportMargin", 10, function(cm){cm.refresh();}, true);
|
| 5354 |
+
option("maxHighlightLength", 10000, resetModeState, true);
|
| 5355 |
+
option("moveInputWithCursor", true, function(cm, val) {
|
| 5356 |
+
if (!val) cm.display.input.resetPosition();
|
| 5357 |
+
});
|
| 5358 |
+
|
| 5359 |
+
option("tabindex", null, function(cm, val) {
|
| 5360 |
+
cm.display.input.getField().tabIndex = val || "";
|
| 5361 |
+
});
|
| 5362 |
+
option("autofocus", null);
|
| 5363 |
+
|
| 5364 |
+
// MODE DEFINITION AND QUERYING
|
| 5365 |
+
|
| 5366 |
+
// Known modes, by name and by MIME
|
| 5367 |
+
var modes = CodeMirror.modes = {}, mimeModes = CodeMirror.mimeModes = {};
|
| 5368 |
+
|
| 5369 |
+
// Extra arguments are stored as the mode's dependencies, which is
|
| 5370 |
+
// used by (legacy) mechanisms like loadmode.js to automatically
|
| 5371 |
+
// load a mode. (Preferred mechanism is the require/define calls.)
|
| 5372 |
+
CodeMirror.defineMode = function(name, mode) {
|
| 5373 |
+
if (!CodeMirror.defaults.mode && name != "null") CodeMirror.defaults.mode = name;
|
| 5374 |
+
if (arguments.length > 2)
|
| 5375 |
+
mode.dependencies = Array.prototype.slice.call(arguments, 2);
|
| 5376 |
+
modes[name] = mode;
|
| 5377 |
+
};
|
| 5378 |
+
|
| 5379 |
+
CodeMirror.defineMIME = function(mime, spec) {
|
| 5380 |
+
mimeModes[mime] = spec;
|
| 5381 |
+
};
|
| 5382 |
+
|
| 5383 |
+
// Given a MIME type, a {name, ...options} config object, or a name
|
| 5384 |
+
// string, return a mode config object.
|
| 5385 |
+
CodeMirror.resolveMode = function(spec) {
|
| 5386 |
+
if (typeof spec == "string" && mimeModes.hasOwnProperty(spec)) {
|
| 5387 |
+
spec = mimeModes[spec];
|
| 5388 |
+
} else if (spec && typeof spec.name == "string" && mimeModes.hasOwnProperty(spec.name)) {
|
| 5389 |
+
var found = mimeModes[spec.name];
|
| 5390 |
+
if (typeof found == "string") found = {name: found};
|
| 5391 |
+
spec = createObj(found, spec);
|
| 5392 |
+
spec.name = found.name;
|
| 5393 |
+
} else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+xml$/.test(spec)) {
|
| 5394 |
+
return CodeMirror.resolveMode("application/xml");
|
| 5395 |
+
}
|
| 5396 |
+
if (typeof spec == "string") return {name: spec};
|
| 5397 |
+
else return spec || {name: "null"};
|
| 5398 |
+
};
|
| 5399 |
+
|
| 5400 |
+
// Given a mode spec (anything that resolveMode accepts), find and
|
| 5401 |
+
// initialize an actual mode object.
|
| 5402 |
+
CodeMirror.getMode = function(options, spec) {
|
| 5403 |
+
var spec = CodeMirror.resolveMode(spec);
|
| 5404 |
+
var mfactory = modes[spec.name];
|
| 5405 |
+
if (!mfactory) return CodeMirror.getMode(options, "text/plain");
|
| 5406 |
+
var modeObj = mfactory(options, spec);
|
| 5407 |
+
if (modeExtensions.hasOwnProperty(spec.name)) {
|
| 5408 |
+
var exts = modeExtensions[spec.name];
|
| 5409 |
+
for (var prop in exts) {
|
| 5410 |
+
if (!exts.hasOwnProperty(prop)) continue;
|
| 5411 |
+
if (modeObj.hasOwnProperty(prop)) modeObj["_" + prop] = modeObj[prop];
|
| 5412 |
+
modeObj[prop] = exts[prop];
|
| 5413 |
+
}
|
| 5414 |
+
}
|
| 5415 |
+
modeObj.name = spec.name;
|
| 5416 |
+
if (spec.helperType) modeObj.helperType = spec.helperType;
|
| 5417 |
+
if (spec.modeProps) for (var prop in spec.modeProps)
|
| 5418 |
+
modeObj[prop] = spec.modeProps[prop];
|
| 5419 |
+
|
| 5420 |
+
return modeObj;
|
| 5421 |
+
};
|
| 5422 |
+
|
| 5423 |
+
// Minimal default mode.
|
| 5424 |
+
CodeMirror.defineMode("null", function() {
|
| 5425 |
+
return {token: function(stream) {stream.skipToEnd();}};
|
| 5426 |
+
});
|
| 5427 |
+
CodeMirror.defineMIME("text/plain", "null");
|
| 5428 |
+
|
| 5429 |
+
// This can be used to attach properties to mode objects from
|
| 5430 |
+
// outside the actual mode definition.
|
| 5431 |
+
var modeExtensions = CodeMirror.modeExtensions = {};
|
| 5432 |
+
CodeMirror.extendMode = function(mode, properties) {
|
| 5433 |
+
var exts = modeExtensions.hasOwnProperty(mode) ? modeExtensions[mode] : (modeExtensions[mode] = {});
|
| 5434 |
+
copyObj(properties, exts);
|
| 5435 |
+
};
|
| 5436 |
+
|
| 5437 |
+
// EXTENSIONS
|
| 5438 |
+
|
| 5439 |
+
CodeMirror.defineExtension = function(name, func) {
|
| 5440 |
+
CodeMirror.prototype[name] = func;
|
| 5441 |
+
};
|
| 5442 |
+
CodeMirror.defineDocExtension = function(name, func) {
|
| 5443 |
+
Doc.prototype[name] = func;
|
| 5444 |
+
};
|
| 5445 |
+
CodeMirror.defineOption = option;
|
| 5446 |
+
|
| 5447 |
+
var initHooks = [];
|
| 5448 |
+
CodeMirror.defineInitHook = function(f) {initHooks.push(f);};
|
| 5449 |
+
|
| 5450 |
+
var helpers = CodeMirror.helpers = {};
|
| 5451 |
+
CodeMirror.registerHelper = function(type, name, value) {
|
| 5452 |
+
if (!helpers.hasOwnProperty(type)) helpers[type] = CodeMirror[type] = {_global: []};
|
| 5453 |
+
helpers[type][name] = value;
|
| 5454 |
+
};
|
| 5455 |
+
CodeMirror.registerGlobalHelper = function(type, name, predicate, value) {
|
| 5456 |
+
CodeMirror.registerHelper(type, name, value);
|
| 5457 |
+
helpers[type]._global.push({pred: predicate, val: value});
|
| 5458 |
+
};
|
| 5459 |
+
|
| 5460 |
+
// MODE STATE HANDLING
|
| 5461 |
+
|
| 5462 |
+
// Utility functions for working with state. Exported because nested
|
| 5463 |
+
// modes need to do this for their inner modes.
|
| 5464 |
+
|
| 5465 |
+
var copyState = CodeMirror.copyState = function(mode, state) {
|
| 5466 |
+
if (state === true) return state;
|
| 5467 |
+
if (mode.copyState) return mode.copyState(state);
|
| 5468 |
+
var nstate = {};
|
| 5469 |
+
for (var n in state) {
|
| 5470 |
+
var val = state[n];
|
| 5471 |
+
if (val instanceof Array) val = val.concat([]);
|
| 5472 |
+
nstate[n] = val;
|
| 5473 |
+
}
|
| 5474 |
+
return nstate;
|
| 5475 |
+
};
|
| 5476 |
+
|
| 5477 |
+
var startState = CodeMirror.startState = function(mode, a1, a2) {
|
| 5478 |
+
return mode.startState ? mode.startState(a1, a2) : true;
|
| 5479 |
+
};
|
| 5480 |
+
|
| 5481 |
+
// Given a mode and a state (for that mode), find the inner mode and
|
| 5482 |
+
// state at the position that the state refers to.
|
| 5483 |
+
CodeMirror.innerMode = function(mode, state) {
|
| 5484 |
+
while (mode.innerMode) {
|
| 5485 |
+
var info = mode.innerMode(state);
|
| 5486 |
+
if (!info || info.mode == mode) break;
|
| 5487 |
+
state = info.state;
|
| 5488 |
+
mode = info.mode;
|
| 5489 |
+
}
|
| 5490 |
+
return info || {mode: mode, state: state};
|
| 5491 |
+
};
|
| 5492 |
+
|
| 5493 |
+
// STANDARD COMMANDS
|
| 5494 |
+
|
| 5495 |
+
// Commands are parameter-less actions that can be performed on an
|
| 5496 |
+
// editor, mostly used for keybindings.
|
| 5497 |
+
var commands = CodeMirror.commands = {
|
| 5498 |
+
selectAll: function(cm) {cm.setSelection(Pos(cm.firstLine(), 0), Pos(cm.lastLine()), sel_dontScroll);},
|
| 5499 |
+
singleSelection: function(cm) {
|
| 5500 |
+
cm.setSelection(cm.getCursor("anchor"), cm.getCursor("head"), sel_dontScroll);
|
| 5501 |
+
},
|
| 5502 |
+
killLine: function(cm) {
|
| 5503 |
+
deleteNearSelection(cm, function(range) {
|
| 5504 |
+
if (range.empty()) {
|
| 5505 |
+
var len = getLine(cm.doc, range.head.line).text.length;
|
| 5506 |
+
if (range.head.ch == len && range.head.line < cm.lastLine())
|
| 5507 |
+
return {from: range.head, to: Pos(range.head.line + 1, 0)};
|
| 5508 |
+
else
|
| 5509 |
+
return {from: range.head, to: Pos(range.head.line, len)};
|
| 5510 |
+
} else {
|
| 5511 |
+
return {from: range.from(), to: range.to()};
|
| 5512 |
+
}
|
| 5513 |
+
});
|
| 5514 |
+
},
|
| 5515 |
+
deleteLine: function(cm) {
|
| 5516 |
+
deleteNearSelection(cm, function(range) {
|
| 5517 |
+
return {from: Pos(range.from().line, 0),
|
| 5518 |
+
to: clipPos(cm.doc, Pos(range.to().line + 1, 0))};
|
| 5519 |
+
});
|
| 5520 |
+
},
|
| 5521 |
+
delLineLeft: function(cm) {
|
| 5522 |
+
deleteNearSelection(cm, function(range) {
|
| 5523 |
+
return {from: Pos(range.from().line, 0), to: range.from()};
|
| 5524 |
+
});
|
| 5525 |
+
},
|
| 5526 |
+
delWrappedLineLeft: function(cm) {
|
| 5527 |
+
deleteNearSelection(cm, function(range) {
|
| 5528 |
+
var top = cm.charCoords(range.head, "div").top + 5;
|
| 5529 |
+
var leftPos = cm.coordsChar({left: 0, top: top}, "div");
|
| 5530 |
+
return {from: leftPos, to: range.from()};
|
| 5531 |
+
});
|
| 5532 |
+
},
|
| 5533 |
+
delWrappedLineRight: function(cm) {
|
| 5534 |
+
deleteNearSelection(cm, function(range) {
|
| 5535 |
+
var top = cm.charCoords(range.head, "div").top + 5;
|
| 5536 |
+
var rightPos = cm.coordsChar({left: cm.display.lineDiv.offsetWidth + 100, top: top}, "div");
|
| 5537 |
+
return {from: range.from(), to: rightPos };
|
| 5538 |
+
});
|
| 5539 |
+
},
|
| 5540 |
+
undo: function(cm) {cm.undo();},
|
| 5541 |
+
redo: function(cm) {cm.redo();},
|
| 5542 |
+
undoSelection: function(cm) {cm.undoSelection();},
|
| 5543 |
+
redoSelection: function(cm) {cm.redoSelection();},
|
| 5544 |
+
goDocStart: function(cm) {cm.extendSelection(Pos(cm.firstLine(), 0));},
|
| 5545 |
+
goDocEnd: function(cm) {cm.extendSelection(Pos(cm.lastLine()));},
|
| 5546 |
+
goLineStart: function(cm) {
|
| 5547 |
+
cm.extendSelectionsBy(function(range) { return lineStart(cm, range.head.line); },
|
| 5548 |
+
{origin: "+move", bias: 1});
|
| 5549 |
+
},
|
| 5550 |
+
goLineStartSmart: function(cm) {
|
| 5551 |
+
cm.extendSelectionsBy(function(range) {
|
| 5552 |
+
return lineStartSmart(cm, range.head);
|
| 5553 |
+
}, {origin: "+move", bias: 1});
|
| 5554 |
+
},
|
| 5555 |
+
goLineEnd: function(cm) {
|
| 5556 |
+
cm.extendSelectionsBy(function(range) { return lineEnd(cm, range.head.line); },
|
| 5557 |
+
{origin: "+move", bias: -1});
|
| 5558 |
+
},
|
| 5559 |
+
goLineRight: function(cm) {
|
| 5560 |
+
cm.extendSelectionsBy(function(range) {
|
| 5561 |
+
var top = cm.charCoords(range.head, "div").top + 5;
|
| 5562 |
+
return cm.coordsChar({left: cm.display.lineDiv.offsetWidth + 100, top: top}, "div");
|
| 5563 |
+
}, sel_move);
|
| 5564 |
+
},
|
| 5565 |
+
goLineLeft: function(cm) {
|
| 5566 |
+
cm.extendSelectionsBy(function(range) {
|
| 5567 |
+
var top = cm.charCoords(range.head, "div").top + 5;
|
| 5568 |
+
return cm.coordsChar({left: 0, top: top}, "div");
|
| 5569 |
+
}, sel_move);
|
| 5570 |
+
},
|
| 5571 |
+
goLineLeftSmart: function(cm) {
|
| 5572 |
+
cm.extendSelectionsBy(function(range) {
|
| 5573 |
+
var top = cm.charCoords(range.head, "div").top + 5;
|
| 5574 |
+
var pos = cm.coordsChar({left: 0, top: top}, "div");
|
| 5575 |
+
if (pos.ch < cm.getLine(pos.line).search(/\S/)) return lineStartSmart(cm, range.head);
|
| 5576 |
+
return pos;
|
| 5577 |
+
}, sel_move);
|
| 5578 |
+
},
|
| 5579 |
+
goLineUp: function(cm) {cm.moveV(-1, "line");},
|
| 5580 |
+
goLineDown: function(cm) {cm.moveV(1, "line");},
|
| 5581 |
+
goPageUp: function(cm) {cm.moveV(-1, "page");},
|
| 5582 |
+
goPageDown: function(cm) {cm.moveV(1, "page");},
|
| 5583 |
+
goCharLeft: function(cm) {cm.moveH(-1, "char");},
|
| 5584 |
+
goCharRight: function(cm) {cm.moveH(1, "char");},
|
| 5585 |
+
goColumnLeft: function(cm) {cm.moveH(-1, "column");},
|
| 5586 |
+
goColumnRight: function(cm) {cm.moveH(1, "column");},
|
| 5587 |
+
goWordLeft: function(cm) {cm.moveH(-1, "word");},
|
| 5588 |
+
goGroupRight: function(cm) {cm.moveH(1, "group");},
|
| 5589 |
+
goGroupLeft: function(cm) {cm.moveH(-1, "group");},
|
| 5590 |
+
goWordRight: function(cm) {cm.moveH(1, "word");},
|
| 5591 |
+
delCharBefore: function(cm) {cm.deleteH(-1, "char");},
|
| 5592 |
+
delCharAfter: function(cm) {cm.deleteH(1, "char");},
|
| 5593 |
+
delWordBefore: function(cm) {cm.deleteH(-1, "word");},
|
| 5594 |
+
delWordAfter: function(cm) {cm.deleteH(1, "word");},
|
| 5595 |
+
delGroupBefore: function(cm) {cm.deleteH(-1, "group");},
|
| 5596 |
+
delGroupAfter: function(cm) {cm.deleteH(1, "group");},
|
| 5597 |
+
indentAuto: function(cm) {cm.indentSelection("smart");},
|
| 5598 |
+
indentMore: function(cm) {cm.indentSelection("add");},
|
| 5599 |
+
indentLess: function(cm) {cm.indentSelection("subtract");},
|
| 5600 |
+
insertTab: function(cm) {cm.replaceSelection("\t");},
|
| 5601 |
+
insertSoftTab: function(cm) {
|
| 5602 |
+
var spaces = [], ranges = cm.listSelections(), tabSize = cm.options.tabSize;
|
| 5603 |
+
for (var i = 0; i < ranges.length; i++) {
|
| 5604 |
+
var pos = ranges[i].from();
|
| 5605 |
+
var col = countColumn(cm.getLine(pos.line), pos.ch, tabSize);
|
| 5606 |
+
spaces.push(new Array(tabSize - col % tabSize + 1).join(" "));
|
| 5607 |
+
}
|
| 5608 |
+
cm.replaceSelections(spaces);
|
| 5609 |
+
},
|
| 5610 |
+
defaultTab: function(cm) {
|
| 5611 |
+
if (cm.somethingSelected()) cm.indentSelection("add");
|
| 5612 |
+
else cm.execCommand("insertTab");
|
| 5613 |
+
},
|
| 5614 |
+
transposeChars: function(cm) {
|
| 5615 |
+
runInOp(cm, function() {
|
| 5616 |
+
var ranges = cm.listSelections(), newSel = [];
|
| 5617 |
+
for (var i = 0; i < ranges.length; i++) {
|
| 5618 |
+
var cur = ranges[i].head, line = getLine(cm.doc, cur.line).text;
|
| 5619 |
+
if (line) {
|
| 5620 |
+
if (cur.ch == line.length) cur = new Pos(cur.line, cur.ch - 1);
|
| 5621 |
+
if (cur.ch > 0) {
|
| 5622 |
+
cur = new Pos(cur.line, cur.ch + 1);
|
| 5623 |
+
cm.replaceRange(line.charAt(cur.ch - 1) + line.charAt(cur.ch - 2),
|
| 5624 |
+
Pos(cur.line, cur.ch - 2), cur, "+transpose");
|
| 5625 |
+
} else if (cur.line > cm.doc.first) {
|
| 5626 |
+
var prev = getLine(cm.doc, cur.line - 1).text;
|
| 5627 |
+
if (prev)
|
| 5628 |
+
cm.replaceRange(line.charAt(0) + "\n" + prev.charAt(prev.length - 1),
|
| 5629 |
+
Pos(cur.line - 1, prev.length - 1), Pos(cur.line, 1), "+transpose");
|
| 5630 |
+
}
|
| 5631 |
+
}
|
| 5632 |
+
newSel.push(new Range(cur, cur));
|
| 5633 |
+
}
|
| 5634 |
+
cm.setSelections(newSel);
|
| 5635 |
+
});
|
| 5636 |
+
},
|
| 5637 |
+
newlineAndIndent: function(cm) {
|
| 5638 |
+
runInOp(cm, function() {
|
| 5639 |
+
var len = cm.listSelections().length;
|
| 5640 |
+
for (var i = 0; i < len; i++) {
|
| 5641 |
+
var range = cm.listSelections()[i];
|
| 5642 |
+
cm.replaceRange("\n", range.anchor, range.head, "+input");
|
| 5643 |
+
cm.indentLine(range.from().line + 1, null, true);
|
| 5644 |
+
ensureCursorVisible(cm);
|
| 5645 |
+
}
|
| 5646 |
+
});
|
| 5647 |
+
},
|
| 5648 |
+
toggleOverwrite: function(cm) {cm.toggleOverwrite();}
|
| 5649 |
+
};
|
| 5650 |
+
|
| 5651 |
+
|
| 5652 |
+
// STANDARD KEYMAPS
|
| 5653 |
+
|
| 5654 |
+
var keyMap = CodeMirror.keyMap = {};
|
| 5655 |
+
|
| 5656 |
+
keyMap.basic = {
|
| 5657 |
+
"Left": "goCharLeft", "Right": "goCharRight", "Up": "goLineUp", "Down": "goLineDown",
|
| 5658 |
+
"End": "goLineEnd", "Home": "goLineStartSmart", "PageUp": "goPageUp", "PageDown": "goPageDown",
|
| 5659 |
+
"Delete": "delCharAfter", "Backspace": "delCharBefore", "Shift-Backspace": "delCharBefore",
|
| 5660 |
+
"Tab": "defaultTab", "Shift-Tab": "indentAuto",
|
| 5661 |
+
"Enter": "newlineAndIndent", "Insert": "toggleOverwrite",
|
| 5662 |
+
"Esc": "singleSelection"
|
| 5663 |
+
};
|
| 5664 |
+
// Note that the save and find-related commands aren't defined by
|
| 5665 |
+
// default. User code or addons can define them. Unknown commands
|
| 5666 |
+
// are simply ignored.
|
| 5667 |
+
keyMap.pcDefault = {
|
| 5668 |
+
"Ctrl-A": "selectAll", "Ctrl-D": "deleteLine", "Ctrl-Z": "undo", "Shift-Ctrl-Z": "redo", "Ctrl-Y": "redo",
|
| 5669 |
+
"Ctrl-Home": "goDocStart", "Ctrl-End": "goDocEnd", "Ctrl-Up": "goLineUp", "Ctrl-Down": "goLineDown",
|
| 5670 |
+
"Ctrl-Left": "goGroupLeft", "Ctrl-Right": "goGroupRight", "Alt-Left": "goLineStart", "Alt-Right": "goLineEnd",
|
| 5671 |
+
"Ctrl-Backspace": "delGroupBefore", "Ctrl-Delete": "delGroupAfter", "Ctrl-S": "save", "Ctrl-F": "find",
|
| 5672 |
+
"Ctrl-G": "findNext", "Shift-Ctrl-G": "findPrev", "Shift-Ctrl-F": "replace", "Shift-Ctrl-R": "replaceAll",
|
| 5673 |
+
"Ctrl-[": "indentLess", "Ctrl-]": "indentMore",
|
| 5674 |
+
"Ctrl-U": "undoSelection", "Shift-Ctrl-U": "redoSelection", "Alt-U": "redoSelection",
|
| 5675 |
+
fallthrough: "basic"
|
| 5676 |
+
};
|
| 5677 |
+
// Very basic readline/emacs-style bindings, which are standard on Mac.
|
| 5678 |
+
keyMap.emacsy = {
|
| 5679 |
+
"Ctrl-F": "goCharRight", "Ctrl-B": "goCharLeft", "Ctrl-P": "goLineUp", "Ctrl-N": "goLineDown",
|
| 5680 |
+
"Alt-F": "goWordRight", "Alt-B": "goWordLeft", "Ctrl-A": "goLineStart", "Ctrl-E": "goLineEnd",
|
| 5681 |
+
"Ctrl-V": "goPageDown", "Shift-Ctrl-V": "goPageUp", "Ctrl-D": "delCharAfter", "Ctrl-H": "delCharBefore",
|
| 5682 |
+
"Alt-D": "delWordAfter", "Alt-Backspace": "delWordBefore", "Ctrl-K": "killLine", "Ctrl-T": "transposeChars"
|
| 5683 |
+
};
|
| 5684 |
+
keyMap.macDefault = {
|
| 5685 |
+
"Cmd-A": "selectAll", "Cmd-D": "deleteLine", "Cmd-Z": "undo", "Shift-Cmd-Z": "redo", "Cmd-Y": "redo",
|
| 5686 |
+
"Cmd-Home": "goDocStart", "Cmd-Up": "goDocStart", "Cmd-End": "goDocEnd", "Cmd-Down": "goDocEnd", "Alt-Left": "goGroupLeft",
|
| 5687 |
+
"Alt-Right": "goGroupRight", "Cmd-Left": "goLineLeft", "Cmd-Right": "goLineRight", "Alt-Backspace": "delGroupBefore",
|
| 5688 |
+
"Ctrl-Alt-Backspace": "delGroupAfter", "Alt-Delete": "delGroupAfter", "Cmd-S": "save", "Cmd-F": "find",
|
| 5689 |
+
"Cmd-G": "findNext", "Shift-Cmd-G": "findPrev", "Cmd-Alt-F": "replace", "Shift-Cmd-Alt-F": "replaceAll",
|
| 5690 |
+
"Cmd-[": "indentLess", "Cmd-]": "indentMore", "Cmd-Backspace": "delWrappedLineLeft", "Cmd-Delete": "delWrappedLineRight",
|
| 5691 |
+
"Cmd-U": "undoSelection", "Shift-Cmd-U": "redoSelection", "Ctrl-Up": "goDocStart", "Ctrl-Down": "goDocEnd",
|
| 5692 |
+
fallthrough: ["basic", "emacsy"]
|
| 5693 |
+
};
|
| 5694 |
+
keyMap["default"] = mac ? keyMap.macDefault : keyMap.pcDefault;
|
| 5695 |
+
|
| 5696 |
+
// KEYMAP DISPATCH
|
| 5697 |
+
|
| 5698 |
+
function normalizeKeyName(name) {
|
| 5699 |
+
var parts = name.split(/-(?!$)/), name = parts[parts.length - 1];
|
| 5700 |
+
var alt, ctrl, shift, cmd;
|
| 5701 |
+
for (var i = 0; i < parts.length - 1; i++) {
|
| 5702 |
+
var mod = parts[i];
|
| 5703 |
+
if (/^(cmd|meta|m)$/i.test(mod)) cmd = true;
|
| 5704 |
+
else if (/^a(lt)?$/i.test(mod)) alt = true;
|
| 5705 |
+
else if (/^(c|ctrl|control)$/i.test(mod)) ctrl = true;
|
| 5706 |
+
else if (/^s(hift)$/i.test(mod)) shift = true;
|
| 5707 |
+
else throw new Error("Unrecognized modifier name: " + mod);
|
| 5708 |
+
}
|
| 5709 |
+
if (alt) name = "Alt-" + name;
|
| 5710 |
+
if (ctrl) name = "Ctrl-" + name;
|
| 5711 |
+
if (cmd) name = "Cmd-" + name;
|
| 5712 |
+
if (shift) name = "Shift-" + name;
|
| 5713 |
+
return name;
|
| 5714 |
+
}
|
| 5715 |
+
|
| 5716 |
+
// This is a kludge to keep keymaps mostly working as raw objects
|
| 5717 |
+
// (backwards compatibility) while at the same time support features
|
| 5718 |
+
// like normalization and multi-stroke key bindings. It compiles a
|
| 5719 |
+
// new normalized keymap, and then updates the old object to reflect
|
| 5720 |
+
// this.
|
| 5721 |
+
CodeMirror.normalizeKeyMap = function(keymap) {
|
| 5722 |
+
var copy = {};
|
| 5723 |
+
for (var keyname in keymap) if (keymap.hasOwnProperty(keyname)) {
|
| 5724 |
+
var value = keymap[keyname];
|
| 5725 |
+
if (/^(name|fallthrough|(de|at)tach)$/.test(keyname)) continue;
|
| 5726 |
+
if (value == "...") { delete keymap[keyname]; continue; }
|
| 5727 |
+
|
| 5728 |
+
var keys = map(keyname.split(" "), normalizeKeyName);
|
| 5729 |
+
for (var i = 0; i < keys.length; i++) {
|
| 5730 |
+
var val, name;
|
| 5731 |
+
if (i == keys.length - 1) {
|
| 5732 |
+
name = keys.join(" ");
|
| 5733 |
+
val = value;
|
| 5734 |
+
} else {
|
| 5735 |
+
name = keys.slice(0, i + 1).join(" ");
|
| 5736 |
+
val = "...";
|
| 5737 |
+
}
|
| 5738 |
+
var prev = copy[name];
|
| 5739 |
+
if (!prev) copy[name] = val;
|
| 5740 |
+
else if (prev != val) throw new Error("Inconsistent bindings for " + name);
|
| 5741 |
+
}
|
| 5742 |
+
delete keymap[keyname];
|
| 5743 |
+
}
|
| 5744 |
+
for (var prop in copy) keymap[prop] = copy[prop];
|
| 5745 |
+
return keymap;
|
| 5746 |
+
};
|
| 5747 |
+
|
| 5748 |
+
var lookupKey = CodeMirror.lookupKey = function(key, map, handle, context) {
|
| 5749 |
+
map = getKeyMap(map);
|
| 5750 |
+
var found = map.call ? map.call(key, context) : map[key];
|
| 5751 |
+
if (found === false) return "nothing";
|
| 5752 |
+
if (found === "...") return "multi";
|
| 5753 |
+
if (found != null && handle(found)) return "handled";
|
| 5754 |
+
|
| 5755 |
+
if (map.fallthrough) {
|
| 5756 |
+
if (Object.prototype.toString.call(map.fallthrough) != "[object Array]")
|
| 5757 |
+
return lookupKey(key, map.fallthrough, handle, context);
|
| 5758 |
+
for (var i = 0; i < map.fallthrough.length; i++) {
|
| 5759 |
+
var result = lookupKey(key, map.fallthrough[i], handle, context);
|
| 5760 |
+
if (result) return result;
|
| 5761 |
+
}
|
| 5762 |
+
}
|
| 5763 |
+
};
|
| 5764 |
+
|
| 5765 |
+
// Modifier key presses don't count as 'real' key presses for the
|
| 5766 |
+
// purpose of keymap fallthrough.
|
| 5767 |
+
var isModifierKey = CodeMirror.isModifierKey = function(value) {
|
| 5768 |
+
var name = typeof value == "string" ? value : keyNames[value.keyCode];
|
| 5769 |
+
return name == "Ctrl" || name == "Alt" || name == "Shift" || name == "Mod";
|
| 5770 |
+
};
|
| 5771 |
+
|
| 5772 |
+
// Look up the name of a key as indicated by an event object.
|
| 5773 |
+
var keyName = CodeMirror.keyName = function(event, noShift) {
|
| 5774 |
+
if (presto && event.keyCode == 34 && event["char"]) return false;
|
| 5775 |
+
var base = keyNames[event.keyCode], name = base;
|
| 5776 |
+
if (name == null || event.altGraphKey) return false;
|
| 5777 |
+
if (event.altKey && base != "Alt") name = "Alt-" + name;
|
| 5778 |
+
if ((flipCtrlCmd ? event.metaKey : event.ctrlKey) && base != "Ctrl") name = "Ctrl-" + name;
|
| 5779 |
+
if ((flipCtrlCmd ? event.ctrlKey : event.metaKey) && base != "Cmd") name = "Cmd-" + name;
|
| 5780 |
+
if (!noShift && event.shiftKey && base != "Shift") name = "Shift-" + name;
|
| 5781 |
+
return name;
|
| 5782 |
+
};
|
| 5783 |
+
|
| 5784 |
+
function getKeyMap(val) {
|
| 5785 |
+
return typeof val == "string" ? keyMap[val] : val;
|
| 5786 |
+
}
|
| 5787 |
+
|
| 5788 |
+
// FROMTEXTAREA
|
| 5789 |
+
|
| 5790 |
+
CodeMirror.fromTextArea = function(textarea, options) {
|
| 5791 |
+
options = options ? copyObj(options) : {};
|
| 5792 |
+
options.value = textarea.value;
|
| 5793 |
+
if (!options.tabindex && textarea.tabIndex)
|
| 5794 |
+
options.tabindex = textarea.tabIndex;
|
| 5795 |
+
if (!options.placeholder && textarea.placeholder)
|
| 5796 |
+
options.placeholder = textarea.placeholder;
|
| 5797 |
+
// Set autofocus to true if this textarea is focused, or if it has
|
| 5798 |
+
// autofocus and no other element is focused.
|
| 5799 |
+
if (options.autofocus == null) {
|
| 5800 |
+
var hasFocus = activeElt();
|
| 5801 |
+
options.autofocus = hasFocus == textarea ||
|
| 5802 |
+
textarea.getAttribute("autofocus") != null && hasFocus == document.body;
|
| 5803 |
+
}
|
| 5804 |
+
|
| 5805 |
+
function save() {textarea.value = cm.getValue();}
|
| 5806 |
+
if (textarea.form) {
|
| 5807 |
+
on(textarea.form, "submit", save);
|
| 5808 |
+
// Deplorable hack to make the submit method do the right thing.
|
| 5809 |
+
if (!options.leaveSubmitMethodAlone) {
|
| 5810 |
+
var form = textarea.form, realSubmit = form.submit;
|
| 5811 |
+
try {
|
| 5812 |
+
var wrappedSubmit = form.submit = function() {
|
| 5813 |
+
save();
|
| 5814 |
+
form.submit = realSubmit;
|
| 5815 |
+
form.submit();
|
| 5816 |
+
form.submit = wrappedSubmit;
|
| 5817 |
+
};
|
| 5818 |
+
} catch(e) {}
|
| 5819 |
+
}
|
| 5820 |
+
}
|
| 5821 |
+
|
| 5822 |
+
options.finishInit = function(cm) {
|
| 5823 |
+
cm.save = save;
|
| 5824 |
+
cm.getTextArea = function() { return textarea; };
|
| 5825 |
+
cm.toTextArea = function() {
|
| 5826 |
+
cm.toTextArea = isNaN; // Prevent this from being ran twice
|
| 5827 |
+
save();
|
| 5828 |
+
textarea.parentNode.removeChild(cm.getWrapperElement());
|
| 5829 |
+
textarea.style.display = "";
|
| 5830 |
+
if (textarea.form) {
|
| 5831 |
+
off(textarea.form, "submit", save);
|
| 5832 |
+
if (typeof textarea.form.submit == "function")
|
| 5833 |
+
textarea.form.submit = realSubmit;
|
| 5834 |
+
}
|
| 5835 |
+
};
|
| 5836 |
+
};
|
| 5837 |
+
|
| 5838 |
+
textarea.style.display = "none";
|
| 5839 |
+
var cm = CodeMirror(function(node) {
|
| 5840 |
+
textarea.parentNode.insertBefore(node, textarea.nextSibling);
|
| 5841 |
+
}, options);
|
| 5842 |
+
return cm;
|
| 5843 |
+
};
|
| 5844 |
+
|
| 5845 |
+
// STRING STREAM
|
| 5846 |
+
|
| 5847 |
+
// Fed to the mode parsers, provides helper functions to make
|
| 5848 |
+
// parsers more succinct.
|
| 5849 |
+
|
| 5850 |
+
var StringStream = CodeMirror.StringStream = function(string, tabSize) {
|
| 5851 |
+
this.pos = this.start = 0;
|
| 5852 |
+
this.string = string;
|
| 5853 |
+
this.tabSize = tabSize || 8;
|
| 5854 |
+
this.lastColumnPos = this.lastColumnValue = 0;
|
| 5855 |
+
this.lineStart = 0;
|
| 5856 |
+
};
|
| 5857 |
+
|
| 5858 |
+
StringStream.prototype = {
|
| 5859 |
+
eol: function() {return this.pos >= this.string.length;},
|
| 5860 |
+
sol: function() {return this.pos == this.lineStart;},
|
| 5861 |
+
peek: function() {return this.string.charAt(this.pos) || undefined;},
|
| 5862 |
+
next: function() {
|
| 5863 |
+
if (this.pos < this.string.length)
|
| 5864 |
+
return this.string.charAt(this.pos++);
|
| 5865 |
+
},
|
| 5866 |
+
eat: function(match) {
|
| 5867 |
+
var ch = this.string.charAt(this.pos);
|
| 5868 |
+
if (typeof match == "string") var ok = ch == match;
|
| 5869 |
+
else var ok = ch && (match.test ? match.test(ch) : match(ch));
|
| 5870 |
+
if (ok) {++this.pos; return ch;}
|
| 5871 |
+
},
|
| 5872 |
+
eatWhile: function(match) {
|
| 5873 |
+
var start = this.pos;
|
| 5874 |
+
while (this.eat(match)){}
|
| 5875 |
+
return this.pos > start;
|
| 5876 |
+
},
|
| 5877 |
+
eatSpace: function() {
|
| 5878 |
+
var start = this.pos;
|
| 5879 |
+
while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) ++this.pos;
|
| 5880 |
+
return this.pos > start;
|
| 5881 |
+
},
|
| 5882 |
+
skipToEnd: function() {this.pos = this.string.length;},
|
| 5883 |
+
skipTo: function(ch) {
|
| 5884 |
+
var found = this.string.indexOf(ch, this.pos);
|
| 5885 |
+
if (found > -1) {this.pos = found; return true;}
|
| 5886 |
+
},
|
| 5887 |
+
backUp: function(n) {this.pos -= n;},
|
| 5888 |
+
column: function() {
|
| 5889 |
+
if (this.lastColumnPos < this.start) {
|
| 5890 |
+
this.lastColumnValue = countColumn(this.string, this.start, this.tabSize, this.lastColumnPos, this.lastColumnValue);
|
| 5891 |
+
this.lastColumnPos = this.start;
|
| 5892 |
+
}
|
| 5893 |
+
return this.lastColumnValue - (this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0);
|
| 5894 |
+
},
|
| 5895 |
+
indentation: function() {
|
| 5896 |
+
return countColumn(this.string, null, this.tabSize) -
|
| 5897 |
+
(this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0);
|
| 5898 |
+
},
|
| 5899 |
+
match: function(pattern, consume, caseInsensitive) {
|
| 5900 |
+
if (typeof pattern == "string") {
|
| 5901 |
+
var cased = function(str) {return caseInsensitive ? str.toLowerCase() : str;};
|
| 5902 |
+
var substr = this.string.substr(this.pos, pattern.length);
|
| 5903 |
+
if (cased(substr) == cased(pattern)) {
|
| 5904 |
+
if (consume !== false) this.pos += pattern.length;
|
| 5905 |
+
return true;
|
| 5906 |
+
}
|
| 5907 |
+
} else {
|
| 5908 |
+
var match = this.string.slice(this.pos).match(pattern);
|
| 5909 |
+
if (match && match.index > 0) return null;
|
| 5910 |
+
if (match && consume !== false) this.pos += match[0].length;
|
| 5911 |
+
return match;
|
| 5912 |
+
}
|
| 5913 |
+
},
|
| 5914 |
+
current: function(){return this.string.slice(this.start, this.pos);},
|
| 5915 |
+
hideFirstChars: function(n, inner) {
|
| 5916 |
+
this.lineStart += n;
|
| 5917 |
+
try { return inner(); }
|
| 5918 |
+
finally { this.lineStart -= n; }
|
| 5919 |
+
}
|
| 5920 |
+
};
|
| 5921 |
+
|
| 5922 |
+
// TEXTMARKERS
|
| 5923 |
+
|
| 5924 |
+
// Created with markText and setBookmark methods. A TextMarker is a
|
| 5925 |
+
// handle that can be used to clear or find a marked position in the
|
| 5926 |
+
// document. Line objects hold arrays (markedSpans) containing
|
| 5927 |
+
// {from, to, marker} object pointing to such marker objects, and
|
| 5928 |
+
// indicating that such a marker is present on that line. Multiple
|
| 5929 |
+
// lines may point to the same marker when it spans across lines.
|
| 5930 |
+
// The spans will have null for their from/to properties when the
|
| 5931 |
+
// marker continues beyond the start/end of the line. Markers have
|
| 5932 |
+
// links back to the lines they currently touch.
|
| 5933 |
+
|
| 5934 |
+
var nextMarkerId = 0;
|
| 5935 |
+
|
| 5936 |
+
var TextMarker = CodeMirror.TextMarker = function(doc, type) {
|
| 5937 |
+
this.lines = [];
|
| 5938 |
+
this.type = type;
|
| 5939 |
+
this.doc = doc;
|
| 5940 |
+
this.id = ++nextMarkerId;
|
| 5941 |
+
};
|
| 5942 |
+
eventMixin(TextMarker);
|
| 5943 |
+
|
| 5944 |
+
// Clear the marker.
|
| 5945 |
+
TextMarker.prototype.clear = function() {
|
| 5946 |
+
if (this.explicitlyCleared) return;
|
| 5947 |
+
var cm = this.doc.cm, withOp = cm && !cm.curOp;
|
| 5948 |
+
if (withOp) startOperation(cm);
|
| 5949 |
+
if (hasHandler(this, "clear")) {
|
| 5950 |
+
var found = this.find();
|
| 5951 |
+
if (found) signalLater(this, "clear", found.from, found.to);
|
| 5952 |
+
}
|
| 5953 |
+
var min = null, max = null;
|
| 5954 |
+
for (var i = 0; i < this.lines.length; ++i) {
|
| 5955 |
+
var line = this.lines[i];
|
| 5956 |
+
var span = getMarkedSpanFor(line.markedSpans, this);
|
| 5957 |
+
if (cm && !this.collapsed) regLineChange(cm, lineNo(line), "text");
|
| 5958 |
+
else if (cm) {
|
| 5959 |
+
if (span.to != null) max = lineNo(line);
|
| 5960 |
+
if (span.from != null) min = lineNo(line);
|
| 5961 |
+
}
|
| 5962 |
+
line.markedSpans = removeMarkedSpan(line.markedSpans, span);
|
| 5963 |
+
if (span.from == null && this.collapsed && !lineIsHidden(this.doc, line) && cm)
|
| 5964 |
+
updateLineHeight(line, textHeight(cm.display));
|
| 5965 |
+
}
|
| 5966 |
+
if (cm && this.collapsed && !cm.options.lineWrapping) for (var i = 0; i < this.lines.length; ++i) {
|
| 5967 |
+
var visual = visualLine(this.lines[i]), len = lineLength(visual);
|
| 5968 |
+
if (len > cm.display.maxLineLength) {
|
| 5969 |
+
cm.display.maxLine = visual;
|
| 5970 |
+
cm.display.maxLineLength = len;
|
| 5971 |
+
cm.display.maxLineChanged = true;
|
| 5972 |
+
}
|
| 5973 |
+
}
|
| 5974 |
+
|
| 5975 |
+
if (min != null && cm && this.collapsed) regChange(cm, min, max + 1);
|
| 5976 |
+
this.lines.length = 0;
|
| 5977 |
+
this.explicitlyCleared = true;
|
| 5978 |
+
if (this.atomic && this.doc.cantEdit) {
|
| 5979 |
+
this.doc.cantEdit = false;
|
| 5980 |
+
if (cm) reCheckSelection(cm.doc);
|
| 5981 |
+
}
|
| 5982 |
+
if (cm) signalLater(cm, "markerCleared", cm, this);
|
| 5983 |
+
if (withOp) endOperation(cm);
|
| 5984 |
+
if (this.parent) this.parent.clear();
|
| 5985 |
+
};
|
| 5986 |
+
|
| 5987 |
+
// Find the position of the marker in the document. Returns a {from,
|
| 5988 |
+
// to} object by default. Side can be passed to get a specific side
|
| 5989 |
+
// -- 0 (both), -1 (left), or 1 (right). When lineObj is true, the
|
| 5990 |
+
// Pos objects returned contain a line object, rather than a line
|
| 5991 |
+
// number (used to prevent looking up the same line twice).
|
| 5992 |
+
TextMarker.prototype.find = function(side, lineObj) {
|
| 5993 |
+
if (side == null && this.type == "bookmark") side = 1;
|
| 5994 |
+
var from, to;
|
| 5995 |
+
for (var i = 0; i < this.lines.length; ++i) {
|
| 5996 |
+
var line = this.lines[i];
|
| 5997 |
+
var span = getMarkedSpanFor(line.markedSpans, this);
|
| 5998 |
+
if (span.from != null) {
|
| 5999 |
+
from = Pos(lineObj ? line : lineNo(line), span.from);
|
| 6000 |
+
if (side == -1) return from;
|
| 6001 |
+
}
|
| 6002 |
+
if (span.to != null) {
|
| 6003 |
+
to = Pos(lineObj ? line : lineNo(line), span.to);
|
| 6004 |
+
if (side == 1) return to;
|
| 6005 |
+
}
|
| 6006 |
+
}
|
| 6007 |
+
return from && {from: from, to: to};
|
| 6008 |
+
};
|
| 6009 |
+
|
| 6010 |
+
// Signals that the marker's widget changed, and surrounding layout
|
| 6011 |
+
// should be recomputed.
|
| 6012 |
+
TextMarker.prototype.changed = function() {
|
| 6013 |
+
var pos = this.find(-1, true), widget = this, cm = this.doc.cm;
|
| 6014 |
+
if (!pos || !cm) return;
|
| 6015 |
+
runInOp(cm, function() {
|
| 6016 |
+
var line = pos.line, lineN = lineNo(pos.line);
|
| 6017 |
+
var view = findViewForLine(cm, lineN);
|
| 6018 |
+
if (view) {
|
| 6019 |
+
clearLineMeasurementCacheFor(view);
|
| 6020 |
+
cm.curOp.selectionChanged = cm.curOp.forceUpdate = true;
|
| 6021 |
+
}
|
| 6022 |
+
cm.curOp.updateMaxLine = true;
|
| 6023 |
+
if (!lineIsHidden(widget.doc, line) && widget.height != null) {
|
| 6024 |
+
var oldHeight = widget.height;
|
| 6025 |
+
widget.height = null;
|
| 6026 |
+
var dHeight = widgetHeight(widget) - oldHeight;
|
| 6027 |
+
if (dHeight)
|
| 6028 |
+
updateLineHeight(line, line.height + dHeight);
|
| 6029 |
+
}
|
| 6030 |
+
});
|
| 6031 |
+
};
|
| 6032 |
+
|
| 6033 |
+
TextMarker.prototype.attachLine = function(line) {
|
| 6034 |
+
if (!this.lines.length && this.doc.cm) {
|
| 6035 |
+
var op = this.doc.cm.curOp;
|
| 6036 |
+
if (!op.maybeHiddenMarkers || indexOf(op.maybeHiddenMarkers, this) == -1)
|
| 6037 |
+
(op.maybeUnhiddenMarkers || (op.maybeUnhiddenMarkers = [])).push(this);
|
| 6038 |
+
}
|
| 6039 |
+
this.lines.push(line);
|
| 6040 |
+
};
|
| 6041 |
+
TextMarker.prototype.detachLine = function(line) {
|
| 6042 |
+
this.lines.splice(indexOf(this.lines, line), 1);
|
| 6043 |
+
if (!this.lines.length && this.doc.cm) {
|
| 6044 |
+
var op = this.doc.cm.curOp;
|
| 6045 |
+
(op.maybeHiddenMarkers || (op.maybeHiddenMarkers = [])).push(this);
|
| 6046 |
+
}
|
| 6047 |
+
};
|
| 6048 |
+
|
| 6049 |
+
// Collapsed markers have unique ids, in order to be able to order
|
| 6050 |
+
// them, which is needed for uniquely determining an outer marker
|
| 6051 |
+
// when they overlap (they may nest, but not partially overlap).
|
| 6052 |
+
var nextMarkerId = 0;
|
| 6053 |
+
|
| 6054 |
+
// Create a marker, wire it up to the right lines, and
|
| 6055 |
+
function markText(doc, from, to, options, type) {
|
| 6056 |
+
// Shared markers (across linked documents) are handled separately
|
| 6057 |
+
// (markTextShared will call out to this again, once per
|
| 6058 |
+
// document).
|
| 6059 |
+
if (options && options.shared) return markTextShared(doc, from, to, options, type);
|
| 6060 |
+
// Ensure we are in an operation.
|
| 6061 |
+
if (doc.cm && !doc.cm.curOp) return operation(doc.cm, markText)(doc, from, to, options, type);
|
| 6062 |
+
|
| 6063 |
+
var marker = new TextMarker(doc, type), diff = cmp(from, to);
|
| 6064 |
+
if (options) copyObj(options, marker, false);
|
| 6065 |
+
// Don't connect empty markers unless clearWhenEmpty is false
|
| 6066 |
+
if (diff > 0 || diff == 0 && marker.clearWhenEmpty !== false)
|
| 6067 |
+
return marker;
|
| 6068 |
+
if (marker.replacedWith) {
|
| 6069 |
+
// Showing up as a widget implies collapsed (widget replaces text)
|
| 6070 |
+
marker.collapsed = true;
|
| 6071 |
+
marker.widgetNode = elt("span", [marker.replacedWith], "CodeMirror-widget");
|
| 6072 |
+
if (!options.handleMouseEvents) marker.widgetNode.setAttribute("cm-ignore-events", "true");
|
| 6073 |
+
if (options.insertLeft) marker.widgetNode.insertLeft = true;
|
| 6074 |
+
}
|
| 6075 |
+
if (marker.collapsed) {
|
| 6076 |
+
if (conflictingCollapsedRange(doc, from.line, from, to, marker) ||
|
| 6077 |
+
from.line != to.line && conflictingCollapsedRange(doc, to.line, from, to, marker))
|
| 6078 |
+
throw new Error("Inserting collapsed marker partially overlapping an existing one");
|
| 6079 |
+
sawCollapsedSpans = true;
|
| 6080 |
+
}
|
| 6081 |
+
|
| 6082 |
+
if (marker.addToHistory)
|
| 6083 |
+
addChangeToHistory(doc, {from: from, to: to, origin: "markText"}, doc.sel, NaN);
|
| 6084 |
+
|
| 6085 |
+
var curLine = from.line, cm = doc.cm, updateMaxLine;
|
| 6086 |
+
doc.iter(curLine, to.line + 1, function(line) {
|
| 6087 |
+
if (cm && marker.collapsed && !cm.options.lineWrapping && visualLine(line) == cm.display.maxLine)
|
| 6088 |
+
updateMaxLine = true;
|
| 6089 |
+
if (marker.collapsed && curLine != from.line) updateLineHeight(line, 0);
|
| 6090 |
+
addMarkedSpan(line, new MarkedSpan(marker,
|
| 6091 |
+
curLine == from.line ? from.ch : null,
|
| 6092 |
+
curLine == to.line ? to.ch : null));
|
| 6093 |
+
++curLine;
|
| 6094 |
+
});
|
| 6095 |
+
// lineIsHidden depends on the presence of the spans, so needs a second pass
|
| 6096 |
+
if (marker.collapsed) doc.iter(from.line, to.line + 1, function(line) {
|
| 6097 |
+
if (lineIsHidden(doc, line)) updateLineHeight(line, 0);
|
| 6098 |
+
});
|
| 6099 |
+
|
| 6100 |
+
if (marker.clearOnEnter) on(marker, "beforeCursorEnter", function() { marker.clear(); });
|
| 6101 |
+
|
| 6102 |
+
if (marker.readOnly) {
|
| 6103 |
+
sawReadOnlySpans = true;
|
| 6104 |
+
if (doc.history.done.length || doc.history.undone.length)
|
| 6105 |
+
doc.clearHistory();
|
| 6106 |
+
}
|
| 6107 |
+
if (marker.collapsed) {
|
| 6108 |
+
marker.id = ++nextMarkerId;
|
| 6109 |
+
marker.atomic = true;
|
| 6110 |
+
}
|
| 6111 |
+
if (cm) {
|
| 6112 |
+
// Sync editor state
|
| 6113 |
+
if (updateMaxLine) cm.curOp.updateMaxLine = true;
|
| 6114 |
+
if (marker.collapsed)
|
| 6115 |
+
regChange(cm, from.line, to.line + 1);
|
| 6116 |
+
else if (marker.className || marker.title || marker.startStyle || marker.endStyle || marker.css)
|
| 6117 |
+
for (var i = from.line; i <= to.line; i++) regLineChange(cm, i, "text");
|
| 6118 |
+
if (marker.atomic) reCheckSelection(cm.doc);
|
| 6119 |
+
signalLater(cm, "markerAdded", cm, marker);
|
| 6120 |
+
}
|
| 6121 |
+
return marker;
|
| 6122 |
+
}
|
| 6123 |
+
|
| 6124 |
+
// SHARED TEXTMARKERS
|
| 6125 |
+
|
| 6126 |
+
// A shared marker spans multiple linked documents. It is
|
| 6127 |
+
// implemented as a meta-marker-object controlling multiple normal
|
| 6128 |
+
// markers.
|
| 6129 |
+
var SharedTextMarker = CodeMirror.SharedTextMarker = function(markers, primary) {
|
| 6130 |
+
this.markers = markers;
|
| 6131 |
+
this.primary = primary;
|
| 6132 |
+
for (var i = 0; i < markers.length; ++i)
|
| 6133 |
+
markers[i].parent = this;
|
| 6134 |
+
};
|
| 6135 |
+
eventMixin(SharedTextMarker);
|
| 6136 |
+
|
| 6137 |
+
SharedTextMarker.prototype.clear = function() {
|
| 6138 |
+
if (this.explicitlyCleared) return;
|
| 6139 |
+
this.explicitlyCleared = true;
|
| 6140 |
+
for (var i = 0; i < this.markers.length; ++i)
|
| 6141 |
+
this.markers[i].clear();
|
| 6142 |
+
signalLater(this, "clear");
|
| 6143 |
+
};
|
| 6144 |
+
SharedTextMarker.prototype.find = function(side, lineObj) {
|
| 6145 |
+
return this.primary.find(side, lineObj);
|
| 6146 |
+
};
|
| 6147 |
+
|
| 6148 |
+
function markTextShared(doc, from, to, options, type) {
|
| 6149 |
+
options = copyObj(options);
|
| 6150 |
+
options.shared = false;
|
| 6151 |
+
var markers = [markText(doc, from, to, options, type)], primary = markers[0];
|
| 6152 |
+
var widget = options.widgetNode;
|
| 6153 |
+
linkedDocs(doc, function(doc) {
|
| 6154 |
+
if (widget) options.widgetNode = widget.cloneNode(true);
|
| 6155 |
+
markers.push(markText(doc, clipPos(doc, from), clipPos(doc, to), options, type));
|
| 6156 |
+
for (var i = 0; i < doc.linked.length; ++i)
|
| 6157 |
+
if (doc.linked[i].isParent) return;
|
| 6158 |
+
primary = lst(markers);
|
| 6159 |
+
});
|
| 6160 |
+
return new SharedTextMarker(markers, primary);
|
| 6161 |
+
}
|
| 6162 |
+
|
| 6163 |
+
function findSharedMarkers(doc) {
|
| 6164 |
+
return doc.findMarks(Pos(doc.first, 0), doc.clipPos(Pos(doc.lastLine())),
|
| 6165 |
+
function(m) { return m.parent; });
|
| 6166 |
+
}
|
| 6167 |
+
|
| 6168 |
+
function copySharedMarkers(doc, markers) {
|
| 6169 |
+
for (var i = 0; i < markers.length; i++) {
|
| 6170 |
+
var marker = markers[i], pos = marker.find();
|
| 6171 |
+
var mFrom = doc.clipPos(pos.from), mTo = doc.clipPos(pos.to);
|
| 6172 |
+
if (cmp(mFrom, mTo)) {
|
| 6173 |
+
var subMark = markText(doc, mFrom, mTo, marker.primary, marker.primary.type);
|
| 6174 |
+
marker.markers.push(subMark);
|
| 6175 |
+
subMark.parent = marker;
|
| 6176 |
+
}
|
| 6177 |
+
}
|
| 6178 |
+
}
|
| 6179 |
+
|
| 6180 |
+
function detachSharedMarkers(markers) {
|
| 6181 |
+
for (var i = 0; i < markers.length; i++) {
|
| 6182 |
+
var marker = markers[i], linked = [marker.primary.doc];;
|
| 6183 |
+
linkedDocs(marker.primary.doc, function(d) { linked.push(d); });
|
| 6184 |
+
for (var j = 0; j < marker.markers.length; j++) {
|
| 6185 |
+
var subMarker = marker.markers[j];
|
| 6186 |
+
if (indexOf(linked, subMarker.doc) == -1) {
|
| 6187 |
+
subMarker.parent = null;
|
| 6188 |
+
marker.markers.splice(j--, 1);
|
| 6189 |
+
}
|
| 6190 |
+
}
|
| 6191 |
+
}
|
| 6192 |
+
}
|
| 6193 |
+
|
| 6194 |
+
// TEXTMARKER SPANS
|
| 6195 |
+
|
| 6196 |
+
function MarkedSpan(marker, from, to) {
|
| 6197 |
+
this.marker = marker;
|
| 6198 |
+
this.from = from; this.to = to;
|
| 6199 |
+
}
|
| 6200 |
+
|
| 6201 |
+
// Search an array of spans for a span matching the given marker.
|
| 6202 |
+
function getMarkedSpanFor(spans, marker) {
|
| 6203 |
+
if (spans) for (var i = 0; i < spans.length; ++i) {
|
| 6204 |
+
var span = spans[i];
|
| 6205 |
+
if (span.marker == marker) return span;
|
| 6206 |
+
}
|
| 6207 |
+
}
|
| 6208 |
+
// Remove a span from an array, returning undefined if no spans are
|
| 6209 |
+
// left (we don't store arrays for lines without spans).
|
| 6210 |
+
function removeMarkedSpan(spans, span) {
|
| 6211 |
+
for (var r, i = 0; i < spans.length; ++i)
|
| 6212 |
+
if (spans[i] != span) (r || (r = [])).push(spans[i]);
|
| 6213 |
+
return r;
|
| 6214 |
+
}
|
| 6215 |
+
// Add a span to a line.
|
| 6216 |
+
function addMarkedSpan(line, span) {
|
| 6217 |
+
line.markedSpans = line.markedSpans ? line.markedSpans.concat([span]) : [span];
|
| 6218 |
+
span.marker.attachLine(line);
|
| 6219 |
+
}
|
| 6220 |
+
|
| 6221 |
+
// Used for the algorithm that adjusts markers for a change in the
|
| 6222 |
+
// document. These functions cut an array of spans at a given
|
| 6223 |
+
// character position, returning an array of remaining chunks (or
|
| 6224 |
+
// undefined if nothing remains).
|
| 6225 |
+
function markedSpansBefore(old, startCh, isInsert) {
|
| 6226 |
+
if (old) for (var i = 0, nw; i < old.length; ++i) {
|
| 6227 |
+
var span = old[i], marker = span.marker;
|
| 6228 |
+
var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= startCh : span.from < startCh);
|
| 6229 |
+
if (startsBefore || span.from == startCh && marker.type == "bookmark" && (!isInsert || !span.marker.insertLeft)) {
|
| 6230 |
+
var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= startCh : span.to > startCh);
|
| 6231 |
+
(nw || (nw = [])).push(new MarkedSpan(marker, span.from, endsAfter ? null : span.to));
|
| 6232 |
+
}
|
| 6233 |
+
}
|
| 6234 |
+
return nw;
|
| 6235 |
+
}
|
| 6236 |
+
function markedSpansAfter(old, endCh, isInsert) {
|
| 6237 |
+
if (old) for (var i = 0, nw; i < old.length; ++i) {
|
| 6238 |
+
var span = old[i], marker = span.marker;
|
| 6239 |
+
var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= endCh : span.to > endCh);
|
| 6240 |
+
if (endsAfter || span.from == endCh && marker.type == "bookmark" && (!isInsert || span.marker.insertLeft)) {
|
| 6241 |
+
var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= endCh : span.from < endCh);
|
| 6242 |
+
(nw || (nw = [])).push(new MarkedSpan(marker, startsBefore ? null : span.from - endCh,
|
| 6243 |
+
span.to == null ? null : span.to - endCh));
|
| 6244 |
+
}
|
| 6245 |
+
}
|
| 6246 |
+
return nw;
|
| 6247 |
+
}
|
| 6248 |
+
|
| 6249 |
+
// Given a change object, compute the new set of marker spans that
|
| 6250 |
+
// cover the line in which the change took place. Removes spans
|
| 6251 |
+
// entirely within the change, reconnects spans belonging to the
|
| 6252 |
+
// same marker that appear on both sides of the change, and cuts off
|
| 6253 |
+
// spans partially within the change. Returns an array of span
|
| 6254 |
+
// arrays with one element for each line in (after) the change.
|
| 6255 |
+
function stretchSpansOverChange(doc, change) {
|
| 6256 |
+
if (change.full) return null;
|
| 6257 |
+
var oldFirst = isLine(doc, change.from.line) && getLine(doc, change.from.line).markedSpans;
|
| 6258 |
+
var oldLast = isLine(doc, change.to.line) && getLine(doc, change.to.line).markedSpans;
|
| 6259 |
+
if (!oldFirst && !oldLast) return null;
|
| 6260 |
+
|
| 6261 |
+
var startCh = change.from.ch, endCh = change.to.ch, isInsert = cmp(change.from, change.to) == 0;
|
| 6262 |
+
// Get the spans that 'stick out' on both sides
|
| 6263 |
+
var first = markedSpansBefore(oldFirst, startCh, isInsert);
|
| 6264 |
+
var last = markedSpansAfter(oldLast, endCh, isInsert);
|
| 6265 |
+
|
| 6266 |
+
// Next, merge those two ends
|
| 6267 |
+
var sameLine = change.text.length == 1, offset = lst(change.text).length + (sameLine ? startCh : 0);
|
| 6268 |
+
if (first) {
|
| 6269 |
+
// Fix up .to properties of first
|
| 6270 |
+
for (var i = 0; i < first.length; ++i) {
|
| 6271 |
+
var span = first[i];
|
| 6272 |
+
if (span.to == null) {
|
| 6273 |
+
var found = getMarkedSpanFor(last, span.marker);
|
| 6274 |
+
if (!found) span.to = startCh;
|
| 6275 |
+
else if (sameLine) span.to = found.to == null ? null : found.to + offset;
|
| 6276 |
+
}
|
| 6277 |
+
}
|
| 6278 |
+
}
|
| 6279 |
+
if (last) {
|
| 6280 |
+
// Fix up .from in last (or move them into first in case of sameLine)
|
| 6281 |
+
for (var i = 0; i < last.length; ++i) {
|
| 6282 |
+
var span = last[i];
|
| 6283 |
+
if (span.to != null) span.to += offset;
|
| 6284 |
+
if (span.from == null) {
|
| 6285 |
+
var found = getMarkedSpanFor(first, span.marker);
|
| 6286 |
+
if (!found) {
|
| 6287 |
+
span.from = offset;
|
| 6288 |
+
if (sameLine) (first || (first = [])).push(span);
|
| 6289 |
+
}
|
| 6290 |
+
} else {
|
| 6291 |
+
span.from += offset;
|
| 6292 |
+
if (sameLine) (first || (first = [])).push(span);
|
| 6293 |
+
}
|
| 6294 |
+
}
|
| 6295 |
+
}
|
| 6296 |
+
// Make sure we didn't create any zero-length spans
|
| 6297 |
+
if (first) first = clearEmptySpans(first);
|
| 6298 |
+
if (last && last != first) last = clearEmptySpans(last);
|
| 6299 |
+
|
| 6300 |
+
var newMarkers = [first];
|
| 6301 |
+
if (!sameLine) {
|
| 6302 |
+
// Fill gap with whole-line-spans
|
| 6303 |
+
var gap = change.text.length - 2, gapMarkers;
|
| 6304 |
+
if (gap > 0 && first)
|
| 6305 |
+
for (var i = 0; i < first.length; ++i)
|
| 6306 |
+
if (first[i].to == null)
|
| 6307 |
+
(gapMarkers || (gapMarkers = [])).push(new MarkedSpan(first[i].marker, null, null));
|
| 6308 |
+
for (var i = 0; i < gap; ++i)
|
| 6309 |
+
newMarkers.push(gapMarkers);
|
| 6310 |
+
newMarkers.push(last);
|
| 6311 |
+
}
|
| 6312 |
+
return newMarkers;
|
| 6313 |
+
}
|
| 6314 |
+
|
| 6315 |
+
// Remove spans that are empty and don't have a clearWhenEmpty
|
| 6316 |
+
// option of false.
|
| 6317 |
+
function clearEmptySpans(spans) {
|
| 6318 |
+
for (var i = 0; i < spans.length; ++i) {
|
| 6319 |
+
var span = spans[i];
|
| 6320 |
+
if (span.from != null && span.from == span.to && span.marker.clearWhenEmpty !== false)
|
| 6321 |
+
spans.splice(i--, 1);
|
| 6322 |
+
}
|
| 6323 |
+
if (!spans.length) return null;
|
| 6324 |
+
return spans;
|
| 6325 |
+
}
|
| 6326 |
+
|
| 6327 |
+
// Used for un/re-doing changes from the history. Combines the
|
| 6328 |
+
// result of computing the existing spans with the set of spans that
|
| 6329 |
+
// existed in the history (so that deleting around a span and then
|
| 6330 |
+
// undoing brings back the span).
|
| 6331 |
+
function mergeOldSpans(doc, change) {
|
| 6332 |
+
var old = getOldSpans(doc, change);
|
| 6333 |
+
var stretched = stretchSpansOverChange(doc, change);
|
| 6334 |
+
if (!old) return stretched;
|
| 6335 |
+
if (!stretched) return old;
|
| 6336 |
+
|
| 6337 |
+
for (var i = 0; i < old.length; ++i) {
|
| 6338 |
+
var oldCur = old[i], stretchCur = stretched[i];
|
| 6339 |
+
if (oldCur && stretchCur) {
|
| 6340 |
+
spans: for (var j = 0; j < stretchCur.length; ++j) {
|
| 6341 |
+
var span = stretchCur[j];
|
| 6342 |
+
for (var k = 0; k < oldCur.length; ++k)
|
| 6343 |
+
if (oldCur[k].marker == span.marker) continue spans;
|
| 6344 |
+
oldCur.push(span);
|
| 6345 |
+
}
|
| 6346 |
+
} else if (stretchCur) {
|
| 6347 |
+
old[i] = stretchCur;
|
| 6348 |
+
}
|
| 6349 |
+
}
|
| 6350 |
+
return old;
|
| 6351 |
+
}
|
| 6352 |
+
|
| 6353 |
+
// Used to 'clip' out readOnly ranges when making a change.
|
| 6354 |
+
function removeReadOnlyRanges(doc, from, to) {
|
| 6355 |
+
var markers = null;
|
| 6356 |
+
doc.iter(from.line, to.line + 1, function(line) {
|
| 6357 |
+
if (line.markedSpans) for (var i = 0; i < line.markedSpans.length; ++i) {
|
| 6358 |
+
var mark = line.markedSpans[i].marker;
|
| 6359 |
+
if (mark.readOnly && (!markers || indexOf(markers, mark) == -1))
|
| 6360 |
+
(markers || (markers = [])).push(mark);
|
| 6361 |
+
}
|
| 6362 |
+
});
|
| 6363 |
+
if (!markers) return null;
|
| 6364 |
+
var parts = [{from: from, to: to}];
|
| 6365 |
+
for (var i = 0; i < markers.length; ++i) {
|
| 6366 |
+
var mk = markers[i], m = mk.find(0);
|
| 6367 |
+
for (var j = 0; j < parts.length; ++j) {
|
| 6368 |
+
var p = parts[j];
|
| 6369 |
+
if (cmp(p.to, m.from) < 0 || cmp(p.from, m.to) > 0) continue;
|
| 6370 |
+
var newParts = [j, 1], dfrom = cmp(p.from, m.from), dto = cmp(p.to, m.to);
|
| 6371 |
+
if (dfrom < 0 || !mk.inclusiveLeft && !dfrom)
|
| 6372 |
+
newParts.push({from: p.from, to: m.from});
|
| 6373 |
+
if (dto > 0 || !mk.inclusiveRight && !dto)
|
| 6374 |
+
newParts.push({from: m.to, to: p.to});
|
| 6375 |
+
parts.splice.apply(parts, newParts);
|
| 6376 |
+
j += newParts.length - 1;
|
| 6377 |
+
}
|
| 6378 |
+
}
|
| 6379 |
+
return parts;
|
| 6380 |
+
}
|
| 6381 |
+
|
| 6382 |
+
// Connect or disconnect spans from a line.
|
| 6383 |
+
function detachMarkedSpans(line) {
|
| 6384 |
+
var spans = line.markedSpans;
|
| 6385 |
+
if (!spans) return;
|
| 6386 |
+
for (var i = 0; i < spans.length; ++i)
|
| 6387 |
+
spans[i].marker.detachLine(line);
|
| 6388 |
+
line.markedSpans = null;
|
| 6389 |
+
}
|
| 6390 |
+
function attachMarkedSpans(line, spans) {
|
| 6391 |
+
if (!spans) return;
|
| 6392 |
+
for (var i = 0; i < spans.length; ++i)
|
| 6393 |
+
spans[i].marker.attachLine(line);
|
| 6394 |
+
line.markedSpans = spans;
|
| 6395 |
+
}
|
| 6396 |
+
|
| 6397 |
+
// Helpers used when computing which overlapping collapsed span
|
| 6398 |
+
// counts as the larger one.
|
| 6399 |
+
function extraLeft(marker) { return marker.inclusiveLeft ? -1 : 0; }
|
| 6400 |
+
function extraRight(marker) { return marker.inclusiveRight ? 1 : 0; }
|
| 6401 |
+
|
| 6402 |
+
// Returns a number indicating which of two overlapping collapsed
|
| 6403 |
+
// spans is larger (and thus includes the other). Falls back to
|
| 6404 |
+
// comparing ids when the spans cover exactly the same range.
|
| 6405 |
+
function compareCollapsedMarkers(a, b) {
|
| 6406 |
+
var lenDiff = a.lines.length - b.lines.length;
|
| 6407 |
+
if (lenDiff != 0) return lenDiff;
|
| 6408 |
+
var aPos = a.find(), bPos = b.find();
|
| 6409 |
+
var fromCmp = cmp(aPos.from, bPos.from) || extraLeft(a) - extraLeft(b);
|
| 6410 |
+
if (fromCmp) return -fromCmp;
|
| 6411 |
+
var toCmp = cmp(aPos.to, bPos.to) || extraRight(a) - extraRight(b);
|
| 6412 |
+
if (toCmp) return toCmp;
|
| 6413 |
+
return b.id - a.id;
|
| 6414 |
+
}
|
| 6415 |
+
|
| 6416 |
+
// Find out whether a line ends or starts in a collapsed span. If
|
| 6417 |
+
// so, return the marker for that span.
|
| 6418 |
+
function collapsedSpanAtSide(line, start) {
|
| 6419 |
+
var sps = sawCollapsedSpans && line.markedSpans, found;
|
| 6420 |
+
if (sps) for (var sp, i = 0; i < sps.length; ++i) {
|
| 6421 |
+
sp = sps[i];
|
| 6422 |
+
if (sp.marker.collapsed && (start ? sp.from : sp.to) == null &&
|
| 6423 |
+
(!found || compareCollapsedMarkers(found, sp.marker) < 0))
|
| 6424 |
+
found = sp.marker;
|
| 6425 |
+
}
|
| 6426 |
+
return found;
|
| 6427 |
+
}
|
| 6428 |
+
function collapsedSpanAtStart(line) { return collapsedSpanAtSide(line, true); }
|
| 6429 |
+
function collapsedSpanAtEnd(line) { return collapsedSpanAtSide(line, false); }
|
| 6430 |
+
|
| 6431 |
+
// Test whether there exists a collapsed span that partially
|
| 6432 |
+
// overlaps (covers the start or end, but not both) of a new span.
|
| 6433 |
+
// Such overlap is not allowed.
|
| 6434 |
+
function conflictingCollapsedRange(doc, lineNo, from, to, marker) {
|
| 6435 |
+
var line = getLine(doc, lineNo);
|
| 6436 |
+
var sps = sawCollapsedSpans && line.markedSpans;
|
| 6437 |
+
if (sps) for (var i = 0; i < sps.length; ++i) {
|
| 6438 |
+
var sp = sps[i];
|
| 6439 |
+
if (!sp.marker.collapsed) continue;
|
| 6440 |
+
var found = sp.marker.find(0);
|
| 6441 |
+
var fromCmp = cmp(found.from, from) || extraLeft(sp.marker) - extraLeft(marker);
|
| 6442 |
+
var toCmp = cmp(found.to, to) || extraRight(sp.marker) - extraRight(marker);
|
| 6443 |
+
if (fromCmp >= 0 && toCmp <= 0 || fromCmp <= 0 && toCmp >= 0) continue;
|
| 6444 |
+
if (fromCmp <= 0 && (cmp(found.to, from) > 0 || (sp.marker.inclusiveRight && marker.inclusiveLeft)) ||
|
| 6445 |
+
fromCmp >= 0 && (cmp(found.from, to) < 0 || (sp.marker.inclusiveLeft && marker.inclusiveRight)))
|
| 6446 |
+
return true;
|
| 6447 |
+
}
|
| 6448 |
+
}
|
| 6449 |
+
|
| 6450 |
+
// A visual line is a line as drawn on the screen. Folding, for
|
| 6451 |
+
// example, can cause multiple logical lines to appear on the same
|
| 6452 |
+
// visual line. This finds the start of the visual line that the
|
| 6453 |
+
// given line is part of (usually that is the line itself).
|
| 6454 |
+
function visualLine(line) {
|
| 6455 |
+
var merged;
|
| 6456 |
+
while (merged = collapsedSpanAtStart(line))
|
| 6457 |
+
line = merged.find(-1, true).line;
|
| 6458 |
+
return line;
|
| 6459 |
+
}
|
| 6460 |
+
|
| 6461 |
+
// Returns an array of logical lines that continue the visual line
|
| 6462 |
+
// started by the argument, or undefined if there are no such lines.
|
| 6463 |
+
function visualLineContinued(line) {
|
| 6464 |
+
var merged, lines;
|
| 6465 |
+
while (merged = collapsedSpanAtEnd(line)) {
|
| 6466 |
+
line = merged.find(1, true).line;
|
| 6467 |
+
(lines || (lines = [])).push(line);
|
| 6468 |
+
}
|
| 6469 |
+
return lines;
|
| 6470 |
+
}
|
| 6471 |
+
|
| 6472 |
+
// Get the line number of the start of the visual line that the
|
| 6473 |
+
// given line number is part of.
|
| 6474 |
+
function visualLineNo(doc, lineN) {
|
| 6475 |
+
var line = getLine(doc, lineN), vis = visualLine(line);
|
| 6476 |
+
if (line == vis) return lineN;
|
| 6477 |
+
return lineNo(vis);
|
| 6478 |
+
}
|
| 6479 |
+
// Get the line number of the start of the next visual line after
|
| 6480 |
+
// the given line.
|
| 6481 |
+
function visualLineEndNo(doc, lineN) {
|
| 6482 |
+
if (lineN > doc.lastLine()) return lineN;
|
| 6483 |
+
var line = getLine(doc, lineN), merged;
|
| 6484 |
+
if (!lineIsHidden(doc, line)) return lineN;
|
| 6485 |
+
while (merged = collapsedSpanAtEnd(line))
|
| 6486 |
+
line = merged.find(1, true).line;
|
| 6487 |
+
return lineNo(line) + 1;
|
| 6488 |
+
}
|
| 6489 |
+
|
| 6490 |
+
// Compute whether a line is hidden. Lines count as hidden when they
|
| 6491 |
+
// are part of a visual line that starts with another line, or when
|
| 6492 |
+
// they are entirely covered by collapsed, non-widget span.
|
| 6493 |
+
function lineIsHidden(doc, line) {
|
| 6494 |
+
var sps = sawCollapsedSpans && line.markedSpans;
|
| 6495 |
+
if (sps) for (var sp, i = 0; i < sps.length; ++i) {
|
| 6496 |
+
sp = sps[i];
|
| 6497 |
+
if (!sp.marker.collapsed) continue;
|
| 6498 |
+
if (sp.from == null) return true;
|
| 6499 |
+
if (sp.marker.widgetNode) continue;
|
| 6500 |
+
if (sp.from == 0 && sp.marker.inclusiveLeft && lineIsHiddenInner(doc, line, sp))
|
| 6501 |
+
return true;
|
| 6502 |
+
}
|
| 6503 |
+
}
|
| 6504 |
+
function lineIsHiddenInner(doc, line, span) {
|
| 6505 |
+
if (span.to == null) {
|
| 6506 |
+
var end = span.marker.find(1, true);
|
| 6507 |
+
return lineIsHiddenInner(doc, end.line, getMarkedSpanFor(end.line.markedSpans, span.marker));
|
| 6508 |
+
}
|
| 6509 |
+
if (span.marker.inclusiveRight && span.to == line.text.length)
|
| 6510 |
+
return true;
|
| 6511 |
+
for (var sp, i = 0; i < line.markedSpans.length; ++i) {
|
| 6512 |
+
sp = line.markedSpans[i];
|
| 6513 |
+
if (sp.marker.collapsed && !sp.marker.widgetNode && sp.from == span.to &&
|
| 6514 |
+
(sp.to == null || sp.to != span.from) &&
|
| 6515 |
+
(sp.marker.inclusiveLeft || span.marker.inclusiveRight) &&
|
| 6516 |
+
lineIsHiddenInner(doc, line, sp)) return true;
|
| 6517 |
+
}
|
| 6518 |
+
}
|
| 6519 |
+
|
| 6520 |
+
// LINE WIDGETS
|
| 6521 |
+
|
| 6522 |
+
// Line widgets are block elements displayed above or below a line.
|
| 6523 |
+
|
| 6524 |
+
var LineWidget = CodeMirror.LineWidget = function(doc, node, options) {
|
| 6525 |
+
if (options) for (var opt in options) if (options.hasOwnProperty(opt))
|
| 6526 |
+
this[opt] = options[opt];
|
| 6527 |
+
this.doc = doc;
|
| 6528 |
+
this.node = node;
|
| 6529 |
+
};
|
| 6530 |
+
eventMixin(LineWidget);
|
| 6531 |
+
|
| 6532 |
+
function adjustScrollWhenAboveVisible(cm, line, diff) {
|
| 6533 |
+
if (heightAtLine(line) < ((cm.curOp && cm.curOp.scrollTop) || cm.doc.scrollTop))
|
| 6534 |
+
addToScrollPos(cm, null, diff);
|
| 6535 |
+
}
|
| 6536 |
+
|
| 6537 |
+
LineWidget.prototype.clear = function() {
|
| 6538 |
+
var cm = this.doc.cm, ws = this.line.widgets, line = this.line, no = lineNo(line);
|
| 6539 |
+
if (no == null || !ws) return;
|
| 6540 |
+
for (var i = 0; i < ws.length; ++i) if (ws[i] == this) ws.splice(i--, 1);
|
| 6541 |
+
if (!ws.length) line.widgets = null;
|
| 6542 |
+
var height = widgetHeight(this);
|
| 6543 |
+
updateLineHeight(line, Math.max(0, line.height - height));
|
| 6544 |
+
if (cm) runInOp(cm, function() {
|
| 6545 |
+
adjustScrollWhenAboveVisible(cm, line, -height);
|
| 6546 |
+
regLineChange(cm, no, "widget");
|
| 6547 |
+
});
|
| 6548 |
+
};
|
| 6549 |
+
LineWidget.prototype.changed = function() {
|
| 6550 |
+
var oldH = this.height, cm = this.doc.cm, line = this.line;
|
| 6551 |
+
this.height = null;
|
| 6552 |
+
var diff = widgetHeight(this) - oldH;
|
| 6553 |
+
if (!diff) return;
|
| 6554 |
+
updateLineHeight(line, line.height + diff);
|
| 6555 |
+
if (cm) runInOp(cm, function() {
|
| 6556 |
+
cm.curOp.forceUpdate = true;
|
| 6557 |
+
adjustScrollWhenAboveVisible(cm, line, diff);
|
| 6558 |
+
});
|
| 6559 |
+
};
|
| 6560 |
+
|
| 6561 |
+
function widgetHeight(widget) {
|
| 6562 |
+
if (widget.height != null) return widget.height;
|
| 6563 |
+
var cm = widget.doc.cm;
|
| 6564 |
+
if (!cm) return 0;
|
| 6565 |
+
if (!contains(document.body, widget.node)) {
|
| 6566 |
+
var parentStyle = "position: relative;";
|
| 6567 |
+
if (widget.coverGutter)
|
| 6568 |
+
parentStyle += "margin-left: -" + cm.display.gutters.offsetWidth + "px;";
|
| 6569 |
+
if (widget.noHScroll)
|
| 6570 |
+
parentStyle += "width: " + cm.display.wrapper.clientWidth + "px;";
|
| 6571 |
+
removeChildrenAndAdd(cm.display.measure, elt("div", [widget.node], null, parentStyle));
|
| 6572 |
+
}
|
| 6573 |
+
return widget.height = widget.node.offsetHeight;
|
| 6574 |
+
}
|
| 6575 |
+
|
| 6576 |
+
function addLineWidget(doc, handle, node, options) {
|
| 6577 |
+
var widget = new LineWidget(doc, node, options);
|
| 6578 |
+
var cm = doc.cm;
|
| 6579 |
+
if (cm && widget.noHScroll) cm.display.alignWidgets = true;
|
| 6580 |
+
changeLine(doc, handle, "widget", function(line) {
|
| 6581 |
+
var widgets = line.widgets || (line.widgets = []);
|
| 6582 |
+
if (widget.insertAt == null) widgets.push(widget);
|
| 6583 |
+
else widgets.splice(Math.min(widgets.length - 1, Math.max(0, widget.insertAt)), 0, widget);
|
| 6584 |
+
widget.line = line;
|
| 6585 |
+
if (cm && !lineIsHidden(doc, line)) {
|
| 6586 |
+
var aboveVisible = heightAtLine(line) < doc.scrollTop;
|
| 6587 |
+
updateLineHeight(line, line.height + widgetHeight(widget));
|
| 6588 |
+
if (aboveVisible) addToScrollPos(cm, null, widget.height);
|
| 6589 |
+
cm.curOp.forceUpdate = true;
|
| 6590 |
+
}
|
| 6591 |
+
return true;
|
| 6592 |
+
});
|
| 6593 |
+
return widget;
|
| 6594 |
+
}
|
| 6595 |
+
|
| 6596 |
+
// LINE DATA STRUCTURE
|
| 6597 |
+
|
| 6598 |
+
// Line objects. These hold state related to a line, including
|
| 6599 |
+
// highlighting info (the styles array).
|
| 6600 |
+
var Line = CodeMirror.Line = function(text, markedSpans, estimateHeight) {
|
| 6601 |
+
this.text = text;
|
| 6602 |
+
attachMarkedSpans(this, markedSpans);
|
| 6603 |
+
this.height = estimateHeight ? estimateHeight(this) : 1;
|
| 6604 |
+
};
|
| 6605 |
+
eventMixin(Line);
|
| 6606 |
+
Line.prototype.lineNo = function() { return lineNo(this); };
|
| 6607 |
+
|
| 6608 |
+
// Change the content (text, markers) of a line. Automatically
|
| 6609 |
+
// invalidates cached information and tries to re-estimate the
|
| 6610 |
+
// line's height.
|
| 6611 |
+
function updateLine(line, text, markedSpans, estimateHeight) {
|
| 6612 |
+
line.text = text;
|
| 6613 |
+
if (line.stateAfter) line.stateAfter = null;
|
| 6614 |
+
if (line.styles) line.styles = null;
|
| 6615 |
+
if (line.order != null) line.order = null;
|
| 6616 |
+
detachMarkedSpans(line);
|
| 6617 |
+
attachMarkedSpans(line, markedSpans);
|
| 6618 |
+
var estHeight = estimateHeight ? estimateHeight(line) : 1;
|
| 6619 |
+
if (estHeight != line.height) updateLineHeight(line, estHeight);
|
| 6620 |
+
}
|
| 6621 |
+
|
| 6622 |
+
// Detach a line from the document tree and its markers.
|
| 6623 |
+
function cleanUpLine(line) {
|
| 6624 |
+
line.parent = null;
|
| 6625 |
+
detachMarkedSpans(line);
|
| 6626 |
+
}
|
| 6627 |
+
|
| 6628 |
+
function extractLineClasses(type, output) {
|
| 6629 |
+
if (type) for (;;) {
|
| 6630 |
+
var lineClass = type.match(/(?:^|\s+)line-(background-)?(\S+)/);
|
| 6631 |
+
if (!lineClass) break;
|
| 6632 |
+
type = type.slice(0, lineClass.index) + type.slice(lineClass.index + lineClass[0].length);
|
| 6633 |
+
var prop = lineClass[1] ? "bgClass" : "textClass";
|
| 6634 |
+
if (output[prop] == null)
|
| 6635 |
+
output[prop] = lineClass[2];
|
| 6636 |
+
else if (!(new RegExp("(?:^|\s)" + lineClass[2] + "(?:$|\s)")).test(output[prop]))
|
| 6637 |
+
output[prop] += " " + lineClass[2];
|
| 6638 |
+
}
|
| 6639 |
+
return type;
|
| 6640 |
+
}
|
| 6641 |
+
|
| 6642 |
+
function callBlankLine(mode, state) {
|
| 6643 |
+
if (mode.blankLine) return mode.blankLine(state);
|
| 6644 |
+
if (!mode.innerMode) return;
|
| 6645 |
+
var inner = CodeMirror.innerMode(mode, state);
|
| 6646 |
+
if (inner.mode.blankLine) return inner.mode.blankLine(inner.state);
|
| 6647 |
+
}
|
| 6648 |
+
|
| 6649 |
+
function readToken(mode, stream, state, inner) {
|
| 6650 |
+
for (var i = 0; i < 10; i++) {
|
| 6651 |
+
if (inner) inner[0] = CodeMirror.innerMode(mode, state).mode;
|
| 6652 |
+
var style = mode.token(stream, state);
|
| 6653 |
+
if (stream.pos > stream.start) return style;
|
| 6654 |
+
}
|
| 6655 |
+
throw new Error("Mode " + mode.name + " failed to advance stream.");
|
| 6656 |
+
}
|
| 6657 |
+
|
| 6658 |
+
// Utility for getTokenAt and getLineTokens
|
| 6659 |
+
function takeToken(cm, pos, precise, asArray) {
|
| 6660 |
+
function getObj(copy) {
|
| 6661 |
+
return {start: stream.start, end: stream.pos,
|
| 6662 |
+
string: stream.current(),
|
| 6663 |
+
type: style || null,
|
| 6664 |
+
state: copy ? copyState(doc.mode, state) : state};
|
| 6665 |
+
}
|
| 6666 |
+
|
| 6667 |
+
var doc = cm.doc, mode = doc.mode, style;
|
| 6668 |
+
pos = clipPos(doc, pos);
|
| 6669 |
+
var line = getLine(doc, pos.line), state = getStateBefore(cm, pos.line, precise);
|
| 6670 |
+
var stream = new StringStream(line.text, cm.options.tabSize), tokens;
|
| 6671 |
+
if (asArray) tokens = [];
|
| 6672 |
+
while ((asArray || stream.pos < pos.ch) && !stream.eol()) {
|
| 6673 |
+
stream.start = stream.pos;
|
| 6674 |
+
style = readToken(mode, stream, state);
|
| 6675 |
+
if (asArray) tokens.push(getObj(true));
|
| 6676 |
+
}
|
| 6677 |
+
return asArray ? tokens : getObj();
|
| 6678 |
+
}
|
| 6679 |
+
|
| 6680 |
+
// Run the given mode's parser over a line, calling f for each token.
|
| 6681 |
+
function runMode(cm, text, mode, state, f, lineClasses, forceToEnd) {
|
| 6682 |
+
var flattenSpans = mode.flattenSpans;
|
| 6683 |
+
if (flattenSpans == null) flattenSpans = cm.options.flattenSpans;
|
| 6684 |
+
var curStart = 0, curStyle = null;
|
| 6685 |
+
var stream = new StringStream(text, cm.options.tabSize), style;
|
| 6686 |
+
var inner = cm.options.addModeClass && [null];
|
| 6687 |
+
if (text == "") extractLineClasses(callBlankLine(mode, state), lineClasses);
|
| 6688 |
+
while (!stream.eol()) {
|
| 6689 |
+
if (stream.pos > cm.options.maxHighlightLength) {
|
| 6690 |
+
flattenSpans = false;
|
| 6691 |
+
if (forceToEnd) processLine(cm, text, state, stream.pos);
|
| 6692 |
+
stream.pos = text.length;
|
| 6693 |
+
style = null;
|
| 6694 |
+
} else {
|
| 6695 |
+
style = extractLineClasses(readToken(mode, stream, state, inner), lineClasses);
|
| 6696 |
+
}
|
| 6697 |
+
if (inner) {
|
| 6698 |
+
var mName = inner[0].name;
|
| 6699 |
+
if (mName) style = "m-" + (style ? mName + " " + style : mName);
|
| 6700 |
+
}
|
| 6701 |
+
if (!flattenSpans || curStyle != style) {
|
| 6702 |
+
while (curStart < stream.start) {
|
| 6703 |
+
curStart = Math.min(stream.start, curStart + 50000);
|
| 6704 |
+
f(curStart, curStyle);
|
| 6705 |
+
}
|
| 6706 |
+
curStyle = style;
|
| 6707 |
+
}
|
| 6708 |
+
stream.start = stream.pos;
|
| 6709 |
+
}
|
| 6710 |
+
while (curStart < stream.pos) {
|
| 6711 |
+
// Webkit seems to refuse to render text nodes longer than 57444 characters
|
| 6712 |
+
var pos = Math.min(stream.pos, curStart + 50000);
|
| 6713 |
+
f(pos, curStyle);
|
| 6714 |
+
curStart = pos;
|
| 6715 |
+
}
|
| 6716 |
+
}
|
| 6717 |
+
|
| 6718 |
+
// Compute a style array (an array starting with a mode generation
|
| 6719 |
+
// -- for invalidation -- followed by pairs of end positions and
|
| 6720 |
+
// style strings), which is used to highlight the tokens on the
|
| 6721 |
+
// line.
|
| 6722 |
+
function highlightLine(cm, line, state, forceToEnd) {
|
| 6723 |
+
// A styles array always starts with a number identifying the
|
| 6724 |
+
// mode/overlays that it is based on (for easy invalidation).
|
| 6725 |
+
var st = [cm.state.modeGen], lineClasses = {};
|
| 6726 |
+
// Compute the base array of styles
|
| 6727 |
+
runMode(cm, line.text, cm.doc.mode, state, function(end, style) {
|
| 6728 |
+
st.push(end, style);
|
| 6729 |
+
}, lineClasses, forceToEnd);
|
| 6730 |
+
|
| 6731 |
+
// Run overlays, adjust style array.
|
| 6732 |
+
for (var o = 0; o < cm.state.overlays.length; ++o) {
|
| 6733 |
+
var overlay = cm.state.overlays[o], i = 1, at = 0;
|
| 6734 |
+
runMode(cm, line.text, overlay.mode, true, function(end, style) {
|
| 6735 |
+
var start = i;
|
| 6736 |
+
// Ensure there's a token end at the current position, and that i points at it
|
| 6737 |
+
while (at < end) {
|
| 6738 |
+
var i_end = st[i];
|
| 6739 |
+
if (i_end > end)
|
| 6740 |
+
st.splice(i, 1, end, st[i+1], i_end);
|
| 6741 |
+
i += 2;
|
| 6742 |
+
at = Math.min(end, i_end);
|
| 6743 |
+
}
|
| 6744 |
+
if (!style) return;
|
| 6745 |
+
if (overlay.opaque) {
|
| 6746 |
+
st.splice(start, i - start, end, "cm-overlay " + style);
|
| 6747 |
+
i = start + 2;
|
| 6748 |
+
} else {
|
| 6749 |
+
for (; start < i; start += 2) {
|
| 6750 |
+
var cur = st[start+1];
|
| 6751 |
+
st[start+1] = (cur ? cur + " " : "") + "cm-overlay " + style;
|
| 6752 |
+
}
|
| 6753 |
+
}
|
| 6754 |
+
}, lineClasses);
|
| 6755 |
+
}
|
| 6756 |
+
|
| 6757 |
+
return {styles: st, classes: lineClasses.bgClass || lineClasses.textClass ? lineClasses : null};
|
| 6758 |
+
}
|
| 6759 |
+
|
| 6760 |
+
function getLineStyles(cm, line, updateFrontier) {
|
| 6761 |
+
if (!line.styles || line.styles[0] != cm.state.modeGen) {
|
| 6762 |
+
var result = highlightLine(cm, line, line.stateAfter = getStateBefore(cm, lineNo(line)));
|
| 6763 |
+
line.styles = result.styles;
|
| 6764 |
+
if (result.classes) line.styleClasses = result.classes;
|
| 6765 |
+
else if (line.styleClasses) line.styleClasses = null;
|
| 6766 |
+
if (updateFrontier === cm.doc.frontier) cm.doc.frontier++;
|
| 6767 |
+
}
|
| 6768 |
+
return line.styles;
|
| 6769 |
+
}
|
| 6770 |
+
|
| 6771 |
+
// Lightweight form of highlight -- proceed over this line and
|
| 6772 |
+
// update state, but don't save a style array. Used for lines that
|
| 6773 |
+
// aren't currently visible.
|
| 6774 |
+
function processLine(cm, text, state, startAt) {
|
| 6775 |
+
var mode = cm.doc.mode;
|
| 6776 |
+
var stream = new StringStream(text, cm.options.tabSize);
|
| 6777 |
+
stream.start = stream.pos = startAt || 0;
|
| 6778 |
+
if (text == "") callBlankLine(mode, state);
|
| 6779 |
+
while (!stream.eol() && stream.pos <= cm.options.maxHighlightLength) {
|
| 6780 |
+
readToken(mode, stream, state);
|
| 6781 |
+
stream.start = stream.pos;
|
| 6782 |
+
}
|
| 6783 |
+
}
|
| 6784 |
+
|
| 6785 |
+
// Convert a style as returned by a mode (either null, or a string
|
| 6786 |
+
// containing one or more styles) to a CSS style. This is cached,
|
| 6787 |
+
// and also looks for line-wide styles.
|
| 6788 |
+
var styleToClassCache = {}, styleToClassCacheWithMode = {};
|
| 6789 |
+
function interpretTokenStyle(style, options) {
|
| 6790 |
+
if (!style || /^\s*$/.test(style)) return null;
|
| 6791 |
+
var cache = options.addModeClass ? styleToClassCacheWithMode : styleToClassCache;
|
| 6792 |
+
return cache[style] ||
|
| 6793 |
+
(cache[style] = style.replace(/\S+/g, "cm-$&"));
|
| 6794 |
+
}
|
| 6795 |
+
|
| 6796 |
+
// Render the DOM representation of the text of a line. Also builds
|
| 6797 |
+
// up a 'line map', which points at the DOM nodes that represent
|
| 6798 |
+
// specific stretches of text, and is used by the measuring code.
|
| 6799 |
+
// The returned object contains the DOM node, this map, and
|
| 6800 |
+
// information about line-wide styles that were set by the mode.
|
| 6801 |
+
function buildLineContent(cm, lineView) {
|
| 6802 |
+
// The padding-right forces the element to have a 'border', which
|
| 6803 |
+
// is needed on Webkit to be able to get line-level bounding
|
| 6804 |
+
// rectangles for it (in measureChar).
|
| 6805 |
+
var content = elt("span", null, null, webkit ? "padding-right: .1px" : null);
|
| 6806 |
+
var builder = {pre: elt("pre", [content]), content: content,
|
| 6807 |
+
col: 0, pos: 0, cm: cm,
|
| 6808 |
+
splitSpaces: (ie || webkit) && cm.getOption("lineWrapping")};
|
| 6809 |
+
lineView.measure = {};
|
| 6810 |
+
|
| 6811 |
+
// Iterate over the logical lines that make up this visual line.
|
| 6812 |
+
for (var i = 0; i <= (lineView.rest ? lineView.rest.length : 0); i++) {
|
| 6813 |
+
var line = i ? lineView.rest[i - 1] : lineView.line, order;
|
| 6814 |
+
builder.pos = 0;
|
| 6815 |
+
builder.addToken = buildToken;
|
| 6816 |
+
// Optionally wire in some hacks into the token-rendering
|
| 6817 |
+
// algorithm, to deal with browser quirks.
|
| 6818 |
+
if (hasBadBidiRects(cm.display.measure) && (order = getOrder(line)))
|
| 6819 |
+
builder.addToken = buildTokenBadBidi(builder.addToken, order);
|
| 6820 |
+
builder.map = [];
|
| 6821 |
+
var allowFrontierUpdate = lineView != cm.display.externalMeasured && lineNo(line);
|
| 6822 |
+
insertLineContent(line, builder, getLineStyles(cm, line, allowFrontierUpdate));
|
| 6823 |
+
if (line.styleClasses) {
|
| 6824 |
+
if (line.styleClasses.bgClass)
|
| 6825 |
+
builder.bgClass = joinClasses(line.styleClasses.bgClass, builder.bgClass || "");
|
| 6826 |
+
if (line.styleClasses.textClass)
|
| 6827 |
+
builder.textClass = joinClasses(line.styleClasses.textClass, builder.textClass || "");
|
| 6828 |
+
}
|
| 6829 |
+
|
| 6830 |
+
// Ensure at least a single node is present, for measuring.
|
| 6831 |
+
if (builder.map.length == 0)
|
| 6832 |
+
builder.map.push(0, 0, builder.content.appendChild(zeroWidthElement(cm.display.measure)));
|
| 6833 |
+
|
| 6834 |
+
// Store the map and a cache object for the current logical line
|
| 6835 |
+
if (i == 0) {
|
| 6836 |
+
lineView.measure.map = builder.map;
|
| 6837 |
+
lineView.measure.cache = {};
|
| 6838 |
+
} else {
|
| 6839 |
+
(lineView.measure.maps || (lineView.measure.maps = [])).push(builder.map);
|
| 6840 |
+
(lineView.measure.caches || (lineView.measure.caches = [])).push({});
|
| 6841 |
+
}
|
| 6842 |
+
}
|
| 6843 |
+
|
| 6844 |
+
// See issue #2901
|
| 6845 |
+
if (webkit && /\bcm-tab\b/.test(builder.content.lastChild.className))
|
| 6846 |
+
builder.content.className = "cm-tab-wrap-hack";
|
| 6847 |
+
|
| 6848 |
+
signal(cm, "renderLine", cm, lineView.line, builder.pre);
|
| 6849 |
+
if (builder.pre.className)
|
| 6850 |
+
builder.textClass = joinClasses(builder.pre.className, builder.textClass || "");
|
| 6851 |
+
|
| 6852 |
+
return builder;
|
| 6853 |
+
}
|
| 6854 |
+
|
| 6855 |
+
function defaultSpecialCharPlaceholder(ch) {
|
| 6856 |
+
var token = elt("span", "\u2022", "cm-invalidchar");
|
| 6857 |
+
token.title = "\\u" + ch.charCodeAt(0).toString(16);
|
| 6858 |
+
token.setAttribute("aria-label", token.title);
|
| 6859 |
+
return token;
|
| 6860 |
+
}
|
| 6861 |
+
|
| 6862 |
+
// Build up the DOM representation for a single token, and add it to
|
| 6863 |
+
// the line map. Takes care to render special characters separately.
|
| 6864 |
+
function buildToken(builder, text, style, startStyle, endStyle, title, css) {
|
| 6865 |
+
if (!text) return;
|
| 6866 |
+
var displayText = builder.splitSpaces ? text.replace(/ {3,}/g, splitSpaces) : text;
|
| 6867 |
+
var special = builder.cm.state.specialChars, mustWrap = false;
|
| 6868 |
+
if (!special.test(text)) {
|
| 6869 |
+
builder.col += text.length;
|
| 6870 |
+
var content = document.createTextNode(displayText);
|
| 6871 |
+
builder.map.push(builder.pos, builder.pos + text.length, content);
|
| 6872 |
+
if (ie && ie_version < 9) mustWrap = true;
|
| 6873 |
+
builder.pos += text.length;
|
| 6874 |
+
} else {
|
| 6875 |
+
var content = document.createDocumentFragment(), pos = 0;
|
| 6876 |
+
while (true) {
|
| 6877 |
+
special.lastIndex = pos;
|
| 6878 |
+
var m = special.exec(text);
|
| 6879 |
+
var skipped = m ? m.index - pos : text.length - pos;
|
| 6880 |
+
if (skipped) {
|
| 6881 |
+
var txt = document.createTextNode(displayText.slice(pos, pos + skipped));
|
| 6882 |
+
if (ie && ie_version < 9) content.appendChild(elt("span", [txt]));
|
| 6883 |
+
else content.appendChild(txt);
|
| 6884 |
+
builder.map.push(builder.pos, builder.pos + skipped, txt);
|
| 6885 |
+
builder.col += skipped;
|
| 6886 |
+
builder.pos += skipped;
|
| 6887 |
+
}
|
| 6888 |
+
if (!m) break;
|
| 6889 |
+
pos += skipped + 1;
|
| 6890 |
+
if (m[0] == "\t") {
|
| 6891 |
+
var tabSize = builder.cm.options.tabSize, tabWidth = tabSize - builder.col % tabSize;
|
| 6892 |
+
var txt = content.appendChild(elt("span", spaceStr(tabWidth), "cm-tab"));
|
| 6893 |
+
txt.setAttribute("role", "presentation");
|
| 6894 |
+
txt.setAttribute("cm-text", "\t");
|
| 6895 |
+
builder.col += tabWidth;
|
| 6896 |
+
} else {
|
| 6897 |
+
var txt = builder.cm.options.specialCharPlaceholder(m[0]);
|
| 6898 |
+
txt.setAttribute("cm-text", m[0]);
|
| 6899 |
+
if (ie && ie_version < 9) content.appendChild(elt("span", [txt]));
|
| 6900 |
+
else content.appendChild(txt);
|
| 6901 |
+
builder.col += 1;
|
| 6902 |
+
}
|
| 6903 |
+
builder.map.push(builder.pos, builder.pos + 1, txt);
|
| 6904 |
+
builder.pos++;
|
| 6905 |
+
}
|
| 6906 |
+
}
|
| 6907 |
+
if (style || startStyle || endStyle || mustWrap || css) {
|
| 6908 |
+
var fullStyle = style || "";
|
| 6909 |
+
if (startStyle) fullStyle += startStyle;
|
| 6910 |
+
if (endStyle) fullStyle += endStyle;
|
| 6911 |
+
var token = elt("span", [content], fullStyle, css);
|
| 6912 |
+
if (title) token.title = title;
|
| 6913 |
+
return builder.content.appendChild(token);
|
| 6914 |
+
}
|
| 6915 |
+
builder.content.appendChild(content);
|
| 6916 |
+
}
|
| 6917 |
+
|
| 6918 |
+
function splitSpaces(old) {
|
| 6919 |
+
var out = " ";
|
| 6920 |
+
for (var i = 0; i < old.length - 2; ++i) out += i % 2 ? " " : "\u00a0";
|
| 6921 |
+
out += " ";
|
| 6922 |
+
return out;
|
| 6923 |
+
}
|
| 6924 |
+
|
| 6925 |
+
// Work around nonsense dimensions being reported for stretches of
|
| 6926 |
+
// right-to-left text.
|
| 6927 |
+
function buildTokenBadBidi(inner, order) {
|
| 6928 |
+
return function(builder, text, style, startStyle, endStyle, title, css) {
|
| 6929 |
+
style = style ? style + " cm-force-border" : "cm-force-border";
|
| 6930 |
+
var start = builder.pos, end = start + text.length;
|
| 6931 |
+
for (;;) {
|
| 6932 |
+
// Find the part that overlaps with the start of this text
|
| 6933 |
+
for (var i = 0; i < order.length; i++) {
|
| 6934 |
+
var part = order[i];
|
| 6935 |
+
if (part.to > start && part.from <= start) break;
|
| 6936 |
+
}
|
| 6937 |
+
if (part.to >= end) return inner(builder, text, style, startStyle, endStyle, title, css);
|
| 6938 |
+
inner(builder, text.slice(0, part.to - start), style, startStyle, null, title, css);
|
| 6939 |
+
startStyle = null;
|
| 6940 |
+
text = text.slice(part.to - start);
|
| 6941 |
+
start = part.to;
|
| 6942 |
+
}
|
| 6943 |
+
};
|
| 6944 |
+
}
|
| 6945 |
+
|
| 6946 |
+
function buildCollapsedSpan(builder, size, marker, ignoreWidget) {
|
| 6947 |
+
var widget = !ignoreWidget && marker.widgetNode;
|
| 6948 |
+
if (widget) builder.map.push(builder.pos, builder.pos + size, widget);
|
| 6949 |
+
if (!ignoreWidget && builder.cm.display.input.needsContentAttribute) {
|
| 6950 |
+
if (!widget)
|
| 6951 |
+
widget = builder.content.appendChild(document.createElement("span"));
|
| 6952 |
+
widget.setAttribute("cm-marker", marker.id);
|
| 6953 |
+
}
|
| 6954 |
+
if (widget) {
|
| 6955 |
+
builder.cm.display.input.setUneditable(widget);
|
| 6956 |
+
builder.content.appendChild(widget);
|
| 6957 |
+
}
|
| 6958 |
+
builder.pos += size;
|
| 6959 |
+
}
|
| 6960 |
+
|
| 6961 |
+
// Outputs a number of spans to make up a line, taking highlighting
|
| 6962 |
+
// and marked text into account.
|
| 6963 |
+
function insertLineContent(line, builder, styles) {
|
| 6964 |
+
var spans = line.markedSpans, allText = line.text, at = 0;
|
| 6965 |
+
if (!spans) {
|
| 6966 |
+
for (var i = 1; i < styles.length; i+=2)
|
| 6967 |
+
builder.addToken(builder, allText.slice(at, at = styles[i]), interpretTokenStyle(styles[i+1], builder.cm.options));
|
| 6968 |
+
return;
|
| 6969 |
+
}
|
| 6970 |
+
|
| 6971 |
+
var len = allText.length, pos = 0, i = 1, text = "", style, css;
|
| 6972 |
+
var nextChange = 0, spanStyle, spanEndStyle, spanStartStyle, title, collapsed;
|
| 6973 |
+
for (;;) {
|
| 6974 |
+
if (nextChange == pos) { // Update current marker set
|
| 6975 |
+
spanStyle = spanEndStyle = spanStartStyle = title = css = "";
|
| 6976 |
+
collapsed = null; nextChange = Infinity;
|
| 6977 |
+
var foundBookmarks = [];
|
| 6978 |
+
for (var j = 0; j < spans.length; ++j) {
|
| 6979 |
+
var sp = spans[j], m = sp.marker;
|
| 6980 |
+
if (m.type == "bookmark" && sp.from == pos && m.widgetNode) {
|
| 6981 |
+
foundBookmarks.push(m);
|
| 6982 |
+
} else if (sp.from <= pos && (sp.to == null || sp.to > pos || m.collapsed && sp.to == pos && sp.from == pos)) {
|
| 6983 |
+
if (sp.to != null && sp.to != pos && nextChange > sp.to) {
|
| 6984 |
+
nextChange = sp.to;
|
| 6985 |
+
spanEndStyle = "";
|
| 6986 |
+
}
|
| 6987 |
+
if (m.className) spanStyle += " " + m.className;
|
| 6988 |
+
if (m.css) css = m.css;
|
| 6989 |
+
if (m.startStyle && sp.from == pos) spanStartStyle += " " + m.startStyle;
|
| 6990 |
+
if (m.endStyle && sp.to == nextChange) spanEndStyle += " " + m.endStyle;
|
| 6991 |
+
if (m.title && !title) title = m.title;
|
| 6992 |
+
if (m.collapsed && (!collapsed || compareCollapsedMarkers(collapsed.marker, m) < 0))
|
| 6993 |
+
collapsed = sp;
|
| 6994 |
+
} else if (sp.from > pos && nextChange > sp.from) {
|
| 6995 |
+
nextChange = sp.from;
|
| 6996 |
+
}
|
| 6997 |
+
}
|
| 6998 |
+
if (collapsed && (collapsed.from || 0) == pos) {
|
| 6999 |
+
buildCollapsedSpan(builder, (collapsed.to == null ? len + 1 : collapsed.to) - pos,
|
| 7000 |
+
collapsed.marker, collapsed.from == null);
|
| 7001 |
+
if (collapsed.to == null) return;
|
| 7002 |
+
if (collapsed.to == pos) collapsed = false;
|
| 7003 |
+
}
|
| 7004 |
+
if (!collapsed && foundBookmarks.length) for (var j = 0; j < foundBookmarks.length; ++j)
|
| 7005 |
+
buildCollapsedSpan(builder, 0, foundBookmarks[j]);
|
| 7006 |
+
}
|
| 7007 |
+
if (pos >= len) break;
|
| 7008 |
+
|
| 7009 |
+
var upto = Math.min(len, nextChange);
|
| 7010 |
+
while (true) {
|
| 7011 |
+
if (text) {
|
| 7012 |
+
var end = pos + text.length;
|
| 7013 |
+
if (!collapsed) {
|
| 7014 |
+
var tokenText = end > upto ? text.slice(0, upto - pos) : text;
|
| 7015 |
+
builder.addToken(builder, tokenText, style ? style + spanStyle : spanStyle,
|
| 7016 |
+
spanStartStyle, pos + tokenText.length == nextChange ? spanEndStyle : "", title, css);
|
| 7017 |
+
}
|
| 7018 |
+
if (end >= upto) {text = text.slice(upto - pos); pos = upto; break;}
|
| 7019 |
+
pos = end;
|
| 7020 |
+
spanStartStyle = "";
|
| 7021 |
+
}
|
| 7022 |
+
text = allText.slice(at, at = styles[i++]);
|
| 7023 |
+
style = interpretTokenStyle(styles[i++], builder.cm.options);
|
| 7024 |
+
}
|
| 7025 |
+
}
|
| 7026 |
+
}
|
| 7027 |
+
|
| 7028 |
+
// DOCUMENT DATA STRUCTURE
|
| 7029 |
+
|
| 7030 |
+
// By default, updates that start and end at the beginning of a line
|
| 7031 |
+
// are treated specially, in order to make the association of line
|
| 7032 |
+
// widgets and marker elements with the text behave more intuitive.
|
| 7033 |
+
function isWholeLineUpdate(doc, change) {
|
| 7034 |
+
return change.from.ch == 0 && change.to.ch == 0 && lst(change.text) == "" &&
|
| 7035 |
+
(!doc.cm || doc.cm.options.wholeLineUpdateBefore);
|
| 7036 |
+
}
|
| 7037 |
+
|
| 7038 |
+
// Perform a change on the document data structure.
|
| 7039 |
+
function updateDoc(doc, change, markedSpans, estimateHeight) {
|
| 7040 |
+
function spansFor(n) {return markedSpans ? markedSpans[n] : null;}
|
| 7041 |
+
function update(line, text, spans) {
|
| 7042 |
+
updateLine(line, text, spans, estimateHeight);
|
| 7043 |
+
signalLater(line, "change", line, change);
|
| 7044 |
+
}
|
| 7045 |
+
function linesFor(start, end) {
|
| 7046 |
+
for (var i = start, result = []; i < end; ++i)
|
| 7047 |
+
result.push(new Line(text[i], spansFor(i), estimateHeight));
|
| 7048 |
+
return result;
|
| 7049 |
+
}
|
| 7050 |
+
|
| 7051 |
+
var from = change.from, to = change.to, text = change.text;
|
| 7052 |
+
var firstLine = getLine(doc, from.line), lastLine = getLine(doc, to.line);
|
| 7053 |
+
var lastText = lst(text), lastSpans = spansFor(text.length - 1), nlines = to.line - from.line;
|
| 7054 |
+
|
| 7055 |
+
// Adjust the line structure
|
| 7056 |
+
if (change.full) {
|
| 7057 |
+
doc.insert(0, linesFor(0, text.length));
|
| 7058 |
+
doc.remove(text.length, doc.size - text.length);
|
| 7059 |
+
} else if (isWholeLineUpdate(doc, change)) {
|
| 7060 |
+
// This is a whole-line replace. Treated specially to make
|
| 7061 |
+
// sure line objects move the way they are supposed to.
|
| 7062 |
+
var added = linesFor(0, text.length - 1);
|
| 7063 |
+
update(lastLine, lastLine.text, lastSpans);
|
| 7064 |
+
if (nlines) doc.remove(from.line, nlines);
|
| 7065 |
+
if (added.length) doc.insert(from.line, added);
|
| 7066 |
+
} else if (firstLine == lastLine) {
|
| 7067 |
+
if (text.length == 1) {
|
| 7068 |
+
update(firstLine, firstLine.text.slice(0, from.ch) + lastText + firstLine.text.slice(to.ch), lastSpans);
|
| 7069 |
+
} else {
|
| 7070 |
+
var added = linesFor(1, text.length - 1);
|
| 7071 |
+
added.push(new Line(lastText + firstLine.text.slice(to.ch), lastSpans, estimateHeight));
|
| 7072 |
+
update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0));
|
| 7073 |
+
doc.insert(from.line + 1, added);
|
| 7074 |
+
}
|
| 7075 |
+
} else if (text.length == 1) {
|
| 7076 |
+
update(firstLine, firstLine.text.slice(0, from.ch) + text[0] + lastLine.text.slice(to.ch), spansFor(0));
|
| 7077 |
+
doc.remove(from.line + 1, nlines);
|
| 7078 |
+
} else {
|
| 7079 |
+
update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0));
|
| 7080 |
+
update(lastLine, lastText + lastLine.text.slice(to.ch), lastSpans);
|
| 7081 |
+
var added = linesFor(1, text.length - 1);
|
| 7082 |
+
if (nlines > 1) doc.remove(from.line + 1, nlines - 1);
|
| 7083 |
+
doc.insert(from.line + 1, added);
|
| 7084 |
+
}
|
| 7085 |
+
|
| 7086 |
+
signalLater(doc, "change", doc, change);
|
| 7087 |
+
}
|
| 7088 |
+
|
| 7089 |
+
// The document is represented as a BTree consisting of leaves, with
|
| 7090 |
+
// chunk of lines in them, and branches, with up to ten leaves or
|
| 7091 |
+
// other branch nodes below them. The top node is always a branch
|
| 7092 |
+
// node, and is the document object itself (meaning it has
|
| 7093 |
+
// additional methods and properties).
|
| 7094 |
+
//
|
| 7095 |
+
// All nodes have parent links. The tree is used both to go from
|
| 7096 |
+
// line numbers to line objects, and to go from objects to numbers.
|
| 7097 |
+
// It also indexes by height, and is used to convert between height
|
| 7098 |
+
// and line object, and to find the total height of the document.
|
| 7099 |
+
//
|
| 7100 |
+
// See also http://marijnhaverbeke.nl/blog/codemirror-line-tree.html
|
| 7101 |
+
|
| 7102 |
+
function LeafChunk(lines) {
|
| 7103 |
+
this.lines = lines;
|
| 7104 |
+
this.parent = null;
|
| 7105 |
+
for (var i = 0, height = 0; i < lines.length; ++i) {
|
| 7106 |
+
lines[i].parent = this;
|
| 7107 |
+
height += lines[i].height;
|
| 7108 |
+
}
|
| 7109 |
+
this.height = height;
|
| 7110 |
+
}
|
| 7111 |
+
|
| 7112 |
+
LeafChunk.prototype = {
|
| 7113 |
+
chunkSize: function() { return this.lines.length; },
|
| 7114 |
+
// Remove the n lines at offset 'at'.
|
| 7115 |
+
removeInner: function(at, n) {
|
| 7116 |
+
for (var i = at, e = at + n; i < e; ++i) {
|
| 7117 |
+
var line = this.lines[i];
|
| 7118 |
+
this.height -= line.height;
|
| 7119 |
+
cleanUpLine(line);
|
| 7120 |
+
signalLater(line, "delete");
|
| 7121 |
+
}
|
| 7122 |
+
this.lines.splice(at, n);
|
| 7123 |
+
},
|
| 7124 |
+
// Helper used to collapse a small branch into a single leaf.
|
| 7125 |
+
collapse: function(lines) {
|
| 7126 |
+
lines.push.apply(lines, this.lines);
|
| 7127 |
+
},
|
| 7128 |
+
// Insert the given array of lines at offset 'at', count them as
|
| 7129 |
+
// having the given height.
|
| 7130 |
+
insertInner: function(at, lines, height) {
|
| 7131 |
+
this.height += height;
|
| 7132 |
+
this.lines = this.lines.slice(0, at).concat(lines).concat(this.lines.slice(at));
|
| 7133 |
+
for (var i = 0; i < lines.length; ++i) lines[i].parent = this;
|
| 7134 |
+
},
|
| 7135 |
+
// Used to iterate over a part of the tree.
|
| 7136 |
+
iterN: function(at, n, op) {
|
| 7137 |
+
for (var e = at + n; at < e; ++at)
|
| 7138 |
+
if (op(this.lines[at])) return true;
|
| 7139 |
+
}
|
| 7140 |
+
};
|
| 7141 |
+
|
| 7142 |
+
function BranchChunk(children) {
|
| 7143 |
+
this.children = children;
|
| 7144 |
+
var size = 0, height = 0;
|
| 7145 |
+
for (var i = 0; i < children.length; ++i) {
|
| 7146 |
+
var ch = children[i];
|
| 7147 |
+
size += ch.chunkSize(); height += ch.height;
|
| 7148 |
+
ch.parent = this;
|
| 7149 |
+
}
|
| 7150 |
+
this.size = size;
|
| 7151 |
+
this.height = height;
|
| 7152 |
+
this.parent = null;
|
| 7153 |
+
}
|
| 7154 |
+
|
| 7155 |
+
BranchChunk.prototype = {
|
| 7156 |
+
chunkSize: function() { return this.size; },
|
| 7157 |
+
removeInner: function(at, n) {
|
| 7158 |
+
this.size -= n;
|
| 7159 |
+
for (var i = 0; i < this.children.length; ++i) {
|
| 7160 |
+
var child = this.children[i], sz = child.chunkSize();
|
| 7161 |
+
if (at < sz) {
|
| 7162 |
+
var rm = Math.min(n, sz - at), oldHeight = child.height;
|
| 7163 |
+
child.removeInner(at, rm);
|
| 7164 |
+
this.height -= oldHeight - child.height;
|
| 7165 |
+
if (sz == rm) { this.children.splice(i--, 1); child.parent = null; }
|
| 7166 |
+
if ((n -= rm) == 0) break;
|
| 7167 |
+
at = 0;
|
| 7168 |
+
} else at -= sz;
|
| 7169 |
+
}
|
| 7170 |
+
// If the result is smaller than 25 lines, ensure that it is a
|
| 7171 |
+
// single leaf node.
|
| 7172 |
+
if (this.size - n < 25 &&
|
| 7173 |
+
(this.children.length > 1 || !(this.children[0] instanceof LeafChunk))) {
|
| 7174 |
+
var lines = [];
|
| 7175 |
+
this.collapse(lines);
|
| 7176 |
+
this.children = [new LeafChunk(lines)];
|
| 7177 |
+
this.children[0].parent = this;
|
| 7178 |
+
}
|
| 7179 |
+
},
|
| 7180 |
+
collapse: function(lines) {
|
| 7181 |
+
for (var i = 0; i < this.children.length; ++i) this.children[i].collapse(lines);
|
| 7182 |
+
},
|
| 7183 |
+
insertInner: function(at, lines, height) {
|
| 7184 |
+
this.size += lines.length;
|
| 7185 |
+
this.height += height;
|
| 7186 |
+
for (var i = 0; i < this.children.length; ++i) {
|
| 7187 |
+
var child = this.children[i], sz = child.chunkSize();
|
| 7188 |
+
if (at <= sz) {
|
| 7189 |
+
child.insertInner(at, lines, height);
|
| 7190 |
+
if (child.lines && child.lines.length > 50) {
|
| 7191 |
+
while (child.lines.length > 50) {
|
| 7192 |
+
var spilled = child.lines.splice(child.lines.length - 25, 25);
|
| 7193 |
+
var newleaf = new LeafChunk(spilled);
|
| 7194 |
+
child.height -= newleaf.height;
|
| 7195 |
+
this.children.splice(i + 1, 0, newleaf);
|
| 7196 |
+
newleaf.parent = this;
|
| 7197 |
+
}
|
| 7198 |
+
this.maybeSpill();
|
| 7199 |
+
}
|
| 7200 |
+
break;
|
| 7201 |
+
}
|
| 7202 |
+
at -= sz;
|
| 7203 |
+
}
|
| 7204 |
+
},
|
| 7205 |
+
// When a node has grown, check whether it should be split.
|
| 7206 |
+
maybeSpill: function() {
|
| 7207 |
+
if (this.children.length <= 10) return;
|
| 7208 |
+
var me = this;
|
| 7209 |
+
do {
|
| 7210 |
+
var spilled = me.children.splice(me.children.length - 5, 5);
|
| 7211 |
+
var sibling = new BranchChunk(spilled);
|
| 7212 |
+
if (!me.parent) { // Become the parent node
|
| 7213 |
+
var copy = new BranchChunk(me.children);
|
| 7214 |
+
copy.parent = me;
|
| 7215 |
+
me.children = [copy, sibling];
|
| 7216 |
+
me = copy;
|
| 7217 |
+
} else {
|
| 7218 |
+
me.size -= sibling.size;
|
| 7219 |
+
me.height -= sibling.height;
|
| 7220 |
+
var myIndex = indexOf(me.parent.children, me);
|
| 7221 |
+
me.parent.children.splice(myIndex + 1, 0, sibling);
|
| 7222 |
+
}
|
| 7223 |
+
sibling.parent = me.parent;
|
| 7224 |
+
} while (me.children.length > 10);
|
| 7225 |
+
me.parent.maybeSpill();
|
| 7226 |
+
},
|
| 7227 |
+
iterN: function(at, n, op) {
|
| 7228 |
+
for (var i = 0; i < this.children.length; ++i) {
|
| 7229 |
+
var child = this.children[i], sz = child.chunkSize();
|
| 7230 |
+
if (at < sz) {
|
| 7231 |
+
var used = Math.min(n, sz - at);
|
| 7232 |
+
if (child.iterN(at, used, op)) return true;
|
| 7233 |
+
if ((n -= used) == 0) break;
|
| 7234 |
+
at = 0;
|
| 7235 |
+
} else at -= sz;
|
| 7236 |
+
}
|
| 7237 |
+
}
|
| 7238 |
+
};
|
| 7239 |
+
|
| 7240 |
+
var nextDocId = 0;
|
| 7241 |
+
var Doc = CodeMirror.Doc = function(text, mode, firstLine) {
|
| 7242 |
+
if (!(this instanceof Doc)) return new Doc(text, mode, firstLine);
|
| 7243 |
+
if (firstLine == null) firstLine = 0;
|
| 7244 |
+
|
| 7245 |
+
BranchChunk.call(this, [new LeafChunk([new Line("", null)])]);
|
| 7246 |
+
this.first = firstLine;
|
| 7247 |
+
this.scrollTop = this.scrollLeft = 0;
|
| 7248 |
+
this.cantEdit = false;
|
| 7249 |
+
this.cleanGeneration = 1;
|
| 7250 |
+
this.frontier = firstLine;
|
| 7251 |
+
var start = Pos(firstLine, 0);
|
| 7252 |
+
this.sel = simpleSelection(start);
|
| 7253 |
+
this.history = new History(null);
|
| 7254 |
+
this.id = ++nextDocId;
|
| 7255 |
+
this.modeOption = mode;
|
| 7256 |
+
|
| 7257 |
+
if (typeof text == "string") text = splitLines(text);
|
| 7258 |
+
updateDoc(this, {from: start, to: start, text: text});
|
| 7259 |
+
setSelection(this, simpleSelection(start), sel_dontScroll);
|
| 7260 |
+
};
|
| 7261 |
+
|
| 7262 |
+
Doc.prototype = createObj(BranchChunk.prototype, {
|
| 7263 |
+
constructor: Doc,
|
| 7264 |
+
// Iterate over the document. Supports two forms -- with only one
|
| 7265 |
+
// argument, it calls that for each line in the document. With
|
| 7266 |
+
// three, it iterates over the range given by the first two (with
|
| 7267 |
+
// the second being non-inclusive).
|
| 7268 |
+
iter: function(from, to, op) {
|
| 7269 |
+
if (op) this.iterN(from - this.first, to - from, op);
|
| 7270 |
+
else this.iterN(this.first, this.first + this.size, from);
|
| 7271 |
+
},
|
| 7272 |
+
|
| 7273 |
+
// Non-public interface for adding and removing lines.
|
| 7274 |
+
insert: function(at, lines) {
|
| 7275 |
+
var height = 0;
|
| 7276 |
+
for (var i = 0; i < lines.length; ++i) height += lines[i].height;
|
| 7277 |
+
this.insertInner(at - this.first, lines, height);
|
| 7278 |
+
},
|
| 7279 |
+
remove: function(at, n) { this.removeInner(at - this.first, n); },
|
| 7280 |
+
|
| 7281 |
+
// From here, the methods are part of the public interface. Most
|
| 7282 |
+
// are also available from CodeMirror (editor) instances.
|
| 7283 |
+
|
| 7284 |
+
getValue: function(lineSep) {
|
| 7285 |
+
var lines = getLines(this, this.first, this.first + this.size);
|
| 7286 |
+
if (lineSep === false) return lines;
|
| 7287 |
+
return lines.join(lineSep || "\n");
|
| 7288 |
+
},
|
| 7289 |
+
setValue: docMethodOp(function(code) {
|
| 7290 |
+
var top = Pos(this.first, 0), last = this.first + this.size - 1;
|
| 7291 |
+
makeChange(this, {from: top, to: Pos(last, getLine(this, last).text.length),
|
| 7292 |
+
text: splitLines(code), origin: "setValue", full: true}, true);
|
| 7293 |
+
setSelection(this, simpleSelection(top));
|
| 7294 |
+
}),
|
| 7295 |
+
replaceRange: function(code, from, to, origin) {
|
| 7296 |
+
from = clipPos(this, from);
|
| 7297 |
+
to = to ? clipPos(this, to) : from;
|
| 7298 |
+
replaceRange(this, code, from, to, origin);
|
| 7299 |
+
},
|
| 7300 |
+
getRange: function(from, to, lineSep) {
|
| 7301 |
+
var lines = getBetween(this, clipPos(this, from), clipPos(this, to));
|
| 7302 |
+
if (lineSep === false) return lines;
|
| 7303 |
+
return lines.join(lineSep || "\n");
|
| 7304 |
+
},
|
| 7305 |
+
|
| 7306 |
+
getLine: function(line) {var l = this.getLineHandle(line); return l && l.text;},
|
| 7307 |
+
|
| 7308 |
+
getLineHandle: function(line) {if (isLine(this, line)) return getLine(this, line);},
|
| 7309 |
+
getLineNumber: function(line) {return lineNo(line);},
|
| 7310 |
+
|
| 7311 |
+
getLineHandleVisualStart: function(line) {
|
| 7312 |
+
if (typeof line == "number") line = getLine(this, line);
|
| 7313 |
+
return visualLine(line);
|
| 7314 |
+
},
|
| 7315 |
+
|
| 7316 |
+
lineCount: function() {return this.size;},
|
| 7317 |
+
firstLine: function() {return this.first;},
|
| 7318 |
+
lastLine: function() {return this.first + this.size - 1;},
|
| 7319 |
+
|
| 7320 |
+
clipPos: function(pos) {return clipPos(this, pos);},
|
| 7321 |
+
|
| 7322 |
+
getCursor: function(start) {
|
| 7323 |
+
var range = this.sel.primary(), pos;
|
| 7324 |
+
if (start == null || start == "head") pos = range.head;
|
| 7325 |
+
else if (start == "anchor") pos = range.anchor;
|
| 7326 |
+
else if (start == "end" || start == "to" || start === false) pos = range.to();
|
| 7327 |
+
else pos = range.from();
|
| 7328 |
+
return pos;
|
| 7329 |
+
},
|
| 7330 |
+
listSelections: function() { return this.sel.ranges; },
|
| 7331 |
+
somethingSelected: function() {return this.sel.somethingSelected();},
|
| 7332 |
+
|
| 7333 |
+
setCursor: docMethodOp(function(line, ch, options) {
|
| 7334 |
+
setSimpleSelection(this, clipPos(this, typeof line == "number" ? Pos(line, ch || 0) : line), null, options);
|
| 7335 |
+
}),
|
| 7336 |
+
setSelection: docMethodOp(function(anchor, head, options) {
|
| 7337 |
+
setSimpleSelection(this, clipPos(this, anchor), clipPos(this, head || anchor), options);
|
| 7338 |
+
}),
|
| 7339 |
+
extendSelection: docMethodOp(function(head, other, options) {
|
| 7340 |
+
extendSelection(this, clipPos(this, head), other && clipPos(this, other), options);
|
| 7341 |
+
}),
|
| 7342 |
+
extendSelections: docMethodOp(function(heads, options) {
|
| 7343 |
+
extendSelections(this, clipPosArray(this, heads, options));
|
| 7344 |
+
}),
|
| 7345 |
+
extendSelectionsBy: docMethodOp(function(f, options) {
|
| 7346 |
+
extendSelections(this, map(this.sel.ranges, f), options);
|
| 7347 |
+
}),
|
| 7348 |
+
setSelections: docMethodOp(function(ranges, primary, options) {
|
| 7349 |
+
if (!ranges.length) return;
|
| 7350 |
+
for (var i = 0, out = []; i < ranges.length; i++)
|
| 7351 |
+
out[i] = new Range(clipPos(this, ranges[i].anchor),
|
| 7352 |
+
clipPos(this, ranges[i].head));
|
| 7353 |
+
if (primary == null) primary = Math.min(ranges.length - 1, this.sel.primIndex);
|
| 7354 |
+
setSelection(this, normalizeSelection(out, primary), options);
|
| 7355 |
+
}),
|
| 7356 |
+
addSelection: docMethodOp(function(anchor, head, options) {
|
| 7357 |
+
var ranges = this.sel.ranges.slice(0);
|
| 7358 |
+
ranges.push(new Range(clipPos(this, anchor), clipPos(this, head || anchor)));
|
| 7359 |
+
setSelection(this, normalizeSelection(ranges, ranges.length - 1), options);
|
| 7360 |
+
}),
|
| 7361 |
+
|
| 7362 |
+
getSelection: function(lineSep) {
|
| 7363 |
+
var ranges = this.sel.ranges, lines;
|
| 7364 |
+
for (var i = 0; i < ranges.length; i++) {
|
| 7365 |
+
var sel = getBetween(this, ranges[i].from(), ranges[i].to());
|
| 7366 |
+
lines = lines ? lines.concat(sel) : sel;
|
| 7367 |
+
}
|
| 7368 |
+
if (lineSep === false) return lines;
|
| 7369 |
+
else return lines.join(lineSep || "\n");
|
| 7370 |
+
},
|
| 7371 |
+
getSelections: function(lineSep) {
|
| 7372 |
+
var parts = [], ranges = this.sel.ranges;
|
| 7373 |
+
for (var i = 0; i < ranges.length; i++) {
|
| 7374 |
+
var sel = getBetween(this, ranges[i].from(), ranges[i].to());
|
| 7375 |
+
if (lineSep !== false) sel = sel.join(lineSep || "\n");
|
| 7376 |
+
parts[i] = sel;
|
| 7377 |
+
}
|
| 7378 |
+
return parts;
|
| 7379 |
+
},
|
| 7380 |
+
replaceSelection: function(code, collapse, origin) {
|
| 7381 |
+
var dup = [];
|
| 7382 |
+
for (var i = 0; i < this.sel.ranges.length; i++)
|
| 7383 |
+
dup[i] = code;
|
| 7384 |
+
this.replaceSelections(dup, collapse, origin || "+input");
|
| 7385 |
+
},
|
| 7386 |
+
replaceSelections: docMethodOp(function(code, collapse, origin) {
|
| 7387 |
+
var changes = [], sel = this.sel;
|
| 7388 |
+
for (var i = 0; i < sel.ranges.length; i++) {
|
| 7389 |
+
var range = sel.ranges[i];
|
| 7390 |
+
changes[i] = {from: range.from(), to: range.to(), text: splitLines(code[i]), origin: origin};
|
| 7391 |
+
}
|
| 7392 |
+
var newSel = collapse && collapse != "end" && computeReplacedSel(this, changes, collapse);
|
| 7393 |
+
for (var i = changes.length - 1; i >= 0; i--)
|
| 7394 |
+
makeChange(this, changes[i]);
|
| 7395 |
+
if (newSel) setSelectionReplaceHistory(this, newSel);
|
| 7396 |
+
else if (this.cm) ensureCursorVisible(this.cm);
|
| 7397 |
+
}),
|
| 7398 |
+
undo: docMethodOp(function() {makeChangeFromHistory(this, "undo");}),
|
| 7399 |
+
redo: docMethodOp(function() {makeChangeFromHistory(this, "redo");}),
|
| 7400 |
+
undoSelection: docMethodOp(function() {makeChangeFromHistory(this, "undo", true);}),
|
| 7401 |
+
redoSelection: docMethodOp(function() {makeChangeFromHistory(this, "redo", true);}),
|
| 7402 |
+
|
| 7403 |
+
setExtending: function(val) {this.extend = val;},
|
| 7404 |
+
getExtending: function() {return this.extend;},
|
| 7405 |
+
|
| 7406 |
+
historySize: function() {
|
| 7407 |
+
var hist = this.history, done = 0, undone = 0;
|
| 7408 |
+
for (var i = 0; i < hist.done.length; i++) if (!hist.done[i].ranges) ++done;
|
| 7409 |
+
for (var i = 0; i < hist.undone.length; i++) if (!hist.undone[i].ranges) ++undone;
|
| 7410 |
+
return {undo: done, redo: undone};
|
| 7411 |
+
},
|
| 7412 |
+
clearHistory: function() {this.history = new History(this.history.maxGeneration);},
|
| 7413 |
+
|
| 7414 |
+
markClean: function() {
|
| 7415 |
+
this.cleanGeneration = this.changeGeneration(true);
|
| 7416 |
+
},
|
| 7417 |
+
changeGeneration: function(forceSplit) {
|
| 7418 |
+
if (forceSplit)
|
| 7419 |
+
this.history.lastOp = this.history.lastSelOp = this.history.lastOrigin = null;
|
| 7420 |
+
return this.history.generation;
|
| 7421 |
+
},
|
| 7422 |
+
isClean: function (gen) {
|
| 7423 |
+
return this.history.generation == (gen || this.cleanGeneration);
|
| 7424 |
+
},
|
| 7425 |
+
|
| 7426 |
+
getHistory: function() {
|
| 7427 |
+
return {done: copyHistoryArray(this.history.done),
|
| 7428 |
+
undone: copyHistoryArray(this.history.undone)};
|
| 7429 |
+
},
|
| 7430 |
+
setHistory: function(histData) {
|
| 7431 |
+
var hist = this.history = new History(this.history.maxGeneration);
|
| 7432 |
+
hist.done = copyHistoryArray(histData.done.slice(0), null, true);
|
| 7433 |
+
hist.undone = copyHistoryArray(histData.undone.slice(0), null, true);
|
| 7434 |
+
},
|
| 7435 |
+
|
| 7436 |
+
addLineClass: docMethodOp(function(handle, where, cls) {
|
| 7437 |
+
return changeLine(this, handle, where == "gutter" ? "gutter" : "class", function(line) {
|
| 7438 |
+
var prop = where == "text" ? "textClass"
|
| 7439 |
+
: where == "background" ? "bgClass"
|
| 7440 |
+
: where == "gutter" ? "gutterClass" : "wrapClass";
|
| 7441 |
+
if (!line[prop]) line[prop] = cls;
|
| 7442 |
+
else if (classTest(cls).test(line[prop])) return false;
|
| 7443 |
+
else line[prop] += " " + cls;
|
| 7444 |
+
return true;
|
| 7445 |
+
});
|
| 7446 |
+
}),
|
| 7447 |
+
removeLineClass: docMethodOp(function(handle, where, cls) {
|
| 7448 |
+
return changeLine(this, handle, where == "gutter" ? "gutter" : "class", function(line) {
|
| 7449 |
+
var prop = where == "text" ? "textClass"
|
| 7450 |
+
: where == "background" ? "bgClass"
|
| 7451 |
+
: where == "gutter" ? "gutterClass" : "wrapClass";
|
| 7452 |
+
var cur = line[prop];
|
| 7453 |
+
if (!cur) return false;
|
| 7454 |
+
else if (cls == null) line[prop] = null;
|
| 7455 |
+
else {
|
| 7456 |
+
var found = cur.match(classTest(cls));
|
| 7457 |
+
if (!found) return false;
|
| 7458 |
+
var end = found.index + found[0].length;
|
| 7459 |
+
line[prop] = cur.slice(0, found.index) + (!found.index || end == cur.length ? "" : " ") + cur.slice(end) || null;
|
| 7460 |
+
}
|
| 7461 |
+
return true;
|
| 7462 |
+
});
|
| 7463 |
+
}),
|
| 7464 |
+
|
| 7465 |
+
addLineWidget: docMethodOp(function(handle, node, options) {
|
| 7466 |
+
return addLineWidget(this, handle, node, options);
|
| 7467 |
+
}),
|
| 7468 |
+
removeLineWidget: function(widget) { widget.clear(); },
|
| 7469 |
+
|
| 7470 |
+
markText: function(from, to, options) {
|
| 7471 |
+
return markText(this, clipPos(this, from), clipPos(this, to), options, "range");
|
| 7472 |
+
},
|
| 7473 |
+
setBookmark: function(pos, options) {
|
| 7474 |
+
var realOpts = {replacedWith: options && (options.nodeType == null ? options.widget : options),
|
| 7475 |
+
insertLeft: options && options.insertLeft,
|
| 7476 |
+
clearWhenEmpty: false, shared: options && options.shared,
|
| 7477 |
+
handleMouseEvents: options && options.handleMouseEvents};
|
| 7478 |
+
pos = clipPos(this, pos);
|
| 7479 |
+
return markText(this, pos, pos, realOpts, "bookmark");
|
| 7480 |
+
},
|
| 7481 |
+
findMarksAt: function(pos) {
|
| 7482 |
+
pos = clipPos(this, pos);
|
| 7483 |
+
var markers = [], spans = getLine(this, pos.line).markedSpans;
|
| 7484 |
+
if (spans) for (var i = 0; i < spans.length; ++i) {
|
| 7485 |
+
var span = spans[i];
|
| 7486 |
+
if ((span.from == null || span.from <= pos.ch) &&
|
| 7487 |
+
(span.to == null || span.to >= pos.ch))
|
| 7488 |
+
markers.push(span.marker.parent || span.marker);
|
| 7489 |
+
}
|
| 7490 |
+
return markers;
|
| 7491 |
+
},
|
| 7492 |
+
findMarks: function(from, to, filter) {
|
| 7493 |
+
from = clipPos(this, from); to = clipPos(this, to);
|
| 7494 |
+
var found = [], lineNo = from.line;
|
| 7495 |
+
this.iter(from.line, to.line + 1, function(line) {
|
| 7496 |
+
var spans = line.markedSpans;
|
| 7497 |
+
if (spans) for (var i = 0; i < spans.length; i++) {
|
| 7498 |
+
var span = spans[i];
|
| 7499 |
+
if (!(lineNo == from.line && from.ch > span.to ||
|
| 7500 |
+
span.from == null && lineNo != from.line||
|
| 7501 |
+
lineNo == to.line && span.from > to.ch) &&
|
| 7502 |
+
(!filter || filter(span.marker)))
|
| 7503 |
+
found.push(span.marker.parent || span.marker);
|
| 7504 |
+
}
|
| 7505 |
+
++lineNo;
|
| 7506 |
+
});
|
| 7507 |
+
return found;
|
| 7508 |
+
},
|
| 7509 |
+
getAllMarks: function() {
|
| 7510 |
+
var markers = [];
|
| 7511 |
+
this.iter(function(line) {
|
| 7512 |
+
var sps = line.markedSpans;
|
| 7513 |
+
if (sps) for (var i = 0; i < sps.length; ++i)
|
| 7514 |
+
if (sps[i].from != null) markers.push(sps[i].marker);
|
| 7515 |
+
});
|
| 7516 |
+
return markers;
|
| 7517 |
+
},
|
| 7518 |
+
|
| 7519 |
+
posFromIndex: function(off) {
|
| 7520 |
+
var ch, lineNo = this.first;
|
| 7521 |
+
this.iter(function(line) {
|
| 7522 |
+
var sz = line.text.length + 1;
|
| 7523 |
+
if (sz > off) { ch = off; return true; }
|
| 7524 |
+
off -= sz;
|
| 7525 |
+
++lineNo;
|
| 7526 |
+
});
|
| 7527 |
+
return clipPos(this, Pos(lineNo, ch));
|
| 7528 |
+
},
|
| 7529 |
+
indexFromPos: function (coords) {
|
| 7530 |
+
coords = clipPos(this, coords);
|
| 7531 |
+
var index = coords.ch;
|
| 7532 |
+
if (coords.line < this.first || coords.ch < 0) return 0;
|
| 7533 |
+
this.iter(this.first, coords.line, function (line) {
|
| 7534 |
+
index += line.text.length + 1;
|
| 7535 |
+
});
|
| 7536 |
+
return index;
|
| 7537 |
+
},
|
| 7538 |
+
|
| 7539 |
+
copy: function(copyHistory) {
|
| 7540 |
+
var doc = new Doc(getLines(this, this.first, this.first + this.size), this.modeOption, this.first);
|
| 7541 |
+
doc.scrollTop = this.scrollTop; doc.scrollLeft = this.scrollLeft;
|
| 7542 |
+
doc.sel = this.sel;
|
| 7543 |
+
doc.extend = false;
|
| 7544 |
+
if (copyHistory) {
|
| 7545 |
+
doc.history.undoDepth = this.history.undoDepth;
|
| 7546 |
+
doc.setHistory(this.getHistory());
|
| 7547 |
+
}
|
| 7548 |
+
return doc;
|
| 7549 |
+
},
|
| 7550 |
+
|
| 7551 |
+
linkedDoc: function(options) {
|
| 7552 |
+
if (!options) options = {};
|
| 7553 |
+
var from = this.first, to = this.first + this.size;
|
| 7554 |
+
if (options.from != null && options.from > from) from = options.from;
|
| 7555 |
+
if (options.to != null && options.to < to) to = options.to;
|
| 7556 |
+
var copy = new Doc(getLines(this, from, to), options.mode || this.modeOption, from);
|
| 7557 |
+
if (options.sharedHist) copy.history = this.history;
|
| 7558 |
+
(this.linked || (this.linked = [])).push({doc: copy, sharedHist: options.sharedHist});
|
| 7559 |
+
copy.linked = [{doc: this, isParent: true, sharedHist: options.sharedHist}];
|
| 7560 |
+
copySharedMarkers(copy, findSharedMarkers(this));
|
| 7561 |
+
return copy;
|
| 7562 |
+
},
|
| 7563 |
+
unlinkDoc: function(other) {
|
| 7564 |
+
if (other instanceof CodeMirror) other = other.doc;
|
| 7565 |
+
if (this.linked) for (var i = 0; i < this.linked.length; ++i) {
|
| 7566 |
+
var link = this.linked[i];
|
| 7567 |
+
if (link.doc != other) continue;
|
| 7568 |
+
this.linked.splice(i, 1);
|
| 7569 |
+
other.unlinkDoc(this);
|
| 7570 |
+
detachSharedMarkers(findSharedMarkers(this));
|
| 7571 |
+
break;
|
| 7572 |
+
}
|
| 7573 |
+
// If the histories were shared, split them again
|
| 7574 |
+
if (other.history == this.history) {
|
| 7575 |
+
var splitIds = [other.id];
|
| 7576 |
+
linkedDocs(other, function(doc) {splitIds.push(doc.id);}, true);
|
| 7577 |
+
other.history = new History(null);
|
| 7578 |
+
other.history.done = copyHistoryArray(this.history.done, splitIds);
|
| 7579 |
+
other.history.undone = copyHistoryArray(this.history.undone, splitIds);
|
| 7580 |
+
}
|
| 7581 |
+
},
|
| 7582 |
+
iterLinkedDocs: function(f) {linkedDocs(this, f);},
|
| 7583 |
+
|
| 7584 |
+
getMode: function() {return this.mode;},
|
| 7585 |
+
getEditor: function() {return this.cm;}
|
| 7586 |
+
});
|
| 7587 |
+
|
| 7588 |
+
// Public alias.
|
| 7589 |
+
Doc.prototype.eachLine = Doc.prototype.iter;
|
| 7590 |
+
|
| 7591 |
+
// Set up methods on CodeMirror's prototype to redirect to the editor's document.
|
| 7592 |
+
var dontDelegate = "iter insert remove copy getEditor".split(" ");
|
| 7593 |
+
for (var prop in Doc.prototype) if (Doc.prototype.hasOwnProperty(prop) && indexOf(dontDelegate, prop) < 0)
|
| 7594 |
+
CodeMirror.prototype[prop] = (function(method) {
|
| 7595 |
+
return function() {return method.apply(this.doc, arguments);};
|
| 7596 |
+
})(Doc.prototype[prop]);
|
| 7597 |
+
|
| 7598 |
+
eventMixin(Doc);
|
| 7599 |
+
|
| 7600 |
+
// Call f for all linked documents.
|
| 7601 |
+
function linkedDocs(doc, f, sharedHistOnly) {
|
| 7602 |
+
function propagate(doc, skip, sharedHist) {
|
| 7603 |
+
if (doc.linked) for (var i = 0; i < doc.linked.length; ++i) {
|
| 7604 |
+
var rel = doc.linked[i];
|
| 7605 |
+
if (rel.doc == skip) continue;
|
| 7606 |
+
var shared = sharedHist && rel.sharedHist;
|
| 7607 |
+
if (sharedHistOnly && !shared) continue;
|
| 7608 |
+
f(rel.doc, shared);
|
| 7609 |
+
propagate(rel.doc, doc, shared);
|
| 7610 |
+
}
|
| 7611 |
+
}
|
| 7612 |
+
propagate(doc, null, true);
|
| 7613 |
+
}
|
| 7614 |
+
|
| 7615 |
+
// Attach a document to an editor.
|
| 7616 |
+
function attachDoc(cm, doc) {
|
| 7617 |
+
if (doc.cm) throw new Error("This document is already in use.");
|
| 7618 |
+
cm.doc = doc;
|
| 7619 |
+
doc.cm = cm;
|
| 7620 |
+
estimateLineHeights(cm);
|
| 7621 |
+
loadMode(cm);
|
| 7622 |
+
if (!cm.options.lineWrapping) findMaxLine(cm);
|
| 7623 |
+
cm.options.mode = doc.modeOption;
|
| 7624 |
+
regChange(cm);
|
| 7625 |
+
}
|
| 7626 |
+
|
| 7627 |
+
// LINE UTILITIES
|
| 7628 |
+
|
| 7629 |
+
// Find the line object corresponding to the given line number.
|
| 7630 |
+
function getLine(doc, n) {
|
| 7631 |
+
n -= doc.first;
|
| 7632 |
+
if (n < 0 || n >= doc.size) throw new Error("There is no line " + (n + doc.first) + " in the document.");
|
| 7633 |
+
for (var chunk = doc; !chunk.lines;) {
|
| 7634 |
+
for (var i = 0;; ++i) {
|
| 7635 |
+
var child = chunk.children[i], sz = child.chunkSize();
|
| 7636 |
+
if (n < sz) { chunk = child; break; }
|
| 7637 |
+
n -= sz;
|
| 7638 |
+
}
|
| 7639 |
+
}
|
| 7640 |
+
return chunk.lines[n];
|
| 7641 |
+
}
|
| 7642 |
+
|
| 7643 |
+
// Get the part of a document between two positions, as an array of
|
| 7644 |
+
// strings.
|
| 7645 |
+
function getBetween(doc, start, end) {
|
| 7646 |
+
var out = [], n = start.line;
|
| 7647 |
+
doc.iter(start.line, end.line + 1, function(line) {
|
| 7648 |
+
var text = line.text;
|
| 7649 |
+
if (n == end.line) text = text.slice(0, end.ch);
|
| 7650 |
+
if (n == start.line) text = text.slice(start.ch);
|
| 7651 |
+
out.push(text);
|
| 7652 |
+
++n;
|
| 7653 |
+
});
|
| 7654 |
+
return out;
|
| 7655 |
+
}
|
| 7656 |
+
// Get the lines between from and to, as array of strings.
|
| 7657 |
+
function getLines(doc, from, to) {
|
| 7658 |
+
var out = [];
|
| 7659 |
+
doc.iter(from, to, function(line) { out.push(line.text); });
|
| 7660 |
+
return out;
|
| 7661 |
+
}
|
| 7662 |
+
|
| 7663 |
+
// Update the height of a line, propagating the height change
|
| 7664 |
+
// upwards to parent nodes.
|
| 7665 |
+
function updateLineHeight(line, height) {
|
| 7666 |
+
var diff = height - line.height;
|
| 7667 |
+
if (diff) for (var n = line; n; n = n.parent) n.height += diff;
|
| 7668 |
+
}
|
| 7669 |
+
|
| 7670 |
+
// Given a line object, find its line number by walking up through
|
| 7671 |
+
// its parent links.
|
| 7672 |
+
function lineNo(line) {
|
| 7673 |
+
if (line.parent == null) return null;
|
| 7674 |
+
var cur = line.parent, no = indexOf(cur.lines, line);
|
| 7675 |
+
for (var chunk = cur.parent; chunk; cur = chunk, chunk = chunk.parent) {
|
| 7676 |
+
for (var i = 0;; ++i) {
|
| 7677 |
+
if (chunk.children[i] == cur) break;
|
| 7678 |
+
no += chunk.children[i].chunkSize();
|
| 7679 |
+
}
|
| 7680 |
+
}
|
| 7681 |
+
return no + cur.first;
|
| 7682 |
+
}
|
| 7683 |
+
|
| 7684 |
+
// Find the line at the given vertical position, using the height
|
| 7685 |
+
// information in the document tree.
|
| 7686 |
+
function lineAtHeight(chunk, h) {
|
| 7687 |
+
var n = chunk.first;
|
| 7688 |
+
outer: do {
|
| 7689 |
+
for (var i = 0; i < chunk.children.length; ++i) {
|
| 7690 |
+
var child = chunk.children[i], ch = child.height;
|
| 7691 |
+
if (h < ch) { chunk = child; continue outer; }
|
| 7692 |
+
h -= ch;
|
| 7693 |
+
n += child.chunkSize();
|
| 7694 |
+
}
|
| 7695 |
+
return n;
|
| 7696 |
+
} while (!chunk.lines);
|
| 7697 |
+
for (var i = 0; i < chunk.lines.length; ++i) {
|
| 7698 |
+
var line = chunk.lines[i], lh = line.height;
|
| 7699 |
+
if (h < lh) break;
|
| 7700 |
+
h -= lh;
|
| 7701 |
+
}
|
| 7702 |
+
return n + i;
|
| 7703 |
+
}
|
| 7704 |
+
|
| 7705 |
+
|
| 7706 |
+
// Find the height above the given line.
|
| 7707 |
+
function heightAtLine(lineObj) {
|
| 7708 |
+
lineObj = visualLine(lineObj);
|
| 7709 |
+
|
| 7710 |
+
var h = 0, chunk = lineObj.parent;
|
| 7711 |
+
for (var i = 0; i < chunk.lines.length; ++i) {
|
| 7712 |
+
var line = chunk.lines[i];
|
| 7713 |
+
if (line == lineObj) break;
|
| 7714 |
+
else h += line.height;
|
| 7715 |
+
}
|
| 7716 |
+
for (var p = chunk.parent; p; chunk = p, p = chunk.parent) {
|
| 7717 |
+
for (var i = 0; i < p.children.length; ++i) {
|
| 7718 |
+
var cur = p.children[i];
|
| 7719 |
+
if (cur == chunk) break;
|
| 7720 |
+
else h += cur.height;
|
| 7721 |
+
}
|
| 7722 |
+
}
|
| 7723 |
+
return h;
|
| 7724 |
+
}
|
| 7725 |
+
|
| 7726 |
+
// Get the bidi ordering for the given line (and cache it). Returns
|
| 7727 |
+
// false for lines that are fully left-to-right, and an array of
|
| 7728 |
+
// BidiSpan objects otherwise.
|
| 7729 |
+
function getOrder(line) {
|
| 7730 |
+
var order = line.order;
|
| 7731 |
+
if (order == null) order = line.order = bidiOrdering(line.text);
|
| 7732 |
+
return order;
|
| 7733 |
+
}
|
| 7734 |
+
|
| 7735 |
+
// HISTORY
|
| 7736 |
+
|
| 7737 |
+
function History(startGen) {
|
| 7738 |
+
// Arrays of change events and selections. Doing something adds an
|
| 7739 |
+
// event to done and clears undo. Undoing moves events from done
|
| 7740 |
+
// to undone, redoing moves them in the other direction.
|
| 7741 |
+
this.done = []; this.undone = [];
|
| 7742 |
+
this.undoDepth = Infinity;
|
| 7743 |
+
// Used to track when changes can be merged into a single undo
|
| 7744 |
+
// event
|
| 7745 |
+
this.lastModTime = this.lastSelTime = 0;
|
| 7746 |
+
this.lastOp = this.lastSelOp = null;
|
| 7747 |
+
this.lastOrigin = this.lastSelOrigin = null;
|
| 7748 |
+
// Used by the isClean() method
|
| 7749 |
+
this.generation = this.maxGeneration = startGen || 1;
|
| 7750 |
+
}
|
| 7751 |
+
|
| 7752 |
+
// Create a history change event from an updateDoc-style change
|
| 7753 |
+
// object.
|
| 7754 |
+
function historyChangeFromChange(doc, change) {
|
| 7755 |
+
var histChange = {from: copyPos(change.from), to: changeEnd(change), text: getBetween(doc, change.from, change.to)};
|
| 7756 |
+
attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1);
|
| 7757 |
+
linkedDocs(doc, function(doc) {attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1);}, true);
|
| 7758 |
+
return histChange;
|
| 7759 |
+
}
|
| 7760 |
+
|
| 7761 |
+
// Pop all selection events off the end of a history array. Stop at
|
| 7762 |
+
// a change event.
|
| 7763 |
+
function clearSelectionEvents(array) {
|
| 7764 |
+
while (array.length) {
|
| 7765 |
+
var last = lst(array);
|
| 7766 |
+
if (last.ranges) array.pop();
|
| 7767 |
+
else break;
|
| 7768 |
+
}
|
| 7769 |
+
}
|
| 7770 |
+
|
| 7771 |
+
// Find the top change event in the history. Pop off selection
|
| 7772 |
+
// events that are in the way.
|
| 7773 |
+
function lastChangeEvent(hist, force) {
|
| 7774 |
+
if (force) {
|
| 7775 |
+
clearSelectionEvents(hist.done);
|
| 7776 |
+
return lst(hist.done);
|
| 7777 |
+
} else if (hist.done.length && !lst(hist.done).ranges) {
|
| 7778 |
+
return lst(hist.done);
|
| 7779 |
+
} else if (hist.done.length > 1 && !hist.done[hist.done.length - 2].ranges) {
|
| 7780 |
+
hist.done.pop();
|
| 7781 |
+
return lst(hist.done);
|
| 7782 |
+
}
|
| 7783 |
+
}
|
| 7784 |
+
|
| 7785 |
+
// Register a change in the history. Merges changes that are within
|
| 7786 |
+
// a single operation, ore are close together with an origin that
|
| 7787 |
+
// allows merging (starting with "+") into a single event.
|
| 7788 |
+
function addChangeToHistory(doc, change, selAfter, opId) {
|
| 7789 |
+
var hist = doc.history;
|
| 7790 |
+
hist.undone.length = 0;
|
| 7791 |
+
var time = +new Date, cur;
|
| 7792 |
+
|
| 7793 |
+
if ((hist.lastOp == opId ||
|
| 7794 |
+
hist.lastOrigin == change.origin && change.origin &&
|
| 7795 |
+
((change.origin.charAt(0) == "+" && doc.cm && hist.lastModTime > time - doc.cm.options.historyEventDelay) ||
|
| 7796 |
+
change.origin.charAt(0) == "*")) &&
|
| 7797 |
+
(cur = lastChangeEvent(hist, hist.lastOp == opId))) {
|
| 7798 |
+
// Merge this change into the last event
|
| 7799 |
+
var last = lst(cur.changes);
|
| 7800 |
+
if (cmp(change.from, change.to) == 0 && cmp(change.from, last.to) == 0) {
|
| 7801 |
+
// Optimized case for simple insertion -- don't want to add
|
| 7802 |
+
// new changesets for every character typed
|
| 7803 |
+
last.to = changeEnd(change);
|
| 7804 |
+
} else {
|
| 7805 |
+
// Add new sub-event
|
| 7806 |
+
cur.changes.push(historyChangeFromChange(doc, change));
|
| 7807 |
+
}
|
| 7808 |
+
} else {
|
| 7809 |
+
// Can not be merged, start a new event.
|
| 7810 |
+
var before = lst(hist.done);
|
| 7811 |
+
if (!before || !before.ranges)
|
| 7812 |
+
pushSelectionToHistory(doc.sel, hist.done);
|
| 7813 |
+
cur = {changes: [historyChangeFromChange(doc, change)],
|
| 7814 |
+
generation: hist.generation};
|
| 7815 |
+
hist.done.push(cur);
|
| 7816 |
+
while (hist.done.length > hist.undoDepth) {
|
| 7817 |
+
hist.done.shift();
|
| 7818 |
+
if (!hist.done[0].ranges) hist.done.shift();
|
| 7819 |
+
}
|
| 7820 |
+
}
|
| 7821 |
+
hist.done.push(selAfter);
|
| 7822 |
+
hist.generation = ++hist.maxGeneration;
|
| 7823 |
+
hist.lastModTime = hist.lastSelTime = time;
|
| 7824 |
+
hist.lastOp = hist.lastSelOp = opId;
|
| 7825 |
+
hist.lastOrigin = hist.lastSelOrigin = change.origin;
|
| 7826 |
+
|
| 7827 |
+
if (!last) signal(doc, "historyAdded");
|
| 7828 |
+
}
|
| 7829 |
+
|
| 7830 |
+
function selectionEventCanBeMerged(doc, origin, prev, sel) {
|
| 7831 |
+
var ch = origin.charAt(0);
|
| 7832 |
+
return ch == "*" ||
|
| 7833 |
+
ch == "+" &&
|
| 7834 |
+
prev.ranges.length == sel.ranges.length &&
|
| 7835 |
+
prev.somethingSelected() == sel.somethingSelected() &&
|
| 7836 |
+
new Date - doc.history.lastSelTime <= (doc.cm ? doc.cm.options.historyEventDelay : 500);
|
| 7837 |
+
}
|
| 7838 |
+
|
| 7839 |
+
// Called whenever the selection changes, sets the new selection as
|
| 7840 |
+
// the pending selection in the history, and pushes the old pending
|
| 7841 |
+
// selection into the 'done' array when it was significantly
|
| 7842 |
+
// different (in number of selected ranges, emptiness, or time).
|
| 7843 |
+
function addSelectionToHistory(doc, sel, opId, options) {
|
| 7844 |
+
var hist = doc.history, origin = options && options.origin;
|
| 7845 |
+
|
| 7846 |
+
// A new event is started when the previous origin does not match
|
| 7847 |
+
// the current, or the origins don't allow matching. Origins
|
| 7848 |
+
// starting with * are always merged, those starting with + are
|
| 7849 |
+
// merged when similar and close together in time.
|
| 7850 |
+
if (opId == hist.lastSelOp ||
|
| 7851 |
+
(origin && hist.lastSelOrigin == origin &&
|
| 7852 |
+
(hist.lastModTime == hist.lastSelTime && hist.lastOrigin == origin ||
|
| 7853 |
+
selectionEventCanBeMerged(doc, origin, lst(hist.done), sel))))
|
| 7854 |
+
hist.done[hist.done.length - 1] = sel;
|
| 7855 |
+
else
|
| 7856 |
+
pushSelectionToHistory(sel, hist.done);
|
| 7857 |
+
|
| 7858 |
+
hist.lastSelTime = +new Date;
|
| 7859 |
+
hist.lastSelOrigin = origin;
|
| 7860 |
+
hist.lastSelOp = opId;
|
| 7861 |
+
if (options && options.clearRedo !== false)
|
| 7862 |
+
clearSelectionEvents(hist.undone);
|
| 7863 |
+
}
|
| 7864 |
+
|
| 7865 |
+
function pushSelectionToHistory(sel, dest) {
|
| 7866 |
+
var top = lst(dest);
|
| 7867 |
+
if (!(top && top.ranges && top.equals(sel)))
|
| 7868 |
+
dest.push(sel);
|
| 7869 |
+
}
|
| 7870 |
+
|
| 7871 |
+
// Used to store marked span information in the history.
|
| 7872 |
+
function attachLocalSpans(doc, change, from, to) {
|
| 7873 |
+
var existing = change["spans_" + doc.id], n = 0;
|
| 7874 |
+
doc.iter(Math.max(doc.first, from), Math.min(doc.first + doc.size, to), function(line) {
|
| 7875 |
+
if (line.markedSpans)
|
| 7876 |
+
(existing || (existing = change["spans_" + doc.id] = {}))[n] = line.markedSpans;
|
| 7877 |
+
++n;
|
| 7878 |
+
});
|
| 7879 |
+
}
|
| 7880 |
+
|
| 7881 |
+
// When un/re-doing restores text containing marked spans, those
|
| 7882 |
+
// that have been explicitly cleared should not be restored.
|
| 7883 |
+
function removeClearedSpans(spans) {
|
| 7884 |
+
if (!spans) return null;
|
| 7885 |
+
for (var i = 0, out; i < spans.length; ++i) {
|
| 7886 |
+
if (spans[i].marker.explicitlyCleared) { if (!out) out = spans.slice(0, i); }
|
| 7887 |
+
else if (out) out.push(spans[i]);
|
| 7888 |
+
}
|
| 7889 |
+
return !out ? spans : out.length ? out : null;
|
| 7890 |
+
}
|
| 7891 |
+
|
| 7892 |
+
// Retrieve and filter the old marked spans stored in a change event.
|
| 7893 |
+
function getOldSpans(doc, change) {
|
| 7894 |
+
var found = change["spans_" + doc.id];
|
| 7895 |
+
if (!found) return null;
|
| 7896 |
+
for (var i = 0, nw = []; i < change.text.length; ++i)
|
| 7897 |
+
nw.push(removeClearedSpans(found[i]));
|
| 7898 |
+
return nw;
|
| 7899 |
+
}
|
| 7900 |
+
|
| 7901 |
+
// Used both to provide a JSON-safe object in .getHistory, and, when
|
| 7902 |
+
// detaching a document, to split the history in two
|
| 7903 |
+
function copyHistoryArray(events, newGroup, instantiateSel) {
|
| 7904 |
+
for (var i = 0, copy = []; i < events.length; ++i) {
|
| 7905 |
+
var event = events[i];
|
| 7906 |
+
if (event.ranges) {
|
| 7907 |
+
copy.push(instantiateSel ? Selection.prototype.deepCopy.call(event) : event);
|
| 7908 |
+
continue;
|
| 7909 |
+
}
|
| 7910 |
+
var changes = event.changes, newChanges = [];
|
| 7911 |
+
copy.push({changes: newChanges});
|
| 7912 |
+
for (var j = 0; j < changes.length; ++j) {
|
| 7913 |
+
var change = changes[j], m;
|
| 7914 |
+
newChanges.push({from: change.from, to: change.to, text: change.text});
|
| 7915 |
+
if (newGroup) for (var prop in change) if (m = prop.match(/^spans_(\d+)$/)) {
|
| 7916 |
+
if (indexOf(newGroup, Number(m[1])) > -1) {
|
| 7917 |
+
lst(newChanges)[prop] = change[prop];
|
| 7918 |
+
delete change[prop];
|
| 7919 |
+
}
|
| 7920 |
+
}
|
| 7921 |
+
}
|
| 7922 |
+
}
|
| 7923 |
+
return copy;
|
| 7924 |
+
}
|
| 7925 |
+
|
| 7926 |
+
// Rebasing/resetting history to deal with externally-sourced changes
|
| 7927 |
+
|
| 7928 |
+
function rebaseHistSelSingle(pos, from, to, diff) {
|
| 7929 |
+
if (to < pos.line) {
|
| 7930 |
+
pos.line += diff;
|
| 7931 |
+
} else if (from < pos.line) {
|
| 7932 |
+
pos.line = from;
|
| 7933 |
+
pos.ch = 0;
|
| 7934 |
+
}
|
| 7935 |
+
}
|
| 7936 |
+
|
| 7937 |
+
// Tries to rebase an array of history events given a change in the
|
| 7938 |
+
// document. If the change touches the same lines as the event, the
|
| 7939 |
+
// event, and everything 'behind' it, is discarded. If the change is
|
| 7940 |
+
// before the event, the event's positions are updated. Uses a
|
| 7941 |
+
// copy-on-write scheme for the positions, to avoid having to
|
| 7942 |
+
// reallocate them all on every rebase, but also avoid problems with
|
| 7943 |
+
// shared position objects being unsafely updated.
|
| 7944 |
+
function rebaseHistArray(array, from, to, diff) {
|
| 7945 |
+
for (var i = 0; i < array.length; ++i) {
|
| 7946 |
+
var sub = array[i], ok = true;
|
| 7947 |
+
if (sub.ranges) {
|
| 7948 |
+
if (!sub.copied) { sub = array[i] = sub.deepCopy(); sub.copied = true; }
|
| 7949 |
+
for (var j = 0; j < sub.ranges.length; j++) {
|
| 7950 |
+
rebaseHistSelSingle(sub.ranges[j].anchor, from, to, diff);
|
| 7951 |
+
rebaseHistSelSingle(sub.ranges[j].head, from, to, diff);
|
| 7952 |
+
}
|
| 7953 |
+
continue;
|
| 7954 |
+
}
|
| 7955 |
+
for (var j = 0; j < sub.changes.length; ++j) {
|
| 7956 |
+
var cur = sub.changes[j];
|
| 7957 |
+
if (to < cur.from.line) {
|
| 7958 |
+
cur.from = Pos(cur.from.line + diff, cur.from.ch);
|
| 7959 |
+
cur.to = Pos(cur.to.line + diff, cur.to.ch);
|
| 7960 |
+
} else if (from <= cur.to.line) {
|
| 7961 |
+
ok = false;
|
| 7962 |
+
break;
|
| 7963 |
+
}
|
| 7964 |
+
}
|
| 7965 |
+
if (!ok) {
|
| 7966 |
+
array.splice(0, i + 1);
|
| 7967 |
+
i = 0;
|
| 7968 |
+
}
|
| 7969 |
+
}
|
| 7970 |
+
}
|
| 7971 |
+
|
| 7972 |
+
function rebaseHist(hist, change) {
|
| 7973 |
+
var from = change.from.line, to = change.to.line, diff = change.text.length - (to - from) - 1;
|
| 7974 |
+
rebaseHistArray(hist.done, from, to, diff);
|
| 7975 |
+
rebaseHistArray(hist.undone, from, to, diff);
|
| 7976 |
+
}
|
| 7977 |
+
|
| 7978 |
+
// EVENT UTILITIES
|
| 7979 |
+
|
| 7980 |
+
// Due to the fact that we still support jurassic IE versions, some
|
| 7981 |
+
// compatibility wrappers are needed.
|
| 7982 |
+
|
| 7983 |
+
var e_preventDefault = CodeMirror.e_preventDefault = function(e) {
|
| 7984 |
+
if (e.preventDefault) e.preventDefault();
|
| 7985 |
+
else e.returnValue = false;
|
| 7986 |
+
};
|
| 7987 |
+
var e_stopPropagation = CodeMirror.e_stopPropagation = function(e) {
|
| 7988 |
+
if (e.stopPropagation) e.stopPropagation();
|
| 7989 |
+
else e.cancelBubble = true;
|
| 7990 |
+
};
|
| 7991 |
+
function e_defaultPrevented(e) {
|
| 7992 |
+
return e.defaultPrevented != null ? e.defaultPrevented : e.returnValue == false;
|
| 7993 |
+
}
|
| 7994 |
+
var e_stop = CodeMirror.e_stop = function(e) {e_preventDefault(e); e_stopPropagation(e);};
|
| 7995 |
+
|
| 7996 |
+
function e_target(e) {return e.target || e.srcElement;}
|
| 7997 |
+
function e_button(e) {
|
| 7998 |
+
var b = e.which;
|
| 7999 |
+
if (b == null) {
|
| 8000 |
+
if (e.button & 1) b = 1;
|
| 8001 |
+
else if (e.button & 2) b = 3;
|
| 8002 |
+
else if (e.button & 4) b = 2;
|
| 8003 |
+
}
|
| 8004 |
+
if (mac && e.ctrlKey && b == 1) b = 3;
|
| 8005 |
+
return b;
|
| 8006 |
+
}
|
| 8007 |
+
|
| 8008 |
+
// EVENT HANDLING
|
| 8009 |
+
|
| 8010 |
+
// Lightweight event framework. on/off also work on DOM nodes,
|
| 8011 |
+
// registering native DOM handlers.
|
| 8012 |
+
|
| 8013 |
+
var on = CodeMirror.on = function(emitter, type, f) {
|
| 8014 |
+
if (emitter.addEventListener)
|
| 8015 |
+
emitter.addEventListener(type, f, false);
|
| 8016 |
+
else if (emitter.attachEvent)
|
| 8017 |
+
emitter.attachEvent("on" + type, f);
|
| 8018 |
+
else {
|
| 8019 |
+
var map = emitter._handlers || (emitter._handlers = {});
|
| 8020 |
+
var arr = map[type] || (map[type] = []);
|
| 8021 |
+
arr.push(f);
|
| 8022 |
+
}
|
| 8023 |
+
};
|
| 8024 |
+
|
| 8025 |
+
var off = CodeMirror.off = function(emitter, type, f) {
|
| 8026 |
+
if (emitter.removeEventListener)
|
| 8027 |
+
emitter.removeEventListener(type, f, false);
|
| 8028 |
+
else if (emitter.detachEvent)
|
| 8029 |
+
emitter.detachEvent("on" + type, f);
|
| 8030 |
+
else {
|
| 8031 |
+
var arr = emitter._handlers && emitter._handlers[type];
|
| 8032 |
+
if (!arr) return;
|
| 8033 |
+
for (var i = 0; i < arr.length; ++i)
|
| 8034 |
+
if (arr[i] == f) { arr.splice(i, 1); break; }
|
| 8035 |
+
}
|
| 8036 |
+
};
|
| 8037 |
+
|
| 8038 |
+
var signal = CodeMirror.signal = function(emitter, type /*, values...*/) {
|
| 8039 |
+
var arr = emitter._handlers && emitter._handlers[type];
|
| 8040 |
+
if (!arr) return;
|
| 8041 |
+
var args = Array.prototype.slice.call(arguments, 2);
|
| 8042 |
+
for (var i = 0; i < arr.length; ++i) arr[i].apply(null, args);
|
| 8043 |
+
};
|
| 8044 |
+
|
| 8045 |
+
var orphanDelayedCallbacks = null;
|
| 8046 |
+
|
| 8047 |
+
// Often, we want to signal events at a point where we are in the
|
| 8048 |
+
// middle of some work, but don't want the handler to start calling
|
| 8049 |
+
// other methods on the editor, which might be in an inconsistent
|
| 8050 |
+
// state or simply not expect any other events to happen.
|
| 8051 |
+
// signalLater looks whether there are any handlers, and schedules
|
| 8052 |
+
// them to be executed when the last operation ends, or, if no
|
| 8053 |
+
// operation is active, when a timeout fires.
|
| 8054 |
+
function signalLater(emitter, type /*, values...*/) {
|
| 8055 |
+
var arr = emitter._handlers && emitter._handlers[type];
|
| 8056 |
+
if (!arr) return;
|
| 8057 |
+
var args = Array.prototype.slice.call(arguments, 2), list;
|
| 8058 |
+
if (operationGroup) {
|
| 8059 |
+
list = operationGroup.delayedCallbacks;
|
| 8060 |
+
} else if (orphanDelayedCallbacks) {
|
| 8061 |
+
list = orphanDelayedCallbacks;
|
| 8062 |
+
} else {
|
| 8063 |
+
list = orphanDelayedCallbacks = [];
|
| 8064 |
+
setTimeout(fireOrphanDelayed, 0);
|
| 8065 |
+
}
|
| 8066 |
+
function bnd(f) {return function(){f.apply(null, args);};};
|
| 8067 |
+
for (var i = 0; i < arr.length; ++i)
|
| 8068 |
+
list.push(bnd(arr[i]));
|
| 8069 |
+
}
|
| 8070 |
+
|
| 8071 |
+
function fireOrphanDelayed() {
|
| 8072 |
+
var delayed = orphanDelayedCallbacks;
|
| 8073 |
+
orphanDelayedCallbacks = null;
|
| 8074 |
+
for (var i = 0; i < delayed.length; ++i) delayed[i]();
|
| 8075 |
+
}
|
| 8076 |
+
|
| 8077 |
+
// The DOM events that CodeMirror handles can be overridden by
|
| 8078 |
+
// registering a (non-DOM) handler on the editor for the event name,
|
| 8079 |
+
// and preventDefault-ing the event in that handler.
|
| 8080 |
+
function signalDOMEvent(cm, e, override) {
|
| 8081 |
+
if (typeof e == "string")
|
| 8082 |
+
e = {type: e, preventDefault: function() { this.defaultPrevented = true; }};
|
| 8083 |
+
signal(cm, override || e.type, cm, e);
|
| 8084 |
+
return e_defaultPrevented(e) || e.codemirrorIgnore;
|
| 8085 |
+
}
|
| 8086 |
+
|
| 8087 |
+
function signalCursorActivity(cm) {
|
| 8088 |
+
var arr = cm._handlers && cm._handlers.cursorActivity;
|
| 8089 |
+
if (!arr) return;
|
| 8090 |
+
var set = cm.curOp.cursorActivityHandlers || (cm.curOp.cursorActivityHandlers = []);
|
| 8091 |
+
for (var i = 0; i < arr.length; ++i) if (indexOf(set, arr[i]) == -1)
|
| 8092 |
+
set.push(arr[i]);
|
| 8093 |
+
}
|
| 8094 |
+
|
| 8095 |
+
function hasHandler(emitter, type) {
|
| 8096 |
+
var arr = emitter._handlers && emitter._handlers[type];
|
| 8097 |
+
return arr && arr.length > 0;
|
| 8098 |
+
}
|
| 8099 |
+
|
| 8100 |
+
// Add on and off methods to a constructor's prototype, to make
|
| 8101 |
+
// registering events on such objects more convenient.
|
| 8102 |
+
function eventMixin(ctor) {
|
| 8103 |
+
ctor.prototype.on = function(type, f) {on(this, type, f);};
|
| 8104 |
+
ctor.prototype.off = function(type, f) {off(this, type, f);};
|
| 8105 |
+
}
|
| 8106 |
+
|
| 8107 |
+
// MISC UTILITIES
|
| 8108 |
+
|
| 8109 |
+
// Number of pixels added to scroller and sizer to hide scrollbar
|
| 8110 |
+
var scrollerGap = 30;
|
| 8111 |
+
|
| 8112 |
+
// Returned or thrown by various protocols to signal 'I'm not
|
| 8113 |
+
// handling this'.
|
| 8114 |
+
var Pass = CodeMirror.Pass = {toString: function(){return "CodeMirror.Pass";}};
|
| 8115 |
+
|
| 8116 |
+
// Reused option objects for setSelection & friends
|
| 8117 |
+
var sel_dontScroll = {scroll: false}, sel_mouse = {origin: "*mouse"}, sel_move = {origin: "+move"};
|
| 8118 |
+
|
| 8119 |
+
function Delayed() {this.id = null;}
|
| 8120 |
+
Delayed.prototype.set = function(ms, f) {
|
| 8121 |
+
clearTimeout(this.id);
|
| 8122 |
+
this.id = setTimeout(f, ms);
|
| 8123 |
+
};
|
| 8124 |
+
|
| 8125 |
+
// Counts the column offset in a string, taking tabs into account.
|
| 8126 |
+
// Used mostly to find indentation.
|
| 8127 |
+
var countColumn = CodeMirror.countColumn = function(string, end, tabSize, startIndex, startValue) {
|
| 8128 |
+
if (end == null) {
|
| 8129 |
+
end = string.search(/[^\s\u00a0]/);
|
| 8130 |
+
if (end == -1) end = string.length;
|
| 8131 |
+
}
|
| 8132 |
+
for (var i = startIndex || 0, n = startValue || 0;;) {
|
| 8133 |
+
var nextTab = string.indexOf("\t", i);
|
| 8134 |
+
if (nextTab < 0 || nextTab >= end)
|
| 8135 |
+
return n + (end - i);
|
| 8136 |
+
n += nextTab - i;
|
| 8137 |
+
n += tabSize - (n % tabSize);
|
| 8138 |
+
i = nextTab + 1;
|
| 8139 |
+
}
|
| 8140 |
+
};
|
| 8141 |
+
|
| 8142 |
+
// The inverse of countColumn -- find the offset that corresponds to
|
| 8143 |
+
// a particular column.
|
| 8144 |
+
function findColumn(string, goal, tabSize) {
|
| 8145 |
+
for (var pos = 0, col = 0;;) {
|
| 8146 |
+
var nextTab = string.indexOf("\t", pos);
|
| 8147 |
+
if (nextTab == -1) nextTab = string.length;
|
| 8148 |
+
var skipped = nextTab - pos;
|
| 8149 |
+
if (nextTab == string.length || col + skipped >= goal)
|
| 8150 |
+
return pos + Math.min(skipped, goal - col);
|
| 8151 |
+
col += nextTab - pos;
|
| 8152 |
+
col += tabSize - (col % tabSize);
|
| 8153 |
+
pos = nextTab + 1;
|
| 8154 |
+
if (col >= goal) return pos;
|
| 8155 |
+
}
|
| 8156 |
+
}
|
| 8157 |
+
|
| 8158 |
+
var spaceStrs = [""];
|
| 8159 |
+
function spaceStr(n) {
|
| 8160 |
+
while (spaceStrs.length <= n)
|
| 8161 |
+
spaceStrs.push(lst(spaceStrs) + " ");
|
| 8162 |
+
return spaceStrs[n];
|
| 8163 |
+
}
|
| 8164 |
+
|
| 8165 |
+
function lst(arr) { return arr[arr.length-1]; }
|
| 8166 |
+
|
| 8167 |
+
var selectInput = function(node) { node.select(); };
|
| 8168 |
+
if (ios) // Mobile Safari apparently has a bug where select() is broken.
|
| 8169 |
+
selectInput = function(node) { node.selectionStart = 0; node.selectionEnd = node.value.length; };
|
| 8170 |
+
else if (ie) // Suppress mysterious IE10 errors
|
| 8171 |
+
selectInput = function(node) { try { node.select(); } catch(_e) {} };
|
| 8172 |
+
|
| 8173 |
+
function indexOf(array, elt) {
|
| 8174 |
+
for (var i = 0; i < array.length; ++i)
|
| 8175 |
+
if (array[i] == elt) return i;
|
| 8176 |
+
return -1;
|
| 8177 |
+
}
|
| 8178 |
+
function map(array, f) {
|
| 8179 |
+
var out = [];
|
| 8180 |
+
for (var i = 0; i < array.length; i++) out[i] = f(array[i], i);
|
| 8181 |
+
return out;
|
| 8182 |
+
}
|
| 8183 |
+
|
| 8184 |
+
function nothing() {}
|
| 8185 |
+
|
| 8186 |
+
function createObj(base, props) {
|
| 8187 |
+
var inst;
|
| 8188 |
+
if (Object.create) {
|
| 8189 |
+
inst = Object.create(base);
|
| 8190 |
+
} else {
|
| 8191 |
+
nothing.prototype = base;
|
| 8192 |
+
inst = new nothing();
|
| 8193 |
+
}
|
| 8194 |
+
if (props) copyObj(props, inst);
|
| 8195 |
+
return inst;
|
| 8196 |
+
};
|
| 8197 |
+
|
| 8198 |
+
function copyObj(obj, target, overwrite) {
|
| 8199 |
+
if (!target) target = {};
|
| 8200 |
+
for (var prop in obj)
|
| 8201 |
+
if (obj.hasOwnProperty(prop) && (overwrite !== false || !target.hasOwnProperty(prop)))
|
| 8202 |
+
target[prop] = obj[prop];
|
| 8203 |
+
return target;
|
| 8204 |
+
}
|
| 8205 |
+
|
| 8206 |
+
function bind(f) {
|
| 8207 |
+
var args = Array.prototype.slice.call(arguments, 1);
|
| 8208 |
+
return function(){return f.apply(null, args);};
|
| 8209 |
+
}
|
| 8210 |
+
|
| 8211 |
+
var nonASCIISingleCaseWordChar = /[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;
|
| 8212 |
+
var isWordCharBasic = CodeMirror.isWordChar = function(ch) {
|
| 8213 |
+
return /\w/.test(ch) || ch > "\x80" &&
|
| 8214 |
+
(ch.toUpperCase() != ch.toLowerCase() || nonASCIISingleCaseWordChar.test(ch));
|
| 8215 |
+
};
|
| 8216 |
+
function isWordChar(ch, helper) {
|
| 8217 |
+
if (!helper) return isWordCharBasic(ch);
|
| 8218 |
+
if (helper.source.indexOf("\\w") > -1 && isWordCharBasic(ch)) return true;
|
| 8219 |
+
return helper.test(ch);
|
| 8220 |
+
}
|
| 8221 |
+
|
| 8222 |
+
function isEmpty(obj) {
|
| 8223 |
+
for (var n in obj) if (obj.hasOwnProperty(n) && obj[n]) return false;
|
| 8224 |
+
return true;
|
| 8225 |
+
}
|
| 8226 |
+
|
| 8227 |
+
// Extending unicode characters. A series of a non-extending char +
|
| 8228 |
+
// any number of extending chars is treated as a single unit as far
|
| 8229 |
+
// as editing and measuring is concerned. This is not fully correct,
|
| 8230 |
+
// since some scripts/fonts/browsers also treat other configurations
|
| 8231 |
+
// of code points as a group.
|
| 8232 |
+
var extendingChars = /[\u0300-\u036f\u0483-\u0489\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u065e\u0670\u06d6-\u06dc\u06de-\u06e4\u06e7\u06e8\u06ea-\u06ed\u0711\u0730-\u074a\u07a6-\u07b0\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0900-\u0902\u093c\u0941-\u0948\u094d\u0951-\u0955\u0962\u0963\u0981\u09bc\u09be\u09c1-\u09c4\u09cd\u09d7\u09e2\u09e3\u0a01\u0a02\u0a3c\u0a41\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a70\u0a71\u0a75\u0a81\u0a82\u0abc\u0ac1-\u0ac5\u0ac7\u0ac8\u0acd\u0ae2\u0ae3\u0b01\u0b3c\u0b3e\u0b3f\u0b41-\u0b44\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b82\u0bbe\u0bc0\u0bcd\u0bd7\u0c3e-\u0c40\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0cbc\u0cbf\u0cc2\u0cc6\u0ccc\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0d3e\u0d41-\u0d44\u0d4d\u0d57\u0d62\u0d63\u0dca\u0dcf\u0dd2-\u0dd4\u0dd6\u0ddf\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0f18\u0f19\u0f35\u0f37\u0f39\u0f71-\u0f7e\u0f80-\u0f84\u0f86\u0f87\u0f90-\u0f97\u0f99-\u0fbc\u0fc6\u102d-\u1030\u1032-\u1037\u1039\u103a\u103d\u103e\u1058\u1059\u105e-\u1060\u1071-\u1074\u1082\u1085\u1086\u108d\u109d\u135f\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b7-\u17bd\u17c6\u17c9-\u17d3\u17dd\u180b-\u180d\u18a9\u1920-\u1922\u1927\u1928\u1932\u1939-\u193b\u1a17\u1a18\u1a56\u1a58-\u1a5e\u1a60\u1a62\u1a65-\u1a6c\u1a73-\u1a7c\u1a7f\u1b00-\u1b03\u1b34\u1b36-\u1b3a\u1b3c\u1b42\u1b6b-\u1b73\u1b80\u1b81\u1ba2-\u1ba5\u1ba8\u1ba9\u1c2c-\u1c33\u1c36\u1c37\u1cd0-\u1cd2\u1cd4-\u1ce0\u1ce2-\u1ce8\u1ced\u1dc0-\u1de6\u1dfd-\u1dff\u200c\u200d\u20d0-\u20f0\u2cef-\u2cf1\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua66f-\ua672\ua67c\ua67d\ua6f0\ua6f1\ua802\ua806\ua80b\ua825\ua826\ua8c4\ua8e0-\ua8f1\ua926-\ua92d\ua947-\ua951\ua980-\ua982\ua9b3\ua9b6-\ua9b9\ua9bc\uaa29-\uaa2e\uaa31\uaa32\uaa35\uaa36\uaa43\uaa4c\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uabe5\uabe8\uabed\udc00-\udfff\ufb1e\ufe00-\ufe0f\ufe20-\ufe26\uff9e\uff9f]/;
|
| 8233 |
+
function isExtendingChar(ch) { return ch.charCodeAt(0) >= 768 && extendingChars.test(ch); }
|
| 8234 |
+
|
| 8235 |
+
// DOM UTILITIES
|
| 8236 |
+
|
| 8237 |
+
function elt(tag, content, className, style) {
|
| 8238 |
+
var e = document.createElement(tag);
|
| 8239 |
+
if (className) e.className = className;
|
| 8240 |
+
if (style) e.style.cssText = style;
|
| 8241 |
+
if (typeof content == "string") e.appendChild(document.createTextNode(content));
|
| 8242 |
+
else if (content) for (var i = 0; i < content.length; ++i) e.appendChild(content[i]);
|
| 8243 |
+
return e;
|
| 8244 |
+
}
|
| 8245 |
+
|
| 8246 |
+
var range;
|
| 8247 |
+
if (document.createRange) range = function(node, start, end, endNode) {
|
| 8248 |
+
var r = document.createRange();
|
| 8249 |
+
r.setEnd(endNode || node, end);
|
| 8250 |
+
r.setStart(node, start);
|
| 8251 |
+
return r;
|
| 8252 |
+
};
|
| 8253 |
+
else range = function(node, start, end) {
|
| 8254 |
+
var r = document.body.createTextRange();
|
| 8255 |
+
try { r.moveToElementText(node.parentNode); }
|
| 8256 |
+
catch(e) { return r; }
|
| 8257 |
+
r.collapse(true);
|
| 8258 |
+
r.moveEnd("character", end);
|
| 8259 |
+
r.moveStart("character", start);
|
| 8260 |
+
return r;
|
| 8261 |
+
};
|
| 8262 |
+
|
| 8263 |
+
function removeChildren(e) {
|
| 8264 |
+
for (var count = e.childNodes.length; count > 0; --count)
|
| 8265 |
+
e.removeChild(e.firstChild);
|
| 8266 |
+
return e;
|
| 8267 |
+
}
|
| 8268 |
+
|
| 8269 |
+
function removeChildrenAndAdd(parent, e) {
|
| 8270 |
+
return removeChildren(parent).appendChild(e);
|
| 8271 |
+
}
|
| 8272 |
+
|
| 8273 |
+
var contains = CodeMirror.contains = function(parent, child) {
|
| 8274 |
+
if (child.nodeType == 3) // Android browser always returns false when child is a textnode
|
| 8275 |
+
child = child.parentNode;
|
| 8276 |
+
if (parent.contains)
|
| 8277 |
+
return parent.contains(child);
|
| 8278 |
+
do {
|
| 8279 |
+
if (child.nodeType == 11) child = child.host;
|
| 8280 |
+
if (child == parent) return true;
|
| 8281 |
+
} while (child = child.parentNode);
|
| 8282 |
+
};
|
| 8283 |
+
|
| 8284 |
+
function activeElt() { return document.activeElement; }
|
| 8285 |
+
// Older versions of IE throws unspecified error when touching
|
| 8286 |
+
// document.activeElement in some cases (during loading, in iframe)
|
| 8287 |
+
if (ie && ie_version < 11) activeElt = function() {
|
| 8288 |
+
try { return document.activeElement; }
|
| 8289 |
+
catch(e) { return document.body; }
|
| 8290 |
+
};
|
| 8291 |
+
|
| 8292 |
+
function classTest(cls) { return new RegExp("(^|\\s)" + cls + "(?:$|\\s)\\s*"); }
|
| 8293 |
+
var rmClass = CodeMirror.rmClass = function(node, cls) {
|
| 8294 |
+
var current = node.className;
|
| 8295 |
+
var match = classTest(cls).exec(current);
|
| 8296 |
+
if (match) {
|
| 8297 |
+
var after = current.slice(match.index + match[0].length);
|
| 8298 |
+
node.className = current.slice(0, match.index) + (after ? match[1] + after : "");
|
| 8299 |
+
}
|
| 8300 |
+
};
|
| 8301 |
+
var addClass = CodeMirror.addClass = function(node, cls) {
|
| 8302 |
+
var current = node.className;
|
| 8303 |
+
if (!classTest(cls).test(current)) node.className += (current ? " " : "") + cls;
|
| 8304 |
+
};
|
| 8305 |
+
function joinClasses(a, b) {
|
| 8306 |
+
var as = a.split(" ");
|
| 8307 |
+
for (var i = 0; i < as.length; i++)
|
| 8308 |
+
if (as[i] && !classTest(as[i]).test(b)) b += " " + as[i];
|
| 8309 |
+
return b;
|
| 8310 |
+
}
|
| 8311 |
+
|
| 8312 |
+
// WINDOW-WIDE EVENTS
|
| 8313 |
+
|
| 8314 |
+
// These must be handled carefully, because naively registering a
|
| 8315 |
+
// handler for each editor will cause the editors to never be
|
| 8316 |
+
// garbage collected.
|
| 8317 |
+
|
| 8318 |
+
function forEachCodeMirror(f) {
|
| 8319 |
+
if (!document.body.getElementsByClassName) return;
|
| 8320 |
+
var byClass = document.body.getElementsByClassName("CodeMirror");
|
| 8321 |
+
for (var i = 0; i < byClass.length; i++) {
|
| 8322 |
+
var cm = byClass[i].CodeMirror;
|
| 8323 |
+
if (cm) f(cm);
|
| 8324 |
+
}
|
| 8325 |
+
}
|
| 8326 |
+
|
| 8327 |
+
var globalsRegistered = false;
|
| 8328 |
+
function ensureGlobalHandlers() {
|
| 8329 |
+
if (globalsRegistered) return;
|
| 8330 |
+
registerGlobalHandlers();
|
| 8331 |
+
globalsRegistered = true;
|
| 8332 |
+
}
|
| 8333 |
+
function registerGlobalHandlers() {
|
| 8334 |
+
// When the window resizes, we need to refresh active editors.
|
| 8335 |
+
var resizeTimer;
|
| 8336 |
+
on(window, "resize", function() {
|
| 8337 |
+
if (resizeTimer == null) resizeTimer = setTimeout(function() {
|
| 8338 |
+
resizeTimer = null;
|
| 8339 |
+
forEachCodeMirror(onResize);
|
| 8340 |
+
}, 100);
|
| 8341 |
+
});
|
| 8342 |
+
// When the window loses focus, we want to show the editor as blurred
|
| 8343 |
+
on(window, "blur", function() {
|
| 8344 |
+
forEachCodeMirror(onBlur);
|
| 8345 |
+
});
|
| 8346 |
+
}
|
| 8347 |
+
|
| 8348 |
+
// FEATURE DETECTION
|
| 8349 |
+
|
| 8350 |
+
// Detect drag-and-drop
|
| 8351 |
+
var dragAndDrop = function() {
|
| 8352 |
+
// There is *some* kind of drag-and-drop support in IE6-8, but I
|
| 8353 |
+
// couldn't get it to work yet.
|
| 8354 |
+
if (ie && ie_version < 9) return false;
|
| 8355 |
+
var div = elt('div');
|
| 8356 |
+
return "draggable" in div || "dragDrop" in div;
|
| 8357 |
+
}();
|
| 8358 |
+
|
| 8359 |
+
var zwspSupported;
|
| 8360 |
+
function zeroWidthElement(measure) {
|
| 8361 |
+
if (zwspSupported == null) {
|
| 8362 |
+
var test = elt("span", "\u200b");
|
| 8363 |
+
removeChildrenAndAdd(measure, elt("span", [test, document.createTextNode("x")]));
|
| 8364 |
+
if (measure.firstChild.offsetHeight != 0)
|
| 8365 |
+
zwspSupported = test.offsetWidth <= 1 && test.offsetHeight > 2 && !(ie && ie_version < 8);
|
| 8366 |
+
}
|
| 8367 |
+
var node = zwspSupported ? elt("span", "\u200b") :
|
| 8368 |
+
elt("span", "\u00a0", null, "display: inline-block; width: 1px; margin-right: -1px");
|
| 8369 |
+
node.setAttribute("cm-text", "");
|
| 8370 |
+
return node;
|
| 8371 |
+
}
|
| 8372 |
+
|
| 8373 |
+
// Feature-detect IE's crummy client rect reporting for bidi text
|
| 8374 |
+
var badBidiRects;
|
| 8375 |
+
function hasBadBidiRects(measure) {
|
| 8376 |
+
if (badBidiRects != null) return badBidiRects;
|
| 8377 |
+
var txt = removeChildrenAndAdd(measure, document.createTextNode("A\u062eA"));
|
| 8378 |
+
var r0 = range(txt, 0, 1).getBoundingClientRect();
|
| 8379 |
+
if (!r0 || r0.left == r0.right) return false; // Safari returns null in some cases (#2780)
|
| 8380 |
+
var r1 = range(txt, 1, 2).getBoundingClientRect();
|
| 8381 |
+
return badBidiRects = (r1.right - r0.right < 3);
|
| 8382 |
+
}
|
| 8383 |
+
|
| 8384 |
+
// See if "".split is the broken IE version, if so, provide an
|
| 8385 |
+
// alternative way to split lines.
|
| 8386 |
+
var splitLines = CodeMirror.splitLines = "\n\nb".split(/\n/).length != 3 ? function(string) {
|
| 8387 |
+
var pos = 0, result = [], l = string.length;
|
| 8388 |
+
while (pos <= l) {
|
| 8389 |
+
var nl = string.indexOf("\n", pos);
|
| 8390 |
+
if (nl == -1) nl = string.length;
|
| 8391 |
+
var line = string.slice(pos, string.charAt(nl - 1) == "\r" ? nl - 1 : nl);
|
| 8392 |
+
var rt = line.indexOf("\r");
|
| 8393 |
+
if (rt != -1) {
|
| 8394 |
+
result.push(line.slice(0, rt));
|
| 8395 |
+
pos += rt + 1;
|
| 8396 |
+
} else {
|
| 8397 |
+
result.push(line);
|
| 8398 |
+
pos = nl + 1;
|
| 8399 |
+
}
|
| 8400 |
+
}
|
| 8401 |
+
return result;
|
| 8402 |
+
} : function(string){return string.split(/\r\n?|\n/);};
|
| 8403 |
+
|
| 8404 |
+
var hasSelection = window.getSelection ? function(te) {
|
| 8405 |
+
try { return te.selectionStart != te.selectionEnd; }
|
| 8406 |
+
catch(e) { return false; }
|
| 8407 |
+
} : function(te) {
|
| 8408 |
+
try {var range = te.ownerDocument.selection.createRange();}
|
| 8409 |
+
catch(e) {}
|
| 8410 |
+
if (!range || range.parentElement() != te) return false;
|
| 8411 |
+
return range.compareEndPoints("StartToEnd", range) != 0;
|
| 8412 |
+
};
|
| 8413 |
+
|
| 8414 |
+
var hasCopyEvent = (function() {
|
| 8415 |
+
var e = elt("div");
|
| 8416 |
+
if ("oncopy" in e) return true;
|
| 8417 |
+
e.setAttribute("oncopy", "return;");
|
| 8418 |
+
return typeof e.oncopy == "function";
|
| 8419 |
+
})();
|
| 8420 |
+
|
| 8421 |
+
var badZoomedRects = null;
|
| 8422 |
+
function hasBadZoomedRects(measure) {
|
| 8423 |
+
if (badZoomedRects != null) return badZoomedRects;
|
| 8424 |
+
var node = removeChildrenAndAdd(measure, elt("span", "x"));
|
| 8425 |
+
var normal = node.getBoundingClientRect();
|
| 8426 |
+
var fromRange = range(node, 0, 1).getBoundingClientRect();
|
| 8427 |
+
return badZoomedRects = Math.abs(normal.left - fromRange.left) > 1;
|
| 8428 |
+
}
|
| 8429 |
+
|
| 8430 |
+
// KEY NAMES
|
| 8431 |
+
|
| 8432 |
+
var keyNames = {3: "Enter", 8: "Backspace", 9: "Tab", 13: "Enter", 16: "Shift", 17: "Ctrl", 18: "Alt",
|
| 8433 |
+
19: "Pause", 20: "CapsLock", 27: "Esc", 32: "Space", 33: "PageUp", 34: "PageDown", 35: "End",
|
| 8434 |
+
36: "Home", 37: "Left", 38: "Up", 39: "Right", 40: "Down", 44: "PrintScrn", 45: "Insert",
|
| 8435 |
+
46: "Delete", 59: ";", 61: "=", 91: "Mod", 92: "Mod", 93: "Mod", 107: "=", 109: "-", 127: "Delete",
|
| 8436 |
+
173: "-", 186: ";", 187: "=", 188: ",", 189: "-", 190: ".", 191: "/", 192: "`", 219: "[", 220: "\\",
|
| 8437 |
+
221: "]", 222: "'", 63232: "Up", 63233: "Down", 63234: "Left", 63235: "Right", 63272: "Delete",
|
| 8438 |
+
63273: "Home", 63275: "End", 63276: "PageUp", 63277: "PageDown", 63302: "Insert"};
|
| 8439 |
+
CodeMirror.keyNames = keyNames;
|
| 8440 |
+
(function() {
|
| 8441 |
+
// Number keys
|
| 8442 |
+
for (var i = 0; i < 10; i++) keyNames[i + 48] = keyNames[i + 96] = String(i);
|
| 8443 |
+
// Alphabetic keys
|
| 8444 |
+
for (var i = 65; i <= 90; i++) keyNames[i] = String.fromCharCode(i);
|
| 8445 |
+
// Function keys
|
| 8446 |
+
for (var i = 1; i <= 12; i++) keyNames[i + 111] = keyNames[i + 63235] = "F" + i;
|
| 8447 |
+
})();
|
| 8448 |
+
|
| 8449 |
+
// BIDI HELPERS
|
| 8450 |
+
|
| 8451 |
+
function iterateBidiSections(order, from, to, f) {
|
| 8452 |
+
if (!order) return f(from, to, "ltr");
|
| 8453 |
+
var found = false;
|
| 8454 |
+
for (var i = 0; i < order.length; ++i) {
|
| 8455 |
+
var part = order[i];
|
| 8456 |
+
if (part.from < to && part.to > from || from == to && part.to == from) {
|
| 8457 |
+
f(Math.max(part.from, from), Math.min(part.to, to), part.level == 1 ? "rtl" : "ltr");
|
| 8458 |
+
found = true;
|
| 8459 |
+
}
|
| 8460 |
+
}
|
| 8461 |
+
if (!found) f(from, to, "ltr");
|
| 8462 |
+
}
|
| 8463 |
+
|
| 8464 |
+
function bidiLeft(part) { return part.level % 2 ? part.to : part.from; }
|
| 8465 |
+
function bidiRight(part) { return part.level % 2 ? part.from : part.to; }
|
| 8466 |
+
|
| 8467 |
+
function lineLeft(line) { var order = getOrder(line); return order ? bidiLeft(order[0]) : 0; }
|
| 8468 |
+
function lineRight(line) {
|
| 8469 |
+
var order = getOrder(line);
|
| 8470 |
+
if (!order) return line.text.length;
|
| 8471 |
+
return bidiRight(lst(order));
|
| 8472 |
+
}
|
| 8473 |
+
|
| 8474 |
+
function lineStart(cm, lineN) {
|
| 8475 |
+
var line = getLine(cm.doc, lineN);
|
| 8476 |
+
var visual = visualLine(line);
|
| 8477 |
+
if (visual != line) lineN = lineNo(visual);
|
| 8478 |
+
var order = getOrder(visual);
|
| 8479 |
+
var ch = !order ? 0 : order[0].level % 2 ? lineRight(visual) : lineLeft(visual);
|
| 8480 |
+
return Pos(lineN, ch);
|
| 8481 |
+
}
|
| 8482 |
+
function lineEnd(cm, lineN) {
|
| 8483 |
+
var merged, line = getLine(cm.doc, lineN);
|
| 8484 |
+
while (merged = collapsedSpanAtEnd(line)) {
|
| 8485 |
+
line = merged.find(1, true).line;
|
| 8486 |
+
lineN = null;
|
| 8487 |
+
}
|
| 8488 |
+
var order = getOrder(line);
|
| 8489 |
+
var ch = !order ? line.text.length : order[0].level % 2 ? lineLeft(line) : lineRight(line);
|
| 8490 |
+
return Pos(lineN == null ? lineNo(line) : lineN, ch);
|
| 8491 |
+
}
|
| 8492 |
+
function lineStartSmart(cm, pos) {
|
| 8493 |
+
var start = lineStart(cm, pos.line);
|
| 8494 |
+
var line = getLine(cm.doc, start.line);
|
| 8495 |
+
var order = getOrder(line);
|
| 8496 |
+
if (!order || order[0].level == 0) {
|
| 8497 |
+
var firstNonWS = Math.max(0, line.text.search(/\S/));
|
| 8498 |
+
var inWS = pos.line == start.line && pos.ch <= firstNonWS && pos.ch;
|
| 8499 |
+
return Pos(start.line, inWS ? 0 : firstNonWS);
|
| 8500 |
+
}
|
| 8501 |
+
return start;
|
| 8502 |
+
}
|
| 8503 |
+
|
| 8504 |
+
function compareBidiLevel(order, a, b) {
|
| 8505 |
+
var linedir = order[0].level;
|
| 8506 |
+
if (a == linedir) return true;
|
| 8507 |
+
if (b == linedir) return false;
|
| 8508 |
+
return a < b;
|
| 8509 |
+
}
|
| 8510 |
+
var bidiOther;
|
| 8511 |
+
function getBidiPartAt(order, pos) {
|
| 8512 |
+
bidiOther = null;
|
| 8513 |
+
for (var i = 0, found; i < order.length; ++i) {
|
| 8514 |
+
var cur = order[i];
|
| 8515 |
+
if (cur.from < pos && cur.to > pos) return i;
|
| 8516 |
+
if ((cur.from == pos || cur.to == pos)) {
|
| 8517 |
+
if (found == null) {
|
| 8518 |
+
found = i;
|
| 8519 |
+
} else if (compareBidiLevel(order, cur.level, order[found].level)) {
|
| 8520 |
+
if (cur.from != cur.to) bidiOther = found;
|
| 8521 |
+
return i;
|
| 8522 |
+
} else {
|
| 8523 |
+
if (cur.from != cur.to) bidiOther = i;
|
| 8524 |
+
return found;
|
| 8525 |
+
}
|
| 8526 |
+
}
|
| 8527 |
+
}
|
| 8528 |
+
return found;
|
| 8529 |
+
}
|
| 8530 |
+
|
| 8531 |
+
function moveInLine(line, pos, dir, byUnit) {
|
| 8532 |
+
if (!byUnit) return pos + dir;
|
| 8533 |
+
do pos += dir;
|
| 8534 |
+
while (pos > 0 && isExtendingChar(line.text.charAt(pos)));
|
| 8535 |
+
return pos;
|
| 8536 |
+
}
|
| 8537 |
+
|
| 8538 |
+
// This is needed in order to move 'visually' through bi-directional
|
| 8539 |
+
// text -- i.e., pressing left should make the cursor go left, even
|
| 8540 |
+
// when in RTL text. The tricky part is the 'jumps', where RTL and
|
| 8541 |
+
// LTR text touch each other. This often requires the cursor offset
|
| 8542 |
+
// to move more than one unit, in order to visually move one unit.
|
| 8543 |
+
function moveVisually(line, start, dir, byUnit) {
|
| 8544 |
+
var bidi = getOrder(line);
|
| 8545 |
+
if (!bidi) return moveLogically(line, start, dir, byUnit);
|
| 8546 |
+
var pos = getBidiPartAt(bidi, start), part = bidi[pos];
|
| 8547 |
+
var target = moveInLine(line, start, part.level % 2 ? -dir : dir, byUnit);
|
| 8548 |
+
|
| 8549 |
+
for (;;) {
|
| 8550 |
+
if (target > part.from && target < part.to) return target;
|
| 8551 |
+
if (target == part.from || target == part.to) {
|
| 8552 |
+
if (getBidiPartAt(bidi, target) == pos) return target;
|
| 8553 |
+
part = bidi[pos += dir];
|
| 8554 |
+
return (dir > 0) == part.level % 2 ? part.to : part.from;
|
| 8555 |
+
} else {
|
| 8556 |
+
part = bidi[pos += dir];
|
| 8557 |
+
if (!part) return null;
|
| 8558 |
+
if ((dir > 0) == part.level % 2)
|
| 8559 |
+
target = moveInLine(line, part.to, -1, byUnit);
|
| 8560 |
+
else
|
| 8561 |
+
target = moveInLine(line, part.from, 1, byUnit);
|
| 8562 |
+
}
|
| 8563 |
+
}
|
| 8564 |
+
}
|
| 8565 |
+
|
| 8566 |
+
function moveLogically(line, start, dir, byUnit) {
|
| 8567 |
+
var target = start + dir;
|
| 8568 |
+
if (byUnit) while (target > 0 && isExtendingChar(line.text.charAt(target))) target += dir;
|
| 8569 |
+
return target < 0 || target > line.text.length ? null : target;
|
| 8570 |
+
}
|
| 8571 |
+
|
| 8572 |
+
// Bidirectional ordering algorithm
|
| 8573 |
+
// See http://unicode.org/reports/tr9/tr9-13.html for the algorithm
|
| 8574 |
+
// that this (partially) implements.
|
| 8575 |
+
|
| 8576 |
+
// One-char codes used for character types:
|
| 8577 |
+
// L (L): Left-to-Right
|
| 8578 |
+
// R (R): Right-to-Left
|
| 8579 |
+
// r (AL): Right-to-Left Arabic
|
| 8580 |
+
// 1 (EN): European Number
|
| 8581 |
+
// + (ES): European Number Separator
|
| 8582 |
+
// % (ET): European Number Terminator
|
| 8583 |
+
// n (AN): Arabic Number
|
| 8584 |
+
// , (CS): Common Number Separator
|
| 8585 |
+
// m (NSM): Non-Spacing Mark
|
| 8586 |
+
// b (BN): Boundary Neutral
|
| 8587 |
+
// s (B): Paragraph Separator
|
| 8588 |
+
// t (S): Segment Separator
|
| 8589 |
+
// w (WS): Whitespace
|
| 8590 |
+
// N (ON): Other Neutrals
|
| 8591 |
+
|
| 8592 |
+
// Returns null if characters are ordered as they appear
|
| 8593 |
+
// (left-to-right), or an array of sections ({from, to, level}
|
| 8594 |
+
// objects) in the order in which they occur visually.
|
| 8595 |
+
var bidiOrdering = (function() {
|
| 8596 |
+
// Character types for codepoints 0 to 0xff
|
| 8597 |
+
var lowTypes = "bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLN";
|
| 8598 |
+
// Character types for codepoints 0x600 to 0x6ff
|
| 8599 |
+
var arabicTypes = "rrrrrrrrrrrr,rNNmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmrrrrrrrnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmNmmmm";
|
| 8600 |
+
function charType(code) {
|
| 8601 |
+
if (code <= 0xf7) return lowTypes.charAt(code);
|
| 8602 |
+
else if (0x590 <= code && code <= 0x5f4) return "R";
|
| 8603 |
+
else if (0x600 <= code && code <= 0x6ed) return arabicTypes.charAt(code - 0x600);
|
| 8604 |
+
else if (0x6ee <= code && code <= 0x8ac) return "r";
|
| 8605 |
+
else if (0x2000 <= code && code <= 0x200b) return "w";
|
| 8606 |
+
else if (code == 0x200c) return "b";
|
| 8607 |
+
else return "L";
|
| 8608 |
+
}
|
| 8609 |
+
|
| 8610 |
+
var bidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;
|
| 8611 |
+
var isNeutral = /[stwN]/, isStrong = /[LRr]/, countsAsLeft = /[Lb1n]/, countsAsNum = /[1n]/;
|
| 8612 |
+
// Browsers seem to always treat the boundaries of block elements as being L.
|
| 8613 |
+
var outerType = "L";
|
| 8614 |
+
|
| 8615 |
+
function BidiSpan(level, from, to) {
|
| 8616 |
+
this.level = level;
|
| 8617 |
+
this.from = from; this.to = to;
|
| 8618 |
+
}
|
| 8619 |
+
|
| 8620 |
+
return function(str) {
|
| 8621 |
+
if (!bidiRE.test(str)) return false;
|
| 8622 |
+
var len = str.length, types = [];
|
| 8623 |
+
for (var i = 0, type; i < len; ++i)
|
| 8624 |
+
types.push(type = charType(str.charCodeAt(i)));
|
| 8625 |
+
|
| 8626 |
+
// W1. Examine each non-spacing mark (NSM) in the level run, and
|
| 8627 |
+
// change the type of the NSM to the type of the previous
|
| 8628 |
+
// character. If the NSM is at the start of the level run, it will
|
| 8629 |
+
// get the type of sor.
|
| 8630 |
+
for (var i = 0, prev = outerType; i < len; ++i) {
|
| 8631 |
+
var type = types[i];
|
| 8632 |
+
if (type == "m") types[i] = prev;
|
| 8633 |
+
else prev = type;
|
| 8634 |
+
}
|
| 8635 |
+
|
| 8636 |
+
// W2. Search backwards from each instance of a European number
|
| 8637 |
+
// until the first strong type (R, L, AL, or sor) is found. If an
|
| 8638 |
+
// AL is found, change the type of the European number to Arabic
|
| 8639 |
+
// number.
|
| 8640 |
+
// W3. Change all ALs to R.
|
| 8641 |
+
for (var i = 0, cur = outerType; i < len; ++i) {
|
| 8642 |
+
var type = types[i];
|
| 8643 |
+
if (type == "1" && cur == "r") types[i] = "n";
|
| 8644 |
+
else if (isStrong.test(type)) { cur = type; if (type == "r") types[i] = "R"; }
|
| 8645 |
+
}
|
| 8646 |
+
|
| 8647 |
+
// W4. A single European separator between two European numbers
|
| 8648 |
+
// changes to a European number. A single common separator between
|
| 8649 |
+
// two numbers of the same type changes to that type.
|
| 8650 |
+
for (var i = 1, prev = types[0]; i < len - 1; ++i) {
|
| 8651 |
+
var type = types[i];
|
| 8652 |
+
if (type == "+" && prev == "1" && types[i+1] == "1") types[i] = "1";
|
| 8653 |
+
else if (type == "," && prev == types[i+1] &&
|
| 8654 |
+
(prev == "1" || prev == "n")) types[i] = prev;
|
| 8655 |
+
prev = type;
|
| 8656 |
+
}
|
| 8657 |
+
|
| 8658 |
+
// W5. A sequence of European terminators adjacent to European
|
| 8659 |
+
// numbers changes to all European numbers.
|
| 8660 |
+
// W6. Otherwise, separators and terminators change to Other
|
| 8661 |
+
// Neutral.
|
| 8662 |
+
for (var i = 0; i < len; ++i) {
|
| 8663 |
+
var type = types[i];
|
| 8664 |
+
if (type == ",") types[i] = "N";
|
| 8665 |
+
else if (type == "%") {
|
| 8666 |
+
for (var end = i + 1; end < len && types[end] == "%"; ++end) {}
|
| 8667 |
+
var replace = (i && types[i-1] == "!") || (end < len && types[end] == "1") ? "1" : "N";
|
| 8668 |
+
for (var j = i; j < end; ++j) types[j] = replace;
|
| 8669 |
+
i = end - 1;
|
| 8670 |
+
}
|
| 8671 |
+
}
|
| 8672 |
+
|
| 8673 |
+
// W7. Search backwards from each instance of a European number
|
| 8674 |
+
// until the first strong type (R, L, or sor) is found. If an L is
|
| 8675 |
+
// found, then change the type of the European number to L.
|
| 8676 |
+
for (var i = 0, cur = outerType; i < len; ++i) {
|
| 8677 |
+
var type = types[i];
|
| 8678 |
+
if (cur == "L" && type == "1") types[i] = "L";
|
| 8679 |
+
else if (isStrong.test(type)) cur = type;
|
| 8680 |
+
}
|
| 8681 |
+
|
| 8682 |
+
// N1. A sequence of neutrals takes the direction of the
|
| 8683 |
+
// surrounding strong text if the text on both sides has the same
|
| 8684 |
+
// direction. European and Arabic numbers act as if they were R in
|
| 8685 |
+
// terms of their influence on neutrals. Start-of-level-run (sor)
|
| 8686 |
+
// and end-of-level-run (eor) are used at level run boundaries.
|
| 8687 |
+
// N2. Any remaining neutrals take the embedding direction.
|
| 8688 |
+
for (var i = 0; i < len; ++i) {
|
| 8689 |
+
if (isNeutral.test(types[i])) {
|
| 8690 |
+
for (var end = i + 1; end < len && isNeutral.test(types[end]); ++end) {}
|
| 8691 |
+
var before = (i ? types[i-1] : outerType) == "L";
|
| 8692 |
+
var after = (end < len ? types[end] : outerType) == "L";
|
| 8693 |
+
var replace = before || after ? "L" : "R";
|
| 8694 |
+
for (var j = i; j < end; ++j) types[j] = replace;
|
| 8695 |
+
i = end - 1;
|
| 8696 |
+
}
|
| 8697 |
+
}
|
| 8698 |
+
|
| 8699 |
+
// Here we depart from the documented algorithm, in order to avoid
|
| 8700 |
+
// building up an actual levels array. Since there are only three
|
| 8701 |
+
// levels (0, 1, 2) in an implementation that doesn't take
|
| 8702 |
+
// explicit embedding into account, we can build up the order on
|
| 8703 |
+
// the fly, without following the level-based algorithm.
|
| 8704 |
+
var order = [], m;
|
| 8705 |
+
for (var i = 0; i < len;) {
|
| 8706 |
+
if (countsAsLeft.test(types[i])) {
|
| 8707 |
+
var start = i;
|
| 8708 |
+
for (++i; i < len && countsAsLeft.test(types[i]); ++i) {}
|
| 8709 |
+
order.push(new BidiSpan(0, start, i));
|
| 8710 |
+
} else {
|
| 8711 |
+
var pos = i, at = order.length;
|
| 8712 |
+
for (++i; i < len && types[i] != "L"; ++i) {}
|
| 8713 |
+
for (var j = pos; j < i;) {
|
| 8714 |
+
if (countsAsNum.test(types[j])) {
|
| 8715 |
+
if (pos < j) order.splice(at, 0, new BidiSpan(1, pos, j));
|
| 8716 |
+
var nstart = j;
|
| 8717 |
+
for (++j; j < i && countsAsNum.test(types[j]); ++j) {}
|
| 8718 |
+
order.splice(at, 0, new BidiSpan(2, nstart, j));
|
| 8719 |
+
pos = j;
|
| 8720 |
+
} else ++j;
|
| 8721 |
+
}
|
| 8722 |
+
if (pos < i) order.splice(at, 0, new BidiSpan(1, pos, i));
|
| 8723 |
+
}
|
| 8724 |
+
}
|
| 8725 |
+
if (order[0].level == 1 && (m = str.match(/^\s+/))) {
|
| 8726 |
+
order[0].from = m[0].length;
|
| 8727 |
+
order.unshift(new BidiSpan(0, 0, m[0].length));
|
| 8728 |
+
}
|
| 8729 |
+
if (lst(order).level == 1 && (m = str.match(/\s+$/))) {
|
| 8730 |
+
lst(order).to -= m[0].length;
|
| 8731 |
+
order.push(new BidiSpan(0, len - m[0].length, len));
|
| 8732 |
+
}
|
| 8733 |
+
if (order[0].level == 2)
|
| 8734 |
+
order.unshift(new BidiSpan(1, order[0].to, order[0].to));
|
| 8735 |
+
if (order[0].level != lst(order).level)
|
| 8736 |
+
order.push(new BidiSpan(order[0].level, len, len));
|
| 8737 |
+
|
| 8738 |
+
return order;
|
| 8739 |
+
};
|
| 8740 |
+
})();
|
| 8741 |
+
|
| 8742 |
+
// THE END
|
| 8743 |
+
|
| 8744 |
+
CodeMirror.version = "5.3.1";
|
| 8745 |
+
|
| 8746 |
+
return CodeMirror;
|
| 8747 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/mode/css/css.js
ADDED
|
@@ -0,0 +1,754 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
"use strict";
|
| 13 |
+
|
| 14 |
+
CodeMirror.defineMode("css", function(config, parserConfig) {
|
| 15 |
+
if (!parserConfig.propertyKeywords) parserConfig = CodeMirror.resolveMode("text/css");
|
| 16 |
+
|
| 17 |
+
var indentUnit = config.indentUnit,
|
| 18 |
+
tokenHooks = parserConfig.tokenHooks,
|
| 19 |
+
documentTypes = parserConfig.documentTypes || {},
|
| 20 |
+
mediaTypes = parserConfig.mediaTypes || {},
|
| 21 |
+
mediaFeatures = parserConfig.mediaFeatures || {},
|
| 22 |
+
propertyKeywords = parserConfig.propertyKeywords || {},
|
| 23 |
+
nonStandardPropertyKeywords = parserConfig.nonStandardPropertyKeywords || {},
|
| 24 |
+
fontProperties = parserConfig.fontProperties || {},
|
| 25 |
+
counterDescriptors = parserConfig.counterDescriptors || {},
|
| 26 |
+
colorKeywords = parserConfig.colorKeywords || {},
|
| 27 |
+
valueKeywords = parserConfig.valueKeywords || {},
|
| 28 |
+
allowNested = parserConfig.allowNested;
|
| 29 |
+
|
| 30 |
+
var type, override;
|
| 31 |
+
function ret(style, tp) { type = tp; return style; }
|
| 32 |
+
|
| 33 |
+
// Tokenizers
|
| 34 |
+
|
| 35 |
+
function tokenBase(stream, state) {
|
| 36 |
+
var ch = stream.next();
|
| 37 |
+
if (tokenHooks[ch]) {
|
| 38 |
+
var result = tokenHooks[ch](stream, state);
|
| 39 |
+
if (result !== false) return result;
|
| 40 |
+
}
|
| 41 |
+
if (ch == "@") {
|
| 42 |
+
stream.eatWhile(/[\w\\\-]/);
|
| 43 |
+
return ret("def", stream.current());
|
| 44 |
+
} else if (ch == "=" || (ch == "~" || ch == "|") && stream.eat("=")) {
|
| 45 |
+
return ret(null, "compare");
|
| 46 |
+
} else if (ch == "\"" || ch == "'") {
|
| 47 |
+
state.tokenize = tokenString(ch);
|
| 48 |
+
return state.tokenize(stream, state);
|
| 49 |
+
} else if (ch == "#") {
|
| 50 |
+
stream.eatWhile(/[\w\\\-]/);
|
| 51 |
+
return ret("atom", "hash");
|
| 52 |
+
} else if (ch == "!") {
|
| 53 |
+
stream.match(/^\s*\w*/);
|
| 54 |
+
return ret("keyword", "important");
|
| 55 |
+
} else if (/\d/.test(ch) || ch == "." && stream.eat(/\d/)) {
|
| 56 |
+
stream.eatWhile(/[\w.%]/);
|
| 57 |
+
return ret("number", "unit");
|
| 58 |
+
} else if (ch === "-") {
|
| 59 |
+
if (/[\d.]/.test(stream.peek())) {
|
| 60 |
+
stream.eatWhile(/[\w.%]/);
|
| 61 |
+
return ret("number", "unit");
|
| 62 |
+
} else if (stream.match(/^-[\w\\\-]+/)) {
|
| 63 |
+
stream.eatWhile(/[\w\\\-]/);
|
| 64 |
+
if (stream.match(/^\s*:/, false))
|
| 65 |
+
return ret("variable-2", "variable-definition");
|
| 66 |
+
return ret("variable-2", "variable");
|
| 67 |
+
} else if (stream.match(/^\w+-/)) {
|
| 68 |
+
return ret("meta", "meta");
|
| 69 |
+
}
|
| 70 |
+
} else if (/[,+>*\/]/.test(ch)) {
|
| 71 |
+
return ret(null, "select-op");
|
| 72 |
+
} else if (ch == "." && stream.match(/^-?[_a-z][_a-z0-9-]*/i)) {
|
| 73 |
+
return ret("qualifier", "qualifier");
|
| 74 |
+
} else if (/[:;{}\[\]\(\)]/.test(ch)) {
|
| 75 |
+
return ret(null, ch);
|
| 76 |
+
} else if ((ch == "u" && stream.match(/rl(-prefix)?\(/)) ||
|
| 77 |
+
(ch == "d" && stream.match("omain(")) ||
|
| 78 |
+
(ch == "r" && stream.match("egexp("))) {
|
| 79 |
+
stream.backUp(1);
|
| 80 |
+
state.tokenize = tokenParenthesized;
|
| 81 |
+
return ret("property", "word");
|
| 82 |
+
} else if (/[\w\\\-]/.test(ch)) {
|
| 83 |
+
stream.eatWhile(/[\w\\\-]/);
|
| 84 |
+
return ret("property", "word");
|
| 85 |
+
} else {
|
| 86 |
+
return ret(null, null);
|
| 87 |
+
}
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
function tokenString(quote) {
|
| 91 |
+
return function(stream, state) {
|
| 92 |
+
var escaped = false, ch;
|
| 93 |
+
while ((ch = stream.next()) != null) {
|
| 94 |
+
if (ch == quote && !escaped) {
|
| 95 |
+
if (quote == ")") stream.backUp(1);
|
| 96 |
+
break;
|
| 97 |
+
}
|
| 98 |
+
escaped = !escaped && ch == "\\";
|
| 99 |
+
}
|
| 100 |
+
if (ch == quote || !escaped && quote != ")") state.tokenize = null;
|
| 101 |
+
return ret("string", "string");
|
| 102 |
+
};
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
function tokenParenthesized(stream, state) {
|
| 106 |
+
stream.next(); // Must be '('
|
| 107 |
+
if (!stream.match(/\s*[\"\')]/, false))
|
| 108 |
+
state.tokenize = tokenString(")");
|
| 109 |
+
else
|
| 110 |
+
state.tokenize = null;
|
| 111 |
+
return ret(null, "(");
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
// Context management
|
| 115 |
+
|
| 116 |
+
function Context(type, indent, prev) {
|
| 117 |
+
this.type = type;
|
| 118 |
+
this.indent = indent;
|
| 119 |
+
this.prev = prev;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
function pushContext(state, stream, type) {
|
| 123 |
+
state.context = new Context(type, stream.indentation() + indentUnit, state.context);
|
| 124 |
+
return type;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
function popContext(state) {
|
| 128 |
+
state.context = state.context.prev;
|
| 129 |
+
return state.context.type;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
function pass(type, stream, state) {
|
| 133 |
+
return states[state.context.type](type, stream, state);
|
| 134 |
+
}
|
| 135 |
+
function popAndPass(type, stream, state, n) {
|
| 136 |
+
for (var i = n || 1; i > 0; i--)
|
| 137 |
+
state.context = state.context.prev;
|
| 138 |
+
return pass(type, stream, state);
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
// Parser
|
| 142 |
+
|
| 143 |
+
function wordAsValue(stream) {
|
| 144 |
+
var word = stream.current().toLowerCase();
|
| 145 |
+
if (valueKeywords.hasOwnProperty(word))
|
| 146 |
+
override = "atom";
|
| 147 |
+
else if (colorKeywords.hasOwnProperty(word))
|
| 148 |
+
override = "keyword";
|
| 149 |
+
else
|
| 150 |
+
override = "variable";
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
var states = {};
|
| 154 |
+
|
| 155 |
+
states.top = function(type, stream, state) {
|
| 156 |
+
if (type == "{") {
|
| 157 |
+
return pushContext(state, stream, "block");
|
| 158 |
+
} else if (type == "}" && state.context.prev) {
|
| 159 |
+
return popContext(state);
|
| 160 |
+
} else if (/@(media|supports|(-moz-)?document)/.test(type)) {
|
| 161 |
+
return pushContext(state, stream, "atBlock");
|
| 162 |
+
} else if (/@(font-face|counter-style)/.test(type)) {
|
| 163 |
+
state.stateArg = type;
|
| 164 |
+
return "restricted_atBlock_before";
|
| 165 |
+
} else if (/^@(-(moz|ms|o|webkit)-)?keyframes$/.test(type)) {
|
| 166 |
+
return "keyframes";
|
| 167 |
+
} else if (type && type.charAt(0) == "@") {
|
| 168 |
+
return pushContext(state, stream, "at");
|
| 169 |
+
} else if (type == "hash") {
|
| 170 |
+
override = "builtin";
|
| 171 |
+
} else if (type == "word") {
|
| 172 |
+
override = "tag";
|
| 173 |
+
} else if (type == "variable-definition") {
|
| 174 |
+
return "maybeprop";
|
| 175 |
+
} else if (type == "interpolation") {
|
| 176 |
+
return pushContext(state, stream, "interpolation");
|
| 177 |
+
} else if (type == ":") {
|
| 178 |
+
return "pseudo";
|
| 179 |
+
} else if (allowNested && type == "(") {
|
| 180 |
+
return pushContext(state, stream, "parens");
|
| 181 |
+
}
|
| 182 |
+
return state.context.type;
|
| 183 |
+
};
|
| 184 |
+
|
| 185 |
+
states.block = function(type, stream, state) {
|
| 186 |
+
if (type == "word") {
|
| 187 |
+
var word = stream.current().toLowerCase();
|
| 188 |
+
if (propertyKeywords.hasOwnProperty(word)) {
|
| 189 |
+
override = "property";
|
| 190 |
+
return "maybeprop";
|
| 191 |
+
} else if (nonStandardPropertyKeywords.hasOwnProperty(word)) {
|
| 192 |
+
override = "string-2";
|
| 193 |
+
return "maybeprop";
|
| 194 |
+
} else if (allowNested) {
|
| 195 |
+
override = stream.match(/^\s*:(?:\s|$)/, false) ? "property" : "tag";
|
| 196 |
+
return "block";
|
| 197 |
+
} else {
|
| 198 |
+
override += " error";
|
| 199 |
+
return "maybeprop";
|
| 200 |
+
}
|
| 201 |
+
} else if (type == "meta") {
|
| 202 |
+
return "block";
|
| 203 |
+
} else if (!allowNested && (type == "hash" || type == "qualifier")) {
|
| 204 |
+
override = "error";
|
| 205 |
+
return "block";
|
| 206 |
+
} else {
|
| 207 |
+
return states.top(type, stream, state);
|
| 208 |
+
}
|
| 209 |
+
};
|
| 210 |
+
|
| 211 |
+
states.maybeprop = function(type, stream, state) {
|
| 212 |
+
if (type == ":") return pushContext(state, stream, "prop");
|
| 213 |
+
return pass(type, stream, state);
|
| 214 |
+
};
|
| 215 |
+
|
| 216 |
+
states.prop = function(type, stream, state) {
|
| 217 |
+
if (type == ";") return popContext(state);
|
| 218 |
+
if (type == "{" && allowNested) return pushContext(state, stream, "propBlock");
|
| 219 |
+
if (type == "}" || type == "{") return popAndPass(type, stream, state);
|
| 220 |
+
if (type == "(") return pushContext(state, stream, "parens");
|
| 221 |
+
|
| 222 |
+
if (type == "hash" && !/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(stream.current())) {
|
| 223 |
+
override += " error";
|
| 224 |
+
} else if (type == "word") {
|
| 225 |
+
wordAsValue(stream);
|
| 226 |
+
} else if (type == "interpolation") {
|
| 227 |
+
return pushContext(state, stream, "interpolation");
|
| 228 |
+
}
|
| 229 |
+
return "prop";
|
| 230 |
+
};
|
| 231 |
+
|
| 232 |
+
states.propBlock = function(type, _stream, state) {
|
| 233 |
+
if (type == "}") return popContext(state);
|
| 234 |
+
if (type == "word") { override = "property"; return "maybeprop"; }
|
| 235 |
+
return state.context.type;
|
| 236 |
+
};
|
| 237 |
+
|
| 238 |
+
states.parens = function(type, stream, state) {
|
| 239 |
+
if (type == "{" || type == "}") return popAndPass(type, stream, state);
|
| 240 |
+
if (type == ")") return popContext(state);
|
| 241 |
+
if (type == "(") return pushContext(state, stream, "parens");
|
| 242 |
+
if (type == "interpolation") return pushContext(state, stream, "interpolation");
|
| 243 |
+
if (type == "word") wordAsValue(stream);
|
| 244 |
+
return "parens";
|
| 245 |
+
};
|
| 246 |
+
|
| 247 |
+
states.pseudo = function(type, stream, state) {
|
| 248 |
+
if (type == "word") {
|
| 249 |
+
override = "variable-3";
|
| 250 |
+
return state.context.type;
|
| 251 |
+
}
|
| 252 |
+
return pass(type, stream, state);
|
| 253 |
+
};
|
| 254 |
+
|
| 255 |
+
states.atBlock = function(type, stream, state) {
|
| 256 |
+
if (type == "(") return pushContext(state, stream, "atBlock_parens");
|
| 257 |
+
if (type == "}") return popAndPass(type, stream, state);
|
| 258 |
+
if (type == "{") return popContext(state) && pushContext(state, stream, allowNested ? "block" : "top");
|
| 259 |
+
|
| 260 |
+
if (type == "word") {
|
| 261 |
+
var word = stream.current().toLowerCase();
|
| 262 |
+
if (word == "only" || word == "not" || word == "and" || word == "or")
|
| 263 |
+
override = "keyword";
|
| 264 |
+
else if (documentTypes.hasOwnProperty(word))
|
| 265 |
+
override = "tag";
|
| 266 |
+
else if (mediaTypes.hasOwnProperty(word))
|
| 267 |
+
override = "attribute";
|
| 268 |
+
else if (mediaFeatures.hasOwnProperty(word))
|
| 269 |
+
override = "property";
|
| 270 |
+
else if (propertyKeywords.hasOwnProperty(word))
|
| 271 |
+
override = "property";
|
| 272 |
+
else if (nonStandardPropertyKeywords.hasOwnProperty(word))
|
| 273 |
+
override = "string-2";
|
| 274 |
+
else if (valueKeywords.hasOwnProperty(word))
|
| 275 |
+
override = "atom";
|
| 276 |
+
else
|
| 277 |
+
override = "error";
|
| 278 |
+
}
|
| 279 |
+
return state.context.type;
|
| 280 |
+
};
|
| 281 |
+
|
| 282 |
+
states.atBlock_parens = function(type, stream, state) {
|
| 283 |
+
if (type == ")") return popContext(state);
|
| 284 |
+
if (type == "{" || type == "}") return popAndPass(type, stream, state, 2);
|
| 285 |
+
return states.atBlock(type, stream, state);
|
| 286 |
+
};
|
| 287 |
+
|
| 288 |
+
states.restricted_atBlock_before = function(type, stream, state) {
|
| 289 |
+
if (type == "{")
|
| 290 |
+
return pushContext(state, stream, "restricted_atBlock");
|
| 291 |
+
if (type == "word" && state.stateArg == "@counter-style") {
|
| 292 |
+
override = "variable";
|
| 293 |
+
return "restricted_atBlock_before";
|
| 294 |
+
}
|
| 295 |
+
return pass(type, stream, state);
|
| 296 |
+
};
|
| 297 |
+
|
| 298 |
+
states.restricted_atBlock = function(type, stream, state) {
|
| 299 |
+
if (type == "}") {
|
| 300 |
+
state.stateArg = null;
|
| 301 |
+
return popContext(state);
|
| 302 |
+
}
|
| 303 |
+
if (type == "word") {
|
| 304 |
+
if ((state.stateArg == "@font-face" && !fontProperties.hasOwnProperty(stream.current().toLowerCase())) ||
|
| 305 |
+
(state.stateArg == "@counter-style" && !counterDescriptors.hasOwnProperty(stream.current().toLowerCase())))
|
| 306 |
+
override = "error";
|
| 307 |
+
else
|
| 308 |
+
override = "property";
|
| 309 |
+
return "maybeprop";
|
| 310 |
+
}
|
| 311 |
+
return "restricted_atBlock";
|
| 312 |
+
};
|
| 313 |
+
|
| 314 |
+
states.keyframes = function(type, stream, state) {
|
| 315 |
+
if (type == "word") { override = "variable"; return "keyframes"; }
|
| 316 |
+
if (type == "{") return pushContext(state, stream, "top");
|
| 317 |
+
return pass(type, stream, state);
|
| 318 |
+
};
|
| 319 |
+
|
| 320 |
+
states.at = function(type, stream, state) {
|
| 321 |
+
if (type == ";") return popContext(state);
|
| 322 |
+
if (type == "{" || type == "}") return popAndPass(type, stream, state);
|
| 323 |
+
if (type == "word") override = "tag";
|
| 324 |
+
else if (type == "hash") override = "builtin";
|
| 325 |
+
return "at";
|
| 326 |
+
};
|
| 327 |
+
|
| 328 |
+
states.interpolation = function(type, stream, state) {
|
| 329 |
+
if (type == "}") return popContext(state);
|
| 330 |
+
if (type == "{" || type == ";") return popAndPass(type, stream, state);
|
| 331 |
+
if (type == "word") override = "variable";
|
| 332 |
+
else if (type != "variable" && type != "(" && type != ")") override = "error";
|
| 333 |
+
return "interpolation";
|
| 334 |
+
};
|
| 335 |
+
|
| 336 |
+
return {
|
| 337 |
+
startState: function(base) {
|
| 338 |
+
return {tokenize: null,
|
| 339 |
+
state: "top",
|
| 340 |
+
stateArg: null,
|
| 341 |
+
context: new Context("top", base || 0, null)};
|
| 342 |
+
},
|
| 343 |
+
|
| 344 |
+
token: function(stream, state) {
|
| 345 |
+
if (!state.tokenize && stream.eatSpace()) return null;
|
| 346 |
+
var style = (state.tokenize || tokenBase)(stream, state);
|
| 347 |
+
if (style && typeof style == "object") {
|
| 348 |
+
type = style[1];
|
| 349 |
+
style = style[0];
|
| 350 |
+
}
|
| 351 |
+
override = style;
|
| 352 |
+
state.state = states[state.state](type, stream, state);
|
| 353 |
+
return override;
|
| 354 |
+
},
|
| 355 |
+
|
| 356 |
+
indent: function(state, textAfter) {
|
| 357 |
+
var cx = state.context, ch = textAfter && textAfter.charAt(0);
|
| 358 |
+
var indent = cx.indent;
|
| 359 |
+
if (cx.type == "prop" && (ch == "}" || ch == ")")) cx = cx.prev;
|
| 360 |
+
if (cx.prev &&
|
| 361 |
+
(ch == "}" && (cx.type == "block" || cx.type == "top" || cx.type == "interpolation" || cx.type == "restricted_atBlock") ||
|
| 362 |
+
ch == ")" && (cx.type == "parens" || cx.type == "atBlock_parens") ||
|
| 363 |
+
ch == "{" && (cx.type == "at" || cx.type == "atBlock"))) {
|
| 364 |
+
indent = cx.indent - indentUnit;
|
| 365 |
+
cx = cx.prev;
|
| 366 |
+
}
|
| 367 |
+
return indent;
|
| 368 |
+
},
|
| 369 |
+
|
| 370 |
+
electricChars: "}",
|
| 371 |
+
blockCommentStart: "/*",
|
| 372 |
+
blockCommentEnd: "*/",
|
| 373 |
+
fold: "brace"
|
| 374 |
+
};
|
| 375 |
+
});
|
| 376 |
+
|
| 377 |
+
function keySet(array) {
|
| 378 |
+
var keys = {};
|
| 379 |
+
for (var i = 0; i < array.length; ++i) {
|
| 380 |
+
keys[array[i]] = true;
|
| 381 |
+
}
|
| 382 |
+
return keys;
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
+
var documentTypes_ = [
|
| 386 |
+
"domain", "regexp", "url", "url-prefix"
|
| 387 |
+
], documentTypes = keySet(documentTypes_);
|
| 388 |
+
|
| 389 |
+
var mediaTypes_ = [
|
| 390 |
+
"all", "aural", "braille", "handheld", "print", "projection", "screen",
|
| 391 |
+
"tty", "tv", "embossed"
|
| 392 |
+
], mediaTypes = keySet(mediaTypes_);
|
| 393 |
+
|
| 394 |
+
var mediaFeatures_ = [
|
| 395 |
+
"width", "min-width", "max-width", "height", "min-height", "max-height",
|
| 396 |
+
"device-width", "min-device-width", "max-device-width", "device-height",
|
| 397 |
+
"min-device-height", "max-device-height", "aspect-ratio",
|
| 398 |
+
"min-aspect-ratio", "max-aspect-ratio", "device-aspect-ratio",
|
| 399 |
+
"min-device-aspect-ratio", "max-device-aspect-ratio", "color", "min-color",
|
| 400 |
+
"max-color", "color-index", "min-color-index", "max-color-index",
|
| 401 |
+
"monochrome", "min-monochrome", "max-monochrome", "resolution",
|
| 402 |
+
"min-resolution", "max-resolution", "scan", "grid"
|
| 403 |
+
], mediaFeatures = keySet(mediaFeatures_);
|
| 404 |
+
|
| 405 |
+
var propertyKeywords_ = [
|
| 406 |
+
"align-content", "align-items", "align-self", "alignment-adjust",
|
| 407 |
+
"alignment-baseline", "anchor-point", "animation", "animation-delay",
|
| 408 |
+
"animation-direction", "animation-duration", "animation-fill-mode",
|
| 409 |
+
"animation-iteration-count", "animation-name", "animation-play-state",
|
| 410 |
+
"animation-timing-function", "appearance", "azimuth", "backface-visibility",
|
| 411 |
+
"background", "background-attachment", "background-clip", "background-color",
|
| 412 |
+
"background-image", "background-origin", "background-position",
|
| 413 |
+
"background-repeat", "background-size", "baseline-shift", "binding",
|
| 414 |
+
"bleed", "bookmark-label", "bookmark-level", "bookmark-state",
|
| 415 |
+
"bookmark-target", "border", "border-bottom", "border-bottom-color",
|
| 416 |
+
"border-bottom-left-radius", "border-bottom-right-radius",
|
| 417 |
+
"border-bottom-style", "border-bottom-width", "border-collapse",
|
| 418 |
+
"border-color", "border-image", "border-image-outset",
|
| 419 |
+
"border-image-repeat", "border-image-slice", "border-image-source",
|
| 420 |
+
"border-image-width", "border-left", "border-left-color",
|
| 421 |
+
"border-left-style", "border-left-width", "border-radius", "border-right",
|
| 422 |
+
"border-right-color", "border-right-style", "border-right-width",
|
| 423 |
+
"border-spacing", "border-style", "border-top", "border-top-color",
|
| 424 |
+
"border-top-left-radius", "border-top-right-radius", "border-top-style",
|
| 425 |
+
"border-top-width", "border-width", "bottom", "box-decoration-break",
|
| 426 |
+
"box-shadow", "box-sizing", "break-after", "break-before", "break-inside",
|
| 427 |
+
"caption-side", "clear", "clip", "color", "color-profile", "column-count",
|
| 428 |
+
"column-fill", "column-gap", "column-rule", "column-rule-color",
|
| 429 |
+
"column-rule-style", "column-rule-width", "column-span", "column-width",
|
| 430 |
+
"columns", "content", "counter-increment", "counter-reset", "crop", "cue",
|
| 431 |
+
"cue-after", "cue-before", "cursor", "direction", "display",
|
| 432 |
+
"dominant-baseline", "drop-initial-after-adjust",
|
| 433 |
+
"drop-initial-after-align", "drop-initial-before-adjust",
|
| 434 |
+
"drop-initial-before-align", "drop-initial-size", "drop-initial-value",
|
| 435 |
+
"elevation", "empty-cells", "fit", "fit-position", "flex", "flex-basis",
|
| 436 |
+
"flex-direction", "flex-flow", "flex-grow", "flex-shrink", "flex-wrap",
|
| 437 |
+
"float", "float-offset", "flow-from", "flow-into", "font", "font-feature-settings",
|
| 438 |
+
"font-family", "font-kerning", "font-language-override", "font-size", "font-size-adjust",
|
| 439 |
+
"font-stretch", "font-style", "font-synthesis", "font-variant",
|
| 440 |
+
"font-variant-alternates", "font-variant-caps", "font-variant-east-asian",
|
| 441 |
+
"font-variant-ligatures", "font-variant-numeric", "font-variant-position",
|
| 442 |
+
"font-weight", "grid", "grid-area", "grid-auto-columns", "grid-auto-flow",
|
| 443 |
+
"grid-auto-position", "grid-auto-rows", "grid-column", "grid-column-end",
|
| 444 |
+
"grid-column-start", "grid-row", "grid-row-end", "grid-row-start",
|
| 445 |
+
"grid-template", "grid-template-areas", "grid-template-columns",
|
| 446 |
+
"grid-template-rows", "hanging-punctuation", "height", "hyphens",
|
| 447 |
+
"icon", "image-orientation", "image-rendering", "image-resolution",
|
| 448 |
+
"inline-box-align", "justify-content", "left", "letter-spacing",
|
| 449 |
+
"line-break", "line-height", "line-stacking", "line-stacking-ruby",
|
| 450 |
+
"line-stacking-shift", "line-stacking-strategy", "list-style",
|
| 451 |
+
"list-style-image", "list-style-position", "list-style-type", "margin",
|
| 452 |
+
"margin-bottom", "margin-left", "margin-right", "margin-top",
|
| 453 |
+
"marker-offset", "marks", "marquee-direction", "marquee-loop",
|
| 454 |
+
"marquee-play-count", "marquee-speed", "marquee-style", "max-height",
|
| 455 |
+
"max-width", "min-height", "min-width", "move-to", "nav-down", "nav-index",
|
| 456 |
+
"nav-left", "nav-right", "nav-up", "object-fit", "object-position",
|
| 457 |
+
"opacity", "order", "orphans", "outline",
|
| 458 |
+
"outline-color", "outline-offset", "outline-style", "outline-width",
|
| 459 |
+
"overflow", "overflow-style", "overflow-wrap", "overflow-x", "overflow-y",
|
| 460 |
+
"padding", "padding-bottom", "padding-left", "padding-right", "padding-top",
|
| 461 |
+
"page", "page-break-after", "page-break-before", "page-break-inside",
|
| 462 |
+
"page-policy", "pause", "pause-after", "pause-before", "perspective",
|
| 463 |
+
"perspective-origin", "pitch", "pitch-range", "play-during", "position",
|
| 464 |
+
"presentation-level", "punctuation-trim", "quotes", "region-break-after",
|
| 465 |
+
"region-break-before", "region-break-inside", "region-fragment",
|
| 466 |
+
"rendering-intent", "resize", "rest", "rest-after", "rest-before", "richness",
|
| 467 |
+
"right", "rotation", "rotation-point", "ruby-align", "ruby-overhang",
|
| 468 |
+
"ruby-position", "ruby-span", "shape-image-threshold", "shape-inside", "shape-margin",
|
| 469 |
+
"shape-outside", "size", "speak", "speak-as", "speak-header",
|
| 470 |
+
"speak-numeral", "speak-punctuation", "speech-rate", "stress", "string-set",
|
| 471 |
+
"tab-size", "table-layout", "target", "target-name", "target-new",
|
| 472 |
+
"target-position", "text-align", "text-align-last", "text-decoration",
|
| 473 |
+
"text-decoration-color", "text-decoration-line", "text-decoration-skip",
|
| 474 |
+
"text-decoration-style", "text-emphasis", "text-emphasis-color",
|
| 475 |
+
"text-emphasis-position", "text-emphasis-style", "text-height",
|
| 476 |
+
"text-indent", "text-justify", "text-outline", "text-overflow", "text-shadow",
|
| 477 |
+
"text-size-adjust", "text-space-collapse", "text-transform", "text-underline-position",
|
| 478 |
+
"text-wrap", "top", "transform", "transform-origin", "transform-style",
|
| 479 |
+
"transition", "transition-delay", "transition-duration",
|
| 480 |
+
"transition-property", "transition-timing-function", "unicode-bidi",
|
| 481 |
+
"vertical-align", "visibility", "voice-balance", "voice-duration",
|
| 482 |
+
"voice-family", "voice-pitch", "voice-range", "voice-rate", "voice-stress",
|
| 483 |
+
"voice-volume", "volume", "white-space", "widows", "width", "word-break",
|
| 484 |
+
"word-spacing", "word-wrap", "z-index",
|
| 485 |
+
// SVG-specific
|
| 486 |
+
"clip-path", "clip-rule", "mask", "enable-background", "filter", "flood-color",
|
| 487 |
+
"flood-opacity", "lighting-color", "stop-color", "stop-opacity", "pointer-events",
|
| 488 |
+
"color-interpolation", "color-interpolation-filters",
|
| 489 |
+
"color-rendering", "fill", "fill-opacity", "fill-rule", "image-rendering",
|
| 490 |
+
"marker", "marker-end", "marker-mid", "marker-start", "shape-rendering", "stroke",
|
| 491 |
+
"stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin",
|
| 492 |
+
"stroke-miterlimit", "stroke-opacity", "stroke-width", "text-rendering",
|
| 493 |
+
"baseline-shift", "dominant-baseline", "glyph-orientation-horizontal",
|
| 494 |
+
"glyph-orientation-vertical", "text-anchor", "writing-mode"
|
| 495 |
+
], propertyKeywords = keySet(propertyKeywords_);
|
| 496 |
+
|
| 497 |
+
var nonStandardPropertyKeywords_ = [
|
| 498 |
+
"scrollbar-arrow-color", "scrollbar-base-color", "scrollbar-dark-shadow-color",
|
| 499 |
+
"scrollbar-face-color", "scrollbar-highlight-color", "scrollbar-shadow-color",
|
| 500 |
+
"scrollbar-3d-light-color", "scrollbar-track-color", "shape-inside",
|
| 501 |
+
"searchfield-cancel-button", "searchfield-decoration", "searchfield-results-button",
|
| 502 |
+
"searchfield-results-decoration", "zoom"
|
| 503 |
+
], nonStandardPropertyKeywords = keySet(nonStandardPropertyKeywords_);
|
| 504 |
+
|
| 505 |
+
var fontProperties_ = [
|
| 506 |
+
"font-family", "src", "unicode-range", "font-variant", "font-feature-settings",
|
| 507 |
+
"font-stretch", "font-weight", "font-style"
|
| 508 |
+
], fontProperties = keySet(fontProperties_);
|
| 509 |
+
|
| 510 |
+
var counterDescriptors_ = [
|
| 511 |
+
"additive-symbols", "fallback", "negative", "pad", "prefix", "range",
|
| 512 |
+
"speak-as", "suffix", "symbols", "system"
|
| 513 |
+
], counterDescriptors = keySet(counterDescriptors_);
|
| 514 |
+
|
| 515 |
+
var colorKeywords_ = [
|
| 516 |
+
"aliceblue", "antiquewhite", "aqua", "aquamarine", "azure", "beige",
|
| 517 |
+
"bisque", "black", "blanchedalmond", "blue", "blueviolet", "brown",
|
| 518 |
+
"burlywood", "cadetblue", "chartreuse", "chocolate", "coral", "cornflowerblue",
|
| 519 |
+
"cornsilk", "crimson", "cyan", "darkblue", "darkcyan", "darkgoldenrod",
|
| 520 |
+
"darkgray", "darkgreen", "darkkhaki", "darkmagenta", "darkolivegreen",
|
| 521 |
+
"darkorange", "darkorchid", "darkred", "darksalmon", "darkseagreen",
|
| 522 |
+
"darkslateblue", "darkslategray", "darkturquoise", "darkviolet",
|
| 523 |
+
"deeppink", "deepskyblue", "dimgray", "dodgerblue", "firebrick",
|
| 524 |
+
"floralwhite", "forestgreen", "fuchsia", "gainsboro", "ghostwhite",
|
| 525 |
+
"gold", "goldenrod", "gray", "grey", "green", "greenyellow", "honeydew",
|
| 526 |
+
"hotpink", "indianred", "indigo", "ivory", "khaki", "lavender",
|
| 527 |
+
"lavenderblush", "lawngreen", "lemonchiffon", "lightblue", "lightcoral",
|
| 528 |
+
"lightcyan", "lightgoldenrodyellow", "lightgray", "lightgreen", "lightpink",
|
| 529 |
+
"lightsalmon", "lightseagreen", "lightskyblue", "lightslategray",
|
| 530 |
+
"lightsteelblue", "lightyellow", "lime", "limegreen", "linen", "magenta",
|
| 531 |
+
"maroon", "mediumaquamarine", "mediumblue", "mediumorchid", "mediumpurple",
|
| 532 |
+
"mediumseagreen", "mediumslateblue", "mediumspringgreen", "mediumturquoise",
|
| 533 |
+
"mediumvioletred", "midnightblue", "mintcream", "mistyrose", "moccasin",
|
| 534 |
+
"navajowhite", "navy", "oldlace", "olive", "olivedrab", "orange", "orangered",
|
| 535 |
+
"orchid", "palegoldenrod", "palegreen", "paleturquoise", "palevioletred",
|
| 536 |
+
"papayawhip", "peachpuff", "peru", "pink", "plum", "powderblue",
|
| 537 |
+
"purple", "rebeccapurple", "red", "rosybrown", "royalblue", "saddlebrown",
|
| 538 |
+
"salmon", "sandybrown", "seagreen", "seashell", "sienna", "silver", "skyblue",
|
| 539 |
+
"slateblue", "slategray", "snow", "springgreen", "steelblue", "tan",
|
| 540 |
+
"teal", "thistle", "tomato", "turquoise", "violet", "wheat", "white",
|
| 541 |
+
"whitesmoke", "yellow", "yellowgreen"
|
| 542 |
+
], colorKeywords = keySet(colorKeywords_);
|
| 543 |
+
|
| 544 |
+
var valueKeywords_ = [
|
| 545 |
+
"above", "absolute", "activeborder", "additive", "activecaption", "afar",
|
| 546 |
+
"after-white-space", "ahead", "alias", "all", "all-scroll", "alphabetic", "alternate",
|
| 547 |
+
"always", "amharic", "amharic-abegede", "antialiased", "appworkspace",
|
| 548 |
+
"arabic-indic", "armenian", "asterisks", "attr", "auto", "avoid", "avoid-column", "avoid-page",
|
| 549 |
+
"avoid-region", "background", "backwards", "baseline", "below", "bidi-override", "binary",
|
| 550 |
+
"bengali", "blink", "block", "block-axis", "bold", "bolder", "border", "border-box",
|
| 551 |
+
"both", "bottom", "break", "break-all", "break-word", "bullets", "button", "button-bevel",
|
| 552 |
+
"buttonface", "buttonhighlight", "buttonshadow", "buttontext", "calc", "cambodian",
|
| 553 |
+
"capitalize", "caps-lock-indicator", "caption", "captiontext", "caret",
|
| 554 |
+
"cell", "center", "checkbox", "circle", "cjk-decimal", "cjk-earthly-branch",
|
| 555 |
+
"cjk-heavenly-stem", "cjk-ideographic", "clear", "clip", "close-quote",
|
| 556 |
+
"col-resize", "collapse", "column", "compact", "condensed", "contain", "content",
|
| 557 |
+
"content-box", "context-menu", "continuous", "copy", "counter", "counters", "cover", "crop",
|
| 558 |
+
"cross", "crosshair", "currentcolor", "cursive", "cyclic", "dashed", "decimal",
|
| 559 |
+
"decimal-leading-zero", "default", "default-button", "destination-atop",
|
| 560 |
+
"destination-in", "destination-out", "destination-over", "devanagari",
|
| 561 |
+
"disc", "discard", "disclosure-closed", "disclosure-open", "document",
|
| 562 |
+
"dot-dash", "dot-dot-dash",
|
| 563 |
+
"dotted", "double", "down", "e-resize", "ease", "ease-in", "ease-in-out", "ease-out",
|
| 564 |
+
"element", "ellipse", "ellipsis", "embed", "end", "ethiopic", "ethiopic-abegede",
|
| 565 |
+
"ethiopic-abegede-am-et", "ethiopic-abegede-gez", "ethiopic-abegede-ti-er",
|
| 566 |
+
"ethiopic-abegede-ti-et", "ethiopic-halehame-aa-er",
|
| 567 |
+
"ethiopic-halehame-aa-et", "ethiopic-halehame-am-et",
|
| 568 |
+
"ethiopic-halehame-gez", "ethiopic-halehame-om-et",
|
| 569 |
+
"ethiopic-halehame-sid-et", "ethiopic-halehame-so-et",
|
| 570 |
+
"ethiopic-halehame-ti-er", "ethiopic-halehame-ti-et", "ethiopic-halehame-tig",
|
| 571 |
+
"ethiopic-numeric", "ew-resize", "expanded", "extends", "extra-condensed",
|
| 572 |
+
"extra-expanded", "fantasy", "fast", "fill", "fixed", "flat", "flex", "footnotes",
|
| 573 |
+
"forwards", "from", "geometricPrecision", "georgian", "graytext", "groove",
|
| 574 |
+
"gujarati", "gurmukhi", "hand", "hangul", "hangul-consonant", "hebrew",
|
| 575 |
+
"help", "hidden", "hide", "higher", "highlight", "highlighttext",
|
| 576 |
+
"hiragana", "hiragana-iroha", "horizontal", "hsl", "hsla", "icon", "ignore",
|
| 577 |
+
"inactiveborder", "inactivecaption", "inactivecaptiontext", "infinite",
|
| 578 |
+
"infobackground", "infotext", "inherit", "initial", "inline", "inline-axis",
|
| 579 |
+
"inline-block", "inline-flex", "inline-table", "inset", "inside", "intrinsic", "invert",
|
| 580 |
+
"italic", "japanese-formal", "japanese-informal", "justify", "kannada",
|
| 581 |
+
"katakana", "katakana-iroha", "keep-all", "khmer",
|
| 582 |
+
"korean-hangul-formal", "korean-hanja-formal", "korean-hanja-informal",
|
| 583 |
+
"landscape", "lao", "large", "larger", "left", "level", "lighter",
|
| 584 |
+
"line-through", "linear", "linear-gradient", "lines", "list-item", "listbox", "listitem",
|
| 585 |
+
"local", "logical", "loud", "lower", "lower-alpha", "lower-armenian",
|
| 586 |
+
"lower-greek", "lower-hexadecimal", "lower-latin", "lower-norwegian",
|
| 587 |
+
"lower-roman", "lowercase", "ltr", "malayalam", "match", "matrix", "matrix3d",
|
| 588 |
+
"media-controls-background", "media-current-time-display",
|
| 589 |
+
"media-fullscreen-button", "media-mute-button", "media-play-button",
|
| 590 |
+
"media-return-to-realtime-button", "media-rewind-button",
|
| 591 |
+
"media-seek-back-button", "media-seek-forward-button", "media-slider",
|
| 592 |
+
"media-sliderthumb", "media-time-remaining-display", "media-volume-slider",
|
| 593 |
+
"media-volume-slider-container", "media-volume-sliderthumb", "medium",
|
| 594 |
+
"menu", "menulist", "menulist-button", "menulist-text",
|
| 595 |
+
"menulist-textfield", "menutext", "message-box", "middle", "min-intrinsic",
|
| 596 |
+
"mix", "mongolian", "monospace", "move", "multiple", "myanmar", "n-resize",
|
| 597 |
+
"narrower", "ne-resize", "nesw-resize", "no-close-quote", "no-drop",
|
| 598 |
+
"no-open-quote", "no-repeat", "none", "normal", "not-allowed", "nowrap",
|
| 599 |
+
"ns-resize", "numbers", "numeric", "nw-resize", "nwse-resize", "oblique", "octal", "open-quote",
|
| 600 |
+
"optimizeLegibility", "optimizeSpeed", "oriya", "oromo", "outset",
|
| 601 |
+
"outside", "outside-shape", "overlay", "overline", "padding", "padding-box",
|
| 602 |
+
"painted", "page", "paused", "persian", "perspective", "plus-darker", "plus-lighter",
|
| 603 |
+
"pointer", "polygon", "portrait", "pre", "pre-line", "pre-wrap", "preserve-3d",
|
| 604 |
+
"progress", "push-button", "radial-gradient", "radio", "read-only",
|
| 605 |
+
"read-write", "read-write-plaintext-only", "rectangle", "region",
|
| 606 |
+
"relative", "repeat", "repeating-linear-gradient",
|
| 607 |
+
"repeating-radial-gradient", "repeat-x", "repeat-y", "reset", "reverse",
|
| 608 |
+
"rgb", "rgba", "ridge", "right", "rotate", "rotate3d", "rotateX", "rotateY",
|
| 609 |
+
"rotateZ", "round", "row-resize", "rtl", "run-in", "running",
|
| 610 |
+
"s-resize", "sans-serif", "scale", "scale3d", "scaleX", "scaleY", "scaleZ",
|
| 611 |
+
"scroll", "scrollbar", "se-resize", "searchfield",
|
| 612 |
+
"searchfield-cancel-button", "searchfield-decoration",
|
| 613 |
+
"searchfield-results-button", "searchfield-results-decoration",
|
| 614 |
+
"semi-condensed", "semi-expanded", "separate", "serif", "show", "sidama",
|
| 615 |
+
"simp-chinese-formal", "simp-chinese-informal", "single",
|
| 616 |
+
"skew", "skewX", "skewY", "skip-white-space", "slide", "slider-horizontal",
|
| 617 |
+
"slider-vertical", "sliderthumb-horizontal", "sliderthumb-vertical", "slow",
|
| 618 |
+
"small", "small-caps", "small-caption", "smaller", "solid", "somali",
|
| 619 |
+
"source-atop", "source-in", "source-out", "source-over", "space", "spell-out", "square",
|
| 620 |
+
"square-button", "start", "static", "status-bar", "stretch", "stroke", "sub",
|
| 621 |
+
"subpixel-antialiased", "super", "sw-resize", "symbolic", "symbols", "table",
|
| 622 |
+
"table-caption", "table-cell", "table-column", "table-column-group",
|
| 623 |
+
"table-footer-group", "table-header-group", "table-row", "table-row-group",
|
| 624 |
+
"tamil",
|
| 625 |
+
"telugu", "text", "text-bottom", "text-top", "textarea", "textfield", "thai",
|
| 626 |
+
"thick", "thin", "threeddarkshadow", "threedface", "threedhighlight",
|
| 627 |
+
"threedlightshadow", "threedshadow", "tibetan", "tigre", "tigrinya-er",
|
| 628 |
+
"tigrinya-er-abegede", "tigrinya-et", "tigrinya-et-abegede", "to", "top",
|
| 629 |
+
"trad-chinese-formal", "trad-chinese-informal",
|
| 630 |
+
"translate", "translate3d", "translateX", "translateY", "translateZ",
|
| 631 |
+
"transparent", "ultra-condensed", "ultra-expanded", "underline", "up",
|
| 632 |
+
"upper-alpha", "upper-armenian", "upper-greek", "upper-hexadecimal",
|
| 633 |
+
"upper-latin", "upper-norwegian", "upper-roman", "uppercase", "urdu", "url",
|
| 634 |
+
"var", "vertical", "vertical-text", "visible", "visibleFill", "visiblePainted",
|
| 635 |
+
"visibleStroke", "visual", "w-resize", "wait", "wave", "wider",
|
| 636 |
+
"window", "windowframe", "windowtext", "words", "x-large", "x-small", "xor",
|
| 637 |
+
"xx-large", "xx-small"
|
| 638 |
+
], valueKeywords = keySet(valueKeywords_);
|
| 639 |
+
|
| 640 |
+
var allWords = documentTypes_.concat(mediaTypes_).concat(mediaFeatures_).concat(propertyKeywords_)
|
| 641 |
+
.concat(nonStandardPropertyKeywords_).concat(colorKeywords_).concat(valueKeywords_);
|
| 642 |
+
CodeMirror.registerHelper("hintWords", "css", allWords);
|
| 643 |
+
|
| 644 |
+
function tokenCComment(stream, state) {
|
| 645 |
+
var maybeEnd = false, ch;
|
| 646 |
+
while ((ch = stream.next()) != null) {
|
| 647 |
+
if (maybeEnd && ch == "/") {
|
| 648 |
+
state.tokenize = null;
|
| 649 |
+
break;
|
| 650 |
+
}
|
| 651 |
+
maybeEnd = (ch == "*");
|
| 652 |
+
}
|
| 653 |
+
return ["comment", "comment"];
|
| 654 |
+
}
|
| 655 |
+
|
| 656 |
+
CodeMirror.defineMIME("text/css", {
|
| 657 |
+
documentTypes: documentTypes,
|
| 658 |
+
mediaTypes: mediaTypes,
|
| 659 |
+
mediaFeatures: mediaFeatures,
|
| 660 |
+
propertyKeywords: propertyKeywords,
|
| 661 |
+
nonStandardPropertyKeywords: nonStandardPropertyKeywords,
|
| 662 |
+
fontProperties: fontProperties,
|
| 663 |
+
counterDescriptors: counterDescriptors,
|
| 664 |
+
colorKeywords: colorKeywords,
|
| 665 |
+
valueKeywords: valueKeywords,
|
| 666 |
+
tokenHooks: {
|
| 667 |
+
"/": function(stream, state) {
|
| 668 |
+
if (!stream.eat("*")) return false;
|
| 669 |
+
state.tokenize = tokenCComment;
|
| 670 |
+
return tokenCComment(stream, state);
|
| 671 |
+
}
|
| 672 |
+
},
|
| 673 |
+
name: "css"
|
| 674 |
+
});
|
| 675 |
+
|
| 676 |
+
CodeMirror.defineMIME("text/x-scss", {
|
| 677 |
+
mediaTypes: mediaTypes,
|
| 678 |
+
mediaFeatures: mediaFeatures,
|
| 679 |
+
propertyKeywords: propertyKeywords,
|
| 680 |
+
nonStandardPropertyKeywords: nonStandardPropertyKeywords,
|
| 681 |
+
colorKeywords: colorKeywords,
|
| 682 |
+
valueKeywords: valueKeywords,
|
| 683 |
+
fontProperties: fontProperties,
|
| 684 |
+
allowNested: true,
|
| 685 |
+
tokenHooks: {
|
| 686 |
+
"/": function(stream, state) {
|
| 687 |
+
if (stream.eat("/")) {
|
| 688 |
+
stream.skipToEnd();
|
| 689 |
+
return ["comment", "comment"];
|
| 690 |
+
} else if (stream.eat("*")) {
|
| 691 |
+
state.tokenize = tokenCComment;
|
| 692 |
+
return tokenCComment(stream, state);
|
| 693 |
+
} else {
|
| 694 |
+
return ["operator", "operator"];
|
| 695 |
+
}
|
| 696 |
+
},
|
| 697 |
+
":": function(stream) {
|
| 698 |
+
if (stream.match(/\s*\{/))
|
| 699 |
+
return [null, "{"];
|
| 700 |
+
return false;
|
| 701 |
+
},
|
| 702 |
+
"$": function(stream) {
|
| 703 |
+
stream.match(/^[\w-]+/);
|
| 704 |
+
if (stream.match(/^\s*:/, false))
|
| 705 |
+
return ["variable-2", "variable-definition"];
|
| 706 |
+
return ["variable-2", "variable"];
|
| 707 |
+
},
|
| 708 |
+
"#": function(stream) {
|
| 709 |
+
if (!stream.eat("{")) return false;
|
| 710 |
+
return [null, "interpolation"];
|
| 711 |
+
}
|
| 712 |
+
},
|
| 713 |
+
name: "css",
|
| 714 |
+
helperType: "scss"
|
| 715 |
+
});
|
| 716 |
+
|
| 717 |
+
CodeMirror.defineMIME("text/x-less", {
|
| 718 |
+
mediaTypes: mediaTypes,
|
| 719 |
+
mediaFeatures: mediaFeatures,
|
| 720 |
+
propertyKeywords: propertyKeywords,
|
| 721 |
+
nonStandardPropertyKeywords: nonStandardPropertyKeywords,
|
| 722 |
+
colorKeywords: colorKeywords,
|
| 723 |
+
valueKeywords: valueKeywords,
|
| 724 |
+
fontProperties: fontProperties,
|
| 725 |
+
allowNested: true,
|
| 726 |
+
tokenHooks: {
|
| 727 |
+
"/": function(stream, state) {
|
| 728 |
+
if (stream.eat("/")) {
|
| 729 |
+
stream.skipToEnd();
|
| 730 |
+
return ["comment", "comment"];
|
| 731 |
+
} else if (stream.eat("*")) {
|
| 732 |
+
state.tokenize = tokenCComment;
|
| 733 |
+
return tokenCComment(stream, state);
|
| 734 |
+
} else {
|
| 735 |
+
return ["operator", "operator"];
|
| 736 |
+
}
|
| 737 |
+
},
|
| 738 |
+
"@": function(stream) {
|
| 739 |
+
if (stream.eat("{")) return [null, "interpolation"];
|
| 740 |
+
if (stream.match(/^(charset|document|font-face|import|(-(moz|ms|o|webkit)-)?keyframes|media|namespace|page|supports)\b/, false)) return false;
|
| 741 |
+
stream.eatWhile(/[\w\\\-]/);
|
| 742 |
+
if (stream.match(/^\s*:/, false))
|
| 743 |
+
return ["variable-2", "variable-definition"];
|
| 744 |
+
return ["variable-2", "variable"];
|
| 745 |
+
},
|
| 746 |
+
"&": function() {
|
| 747 |
+
return ["atom", "atom"];
|
| 748 |
+
}
|
| 749 |
+
},
|
| 750 |
+
name: "css",
|
| 751 |
+
helperType: "less"
|
| 752 |
+
});
|
| 753 |
+
|
| 754 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/mode/htmlmixed/htmlmixed.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"), require("../xml/xml"), require("../javascript/javascript"), require("../css/css"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror", "../xml/xml", "../javascript/javascript", "../css/css"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
"use strict";
|
| 13 |
+
|
| 14 |
+
CodeMirror.defineMode("htmlmixed", function(config, parserConfig) {
|
| 15 |
+
var htmlMode = CodeMirror.getMode(config, {name: "xml",
|
| 16 |
+
htmlMode: true,
|
| 17 |
+
multilineTagIndentFactor: parserConfig.multilineTagIndentFactor,
|
| 18 |
+
multilineTagIndentPastTag: parserConfig.multilineTagIndentPastTag});
|
| 19 |
+
var cssMode = CodeMirror.getMode(config, "css");
|
| 20 |
+
|
| 21 |
+
var scriptTypes = [], scriptTypesConf = parserConfig && parserConfig.scriptTypes;
|
| 22 |
+
scriptTypes.push({matches: /^(?:text|application)\/(?:x-)?(?:java|ecma)script$|^$/i,
|
| 23 |
+
mode: CodeMirror.getMode(config, "javascript")});
|
| 24 |
+
if (scriptTypesConf) for (var i = 0; i < scriptTypesConf.length; ++i) {
|
| 25 |
+
var conf = scriptTypesConf[i];
|
| 26 |
+
scriptTypes.push({matches: conf.matches, mode: conf.mode && CodeMirror.getMode(config, conf.mode)});
|
| 27 |
+
}
|
| 28 |
+
scriptTypes.push({matches: /./,
|
| 29 |
+
mode: CodeMirror.getMode(config, "text/plain")});
|
| 30 |
+
|
| 31 |
+
function html(stream, state) {
|
| 32 |
+
var tagName = state.htmlState.tagName;
|
| 33 |
+
if (tagName) tagName = tagName.toLowerCase();
|
| 34 |
+
var style = htmlMode.token(stream, state.htmlState);
|
| 35 |
+
if (tagName == "script" && /\btag\b/.test(style) && stream.current() == ">") {
|
| 36 |
+
// Script block: mode to change to depends on type attribute
|
| 37 |
+
var scriptType = stream.string.slice(Math.max(0, stream.pos - 100), stream.pos).match(/\btype\s*=\s*("[^"]+"|'[^']+'|\S+)[^<]*$/i);
|
| 38 |
+
scriptType = scriptType ? scriptType[1] : "";
|
| 39 |
+
if (scriptType && /[\"\']/.test(scriptType.charAt(0))) scriptType = scriptType.slice(1, scriptType.length - 1);
|
| 40 |
+
for (var i = 0; i < scriptTypes.length; ++i) {
|
| 41 |
+
var tp = scriptTypes[i];
|
| 42 |
+
if (typeof tp.matches == "string" ? scriptType == tp.matches : tp.matches.test(scriptType)) {
|
| 43 |
+
if (tp.mode) {
|
| 44 |
+
state.token = script;
|
| 45 |
+
state.localMode = tp.mode;
|
| 46 |
+
state.localState = tp.mode.startState && tp.mode.startState(htmlMode.indent(state.htmlState, ""));
|
| 47 |
+
}
|
| 48 |
+
break;
|
| 49 |
+
}
|
| 50 |
+
}
|
| 51 |
+
} else if (tagName == "style" && /\btag\b/.test(style) && stream.current() == ">") {
|
| 52 |
+
state.token = css;
|
| 53 |
+
state.localMode = cssMode;
|
| 54 |
+
state.localState = cssMode.startState(htmlMode.indent(state.htmlState, ""));
|
| 55 |
+
}
|
| 56 |
+
return style;
|
| 57 |
+
}
|
| 58 |
+
function maybeBackup(stream, pat, style) {
|
| 59 |
+
var cur = stream.current();
|
| 60 |
+
var close = cur.search(pat), m;
|
| 61 |
+
if (close > -1) stream.backUp(cur.length - close);
|
| 62 |
+
else if (m = cur.match(/<\/?$/)) {
|
| 63 |
+
stream.backUp(cur.length);
|
| 64 |
+
if (!stream.match(pat, false)) stream.match(cur);
|
| 65 |
+
}
|
| 66 |
+
return style;
|
| 67 |
+
}
|
| 68 |
+
function script(stream, state) {
|
| 69 |
+
if (stream.match(/^<\/\s*script\s*>/i, false)) {
|
| 70 |
+
state.token = html;
|
| 71 |
+
state.localState = state.localMode = null;
|
| 72 |
+
return null;
|
| 73 |
+
}
|
| 74 |
+
return maybeBackup(stream, /<\/\s*script\s*>/,
|
| 75 |
+
state.localMode.token(stream, state.localState));
|
| 76 |
+
}
|
| 77 |
+
function css(stream, state) {
|
| 78 |
+
if (stream.match(/^<\/\s*style\s*>/i, false)) {
|
| 79 |
+
state.token = html;
|
| 80 |
+
state.localState = state.localMode = null;
|
| 81 |
+
return null;
|
| 82 |
+
}
|
| 83 |
+
return maybeBackup(stream, /<\/\s*style\s*>/,
|
| 84 |
+
cssMode.token(stream, state.localState));
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
return {
|
| 88 |
+
startState: function() {
|
| 89 |
+
var state = htmlMode.startState();
|
| 90 |
+
return {token: html, localMode: null, localState: null, htmlState: state};
|
| 91 |
+
},
|
| 92 |
+
|
| 93 |
+
copyState: function(state) {
|
| 94 |
+
if (state.localState)
|
| 95 |
+
var local = CodeMirror.copyState(state.localMode, state.localState);
|
| 96 |
+
return {token: state.token, localMode: state.localMode, localState: local,
|
| 97 |
+
htmlState: CodeMirror.copyState(htmlMode, state.htmlState)};
|
| 98 |
+
},
|
| 99 |
+
|
| 100 |
+
token: function(stream, state) {
|
| 101 |
+
return state.token(stream, state);
|
| 102 |
+
},
|
| 103 |
+
|
| 104 |
+
indent: function(state, textAfter) {
|
| 105 |
+
if (!state.localMode || /^\s*<\//.test(textAfter))
|
| 106 |
+
return htmlMode.indent(state.htmlState, textAfter);
|
| 107 |
+
else if (state.localMode.indent)
|
| 108 |
+
return state.localMode.indent(state.localState, textAfter);
|
| 109 |
+
else
|
| 110 |
+
return CodeMirror.Pass;
|
| 111 |
+
},
|
| 112 |
+
|
| 113 |
+
innerMode: function(state) {
|
| 114 |
+
return {state: state.localState || state.htmlState, mode: state.localMode || htmlMode};
|
| 115 |
+
}
|
| 116 |
+
};
|
| 117 |
+
}, "xml", "javascript", "css");
|
| 118 |
+
|
| 119 |
+
CodeMirror.defineMIME("text/html", "htmlmixed");
|
| 120 |
+
|
| 121 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/mode/javascript/javascript.js
ADDED
|
@@ -0,0 +1,701 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
// TODO actually recognize syntax of TypeScript constructs
|
| 5 |
+
|
| 6 |
+
(function(mod) {
|
| 7 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 8 |
+
mod(require("../../lib/codemirror"));
|
| 9 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 10 |
+
define(["../../lib/codemirror"], mod);
|
| 11 |
+
else // Plain browser env
|
| 12 |
+
mod(CodeMirror);
|
| 13 |
+
})(function(CodeMirror) {
|
| 14 |
+
"use strict";
|
| 15 |
+
|
| 16 |
+
CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
| 17 |
+
var indentUnit = config.indentUnit;
|
| 18 |
+
var statementIndent = parserConfig.statementIndent;
|
| 19 |
+
var jsonldMode = parserConfig.jsonld;
|
| 20 |
+
var jsonMode = parserConfig.json || jsonldMode;
|
| 21 |
+
var isTS = parserConfig.typescript;
|
| 22 |
+
var wordRE = parserConfig.wordCharacters || /[\w$\xa1-\uffff]/;
|
| 23 |
+
|
| 24 |
+
// Tokenizer
|
| 25 |
+
|
| 26 |
+
var keywords = function(){
|
| 27 |
+
function kw(type) {return {type: type, style: "keyword"};}
|
| 28 |
+
var A = kw("keyword a"), B = kw("keyword b"), C = kw("keyword c");
|
| 29 |
+
var operator = kw("operator"), atom = {type: "atom", style: "atom"};
|
| 30 |
+
|
| 31 |
+
var jsKeywords = {
|
| 32 |
+
"if": kw("if"), "while": A, "with": A, "else": B, "do": B, "try": B, "finally": B,
|
| 33 |
+
"return": C, "break": C, "continue": C, "new": C, "delete": C, "throw": C, "debugger": C,
|
| 34 |
+
"var": kw("var"), "const": kw("var"), "let": kw("var"),
|
| 35 |
+
"function": kw("function"), "catch": kw("catch"),
|
| 36 |
+
"for": kw("for"), "switch": kw("switch"), "case": kw("case"), "default": kw("default"),
|
| 37 |
+
"in": operator, "typeof": operator, "instanceof": operator,
|
| 38 |
+
"true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom,
|
| 39 |
+
"this": kw("this"), "module": kw("module"), "class": kw("class"), "super": kw("atom"),
|
| 40 |
+
"yield": C, "export": kw("export"), "import": kw("import"), "extends": C
|
| 41 |
+
};
|
| 42 |
+
|
| 43 |
+
// Extend the 'normal' keywords with the TypeScript language extensions
|
| 44 |
+
if (isTS) {
|
| 45 |
+
var type = {type: "variable", style: "variable-3"};
|
| 46 |
+
var tsKeywords = {
|
| 47 |
+
// object-like things
|
| 48 |
+
"interface": kw("interface"),
|
| 49 |
+
"extends": kw("extends"),
|
| 50 |
+
"constructor": kw("constructor"),
|
| 51 |
+
|
| 52 |
+
// scope modifiers
|
| 53 |
+
"public": kw("public"),
|
| 54 |
+
"private": kw("private"),
|
| 55 |
+
"protected": kw("protected"),
|
| 56 |
+
"static": kw("static"),
|
| 57 |
+
|
| 58 |
+
// types
|
| 59 |
+
"string": type, "number": type, "bool": type, "any": type
|
| 60 |
+
};
|
| 61 |
+
|
| 62 |
+
for (var attr in tsKeywords) {
|
| 63 |
+
jsKeywords[attr] = tsKeywords[attr];
|
| 64 |
+
}
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
return jsKeywords;
|
| 68 |
+
}();
|
| 69 |
+
|
| 70 |
+
var isOperatorChar = /[+\-*&%=<>!?|~^]/;
|
| 71 |
+
var isJsonldKeyword = /^@(context|id|value|language|type|container|list|set|reverse|index|base|vocab|graph)"/;
|
| 72 |
+
|
| 73 |
+
function readRegexp(stream) {
|
| 74 |
+
var escaped = false, next, inSet = false;
|
| 75 |
+
while ((next = stream.next()) != null) {
|
| 76 |
+
if (!escaped) {
|
| 77 |
+
if (next == "/" && !inSet) return;
|
| 78 |
+
if (next == "[") inSet = true;
|
| 79 |
+
else if (inSet && next == "]") inSet = false;
|
| 80 |
+
}
|
| 81 |
+
escaped = !escaped && next == "\\";
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
// Used as scratch variables to communicate multiple values without
|
| 86 |
+
// consing up tons of objects.
|
| 87 |
+
var type, content;
|
| 88 |
+
function ret(tp, style, cont) {
|
| 89 |
+
type = tp; content = cont;
|
| 90 |
+
return style;
|
| 91 |
+
}
|
| 92 |
+
function tokenBase(stream, state) {
|
| 93 |
+
var ch = stream.next();
|
| 94 |
+
if (ch == '"' || ch == "'") {
|
| 95 |
+
state.tokenize = tokenString(ch);
|
| 96 |
+
return state.tokenize(stream, state);
|
| 97 |
+
} else if (ch == "." && stream.match(/^\d+(?:[eE][+\-]?\d+)?/)) {
|
| 98 |
+
return ret("number", "number");
|
| 99 |
+
} else if (ch == "." && stream.match("..")) {
|
| 100 |
+
return ret("spread", "meta");
|
| 101 |
+
} else if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
|
| 102 |
+
return ret(ch);
|
| 103 |
+
} else if (ch == "=" && stream.eat(">")) {
|
| 104 |
+
return ret("=>", "operator");
|
| 105 |
+
} else if (ch == "0" && stream.eat(/x/i)) {
|
| 106 |
+
stream.eatWhile(/[\da-f]/i);
|
| 107 |
+
return ret("number", "number");
|
| 108 |
+
} else if (/\d/.test(ch)) {
|
| 109 |
+
stream.match(/^\d*(?:\.\d*)?(?:[eE][+\-]?\d+)?/);
|
| 110 |
+
return ret("number", "number");
|
| 111 |
+
} else if (ch == "/") {
|
| 112 |
+
if (stream.eat("*")) {
|
| 113 |
+
state.tokenize = tokenComment;
|
| 114 |
+
return tokenComment(stream, state);
|
| 115 |
+
} else if (stream.eat("/")) {
|
| 116 |
+
stream.skipToEnd();
|
| 117 |
+
return ret("comment", "comment");
|
| 118 |
+
} else if (state.lastType == "operator" || state.lastType == "keyword c" ||
|
| 119 |
+
state.lastType == "sof" || /^[\[{}\(,;:]$/.test(state.lastType)) {
|
| 120 |
+
readRegexp(stream);
|
| 121 |
+
stream.match(/^\b(([gimyu])(?![gimyu]*\2))+\b/);
|
| 122 |
+
return ret("regexp", "string-2");
|
| 123 |
+
} else {
|
| 124 |
+
stream.eatWhile(isOperatorChar);
|
| 125 |
+
return ret("operator", "operator", stream.current());
|
| 126 |
+
}
|
| 127 |
+
} else if (ch == "`") {
|
| 128 |
+
state.tokenize = tokenQuasi;
|
| 129 |
+
return tokenQuasi(stream, state);
|
| 130 |
+
} else if (ch == "#") {
|
| 131 |
+
stream.skipToEnd();
|
| 132 |
+
return ret("error", "error");
|
| 133 |
+
} else if (isOperatorChar.test(ch)) {
|
| 134 |
+
stream.eatWhile(isOperatorChar);
|
| 135 |
+
return ret("operator", "operator", stream.current());
|
| 136 |
+
} else if (wordRE.test(ch)) {
|
| 137 |
+
stream.eatWhile(wordRE);
|
| 138 |
+
var word = stream.current(), known = keywords.propertyIsEnumerable(word) && keywords[word];
|
| 139 |
+
return (known && state.lastType != ".") ? ret(known.type, known.style, word) :
|
| 140 |
+
ret("variable", "variable", word);
|
| 141 |
+
}
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
function tokenString(quote) {
|
| 145 |
+
return function(stream, state) {
|
| 146 |
+
var escaped = false, next;
|
| 147 |
+
if (jsonldMode && stream.peek() == "@" && stream.match(isJsonldKeyword)){
|
| 148 |
+
state.tokenize = tokenBase;
|
| 149 |
+
return ret("jsonld-keyword", "meta");
|
| 150 |
+
}
|
| 151 |
+
while ((next = stream.next()) != null) {
|
| 152 |
+
if (next == quote && !escaped) break;
|
| 153 |
+
escaped = !escaped && next == "\\";
|
| 154 |
+
}
|
| 155 |
+
if (!escaped) state.tokenize = tokenBase;
|
| 156 |
+
return ret("string", "string");
|
| 157 |
+
};
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
function tokenComment(stream, state) {
|
| 161 |
+
var maybeEnd = false, ch;
|
| 162 |
+
while (ch = stream.next()) {
|
| 163 |
+
if (ch == "/" && maybeEnd) {
|
| 164 |
+
state.tokenize = tokenBase;
|
| 165 |
+
break;
|
| 166 |
+
}
|
| 167 |
+
maybeEnd = (ch == "*");
|
| 168 |
+
}
|
| 169 |
+
return ret("comment", "comment");
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
function tokenQuasi(stream, state) {
|
| 173 |
+
var escaped = false, next;
|
| 174 |
+
while ((next = stream.next()) != null) {
|
| 175 |
+
if (!escaped && (next == "`" || next == "$" && stream.eat("{"))) {
|
| 176 |
+
state.tokenize = tokenBase;
|
| 177 |
+
break;
|
| 178 |
+
}
|
| 179 |
+
escaped = !escaped && next == "\\";
|
| 180 |
+
}
|
| 181 |
+
return ret("quasi", "string-2", stream.current());
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
var brackets = "([{}])";
|
| 185 |
+
// This is a crude lookahead trick to try and notice that we're
|
| 186 |
+
// parsing the argument patterns for a fat-arrow function before we
|
| 187 |
+
// actually hit the arrow token. It only works if the arrow is on
|
| 188 |
+
// the same line as the arguments and there's no strange noise
|
| 189 |
+
// (comments) in between. Fallback is to only notice when we hit the
|
| 190 |
+
// arrow, and not declare the arguments as locals for the arrow
|
| 191 |
+
// body.
|
| 192 |
+
function findFatArrow(stream, state) {
|
| 193 |
+
if (state.fatArrowAt) state.fatArrowAt = null;
|
| 194 |
+
var arrow = stream.string.indexOf("=>", stream.start);
|
| 195 |
+
if (arrow < 0) return;
|
| 196 |
+
|
| 197 |
+
var depth = 0, sawSomething = false;
|
| 198 |
+
for (var pos = arrow - 1; pos >= 0; --pos) {
|
| 199 |
+
var ch = stream.string.charAt(pos);
|
| 200 |
+
var bracket = brackets.indexOf(ch);
|
| 201 |
+
if (bracket >= 0 && bracket < 3) {
|
| 202 |
+
if (!depth) { ++pos; break; }
|
| 203 |
+
if (--depth == 0) break;
|
| 204 |
+
} else if (bracket >= 3 && bracket < 6) {
|
| 205 |
+
++depth;
|
| 206 |
+
} else if (wordRE.test(ch)) {
|
| 207 |
+
sawSomething = true;
|
| 208 |
+
} else if (/["'\/]/.test(ch)) {
|
| 209 |
+
return;
|
| 210 |
+
} else if (sawSomething && !depth) {
|
| 211 |
+
++pos;
|
| 212 |
+
break;
|
| 213 |
+
}
|
| 214 |
+
}
|
| 215 |
+
if (sawSomething && !depth) state.fatArrowAt = pos;
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
// Parser
|
| 219 |
+
|
| 220 |
+
var atomicTypes = {"atom": true, "number": true, "variable": true, "string": true, "regexp": true, "this": true, "jsonld-keyword": true};
|
| 221 |
+
|
| 222 |
+
function JSLexical(indented, column, type, align, prev, info) {
|
| 223 |
+
this.indented = indented;
|
| 224 |
+
this.column = column;
|
| 225 |
+
this.type = type;
|
| 226 |
+
this.prev = prev;
|
| 227 |
+
this.info = info;
|
| 228 |
+
if (align != null) this.align = align;
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
function inScope(state, varname) {
|
| 232 |
+
for (var v = state.localVars; v; v = v.next)
|
| 233 |
+
if (v.name == varname) return true;
|
| 234 |
+
for (var cx = state.context; cx; cx = cx.prev) {
|
| 235 |
+
for (var v = cx.vars; v; v = v.next)
|
| 236 |
+
if (v.name == varname) return true;
|
| 237 |
+
}
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
function parseJS(state, style, type, content, stream) {
|
| 241 |
+
var cc = state.cc;
|
| 242 |
+
// Communicate our context to the combinators.
|
| 243 |
+
// (Less wasteful than consing up a hundred closures on every call.)
|
| 244 |
+
cx.state = state; cx.stream = stream; cx.marked = null, cx.cc = cc; cx.style = style;
|
| 245 |
+
|
| 246 |
+
if (!state.lexical.hasOwnProperty("align"))
|
| 247 |
+
state.lexical.align = true;
|
| 248 |
+
|
| 249 |
+
while(true) {
|
| 250 |
+
var combinator = cc.length ? cc.pop() : jsonMode ? expression : statement;
|
| 251 |
+
if (combinator(type, content)) {
|
| 252 |
+
while(cc.length && cc[cc.length - 1].lex)
|
| 253 |
+
cc.pop()();
|
| 254 |
+
if (cx.marked) return cx.marked;
|
| 255 |
+
if (type == "variable" && inScope(state, content)) return "variable-2";
|
| 256 |
+
return style;
|
| 257 |
+
}
|
| 258 |
+
}
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
// Combinator utils
|
| 262 |
+
|
| 263 |
+
var cx = {state: null, column: null, marked: null, cc: null};
|
| 264 |
+
function pass() {
|
| 265 |
+
for (var i = arguments.length - 1; i >= 0; i--) cx.cc.push(arguments[i]);
|
| 266 |
+
}
|
| 267 |
+
function cont() {
|
| 268 |
+
pass.apply(null, arguments);
|
| 269 |
+
return true;
|
| 270 |
+
}
|
| 271 |
+
function register(varname) {
|
| 272 |
+
function inList(list) {
|
| 273 |
+
for (var v = list; v; v = v.next)
|
| 274 |
+
if (v.name == varname) return true;
|
| 275 |
+
return false;
|
| 276 |
+
}
|
| 277 |
+
var state = cx.state;
|
| 278 |
+
if (state.context) {
|
| 279 |
+
cx.marked = "def";
|
| 280 |
+
if (inList(state.localVars)) return;
|
| 281 |
+
state.localVars = {name: varname, next: state.localVars};
|
| 282 |
+
} else {
|
| 283 |
+
if (inList(state.globalVars)) return;
|
| 284 |
+
if (parserConfig.globalVars)
|
| 285 |
+
state.globalVars = {name: varname, next: state.globalVars};
|
| 286 |
+
}
|
| 287 |
+
}
|
| 288 |
+
|
| 289 |
+
// Combinators
|
| 290 |
+
|
| 291 |
+
var defaultVars = {name: "this", next: {name: "arguments"}};
|
| 292 |
+
function pushcontext() {
|
| 293 |
+
cx.state.context = {prev: cx.state.context, vars: cx.state.localVars};
|
| 294 |
+
cx.state.localVars = defaultVars;
|
| 295 |
+
}
|
| 296 |
+
function popcontext() {
|
| 297 |
+
cx.state.localVars = cx.state.context.vars;
|
| 298 |
+
cx.state.context = cx.state.context.prev;
|
| 299 |
+
}
|
| 300 |
+
function pushlex(type, info) {
|
| 301 |
+
var result = function() {
|
| 302 |
+
var state = cx.state, indent = state.indented;
|
| 303 |
+
if (state.lexical.type == "stat") indent = state.lexical.indented;
|
| 304 |
+
else for (var outer = state.lexical; outer && outer.type == ")" && outer.align; outer = outer.prev)
|
| 305 |
+
indent = outer.indented;
|
| 306 |
+
state.lexical = new JSLexical(indent, cx.stream.column(), type, null, state.lexical, info);
|
| 307 |
+
};
|
| 308 |
+
result.lex = true;
|
| 309 |
+
return result;
|
| 310 |
+
}
|
| 311 |
+
function poplex() {
|
| 312 |
+
var state = cx.state;
|
| 313 |
+
if (state.lexical.prev) {
|
| 314 |
+
if (state.lexical.type == ")")
|
| 315 |
+
state.indented = state.lexical.indented;
|
| 316 |
+
state.lexical = state.lexical.prev;
|
| 317 |
+
}
|
| 318 |
+
}
|
| 319 |
+
poplex.lex = true;
|
| 320 |
+
|
| 321 |
+
function expect(wanted) {
|
| 322 |
+
function exp(type) {
|
| 323 |
+
if (type == wanted) return cont();
|
| 324 |
+
else if (wanted == ";") return pass();
|
| 325 |
+
else return cont(exp);
|
| 326 |
+
};
|
| 327 |
+
return exp;
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
function statement(type, value) {
|
| 331 |
+
if (type == "var") return cont(pushlex("vardef", value.length), vardef, expect(";"), poplex);
|
| 332 |
+
if (type == "keyword a") return cont(pushlex("form"), expression, statement, poplex);
|
| 333 |
+
if (type == "keyword b") return cont(pushlex("form"), statement, poplex);
|
| 334 |
+
if (type == "{") return cont(pushlex("}"), block, poplex);
|
| 335 |
+
if (type == ";") return cont();
|
| 336 |
+
if (type == "if") {
|
| 337 |
+
if (cx.state.lexical.info == "else" && cx.state.cc[cx.state.cc.length - 1] == poplex)
|
| 338 |
+
cx.state.cc.pop()();
|
| 339 |
+
return cont(pushlex("form"), expression, statement, poplex, maybeelse);
|
| 340 |
+
}
|
| 341 |
+
if (type == "function") return cont(functiondef);
|
| 342 |
+
if (type == "for") return cont(pushlex("form"), forspec, statement, poplex);
|
| 343 |
+
if (type == "variable") return cont(pushlex("stat"), maybelabel);
|
| 344 |
+
if (type == "switch") return cont(pushlex("form"), expression, pushlex("}", "switch"), expect("{"),
|
| 345 |
+
block, poplex, poplex);
|
| 346 |
+
if (type == "case") return cont(expression, expect(":"));
|
| 347 |
+
if (type == "default") return cont(expect(":"));
|
| 348 |
+
if (type == "catch") return cont(pushlex("form"), pushcontext, expect("("), funarg, expect(")"),
|
| 349 |
+
statement, poplex, popcontext);
|
| 350 |
+
if (type == "module") return cont(pushlex("form"), pushcontext, afterModule, popcontext, poplex);
|
| 351 |
+
if (type == "class") return cont(pushlex("form"), className, poplex);
|
| 352 |
+
if (type == "export") return cont(pushlex("form"), afterExport, poplex);
|
| 353 |
+
if (type == "import") return cont(pushlex("form"), afterImport, poplex);
|
| 354 |
+
return pass(pushlex("stat"), expression, expect(";"), poplex);
|
| 355 |
+
}
|
| 356 |
+
function expression(type) {
|
| 357 |
+
return expressionInner(type, false);
|
| 358 |
+
}
|
| 359 |
+
function expressionNoComma(type) {
|
| 360 |
+
return expressionInner(type, true);
|
| 361 |
+
}
|
| 362 |
+
function expressionInner(type, noComma) {
|
| 363 |
+
if (cx.state.fatArrowAt == cx.stream.start) {
|
| 364 |
+
var body = noComma ? arrowBodyNoComma : arrowBody;
|
| 365 |
+
if (type == "(") return cont(pushcontext, pushlex(")"), commasep(pattern, ")"), poplex, expect("=>"), body, popcontext);
|
| 366 |
+
else if (type == "variable") return pass(pushcontext, pattern, expect("=>"), body, popcontext);
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
var maybeop = noComma ? maybeoperatorNoComma : maybeoperatorComma;
|
| 370 |
+
if (atomicTypes.hasOwnProperty(type)) return cont(maybeop);
|
| 371 |
+
if (type == "function") return cont(functiondef, maybeop);
|
| 372 |
+
if (type == "keyword c") return cont(noComma ? maybeexpressionNoComma : maybeexpression);
|
| 373 |
+
if (type == "(") return cont(pushlex(")"), maybeexpression, comprehension, expect(")"), poplex, maybeop);
|
| 374 |
+
if (type == "operator" || type == "spread") return cont(noComma ? expressionNoComma : expression);
|
| 375 |
+
if (type == "[") return cont(pushlex("]"), arrayLiteral, poplex, maybeop);
|
| 376 |
+
if (type == "{") return contCommasep(objprop, "}", null, maybeop);
|
| 377 |
+
if (type == "quasi") { return pass(quasi, maybeop); }
|
| 378 |
+
return cont();
|
| 379 |
+
}
|
| 380 |
+
function maybeexpression(type) {
|
| 381 |
+
if (type.match(/[;\}\)\],]/)) return pass();
|
| 382 |
+
return pass(expression);
|
| 383 |
+
}
|
| 384 |
+
function maybeexpressionNoComma(type) {
|
| 385 |
+
if (type.match(/[;\}\)\],]/)) return pass();
|
| 386 |
+
return pass(expressionNoComma);
|
| 387 |
+
}
|
| 388 |
+
|
| 389 |
+
function maybeoperatorComma(type, value) {
|
| 390 |
+
if (type == ",") return cont(expression);
|
| 391 |
+
return maybeoperatorNoComma(type, value, false);
|
| 392 |
+
}
|
| 393 |
+
function maybeoperatorNoComma(type, value, noComma) {
|
| 394 |
+
var me = noComma == false ? maybeoperatorComma : maybeoperatorNoComma;
|
| 395 |
+
var expr = noComma == false ? expression : expressionNoComma;
|
| 396 |
+
if (type == "=>") return cont(pushcontext, noComma ? arrowBodyNoComma : arrowBody, popcontext);
|
| 397 |
+
if (type == "operator") {
|
| 398 |
+
if (/\+\+|--/.test(value)) return cont(me);
|
| 399 |
+
if (value == "?") return cont(expression, expect(":"), expr);
|
| 400 |
+
return cont(expr);
|
| 401 |
+
}
|
| 402 |
+
if (type == "quasi") { return pass(quasi, me); }
|
| 403 |
+
if (type == ";") return;
|
| 404 |
+
if (type == "(") return contCommasep(expressionNoComma, ")", "call", me);
|
| 405 |
+
if (type == ".") return cont(property, me);
|
| 406 |
+
if (type == "[") return cont(pushlex("]"), maybeexpression, expect("]"), poplex, me);
|
| 407 |
+
}
|
| 408 |
+
function quasi(type, value) {
|
| 409 |
+
if (type != "quasi") return pass();
|
| 410 |
+
if (value.slice(value.length - 2) != "${") return cont(quasi);
|
| 411 |
+
return cont(expression, continueQuasi);
|
| 412 |
+
}
|
| 413 |
+
function continueQuasi(type) {
|
| 414 |
+
if (type == "}") {
|
| 415 |
+
cx.marked = "string-2";
|
| 416 |
+
cx.state.tokenize = tokenQuasi;
|
| 417 |
+
return cont(quasi);
|
| 418 |
+
}
|
| 419 |
+
}
|
| 420 |
+
function arrowBody(type) {
|
| 421 |
+
findFatArrow(cx.stream, cx.state);
|
| 422 |
+
return pass(type == "{" ? statement : expression);
|
| 423 |
+
}
|
| 424 |
+
function arrowBodyNoComma(type) {
|
| 425 |
+
findFatArrow(cx.stream, cx.state);
|
| 426 |
+
return pass(type == "{" ? statement : expressionNoComma);
|
| 427 |
+
}
|
| 428 |
+
function maybelabel(type) {
|
| 429 |
+
if (type == ":") return cont(poplex, statement);
|
| 430 |
+
return pass(maybeoperatorComma, expect(";"), poplex);
|
| 431 |
+
}
|
| 432 |
+
function property(type) {
|
| 433 |
+
if (type == "variable") {cx.marked = "property"; return cont();}
|
| 434 |
+
}
|
| 435 |
+
function objprop(type, value) {
|
| 436 |
+
if (type == "variable" || cx.style == "keyword") {
|
| 437 |
+
cx.marked = "property";
|
| 438 |
+
if (value == "get" || value == "set") return cont(getterSetter);
|
| 439 |
+
return cont(afterprop);
|
| 440 |
+
} else if (type == "number" || type == "string") {
|
| 441 |
+
cx.marked = jsonldMode ? "property" : (cx.style + " property");
|
| 442 |
+
return cont(afterprop);
|
| 443 |
+
} else if (type == "jsonld-keyword") {
|
| 444 |
+
return cont(afterprop);
|
| 445 |
+
} else if (type == "[") {
|
| 446 |
+
return cont(expression, expect("]"), afterprop);
|
| 447 |
+
}
|
| 448 |
+
}
|
| 449 |
+
function getterSetter(type) {
|
| 450 |
+
if (type != "variable") return pass(afterprop);
|
| 451 |
+
cx.marked = "property";
|
| 452 |
+
return cont(functiondef);
|
| 453 |
+
}
|
| 454 |
+
function afterprop(type) {
|
| 455 |
+
if (type == ":") return cont(expressionNoComma);
|
| 456 |
+
if (type == "(") return pass(functiondef);
|
| 457 |
+
}
|
| 458 |
+
function commasep(what, end) {
|
| 459 |
+
function proceed(type) {
|
| 460 |
+
if (type == ",") {
|
| 461 |
+
var lex = cx.state.lexical;
|
| 462 |
+
if (lex.info == "call") lex.pos = (lex.pos || 0) + 1;
|
| 463 |
+
return cont(what, proceed);
|
| 464 |
+
}
|
| 465 |
+
if (type == end) return cont();
|
| 466 |
+
return cont(expect(end));
|
| 467 |
+
}
|
| 468 |
+
return function(type) {
|
| 469 |
+
if (type == end) return cont();
|
| 470 |
+
return pass(what, proceed);
|
| 471 |
+
};
|
| 472 |
+
}
|
| 473 |
+
function contCommasep(what, end, info) {
|
| 474 |
+
for (var i = 3; i < arguments.length; i++)
|
| 475 |
+
cx.cc.push(arguments[i]);
|
| 476 |
+
return cont(pushlex(end, info), commasep(what, end), poplex);
|
| 477 |
+
}
|
| 478 |
+
function block(type) {
|
| 479 |
+
if (type == "}") return cont();
|
| 480 |
+
return pass(statement, block);
|
| 481 |
+
}
|
| 482 |
+
function maybetype(type) {
|
| 483 |
+
if (isTS && type == ":") return cont(typedef);
|
| 484 |
+
}
|
| 485 |
+
function typedef(type) {
|
| 486 |
+
if (type == "variable"){cx.marked = "variable-3"; return cont();}
|
| 487 |
+
}
|
| 488 |
+
function vardef() {
|
| 489 |
+
return pass(pattern, maybetype, maybeAssign, vardefCont);
|
| 490 |
+
}
|
| 491 |
+
function pattern(type, value) {
|
| 492 |
+
if (type == "variable") { register(value); return cont(); }
|
| 493 |
+
if (type == "[") return contCommasep(pattern, "]");
|
| 494 |
+
if (type == "{") return contCommasep(proppattern, "}");
|
| 495 |
+
}
|
| 496 |
+
function proppattern(type, value) {
|
| 497 |
+
if (type == "variable" && !cx.stream.match(/^\s*:/, false)) {
|
| 498 |
+
register(value);
|
| 499 |
+
return cont(maybeAssign);
|
| 500 |
+
}
|
| 501 |
+
if (type == "variable") cx.marked = "property";
|
| 502 |
+
return cont(expect(":"), pattern, maybeAssign);
|
| 503 |
+
}
|
| 504 |
+
function maybeAssign(_type, value) {
|
| 505 |
+
if (value == "=") return cont(expressionNoComma);
|
| 506 |
+
}
|
| 507 |
+
function vardefCont(type) {
|
| 508 |
+
if (type == ",") return cont(vardef);
|
| 509 |
+
}
|
| 510 |
+
function maybeelse(type, value) {
|
| 511 |
+
if (type == "keyword b" && value == "else") return cont(pushlex("form", "else"), statement, poplex);
|
| 512 |
+
}
|
| 513 |
+
function forspec(type) {
|
| 514 |
+
if (type == "(") return cont(pushlex(")"), forspec1, expect(")"), poplex);
|
| 515 |
+
}
|
| 516 |
+
function forspec1(type) {
|
| 517 |
+
if (type == "var") return cont(vardef, expect(";"), forspec2);
|
| 518 |
+
if (type == ";") return cont(forspec2);
|
| 519 |
+
if (type == "variable") return cont(formaybeinof);
|
| 520 |
+
return pass(expression, expect(";"), forspec2);
|
| 521 |
+
}
|
| 522 |
+
function formaybeinof(_type, value) {
|
| 523 |
+
if (value == "in" || value == "of") { cx.marked = "keyword"; return cont(expression); }
|
| 524 |
+
return cont(maybeoperatorComma, forspec2);
|
| 525 |
+
}
|
| 526 |
+
function forspec2(type, value) {
|
| 527 |
+
if (type == ";") return cont(forspec3);
|
| 528 |
+
if (value == "in" || value == "of") { cx.marked = "keyword"; return cont(expression); }
|
| 529 |
+
return pass(expression, expect(";"), forspec3);
|
| 530 |
+
}
|
| 531 |
+
function forspec3(type) {
|
| 532 |
+
if (type != ")") cont(expression);
|
| 533 |
+
}
|
| 534 |
+
function functiondef(type, value) {
|
| 535 |
+
if (value == "*") {cx.marked = "keyword"; return cont(functiondef);}
|
| 536 |
+
if (type == "variable") {register(value); return cont(functiondef);}
|
| 537 |
+
if (type == "(") return cont(pushcontext, pushlex(")"), commasep(funarg, ")"), poplex, statement, popcontext);
|
| 538 |
+
}
|
| 539 |
+
function funarg(type) {
|
| 540 |
+
if (type == "spread") return cont(funarg);
|
| 541 |
+
return pass(pattern, maybetype);
|
| 542 |
+
}
|
| 543 |
+
function className(type, value) {
|
| 544 |
+
if (type == "variable") {register(value); return cont(classNameAfter);}
|
| 545 |
+
}
|
| 546 |
+
function classNameAfter(type, value) {
|
| 547 |
+
if (value == "extends") return cont(expression, classNameAfter);
|
| 548 |
+
if (type == "{") return cont(pushlex("}"), classBody, poplex);
|
| 549 |
+
}
|
| 550 |
+
function classBody(type, value) {
|
| 551 |
+
if (type == "variable" || cx.style == "keyword") {
|
| 552 |
+
if (value == "static") {
|
| 553 |
+
cx.marked = "keyword";
|
| 554 |
+
return cont(classBody);
|
| 555 |
+
}
|
| 556 |
+
cx.marked = "property";
|
| 557 |
+
if (value == "get" || value == "set") return cont(classGetterSetter, functiondef, classBody);
|
| 558 |
+
return cont(functiondef, classBody);
|
| 559 |
+
}
|
| 560 |
+
if (value == "*") {
|
| 561 |
+
cx.marked = "keyword";
|
| 562 |
+
return cont(classBody);
|
| 563 |
+
}
|
| 564 |
+
if (type == ";") return cont(classBody);
|
| 565 |
+
if (type == "}") return cont();
|
| 566 |
+
}
|
| 567 |
+
function classGetterSetter(type) {
|
| 568 |
+
if (type != "variable") return pass();
|
| 569 |
+
cx.marked = "property";
|
| 570 |
+
return cont();
|
| 571 |
+
}
|
| 572 |
+
function afterModule(type, value) {
|
| 573 |
+
if (type == "string") return cont(statement);
|
| 574 |
+
if (type == "variable") { register(value); return cont(maybeFrom); }
|
| 575 |
+
}
|
| 576 |
+
function afterExport(_type, value) {
|
| 577 |
+
if (value == "*") { cx.marked = "keyword"; return cont(maybeFrom, expect(";")); }
|
| 578 |
+
if (value == "default") { cx.marked = "keyword"; return cont(expression, expect(";")); }
|
| 579 |
+
return pass(statement);
|
| 580 |
+
}
|
| 581 |
+
function afterImport(type) {
|
| 582 |
+
if (type == "string") return cont();
|
| 583 |
+
return pass(importSpec, maybeFrom);
|
| 584 |
+
}
|
| 585 |
+
function importSpec(type, value) {
|
| 586 |
+
if (type == "{") return contCommasep(importSpec, "}");
|
| 587 |
+
if (type == "variable") register(value);
|
| 588 |
+
if (value == "*") cx.marked = "keyword";
|
| 589 |
+
return cont(maybeAs);
|
| 590 |
+
}
|
| 591 |
+
function maybeAs(_type, value) {
|
| 592 |
+
if (value == "as") { cx.marked = "keyword"; return cont(importSpec); }
|
| 593 |
+
}
|
| 594 |
+
function maybeFrom(_type, value) {
|
| 595 |
+
if (value == "from") { cx.marked = "keyword"; return cont(expression); }
|
| 596 |
+
}
|
| 597 |
+
function arrayLiteral(type) {
|
| 598 |
+
if (type == "]") return cont();
|
| 599 |
+
return pass(expressionNoComma, maybeArrayComprehension);
|
| 600 |
+
}
|
| 601 |
+
function maybeArrayComprehension(type) {
|
| 602 |
+
if (type == "for") return pass(comprehension, expect("]"));
|
| 603 |
+
if (type == ",") return cont(commasep(maybeexpressionNoComma, "]"));
|
| 604 |
+
return pass(commasep(expressionNoComma, "]"));
|
| 605 |
+
}
|
| 606 |
+
function comprehension(type) {
|
| 607 |
+
if (type == "for") return cont(forspec, comprehension);
|
| 608 |
+
if (type == "if") return cont(expression, comprehension);
|
| 609 |
+
}
|
| 610 |
+
|
| 611 |
+
function isContinuedStatement(state, textAfter) {
|
| 612 |
+
return state.lastType == "operator" || state.lastType == "," ||
|
| 613 |
+
isOperatorChar.test(textAfter.charAt(0)) ||
|
| 614 |
+
/[,.]/.test(textAfter.charAt(0));
|
| 615 |
+
}
|
| 616 |
+
|
| 617 |
+
// Interface
|
| 618 |
+
|
| 619 |
+
return {
|
| 620 |
+
startState: function(basecolumn) {
|
| 621 |
+
var state = {
|
| 622 |
+
tokenize: tokenBase,
|
| 623 |
+
lastType: "sof",
|
| 624 |
+
cc: [],
|
| 625 |
+
lexical: new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false),
|
| 626 |
+
localVars: parserConfig.localVars,
|
| 627 |
+
context: parserConfig.localVars && {vars: parserConfig.localVars},
|
| 628 |
+
indented: 0
|
| 629 |
+
};
|
| 630 |
+
if (parserConfig.globalVars && typeof parserConfig.globalVars == "object")
|
| 631 |
+
state.globalVars = parserConfig.globalVars;
|
| 632 |
+
return state;
|
| 633 |
+
},
|
| 634 |
+
|
| 635 |
+
token: function(stream, state) {
|
| 636 |
+
if (stream.sol()) {
|
| 637 |
+
if (!state.lexical.hasOwnProperty("align"))
|
| 638 |
+
state.lexical.align = false;
|
| 639 |
+
state.indented = stream.indentation();
|
| 640 |
+
findFatArrow(stream, state);
|
| 641 |
+
}
|
| 642 |
+
if (state.tokenize != tokenComment && stream.eatSpace()) return null;
|
| 643 |
+
var style = state.tokenize(stream, state);
|
| 644 |
+
if (type == "comment") return style;
|
| 645 |
+
state.lastType = type == "operator" && (content == "++" || content == "--") ? "incdec" : type;
|
| 646 |
+
return parseJS(state, style, type, content, stream);
|
| 647 |
+
},
|
| 648 |
+
|
| 649 |
+
indent: function(state, textAfter) {
|
| 650 |
+
if (state.tokenize == tokenComment) return CodeMirror.Pass;
|
| 651 |
+
if (state.tokenize != tokenBase) return 0;
|
| 652 |
+
var firstChar = textAfter && textAfter.charAt(0), lexical = state.lexical;
|
| 653 |
+
// Kludge to prevent 'maybelse' from blocking lexical scope pops
|
| 654 |
+
if (!/^\s*else\b/.test(textAfter)) for (var i = state.cc.length - 1; i >= 0; --i) {
|
| 655 |
+
var c = state.cc[i];
|
| 656 |
+
if (c == poplex) lexical = lexical.prev;
|
| 657 |
+
else if (c != maybeelse) break;
|
| 658 |
+
}
|
| 659 |
+
if (lexical.type == "stat" && firstChar == "}") lexical = lexical.prev;
|
| 660 |
+
if (statementIndent && lexical.type == ")" && lexical.prev.type == "stat")
|
| 661 |
+
lexical = lexical.prev;
|
| 662 |
+
var type = lexical.type, closing = firstChar == type;
|
| 663 |
+
|
| 664 |
+
if (type == "vardef") return lexical.indented + (state.lastType == "operator" || state.lastType == "," ? lexical.info + 1 : 0);
|
| 665 |
+
else if (type == "form" && firstChar == "{") return lexical.indented;
|
| 666 |
+
else if (type == "form") return lexical.indented + indentUnit;
|
| 667 |
+
else if (type == "stat")
|
| 668 |
+
return lexical.indented + (isContinuedStatement(state, textAfter) ? statementIndent || indentUnit : 0);
|
| 669 |
+
else if (lexical.info == "switch" && !closing && parserConfig.doubleIndentSwitch != false)
|
| 670 |
+
return lexical.indented + (/^(?:case|default)\b/.test(textAfter) ? indentUnit : 2 * indentUnit);
|
| 671 |
+
else if (lexical.align) return lexical.column + (closing ? 0 : 1);
|
| 672 |
+
else return lexical.indented + (closing ? 0 : indentUnit);
|
| 673 |
+
},
|
| 674 |
+
|
| 675 |
+
electricInput: /^\s*(?:case .*?:|default:|\{|\})$/,
|
| 676 |
+
blockCommentStart: jsonMode ? null : "/*",
|
| 677 |
+
blockCommentEnd: jsonMode ? null : "*/",
|
| 678 |
+
lineComment: jsonMode ? null : "//",
|
| 679 |
+
fold: "brace",
|
| 680 |
+
closeBrackets: "()[]{}''\"\"``",
|
| 681 |
+
|
| 682 |
+
helperType: jsonMode ? "json" : "javascript",
|
| 683 |
+
jsonldMode: jsonldMode,
|
| 684 |
+
jsonMode: jsonMode
|
| 685 |
+
};
|
| 686 |
+
});
|
| 687 |
+
|
| 688 |
+
CodeMirror.registerHelper("wordChars", "javascript", /[\w$]/);
|
| 689 |
+
|
| 690 |
+
CodeMirror.defineMIME("text/javascript", "javascript");
|
| 691 |
+
CodeMirror.defineMIME("text/ecmascript", "javascript");
|
| 692 |
+
CodeMirror.defineMIME("application/javascript", "javascript");
|
| 693 |
+
CodeMirror.defineMIME("application/x-javascript", "javascript");
|
| 694 |
+
CodeMirror.defineMIME("application/ecmascript", "javascript");
|
| 695 |
+
CodeMirror.defineMIME("application/json", {name: "javascript", json: true});
|
| 696 |
+
CodeMirror.defineMIME("application/x-json", {name: "javascript", json: true});
|
| 697 |
+
CodeMirror.defineMIME("application/ld+json", {name: "javascript", jsonld: true});
|
| 698 |
+
CodeMirror.defineMIME("text/typescript", { name: "javascript", typescript: true });
|
| 699 |
+
CodeMirror.defineMIME("application/typescript", { name: "javascript", typescript: true });
|
| 700 |
+
|
| 701 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/mode/xml/xml.js
ADDED
|
@@ -0,0 +1,384 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
| 2 |
+
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
| 3 |
+
|
| 4 |
+
(function(mod) {
|
| 5 |
+
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
| 6 |
+
mod(require("../../lib/codemirror"));
|
| 7 |
+
else if (typeof define == "function" && define.amd) // AMD
|
| 8 |
+
define(["../../lib/codemirror"], mod);
|
| 9 |
+
else // Plain browser env
|
| 10 |
+
mod(CodeMirror);
|
| 11 |
+
})(function(CodeMirror) {
|
| 12 |
+
"use strict";
|
| 13 |
+
|
| 14 |
+
CodeMirror.defineMode("xml", function(config, parserConfig) {
|
| 15 |
+
var indentUnit = config.indentUnit;
|
| 16 |
+
var multilineTagIndentFactor = parserConfig.multilineTagIndentFactor || 1;
|
| 17 |
+
var multilineTagIndentPastTag = parserConfig.multilineTagIndentPastTag;
|
| 18 |
+
if (multilineTagIndentPastTag == null) multilineTagIndentPastTag = true;
|
| 19 |
+
|
| 20 |
+
var Kludges = parserConfig.htmlMode ? {
|
| 21 |
+
autoSelfClosers: {'area': true, 'base': true, 'br': true, 'col': true, 'command': true,
|
| 22 |
+
'embed': true, 'frame': true, 'hr': true, 'img': true, 'input': true,
|
| 23 |
+
'keygen': true, 'link': true, 'meta': true, 'param': true, 'source': true,
|
| 24 |
+
'track': true, 'wbr': true, 'menuitem': true},
|
| 25 |
+
implicitlyClosed: {'dd': true, 'li': true, 'optgroup': true, 'option': true, 'p': true,
|
| 26 |
+
'rp': true, 'rt': true, 'tbody': true, 'td': true, 'tfoot': true,
|
| 27 |
+
'th': true, 'tr': true},
|
| 28 |
+
contextGrabbers: {
|
| 29 |
+
'dd': {'dd': true, 'dt': true},
|
| 30 |
+
'dt': {'dd': true, 'dt': true},
|
| 31 |
+
'li': {'li': true},
|
| 32 |
+
'option': {'option': true, 'optgroup': true},
|
| 33 |
+
'optgroup': {'optgroup': true},
|
| 34 |
+
'p': {'address': true, 'article': true, 'aside': true, 'blockquote': true, 'dir': true,
|
| 35 |
+
'div': true, 'dl': true, 'fieldset': true, 'footer': true, 'form': true,
|
| 36 |
+
'h1': true, 'h2': true, 'h3': true, 'h4': true, 'h5': true, 'h6': true,
|
| 37 |
+
'header': true, 'hgroup': true, 'hr': true, 'menu': true, 'nav': true, 'ol': true,
|
| 38 |
+
'p': true, 'pre': true, 'section': true, 'table': true, 'ul': true},
|
| 39 |
+
'rp': {'rp': true, 'rt': true},
|
| 40 |
+
'rt': {'rp': true, 'rt': true},
|
| 41 |
+
'tbody': {'tbody': true, 'tfoot': true},
|
| 42 |
+
'td': {'td': true, 'th': true},
|
| 43 |
+
'tfoot': {'tbody': true},
|
| 44 |
+
'th': {'td': true, 'th': true},
|
| 45 |
+
'thead': {'tbody': true, 'tfoot': true},
|
| 46 |
+
'tr': {'tr': true}
|
| 47 |
+
},
|
| 48 |
+
doNotIndent: {"pre": true},
|
| 49 |
+
allowUnquoted: true,
|
| 50 |
+
allowMissing: true,
|
| 51 |
+
caseFold: true
|
| 52 |
+
} : {
|
| 53 |
+
autoSelfClosers: {},
|
| 54 |
+
implicitlyClosed: {},
|
| 55 |
+
contextGrabbers: {},
|
| 56 |
+
doNotIndent: {},
|
| 57 |
+
allowUnquoted: false,
|
| 58 |
+
allowMissing: false,
|
| 59 |
+
caseFold: false
|
| 60 |
+
};
|
| 61 |
+
var alignCDATA = parserConfig.alignCDATA;
|
| 62 |
+
|
| 63 |
+
// Return variables for tokenizers
|
| 64 |
+
var type, setStyle;
|
| 65 |
+
|
| 66 |
+
function inText(stream, state) {
|
| 67 |
+
function chain(parser) {
|
| 68 |
+
state.tokenize = parser;
|
| 69 |
+
return parser(stream, state);
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
var ch = stream.next();
|
| 73 |
+
if (ch == "<") {
|
| 74 |
+
if (stream.eat("!")) {
|
| 75 |
+
if (stream.eat("[")) {
|
| 76 |
+
if (stream.match("CDATA[")) return chain(inBlock("atom", "]]>"));
|
| 77 |
+
else return null;
|
| 78 |
+
} else if (stream.match("--")) {
|
| 79 |
+
return chain(inBlock("comment", "-->"));
|
| 80 |
+
} else if (stream.match("DOCTYPE", true, true)) {
|
| 81 |
+
stream.eatWhile(/[\w\._\-]/);
|
| 82 |
+
return chain(doctype(1));
|
| 83 |
+
} else {
|
| 84 |
+
return null;
|
| 85 |
+
}
|
| 86 |
+
} else if (stream.eat("?")) {
|
| 87 |
+
stream.eatWhile(/[\w\._\-]/);
|
| 88 |
+
state.tokenize = inBlock("meta", "?>");
|
| 89 |
+
return "meta";
|
| 90 |
+
} else {
|
| 91 |
+
type = stream.eat("/") ? "closeTag" : "openTag";
|
| 92 |
+
state.tokenize = inTag;
|
| 93 |
+
return "tag bracket";
|
| 94 |
+
}
|
| 95 |
+
} else if (ch == "&") {
|
| 96 |
+
var ok;
|
| 97 |
+
if (stream.eat("#")) {
|
| 98 |
+
if (stream.eat("x")) {
|
| 99 |
+
ok = stream.eatWhile(/[a-fA-F\d]/) && stream.eat(";");
|
| 100 |
+
} else {
|
| 101 |
+
ok = stream.eatWhile(/[\d]/) && stream.eat(";");
|
| 102 |
+
}
|
| 103 |
+
} else {
|
| 104 |
+
ok = stream.eatWhile(/[\w\.\-:]/) && stream.eat(";");
|
| 105 |
+
}
|
| 106 |
+
return ok ? "atom" : "error";
|
| 107 |
+
} else {
|
| 108 |
+
stream.eatWhile(/[^&<]/);
|
| 109 |
+
return null;
|
| 110 |
+
}
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
function inTag(stream, state) {
|
| 114 |
+
var ch = stream.next();
|
| 115 |
+
if (ch == ">" || (ch == "/" && stream.eat(">"))) {
|
| 116 |
+
state.tokenize = inText;
|
| 117 |
+
type = ch == ">" ? "endTag" : "selfcloseTag";
|
| 118 |
+
return "tag bracket";
|
| 119 |
+
} else if (ch == "=") {
|
| 120 |
+
type = "equals";
|
| 121 |
+
return null;
|
| 122 |
+
} else if (ch == "<") {
|
| 123 |
+
state.tokenize = inText;
|
| 124 |
+
state.state = baseState;
|
| 125 |
+
state.tagName = state.tagStart = null;
|
| 126 |
+
var next = state.tokenize(stream, state);
|
| 127 |
+
return next ? next + " tag error" : "tag error";
|
| 128 |
+
} else if (/[\'\"]/.test(ch)) {
|
| 129 |
+
state.tokenize = inAttribute(ch);
|
| 130 |
+
state.stringStartCol = stream.column();
|
| 131 |
+
return state.tokenize(stream, state);
|
| 132 |
+
} else {
|
| 133 |
+
stream.match(/^[^\s\u00a0=<>\"\']*[^\s\u00a0=<>\"\'\/]/);
|
| 134 |
+
return "word";
|
| 135 |
+
}
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
function inAttribute(quote) {
|
| 139 |
+
var closure = function(stream, state) {
|
| 140 |
+
while (!stream.eol()) {
|
| 141 |
+
if (stream.next() == quote) {
|
| 142 |
+
state.tokenize = inTag;
|
| 143 |
+
break;
|
| 144 |
+
}
|
| 145 |
+
}
|
| 146 |
+
return "string";
|
| 147 |
+
};
|
| 148 |
+
closure.isInAttribute = true;
|
| 149 |
+
return closure;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
function inBlock(style, terminator) {
|
| 153 |
+
return function(stream, state) {
|
| 154 |
+
while (!stream.eol()) {
|
| 155 |
+
if (stream.match(terminator)) {
|
| 156 |
+
state.tokenize = inText;
|
| 157 |
+
break;
|
| 158 |
+
}
|
| 159 |
+
stream.next();
|
| 160 |
+
}
|
| 161 |
+
return style;
|
| 162 |
+
};
|
| 163 |
+
}
|
| 164 |
+
function doctype(depth) {
|
| 165 |
+
return function(stream, state) {
|
| 166 |
+
var ch;
|
| 167 |
+
while ((ch = stream.next()) != null) {
|
| 168 |
+
if (ch == "<") {
|
| 169 |
+
state.tokenize = doctype(depth + 1);
|
| 170 |
+
return state.tokenize(stream, state);
|
| 171 |
+
} else if (ch == ">") {
|
| 172 |
+
if (depth == 1) {
|
| 173 |
+
state.tokenize = inText;
|
| 174 |
+
break;
|
| 175 |
+
} else {
|
| 176 |
+
state.tokenize = doctype(depth - 1);
|
| 177 |
+
return state.tokenize(stream, state);
|
| 178 |
+
}
|
| 179 |
+
}
|
| 180 |
+
}
|
| 181 |
+
return "meta";
|
| 182 |
+
};
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
function Context(state, tagName, startOfLine) {
|
| 186 |
+
this.prev = state.context;
|
| 187 |
+
this.tagName = tagName;
|
| 188 |
+
this.indent = state.indented;
|
| 189 |
+
this.startOfLine = startOfLine;
|
| 190 |
+
if (Kludges.doNotIndent.hasOwnProperty(tagName) || (state.context && state.context.noIndent))
|
| 191 |
+
this.noIndent = true;
|
| 192 |
+
}
|
| 193 |
+
function popContext(state) {
|
| 194 |
+
if (state.context) state.context = state.context.prev;
|
| 195 |
+
}
|
| 196 |
+
function maybePopContext(state, nextTagName) {
|
| 197 |
+
var parentTagName;
|
| 198 |
+
while (true) {
|
| 199 |
+
if (!state.context) {
|
| 200 |
+
return;
|
| 201 |
+
}
|
| 202 |
+
parentTagName = state.context.tagName;
|
| 203 |
+
if (!Kludges.contextGrabbers.hasOwnProperty(parentTagName) ||
|
| 204 |
+
!Kludges.contextGrabbers[parentTagName].hasOwnProperty(nextTagName)) {
|
| 205 |
+
return;
|
| 206 |
+
}
|
| 207 |
+
popContext(state);
|
| 208 |
+
}
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
function baseState(type, stream, state) {
|
| 212 |
+
if (type == "openTag") {
|
| 213 |
+
state.tagStart = stream.column();
|
| 214 |
+
return tagNameState;
|
| 215 |
+
} else if (type == "closeTag") {
|
| 216 |
+
return closeTagNameState;
|
| 217 |
+
} else {
|
| 218 |
+
return baseState;
|
| 219 |
+
}
|
| 220 |
+
}
|
| 221 |
+
function tagNameState(type, stream, state) {
|
| 222 |
+
if (type == "word") {
|
| 223 |
+
state.tagName = stream.current();
|
| 224 |
+
setStyle = "tag";
|
| 225 |
+
return attrState;
|
| 226 |
+
} else {
|
| 227 |
+
setStyle = "error";
|
| 228 |
+
return tagNameState;
|
| 229 |
+
}
|
| 230 |
+
}
|
| 231 |
+
function closeTagNameState(type, stream, state) {
|
| 232 |
+
if (type == "word") {
|
| 233 |
+
var tagName = stream.current();
|
| 234 |
+
if (state.context && state.context.tagName != tagName &&
|
| 235 |
+
Kludges.implicitlyClosed.hasOwnProperty(state.context.tagName))
|
| 236 |
+
popContext(state);
|
| 237 |
+
if (state.context && state.context.tagName == tagName) {
|
| 238 |
+
setStyle = "tag";
|
| 239 |
+
return closeState;
|
| 240 |
+
} else {
|
| 241 |
+
setStyle = "tag error";
|
| 242 |
+
return closeStateErr;
|
| 243 |
+
}
|
| 244 |
+
} else {
|
| 245 |
+
setStyle = "error";
|
| 246 |
+
return closeStateErr;
|
| 247 |
+
}
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
function closeState(type, _stream, state) {
|
| 251 |
+
if (type != "endTag") {
|
| 252 |
+
setStyle = "error";
|
| 253 |
+
return closeState;
|
| 254 |
+
}
|
| 255 |
+
popContext(state);
|
| 256 |
+
return baseState;
|
| 257 |
+
}
|
| 258 |
+
function closeStateErr(type, stream, state) {
|
| 259 |
+
setStyle = "error";
|
| 260 |
+
return closeState(type, stream, state);
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
function attrState(type, _stream, state) {
|
| 264 |
+
if (type == "word") {
|
| 265 |
+
setStyle = "attribute";
|
| 266 |
+
return attrEqState;
|
| 267 |
+
} else if (type == "endTag" || type == "selfcloseTag") {
|
| 268 |
+
var tagName = state.tagName, tagStart = state.tagStart;
|
| 269 |
+
state.tagName = state.tagStart = null;
|
| 270 |
+
if (type == "selfcloseTag" ||
|
| 271 |
+
Kludges.autoSelfClosers.hasOwnProperty(tagName)) {
|
| 272 |
+
maybePopContext(state, tagName);
|
| 273 |
+
} else {
|
| 274 |
+
maybePopContext(state, tagName);
|
| 275 |
+
state.context = new Context(state, tagName, tagStart == state.indented);
|
| 276 |
+
}
|
| 277 |
+
return baseState;
|
| 278 |
+
}
|
| 279 |
+
setStyle = "error";
|
| 280 |
+
return attrState;
|
| 281 |
+
}
|
| 282 |
+
function attrEqState(type, stream, state) {
|
| 283 |
+
if (type == "equals") return attrValueState;
|
| 284 |
+
if (!Kludges.allowMissing) setStyle = "error";
|
| 285 |
+
return attrState(type, stream, state);
|
| 286 |
+
}
|
| 287 |
+
function attrValueState(type, stream, state) {
|
| 288 |
+
if (type == "string") return attrContinuedState;
|
| 289 |
+
if (type == "word" && Kludges.allowUnquoted) {setStyle = "string"; return attrState;}
|
| 290 |
+
setStyle = "error";
|
| 291 |
+
return attrState(type, stream, state);
|
| 292 |
+
}
|
| 293 |
+
function attrContinuedState(type, stream, state) {
|
| 294 |
+
if (type == "string") return attrContinuedState;
|
| 295 |
+
return attrState(type, stream, state);
|
| 296 |
+
}
|
| 297 |
+
|
| 298 |
+
return {
|
| 299 |
+
startState: function() {
|
| 300 |
+
return {tokenize: inText,
|
| 301 |
+
state: baseState,
|
| 302 |
+
indented: 0,
|
| 303 |
+
tagName: null, tagStart: null,
|
| 304 |
+
context: null};
|
| 305 |
+
},
|
| 306 |
+
|
| 307 |
+
token: function(stream, state) {
|
| 308 |
+
if (!state.tagName && stream.sol())
|
| 309 |
+
state.indented = stream.indentation();
|
| 310 |
+
|
| 311 |
+
if (stream.eatSpace()) return null;
|
| 312 |
+
type = null;
|
| 313 |
+
var style = state.tokenize(stream, state);
|
| 314 |
+
if ((style || type) && style != "comment") {
|
| 315 |
+
setStyle = null;
|
| 316 |
+
state.state = state.state(type || style, stream, state);
|
| 317 |
+
if (setStyle)
|
| 318 |
+
style = setStyle == "error" ? style + " error" : setStyle;
|
| 319 |
+
}
|
| 320 |
+
return style;
|
| 321 |
+
},
|
| 322 |
+
|
| 323 |
+
indent: function(state, textAfter, fullLine) {
|
| 324 |
+
var context = state.context;
|
| 325 |
+
// Indent multi-line strings (e.g. css).
|
| 326 |
+
if (state.tokenize.isInAttribute) {
|
| 327 |
+
if (state.tagStart == state.indented)
|
| 328 |
+
return state.stringStartCol + 1;
|
| 329 |
+
else
|
| 330 |
+
return state.indented + indentUnit;
|
| 331 |
+
}
|
| 332 |
+
if (context && context.noIndent) return CodeMirror.Pass;
|
| 333 |
+
if (state.tokenize != inTag && state.tokenize != inText)
|
| 334 |
+
return fullLine ? fullLine.match(/^(\s*)/)[0].length : 0;
|
| 335 |
+
// Indent the starts of attribute names.
|
| 336 |
+
if (state.tagName) {
|
| 337 |
+
if (multilineTagIndentPastTag)
|
| 338 |
+
return state.tagStart + state.tagName.length + 2;
|
| 339 |
+
else
|
| 340 |
+
return state.tagStart + indentUnit * multilineTagIndentFactor;
|
| 341 |
+
}
|
| 342 |
+
if (alignCDATA && /<!\[CDATA\[/.test(textAfter)) return 0;
|
| 343 |
+
var tagAfter = textAfter && /^<(\/)?([\w_:\.-]*)/.exec(textAfter);
|
| 344 |
+
if (tagAfter && tagAfter[1]) { // Closing tag spotted
|
| 345 |
+
while (context) {
|
| 346 |
+
if (context.tagName == tagAfter[2]) {
|
| 347 |
+
context = context.prev;
|
| 348 |
+
break;
|
| 349 |
+
} else if (Kludges.implicitlyClosed.hasOwnProperty(context.tagName)) {
|
| 350 |
+
context = context.prev;
|
| 351 |
+
} else {
|
| 352 |
+
break;
|
| 353 |
+
}
|
| 354 |
+
}
|
| 355 |
+
} else if (tagAfter) { // Opening tag spotted
|
| 356 |
+
while (context) {
|
| 357 |
+
var grabbers = Kludges.contextGrabbers[context.tagName];
|
| 358 |
+
if (grabbers && grabbers.hasOwnProperty(tagAfter[2]))
|
| 359 |
+
context = context.prev;
|
| 360 |
+
else
|
| 361 |
+
break;
|
| 362 |
+
}
|
| 363 |
+
}
|
| 364 |
+
while (context && !context.startOfLine)
|
| 365 |
+
context = context.prev;
|
| 366 |
+
if (context) return context.indent + indentUnit;
|
| 367 |
+
else return 0;
|
| 368 |
+
},
|
| 369 |
+
|
| 370 |
+
electricInput: /<\/[\s\w:]+>$/,
|
| 371 |
+
blockCommentStart: "<!--",
|
| 372 |
+
blockCommentEnd: "-->",
|
| 373 |
+
|
| 374 |
+
configuration: parserConfig.htmlMode ? "html" : "xml",
|
| 375 |
+
helperType: parserConfig.htmlMode ? "html" : "xml"
|
| 376 |
+
};
|
| 377 |
+
});
|
| 378 |
+
|
| 379 |
+
CodeMirror.defineMIME("text/xml", "xml");
|
| 380 |
+
CodeMirror.defineMIME("application/xml", "xml");
|
| 381 |
+
if (!CodeMirror.mimeModes.hasOwnProperty("text/html"))
|
| 382 |
+
CodeMirror.defineMIME("text/html", {name: "xml", htmlMode: true});
|
| 383 |
+
|
| 384 |
+
});
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/theme/3024-day.css
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
|
| 3 |
+
Name: 3024 day
|
| 4 |
+
Author: Jan T. Sott (http://github.com/idleberg)
|
| 5 |
+
|
| 6 |
+
CodeMirror template by Jan T. Sott (https://github.com/idleberg/base16-codemirror)
|
| 7 |
+
Original Base16 color scheme by Chris Kempson (https://github.com/chriskempson/base16)
|
| 8 |
+
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
.cm-s-3024-day.CodeMirror {background: #f7f7f7; color: #3a3432;}
|
| 12 |
+
.cm-s-3024-day div.CodeMirror-selected {background: #d6d5d4 !important;}
|
| 13 |
+
.cm-s-3024-day.CodeMirror ::selection { background: #d6d5d4; }
|
| 14 |
+
.cm-s-3024-day.CodeMirror ::-moz-selection { background: #d9d9d9; }
|
| 15 |
+
|
| 16 |
+
.cm-s-3024-day .CodeMirror-gutters {background: #f7f7f7; border-right: 0px;}
|
| 17 |
+
.cm-s-3024-day .CodeMirror-guttermarker { color: #db2d20; }
|
| 18 |
+
.cm-s-3024-day .CodeMirror-guttermarker-subtle { color: #807d7c; }
|
| 19 |
+
.cm-s-3024-day .CodeMirror-linenumber {color: #807d7c;}
|
| 20 |
+
|
| 21 |
+
.cm-s-3024-day .CodeMirror-cursor {border-left: 1px solid #5c5855 !important;}
|
| 22 |
+
|
| 23 |
+
.cm-s-3024-day span.cm-comment {color: #cdab53;}
|
| 24 |
+
.cm-s-3024-day span.cm-atom {color: #a16a94;}
|
| 25 |
+
.cm-s-3024-day span.cm-number {color: #a16a94;}
|
| 26 |
+
|
| 27 |
+
.cm-s-3024-day span.cm-property, .cm-s-3024-day span.cm-attribute {color: #01a252;}
|
| 28 |
+
.cm-s-3024-day span.cm-keyword {color: #db2d20;}
|
| 29 |
+
.cm-s-3024-day span.cm-string {color: #fded02;}
|
| 30 |
+
|
| 31 |
+
.cm-s-3024-day span.cm-variable {color: #01a252;}
|
| 32 |
+
.cm-s-3024-day span.cm-variable-2 {color: #01a0e4;}
|
| 33 |
+
.cm-s-3024-day span.cm-def {color: #e8bbd0;}
|
| 34 |
+
.cm-s-3024-day span.cm-bracket {color: #3a3432;}
|
| 35 |
+
.cm-s-3024-day span.cm-tag {color: #db2d20;}
|
| 36 |
+
.cm-s-3024-day span.cm-link {color: #a16a94;}
|
| 37 |
+
.cm-s-3024-day span.cm-error {background: #db2d20; color: #5c5855;}
|
| 38 |
+
|
| 39 |
+
.cm-s-3024-day .CodeMirror-activeline-background {background: #e8f2ff !important;}
|
| 40 |
+
.cm-s-3024-day .CodeMirror-matchingbracket { text-decoration: underline; color: #a16a94 !important;}
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/theme/3024-night.css
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
|
| 3 |
+
Name: 3024 night
|
| 4 |
+
Author: Jan T. Sott (http://github.com/idleberg)
|
| 5 |
+
|
| 6 |
+
CodeMirror template by Jan T. Sott (https://github.com/idleberg/base16-codemirror)
|
| 7 |
+
Original Base16 color scheme by Chris Kempson (https://github.com/chriskempson/base16)
|
| 8 |
+
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
.cm-s-3024-night.CodeMirror {background: #090300; color: #d6d5d4;}
|
| 12 |
+
.cm-s-3024-night div.CodeMirror-selected {background: #3a3432 !important;}
|
| 13 |
+
.cm-s-3024-night.CodeMirror ::selection { background: rgba(58, 52, 50, .99); }
|
| 14 |
+
.cm-s-3024-night.CodeMirror ::-moz-selection { background: rgba(58, 52, 50, .99); }
|
| 15 |
+
.cm-s-3024-night .CodeMirror-gutters {background: #090300; border-right: 0px;}
|
| 16 |
+
.cm-s-3024-night .CodeMirror-guttermarker { color: #db2d20; }
|
| 17 |
+
.cm-s-3024-night .CodeMirror-guttermarker-subtle { color: #5c5855; }
|
| 18 |
+
.cm-s-3024-night .CodeMirror-linenumber {color: #5c5855;}
|
| 19 |
+
|
| 20 |
+
.cm-s-3024-night .CodeMirror-cursor {border-left: 1px solid #807d7c !important;}
|
| 21 |
+
|
| 22 |
+
.cm-s-3024-night span.cm-comment {color: #cdab53;}
|
| 23 |
+
.cm-s-3024-night span.cm-atom {color: #a16a94;}
|
| 24 |
+
.cm-s-3024-night span.cm-number {color: #a16a94;}
|
| 25 |
+
|
| 26 |
+
.cm-s-3024-night span.cm-property, .cm-s-3024-night span.cm-attribute {color: #01a252;}
|
| 27 |
+
.cm-s-3024-night span.cm-keyword {color: #db2d20;}
|
| 28 |
+
.cm-s-3024-night span.cm-string {color: #fded02;}
|
| 29 |
+
|
| 30 |
+
.cm-s-3024-night span.cm-variable {color: #01a252;}
|
| 31 |
+
.cm-s-3024-night span.cm-variable-2 {color: #01a0e4;}
|
| 32 |
+
.cm-s-3024-night span.cm-def {color: #e8bbd0;}
|
| 33 |
+
.cm-s-3024-night span.cm-bracket {color: #d6d5d4;}
|
| 34 |
+
.cm-s-3024-night span.cm-tag {color: #db2d20;}
|
| 35 |
+
.cm-s-3024-night span.cm-link {color: #a16a94;}
|
| 36 |
+
.cm-s-3024-night span.cm-error {background: #db2d20; color: #807d7c;}
|
| 37 |
+
|
| 38 |
+
.cm-s-3024-night .CodeMirror-activeline-background {background: #2F2F2F !important;}
|
| 39 |
+
.cm-s-3024-night .CodeMirror-matchingbracket { text-decoration: underline; color: white !important;}
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/theme/ambiance-mobile.css
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.cm-s-ambiance.CodeMirror {
|
| 2 |
+
-webkit-box-shadow: none;
|
| 3 |
+
-moz-box-shadow: none;
|
| 4 |
+
box-shadow: none;
|
| 5 |
+
}
|
js/tiny_mce/plugins/esites_editor/js/vendor/codemirror/theme/ambiance.css
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* ambiance theme for codemirror */
|
| 2 |
+
|
| 3 |
+
/* Color scheme */
|
| 4 |
+
|
| 5 |
+
.cm-s-ambiance .cm-keyword { color: #cda869; }
|
| 6 |
+
.cm-s-ambiance .cm-atom { color: #CF7EA9; }
|
| 7 |
+
.cm-s-ambiance .cm-number { color: #78CF8A; }
|
| 8 |
+
.cm-s-ambiance .cm-def { color: #aac6e3;
|
