Merge m-c to inbound a=merge

This commit is contained in:
Wes Kocher 2014-06-23 18:59:54 -07:00
commit 4c297ef8c0
180 changed files with 8487 additions and 5340 deletions

View File

@ -911,9 +911,6 @@ pref("gfx.canvas.max-size-for-skia-gl", -1);
// enable fence with readpixels for SurfaceStream
pref("gfx.gralloc.fence-with-readpixels", true);
// Cell Broadcast API
pref("ril.cellbroadcast.disabled", false);
// The url of the page used to display network error details.
pref("b2g.neterror.url", "app://system.gaiamobile.org/net_error.html");

View File

@ -664,13 +664,13 @@ let settingsToObserve = {
defaultValue: false
},
'devtools.eventlooplag.threshold': 100,
'dom.mozApps.use_reviewer_certs': false,
'layers.draw-borders': false,
'layers.draw-tile-borders': false,
'layers.dump': false,
'layers.enable-tiles': true,
'layers.simple-tiles': false,
'privacy.donottrackheader.enabled': false,
'ril.cellbroadcast.disabled': false,
'ril.radio.disabled': false,
'ril.mms.requestReadReport.enabled': {
prefName: 'dom.mms.requestReadReport',

View File

@ -40,6 +40,7 @@ category app-startup ProcessGlobal service,@mozilla.org/b2g-process-global;1
# OMAContentHandler.js
component {a6b2ab13-9037-423a-9897-dde1081be323} OMAContentHandler.js
contract @mozilla.org/uriloader/content-handler;1?type=application/vnd.oma.drm.message {a6b2ab13-9037-423a-9897-dde1081be323}
contract @mozilla.org/uriloader/content-handler;1?type=application/vnd.oma.dd+xml {a6b2ab13-9037-423a-9897-dde1081be323}
# PaymentGlue.js
component {8b83eabc-7929-47f4-8b48-4dea8d887e4b} PaymentGlue.js

View File

@ -19,13 +19,13 @@
<copyfile dest="Makefile" src="core/root.mk"/>
</project>
<project name="fake-dalvik" path="dalvik" remote="b2g" revision="ca1f327d5acc198bb4be62fa51db2c039032c9ce"/>
<project name="gaia.git" path="gaia" remote="mozillaorg" revision="41cc1de26e4edbe12add0009cdc0bd292f2e94fe"/>
<project name="gaia.git" path="gaia" remote="mozillaorg" revision="45479c07cb6ba8c733093d6ee32c767c090c9a28"/>
<project name="gonk-misc" path="gonk-misc" remote="b2g" revision="bbb7659d8ea2afb396f99b3dc971ab3c42da3778"/>
<project name="rilproxy" path="rilproxy" remote="b2g" revision="827214fcf38d6569aeb5c6d6f31cb296d1f09272"/>
<project name="platform_hardware_ril" path="hardware/ril" remote="b2g" revision="cd88d860656c31c7da7bb310d6a160d0011b0961"/>
<project name="platform_external_qemu" path="external/qemu" remote="b2g" revision="3326b51017252e09ccdd715dec6c5e12a7d1ecfe"/>
<project name="moztt" path="external/moztt" remote="b2g" revision="c510babaf88dfa2cfe2c202afb2649ee124569af"/>
<project name="apitrace" path="external/apitrace" remote="apitrace" revision="23db533981ee2cd04fc5d946420402aed2792381"/>
<project name="apitrace" path="external/apitrace" remote="apitrace" revision="c2544b1797eb5c59f484c442a24c4dc14c37e68c"/>
<!-- Stock Android things -->
<project name="platform/abi/cpp" path="abi/cpp" revision="dd924f92906085b831bf1cbbc7484d3c043d613c"/>
<project name="platform/bionic" path="bionic" revision="c72b8f6359de7ed17c11ddc9dfdde3f615d188a9"/>

View File

@ -17,10 +17,10 @@
</project>
<project name="rilproxy" path="rilproxy" remote="b2g" revision="827214fcf38d6569aeb5c6d6f31cb296d1f09272"/>
<project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
<project name="gaia" path="gaia" remote="mozillaorg" revision="41cc1de26e4edbe12add0009cdc0bd292f2e94fe"/>
<project name="gaia" path="gaia" remote="mozillaorg" revision="45479c07cb6ba8c733093d6ee32c767c090c9a28"/>
<project name="gonk-misc" path="gonk-misc" remote="b2g" revision="bbb7659d8ea2afb396f99b3dc971ab3c42da3778"/>
<project name="moztt" path="external/moztt" remote="b2g" revision="c510babaf88dfa2cfe2c202afb2649ee124569af"/>
<project name="apitrace" path="external/apitrace" remote="apitrace" revision="23db533981ee2cd04fc5d946420402aed2792381"/>
<project name="apitrace" path="external/apitrace" remote="apitrace" revision="c2544b1797eb5c59f484c442a24c4dc14c37e68c"/>
<project name="valgrind" path="external/valgrind" remote="b2g" revision="daa61633c32b9606f58799a3186395fd2bbb8d8c"/>
<project name="vex" path="external/VEX" remote="b2g" revision="47f031c320888fe9f3e656602588565b52d43010"/>
<!-- Stock Android things -->

View File

@ -15,7 +15,7 @@
<project name="platform_build" path="build" remote="b2g" revision="276ce45e78b09c4a4ee643646f691d22804754c1">
<copyfile dest="Makefile" src="core/root.mk"/>
</project>
<project name="gaia" path="gaia" remote="mozillaorg" revision="41cc1de26e4edbe12add0009cdc0bd292f2e94fe"/>
<project name="gaia" path="gaia" remote="mozillaorg" revision="45479c07cb6ba8c733093d6ee32c767c090c9a28"/>
<project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
<project name="gonk-misc" path="gonk-misc" remote="b2g" revision="bbb7659d8ea2afb396f99b3dc971ab3c42da3778"/>
<project name="librecovery" path="librecovery" remote="b2g" revision="891e5069c0ad330d8191bf8c7b879c814258c89f"/>
@ -23,7 +23,7 @@
<project name="rilproxy" path="rilproxy" remote="b2g" revision="827214fcf38d6569aeb5c6d6f31cb296d1f09272"/>
<project name="valgrind" path="external/valgrind" remote="b2g" revision="daa61633c32b9606f58799a3186395fd2bbb8d8c"/>
<project name="vex" path="external/VEX" remote="b2g" revision="47f031c320888fe9f3e656602588565b52d43010"/>
<project name="apitrace" path="external/apitrace" remote="apitrace" revision="23db533981ee2cd04fc5d946420402aed2792381"/>
<project name="apitrace" path="external/apitrace" remote="apitrace" revision="c2544b1797eb5c59f484c442a24c4dc14c37e68c"/>
<!-- Stock Android things -->
<project groups="linux" name="platform/prebuilts/gcc/linux-x86/host/i686-linux-glibc2.7-4.6" path="prebuilts/gcc/linux-x86/host/i686-linux-glibc2.7-4.6" revision="f92a936f2aa97526d4593386754bdbf02db07a12"/>
<project groups="linux" name="platform/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6" path="prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6" revision="6e47ff2790f5656b5b074407829ceecf3e6188c4"/>

View File

@ -19,13 +19,13 @@
<copyfile dest="Makefile" src="core/root.mk"/>
</project>
<project name="fake-dalvik" path="dalvik" remote="b2g" revision="ca1f327d5acc198bb4be62fa51db2c039032c9ce"/>
<project name="gaia.git" path="gaia" remote="mozillaorg" revision="41cc1de26e4edbe12add0009cdc0bd292f2e94fe"/>
<project name="gaia.git" path="gaia" remote="mozillaorg" revision="45479c07cb6ba8c733093d6ee32c767c090c9a28"/>
<project name="gonk-misc" path="gonk-misc" remote="b2g" revision="bbb7659d8ea2afb396f99b3dc971ab3c42da3778"/>
<project name="rilproxy" path="rilproxy" remote="b2g" revision="827214fcf38d6569aeb5c6d6f31cb296d1f09272"/>
<project name="platform_hardware_ril" path="hardware/ril" remote="b2g" revision="cd88d860656c31c7da7bb310d6a160d0011b0961"/>
<project name="platform_external_qemu" path="external/qemu" remote="b2g" revision="3326b51017252e09ccdd715dec6c5e12a7d1ecfe"/>
<project name="moztt" path="external/moztt" remote="b2g" revision="c510babaf88dfa2cfe2c202afb2649ee124569af"/>
<project name="apitrace" path="external/apitrace" remote="apitrace" revision="23db533981ee2cd04fc5d946420402aed2792381"/>
<project name="apitrace" path="external/apitrace" remote="apitrace" revision="c2544b1797eb5c59f484c442a24c4dc14c37e68c"/>
<!-- Stock Android things -->
<project name="platform/abi/cpp" path="abi/cpp" revision="dd924f92906085b831bf1cbbc7484d3c043d613c"/>
<project name="platform/bionic" path="bionic" revision="c72b8f6359de7ed17c11ddc9dfdde3f615d188a9"/>

View File

@ -17,10 +17,10 @@
</project>
<project name="librecovery" path="librecovery" remote="b2g" revision="891e5069c0ad330d8191bf8c7b879c814258c89f"/>
<project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
<project name="gaia" path="gaia" remote="mozillaorg" revision="41cc1de26e4edbe12add0009cdc0bd292f2e94fe"/>
<project name="gaia" path="gaia" remote="mozillaorg" revision="45479c07cb6ba8c733093d6ee32c767c090c9a28"/>
<project name="gonk-misc" path="gonk-misc" remote="b2g" revision="bbb7659d8ea2afb396f99b3dc971ab3c42da3778"/>
<project name="moztt" path="external/moztt" remote="b2g" revision="c510babaf88dfa2cfe2c202afb2649ee124569af"/>
<project name="apitrace" path="external/apitrace" remote="apitrace" revision="23db533981ee2cd04fc5d946420402aed2792381"/>
<project name="apitrace" path="external/apitrace" remote="apitrace" revision="c2544b1797eb5c59f484c442a24c4dc14c37e68c"/>
<project name="valgrind" path="external/valgrind" remote="b2g" revision="daa61633c32b9606f58799a3186395fd2bbb8d8c"/>
<project name="vex" path="external/VEX" remote="b2g" revision="47f031c320888fe9f3e656602588565b52d43010"/>
<!-- Stock Android things -->
@ -114,11 +114,13 @@
<project name="platform/system/netd" path="system/netd" revision="ea8103eae5642621ca8202e00620f4ca954ed413"/>
<project name="platform/system/security" path="system/security" revision="360f51f7af191316cd739f229db1c5f7233be063"/>
<project name="platform/system/vold" path="system/vold" revision="153df4d067a4149c7d78f1c92fed2ce2bd6a272e"/>
<!--original fetch url was git://github.com/t2m-foxfone/-->
<remote fetch="https://git.mozilla.org/external/t2m-foxfone" name="t2m"/>
<default remote="caf" revision="jb_3.2" sync-j="4"/>
<!-- Flame specific things -->
<project name="device/generic/armv7-a-neon" path="device/generic/armv7-a-neon" revision="e8a318f7690092e639ba88891606f4183e846d3f"/>
<project name="device/qcom/common" path="device/qcom/common" revision="34ed8345250bb97262d70a052217a92e83444ede"/>
<project name="device-flame" path="device/t2m/flame" remote="b2g" revision="243b6f3d219592a84c7318e9446cde397233ae39"/>
<project name="device-flame" path="device/t2m/flame" remote="b2g" revision="33faca8033c6f8cda0c383ab40d69c7a45e6db38"/>
<project name="codeaurora_kernel_msm" path="kernel" remote="b2g" revision="30a441fb7275fc5bc347f84ccb29e977a7eca34e"/>
<project name="kernel_lk" path="bootable/bootloader/lk" remote="b2g" revision="2b1d8b5b7a760230f4c94c02e733e3929f44253a"/>
<project name="platform_bootable_recovery" path="bootable/recovery" remote="b2g" revision="e81502511cda303c803e63f049574634bc96f9f2"/>
@ -126,7 +128,7 @@
<project name="platform/external/bluetooth/bluez" path="external/bluetooth/bluez" revision="f0689ac1914cdbc59e53bdc9edd9013dc157c299"/>
<project name="platform/external/bluetooth/glib" path="external/bluetooth/glib" revision="dd925f76e4f149c3d5571b80e12f7e24bbe89c59"/>
<project name="platform/external/dbus" path="external/dbus" revision="ea87119c843116340f5df1d94eaf8275e1055ae8"/>
<project name="platform/external/libnfc-nci" path="external/libnfc-nci" revision="494c177966fdc31183a5f7af82dc9130f523da4b"/>
<project name="platform_external_libnfc-nci" path="external/libnfc-nci" remote="t2m" revision="4186bdecb4dae911b39a8202252cc2310d91b0be"/>
<project name="platform/external/wpa_supplicant_8" path="external/wpa_supplicant_8" revision="320b05a5761eb2a4816f7529c91ea49422979b55"/>
<project name="platform/frameworks/av" path="frameworks/av" revision="5b934dc57dae25f286b0e7210dc6ff47f3244927"/>
<project name="platform/frameworks/base" path="frameworks/base" revision="af3e4fbdc9369643a92015ea2657361f3b1b46fe"/>

View File

@ -4,6 +4,6 @@
"remote": "",
"branch": ""
},
"revision": "aba00cfd579caaf205e05c269f0a8100f242f39c",
"revision": "8ac363347c96715adf6bec5fc30a975a2cfbaafd",
"repo_path": "/integration/gaia-central"
}

View File

@ -17,12 +17,12 @@
<copyfile dest="Makefile" src="core/root.mk"/>
</project>
<project name="fake-dalvik" path="dalvik" remote="b2g" revision="ca1f327d5acc198bb4be62fa51db2c039032c9ce"/>
<project name="gaia.git" path="gaia" remote="mozillaorg" revision="41cc1de26e4edbe12add0009cdc0bd292f2e94fe"/>
<project name="gaia.git" path="gaia" remote="mozillaorg" revision="45479c07cb6ba8c733093d6ee32c767c090c9a28"/>
<project name="gonk-misc" path="gonk-misc" remote="b2g" revision="bbb7659d8ea2afb396f99b3dc971ab3c42da3778"/>
<project name="rilproxy" path="rilproxy" remote="b2g" revision="827214fcf38d6569aeb5c6d6f31cb296d1f09272"/>
<project name="librecovery" path="librecovery" remote="b2g" revision="891e5069c0ad330d8191bf8c7b879c814258c89f"/>
<project name="moztt" path="external/moztt" remote="b2g" revision="c510babaf88dfa2cfe2c202afb2649ee124569af"/>
<project name="apitrace" path="external/apitrace" remote="apitrace" revision="23db533981ee2cd04fc5d946420402aed2792381"/>
<project name="apitrace" path="external/apitrace" remote="apitrace" revision="c2544b1797eb5c59f484c442a24c4dc14c37e68c"/>
<!-- Stock Android things -->
<project name="platform/abi/cpp" path="abi/cpp" revision="6426040f1be4a844082c9769171ce7f5341a5528"/>
<project name="platform/bionic" path="bionic" revision="d2eb6c7b6e1bc7643c17df2d9d9bcb1704d0b9ab"/>

View File

@ -15,7 +15,7 @@
<copyfile dest="Makefile" src="core/root.mk"/>
</project>
<project name="fake-dalvik" path="dalvik" remote="b2g" revision="ca1f327d5acc198bb4be62fa51db2c039032c9ce"/>
<project name="gaia.git" path="gaia" remote="mozillaorg" revision="41cc1de26e4edbe12add0009cdc0bd292f2e94fe"/>
<project name="gaia.git" path="gaia" remote="mozillaorg" revision="45479c07cb6ba8c733093d6ee32c767c090c9a28"/>
<project name="gonk-misc" path="gonk-misc" remote="b2g" revision="bbb7659d8ea2afb396f99b3dc971ab3c42da3778"/>
<project name="rilproxy" path="rilproxy" remote="b2g" revision="827214fcf38d6569aeb5c6d6f31cb296d1f09272"/>
<project name="librecovery" path="librecovery" remote="b2g" revision="891e5069c0ad330d8191bf8c7b879c814258c89f"/>

View File

@ -17,10 +17,10 @@
</project>
<project name="rilproxy" path="rilproxy" remote="b2g" revision="827214fcf38d6569aeb5c6d6f31cb296d1f09272"/>
<project name="fake-libdvm" path="dalvik" remote="b2g" revision="d50ae982b19f42f0b66d08b9eb306be81687869f"/>
<project name="gaia" path="gaia" remote="mozillaorg" revision="41cc1de26e4edbe12add0009cdc0bd292f2e94fe"/>
<project name="gaia" path="gaia" remote="mozillaorg" revision="45479c07cb6ba8c733093d6ee32c767c090c9a28"/>
<project name="gonk-misc" path="gonk-misc" remote="b2g" revision="bbb7659d8ea2afb396f99b3dc971ab3c42da3778"/>
<project name="moztt" path="external/moztt" remote="b2g" revision="c510babaf88dfa2cfe2c202afb2649ee124569af"/>
<project name="apitrace" path="external/apitrace" remote="apitrace" revision="23db533981ee2cd04fc5d946420402aed2792381"/>
<project name="apitrace" path="external/apitrace" remote="apitrace" revision="c2544b1797eb5c59f484c442a24c4dc14c37e68c"/>
<project name="valgrind" path="external/valgrind" remote="b2g" revision="daa61633c32b9606f58799a3186395fd2bbb8d8c"/>
<project name="vex" path="external/VEX" remote="b2g" revision="47f031c320888fe9f3e656602588565b52d43010"/>
<!-- Stock Android things -->

View File

@ -17,12 +17,12 @@
<copyfile dest="Makefile" src="core/root.mk"/>
</project>
<project name="fake-dalvik" path="dalvik" remote="b2g" revision="ca1f327d5acc198bb4be62fa51db2c039032c9ce"/>
<project name="gaia.git" path="gaia" remote="mozillaorg" revision="41cc1de26e4edbe12add0009cdc0bd292f2e94fe"/>
<project name="gaia.git" path="gaia" remote="mozillaorg" revision="45479c07cb6ba8c733093d6ee32c767c090c9a28"/>
<project name="gonk-misc" path="gonk-misc" remote="b2g" revision="bbb7659d8ea2afb396f99b3dc971ab3c42da3778"/>
<project name="rilproxy" path="rilproxy" remote="b2g" revision="827214fcf38d6569aeb5c6d6f31cb296d1f09272"/>
<project name="librecovery" path="librecovery" remote="b2g" revision="891e5069c0ad330d8191bf8c7b879c814258c89f"/>
<project name="moztt" path="external/moztt" remote="b2g" revision="c510babaf88dfa2cfe2c202afb2649ee124569af"/>
<project name="apitrace" path="external/apitrace" remote="apitrace" revision="23db533981ee2cd04fc5d946420402aed2792381"/>
<project name="apitrace" path="external/apitrace" remote="apitrace" revision="c2544b1797eb5c59f484c442a24c4dc14c37e68c"/>
<project name="gonk-patches" path="patches" remote="b2g" revision="223a2421006e8f5da33f516f6891c87cae86b0f6"/>
<!-- Stock Android things -->
<project name="platform/abi/cpp" path="abi/cpp" revision="6426040f1be4a844082c9769171ce7f5341a5528"/>

View File

@ -503,6 +503,9 @@
<menuitem id="menu_devAppMgr"
observes="devtoolsMenuBroadcaster_DevAppMgr"
accesskey="&devAppMgrMenu.accesskey;"/>
<menuitem id="menu_webide"
observes="devtoolsMenuBroadcaster_webide"
accesskey="&webide.accesskey;"/>
<menuitem id="menu_browserToolbox"
observes="devtoolsMenuBroadcaster_BrowserToolbox"
accesskey="&browserToolboxMenu.accesskey;"/>

View File

@ -98,6 +98,7 @@
<command id="Tools:DevToolbar" oncommand="DeveloperToolbar.toggle();" disabled="true" hidden="true"/>
<command id="Tools:DevToolbarFocus" oncommand="DeveloperToolbar.focusToggle();" disabled="true"/>
<command id="Tools:DevAppMgr" oncommand="gDevToolsBrowser.openAppManager(gBrowser);" disabled="true" hidden="true"/>
<command id="Tools:WebIDE" oncommand="gDevToolsBrowser.openWebIDE();" disabled="true" hidden="true"/>
<command id="Tools:BrowserToolbox" oncommand="BrowserToolboxProcess.init();" disabled="true" hidden="true"/>
<command id="Tools:BrowserConsole" oncommand="HUDService.toggleBrowserConsole();"/>
<command id="Tools:Scratchpad" oncommand="Scratchpad.openScratchpad();"/>
@ -198,6 +199,9 @@
<broadcaster id="devtoolsMenuBroadcaster_DevAppMgr"
label="&devAppMgrMenu.label;"
command="Tools:DevAppMgr"/>
<broadcaster id="devtoolsMenuBroadcaster_webide"
label="&webide.label;"
command="Tools:WebIDE"/>
<broadcaster id="devtoolsMenuBroadcaster_BrowserToolbox"
label="&browserToolboxMenu.label;"
command="Tools:BrowserToolbox"/>

View File

@ -292,6 +292,14 @@ HandlerInfoWrapper.prototype = {
},
set preferredAction(aNewValue) {
// If the action is to use the plugin,
// we must set the preferred action to "save to disk".
// But only if it's not currently the preferred action.
if ((aNewValue == kActionUsePlugin) &&
(this.preferredAction != Ci.nsIHandlerInfo.saveToDisk)) {
aNewValue = Ci.nsIHandlerInfo.saveToDisk;
}
// We don't modify the preferred action if the new action is to use a plugin
// because handler info objects don't understand our custom "use plugin"
// value. Also, leaving it untouched means that we can automatically revert
@ -1644,33 +1652,31 @@ var gApplicationsPane = {
var typeItem = this._list.selectedItem;
var handlerInfo = this._handledTypes[typeItem.type];
if (aActionItem.hasAttribute("alwaysAsk")) {
let action = parseInt(aActionItem.getAttribute("action"), 10);
// Set the plugin state if we're enabling or disabling a plugin.
if (action == kActionUsePlugin)
handlerInfo.enablePluginType();
else if (handlerInfo.pluginName && !handlerInfo.isDisabledPluginType)
handlerInfo.disablePluginType();
// Set the preferred application handler.
// We leave the existing preferred app in the list when we set
// the preferred action to something other than useHelperApp so that
// legacy datastores that don't have the preferred app in the list
// of possible apps still include the preferred app in the list of apps
// the user can choose to handle the type.
if (action == Ci.nsIHandlerInfo.useHelperApp)
handlerInfo.preferredApplicationHandler = aActionItem.handlerApp;
// Set the "always ask" flag.
if (action == Ci.nsIHandlerInfo.alwaysAsk)
handlerInfo.alwaysAskBeforeHandling = true;
}
else if (aActionItem.hasAttribute("action")) {
let action = parseInt(aActionItem.getAttribute("action"));
// Set the plugin state if we're enabling or disabling a plugin.
if (action == kActionUsePlugin)
handlerInfo.enablePluginType();
else if (handlerInfo.pluginName && !handlerInfo.isDisabledPluginType)
handlerInfo.disablePluginType();
// Set the preferred application handler.
// We leave the existing preferred app in the list when we set
// the preferred action to something other than useHelperApp so that
// legacy datastores that don't have the preferred app in the list
// of possible apps still include the preferred app in the list of apps
// the user can choose to handle the type.
if (action == Ci.nsIHandlerInfo.useHelperApp)
handlerInfo.preferredApplicationHandler = aActionItem.handlerApp;
// Set the "always ask" flag.
else
handlerInfo.alwaysAskBeforeHandling = false;
// Set the preferred action.
handlerInfo.preferredAction = action;
}
// Set the preferred action.
handlerInfo.preferredAction = action;
handlerInfo.store();

View File

@ -284,6 +284,14 @@ HandlerInfoWrapper.prototype = {
},
set preferredAction(aNewValue) {
// If the action is to use the plugin,
// we must set the preferred action to "save to disk".
// But only if it's not currently the preferred action.
if ((aNewValue == kActionUsePlugin) &&
(this.preferredAction != Ci.nsIHandlerInfo.saveToDisk)) {
aNewValue = Ci.nsIHandlerInfo.saveToDisk;
}
// We don't modify the preferred action if the new action is to use a plugin
// because handler info objects don't understand our custom "use plugin"
// value. Also, leaving it untouched means that we can automatically revert
@ -1636,33 +1644,31 @@ var gApplicationsPane = {
var typeItem = this._list.selectedItem;
var handlerInfo = this._handledTypes[typeItem.type];
if (aActionItem.hasAttribute("alwaysAsk")) {
let action = parseInt(aActionItem.getAttribute("action"));
// Set the plugin state if we're enabling or disabling a plugin.
if (action == kActionUsePlugin)
handlerInfo.enablePluginType();
else if (handlerInfo.pluginName && !handlerInfo.isDisabledPluginType)
handlerInfo.disablePluginType();
// Set the preferred application handler.
// We leave the existing preferred app in the list when we set
// the preferred action to something other than useHelperApp so that
// legacy datastores that don't have the preferred app in the list
// of possible apps still include the preferred app in the list of apps
// the user can choose to handle the type.
if (action == Ci.nsIHandlerInfo.useHelperApp)
handlerInfo.preferredApplicationHandler = aActionItem.handlerApp;
// Set the "always ask" flag.
if (action == Ci.nsIHandlerInfo.alwaysAsk)
handlerInfo.alwaysAskBeforeHandling = true;
}
else if (aActionItem.hasAttribute("action")) {
let action = parseInt(aActionItem.getAttribute("action"));
// Set the plugin state if we're enabling or disabling a plugin.
if (action == kActionUsePlugin)
handlerInfo.enablePluginType();
else if (handlerInfo.pluginName && !handlerInfo.isDisabledPluginType)
handlerInfo.disablePluginType();
// Set the preferred application handler.
// We leave the existing preferred app in the list when we set
// the preferred action to something other than useHelperApp so that
// legacy datastores that don't have the preferred app in the list
// of possible apps still include the preferred app in the list of apps
// the user can choose to handle the type.
if (action == Ci.nsIHandlerInfo.useHelperApp)
handlerInfo.preferredApplicationHandler = aActionItem.handlerApp;
// Set the "always ask" flag.
else
handlerInfo.alwaysAskBeforeHandling = false;
// Set the preferred action.
handlerInfo.preferredAction = action;
}
// Set the preferred action.
handlerInfo.preferredAction = action;
handlerInfo.store();

View File

@ -14,6 +14,7 @@ const commandModules = [
"gcli/commands/cmd",
"gcli/commands/cookie",
"gcli/commands/csscoverage",
"gcli/commands/folder",
"gcli/commands/inject",
"gcli/commands/jsb",
"gcli/commands/listen",

View File

@ -50,6 +50,7 @@ support-files =
browser_cmd_csscoverage_sheetB.css
browser_cmd_csscoverage_sheetC.css
browser_cmd_csscoverage_sheetD.css
[browser_cmd_folder.js]
[browser_cmd_inject.js]
support-files =
browser_cmd_inject.html

View File

@ -0,0 +1,58 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
// Tests that the folder commands works as they should
const TEST_URI = "data:text/html;charset=utf-8,cmd-folder";
function test() {
helpers.addTabWithToolbar(TEST_URI, function(options) {
return helpers.audit(options, [
{
setup: 'folder',
check: {
input: 'folder',
hints: ' open',
markup: 'IIIIII',
status: 'ERROR'
},
},
{
setup: 'folder open',
check: {
input: 'folder open',
hints: ' [path]',
markup: 'VVVVVVVVVVV',
status: 'VALID'
}
},
{
setup: 'folder open ~',
check: {
input: 'folder open ~',
hints: '',
markup: 'VVVVVVVVVVVVV',
status: 'VALID'
}
},
{
setup: 'folder openprofile',
check: {
input: 'folder openprofile',
hints: '',
markup: 'VVVVVVVVVVVVVVVVVV',
status: 'VALID'
}
},
{
setup: 'folder openprofile WRONG',
check: {
input: 'folder openprofile WRONG',
hints: '',
markup: 'VVVVVVVVVVVVVVVVVVVEEEEE',
status: 'ERROR'
}
}
]);
}).then(finish, helpers.handleError);
}

View File

@ -432,9 +432,13 @@ let gDevToolsBrowser = {
win.DeveloperToolbar.show(false);
}
// Enable WebIDE?
let webIDEEnabled = Services.prefs.getBoolPref("devtools.webide.enabled");
toggleCmd("Tools:WebIDE", webIDEEnabled);
// Enable App Manager?
let appMgrEnabled = Services.prefs.getBoolPref("devtools.appmanager.enabled");
toggleCmd("Tools:DevAppMgr", appMgrEnabled);
toggleCmd("Tools:DevAppMgr", !webIDEEnabled && appMgrEnabled);
// Enable Browser Toolbox?
let chromeEnabled = Services.prefs.getBoolPref("devtools.chrome.enabled");
@ -522,16 +526,19 @@ let gDevToolsBrowser = {
* Open the App Manager
*/
openAppManager: function(gBrowser) {
if (Services.prefs.getBoolPref("devtools.webide.enabled")) {
let win = Services.wm.getMostRecentWindow("devtools:webide");
if (win) {
win.focus();
} else {
let ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].getService(Ci.nsIWindowWatcher);
ww.openWindow(null, "chrome://webide/content/", "webide", "chrome,centerscreen,resizable", null);
}
gBrowser.selectedTab = gBrowser.addTab("about:app-manager");
},
/**
* Open WebIDE
*/
openWebIDE: function() {
let win = Services.wm.getMostRecentWindow("devtools:webide");
if (win) {
win.focus();
} else {
gBrowser.selectedTab = gBrowser.addTab("about:app-manager");
let ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].getService(Ci.nsIWindowWatcher);
ww.openWindow(null, "chrome://webide/content/", "webide", "chrome,centerscreen,resizable", null);
}
},

View File

@ -36,16 +36,16 @@ browser.jar:
content/browser/devtools/fontinspector/font-inspector.css (fontinspector/font-inspector.css)
content/browser/devtools/codemirror/codemirror.js (sourceeditor/codemirror/codemirror.js)
content/browser/devtools/codemirror/codemirror.css (sourceeditor/codemirror/codemirror.css)
content/browser/devtools/codemirror/javascript.js (sourceeditor/codemirror/javascript.js)
content/browser/devtools/codemirror/xml.js (sourceeditor/codemirror/xml.js)
content/browser/devtools/codemirror/css.js (sourceeditor/codemirror/css.js)
content/browser/devtools/codemirror/htmlmixed.js (sourceeditor/codemirror/htmlmixed.js)
content/browser/devtools/codemirror/clike.js (sourceeditor/codemirror/clike.js)
content/browser/devtools/codemirror/activeline.js (sourceeditor/codemirror/activeline.js)
content/browser/devtools/codemirror/trailingspace.js (sourceeditor/codemirror/trailingspace.js)
content/browser/devtools/codemirror/matchbrackets.js (sourceeditor/codemirror/matchbrackets.js)
content/browser/devtools/codemirror/closebrackets.js (sourceeditor/codemirror/closebrackets.js)
content/browser/devtools/codemirror/comment.js (sourceeditor/codemirror/comment.js)
content/browser/devtools/codemirror/javascript.js (sourceeditor/codemirror/mode/javascript.js)
content/browser/devtools/codemirror/xml.js (sourceeditor/codemirror/mode/xml.js)
content/browser/devtools/codemirror/css.js (sourceeditor/codemirror/mode/css.js)
content/browser/devtools/codemirror/htmlmixed.js (sourceeditor/codemirror/mode/htmlmixed.js)
content/browser/devtools/codemirror/clike.js (sourceeditor/codemirror/mode/clike.js)
content/browser/devtools/codemirror/activeline.js (sourceeditor/codemirror/selection/active-line.js)
content/browser/devtools/codemirror/trailingspace.js (sourceeditor/codemirror/edit/trailingspace.js)
content/browser/devtools/codemirror/matchbrackets.js (sourceeditor/codemirror/edit/matchbrackets.js)
content/browser/devtools/codemirror/closebrackets.js (sourceeditor/codemirror/edit/closebrackets.js)
content/browser/devtools/codemirror/comment.js (sourceeditor/codemirror/comment/comment.js)
content/browser/devtools/codemirror/searchcursor.js (sourceeditor/codemirror/search/searchcursor.js)
content/browser/devtools/codemirror/search.js (sourceeditor/codemirror/search/search.js)
content/browser/devtools/codemirror/dialog.js (sourceeditor/codemirror/dialog/dialog.js)
@ -58,8 +58,8 @@ browser.jar:
content/browser/devtools/codemirror/comment-fold.js (sourceeditor/codemirror/fold/comment-fold.js)
content/browser/devtools/codemirror/xml-fold.js (sourceeditor/codemirror/fold/xml-fold.js)
content/browser/devtools/codemirror/foldgutter.js (sourceeditor/codemirror/fold/foldgutter.js)
content/browser/devtools/codemirror/tern.js (sourceeditor/codemirror/tern.js)
content/browser/devtools/codemirror/show-hint.js (sourceeditor/codemirror/show-hint.js)
content/browser/devtools/codemirror/tern.js (sourceeditor/codemirror/tern/tern.js)
content/browser/devtools/codemirror/show-hint.js (sourceeditor/codemirror/hint/show-hint.js)
content/browser/devtools/codemirror/mozilla.css (sourceeditor/codemirror/mozilla.css)
content/browser/devtools/debugger.xul (debugger/debugger.xul)
content/browser/devtools/debugger.css (debugger/debugger.css)

View File

@ -156,21 +156,28 @@ MarkupView.prototype = {
},
_hoveredNode: null,
_showContainerAsHovered: function(nodeFront) {
if (this._hoveredNode !== nodeFront) {
if (this._hoveredNode) {
this._containers.get(this._hoveredNode).hovered = false;
}
this._containers.get(nodeFront).hovered = true;
this._hoveredNode = nodeFront;
/**
* Show a NodeFront's container as being hovered
* @param {NodeFront} nodeFront The node to show as hovered
*/
_showContainerAsHovered: function(nodeFront) {
if (this._hoveredNode === nodeFront) {
return;
}
if (this._hoveredNode) {
this.getContainer(this._hoveredNode).hovered = false;
}
this.getContainer(nodeFront).hovered = true;
this._hoveredNode = nodeFront;
},
_onMouseLeave: function() {
this._hideBoxModel(true);
if (this._hoveredNode) {
this._containers.get(this._hoveredNode).hovered = false;
this.getContainer(this._hoveredNode).hovered = false;
}
this._hoveredNode = null;
},
@ -305,6 +312,11 @@ MarkupView.prototype = {
let selection = this._inspector.selection;
this.htmlEditor.hide();
if (this._hoveredNode && this._hoveredNode !== selection.nodeFront) {
this.getContainer(this._hoveredNode).hovered = false;
this._hoveredNode = null;
}
let done = this._inspector.updating("markup-view");
if (selection.isNode()) {
if (this._shouldNewSelectionBeHighlighted()) {
@ -377,7 +389,7 @@ MarkupView.prototype = {
this.deleteNode(this._selectedContainer.node);
break;
case Ci.nsIDOMKeyEvent.DOM_VK_HOME:
let rootContainer = this._containers.get(this._rootNode);
let rootContainer = this.getContainer(this._rootNode);
this.navigate(rootContainer.children.firstChild.container);
break;
case Ci.nsIDOMKeyEvent.DOM_VK_LEFT:
@ -462,7 +474,7 @@ MarkupView.prototype = {
return;
}
let container = this._containers.get(aNode);
let container = this.getContainer(aNode);
// Retain the node so we can undo this...
this.walker.retainNode(aNode).then(() => {
@ -470,7 +482,7 @@ MarkupView.prototype = {
let sibling = null;
this.undo.do(() => {
if (container.selected) {
this.navigate(this._containers.get(parent));
this.navigate(this.getContainer(parent));
}
this.walker.removeNode(aNode).then(nextSibling => {
sibling = nextSibling;
@ -531,7 +543,7 @@ MarkupView.prototype = {
}
if (this._containers.has(aNode)) {
return this._containers.get(aNode);
return this.getContainer(aNode);
}
if (aNode === this.walker.rootNode) {
@ -575,7 +587,7 @@ MarkupView.prototype = {
}
}
let container = this._containers.get(target);
let container = this.getContainer(target);
if (!container) {
// Container might not exist if this came from a load event for a node
// we're not viewing.
@ -624,7 +636,7 @@ MarkupView.prototype = {
if (this._inspector.selection.nodeFront === reselectParent) {
this.walker.children(reselectParent).then((o) => {
let node = o.nodes[reselectChildIndex];
let container = this._containers.get(node);
let container = this.getContainer(node);
if (node && container) {
this.markNodeAsSelected(node, "outerhtml");
if (container.hasChildren) {
@ -643,7 +655,7 @@ MarkupView.prototype = {
*/
_onDisplayChange: function(nodes) {
for (let node of nodes) {
let container = this._containers.get(node);
let container = this.getContainer(node);
if (container) {
container.isDisplayed = node.isDisplayed;
}
@ -659,7 +671,7 @@ MarkupView.prototype = {
let removedContainers = new Set();
for (let {type, target, added, removed} of aMutations) {
let container = this._containers.get(target);
let container = this.getContainer(target);
if (container) {
if (type === "attributes" || type === "characterData") {
@ -672,7 +684,7 @@ MarkupView.prototype = {
// If there has been additions, flash the nodes
added.forEach(added => {
let addedContainer = this._containers.get(added);
let addedContainer = this.getContainer(added);
addedOrEditedContainers.add(addedContainer);
// The node may be added as a result of an append, in which case it
@ -711,7 +723,7 @@ MarkupView.prototype = {
return this._ensureVisible(aNode);
}).then(() => {
// Why is this not working?
this.layoutHelpers.scrollIntoViewIfNeeded(this._containers.get(aNode).editor.elt, centered);
this.layoutHelpers.scrollIntoViewIfNeeded(this.getContainer(aNode).editor.elt, centered);
});
},
@ -728,7 +740,7 @@ MarkupView.prototype = {
* Expand the node's children.
*/
expandNode: function(aNode) {
let container = this._containers.get(aNode);
let container = this.getContainer(aNode);
this._expandContainer(container);
},
@ -757,14 +769,14 @@ MarkupView.prototype = {
*/
expandAll: function(aNode) {
aNode = aNode || this._rootNode;
return this._expandAll(this._containers.get(aNode));
return this._expandAll(this.getContainer(aNode));
},
/**
* Collapse the node's children.
*/
collapseNode: function(aNode) {
let container = this._containers.get(aNode);
let container = this.getContainer(aNode);
container.expanded = false;
},
@ -816,7 +828,7 @@ MarkupView.prototype = {
* If the child cannot be found, returns -1
*/
updateNodeOuterHTML: function(aNode, newValue, oldValue) {
let container = this._containers.get(aNode);
let container = this.getContainer(aNode);
if (!container) {
return;
}
@ -839,7 +851,7 @@ MarkupView.prototype = {
*/
beginEditingOuterHTML: function(aNode) {
this.getNodeOuterHTML(aNode).then((oldValue)=> {
let container = this._containers.get(aNode);
let container = this.getContainer(aNode);
if (!container) {
return;
}
@ -880,7 +892,7 @@ MarkupView.prototype = {
* @param aNode The NodeFront to mark as selected.
*/
markNodeAsSelected: function(aNode, reason) {
let container = this._containers.get(aNode);
let container = this.getContainer(aNode);
if (this._selectedContainer === container) {
return false;
}
@ -902,10 +914,10 @@ MarkupView.prototype = {
*/
_ensureVisible: function(node) {
while (node) {
let container = this._containers.get(node);
let container = this.getContainer(node);
let parent = node.parentNode();
if (!container.elt.parentNode) {
let parentContainer = this._containers.get(parent);
let parentContainer = this.getContainer(parent);
if (parentContainer) {
parentContainer.childrenDirty = true;
this._updateChildren(parentContainer, {expand: node});

View File

@ -20,6 +20,7 @@ support-files =
[browser_markupview_css_completion_style_attribute.js]
[browser_markupview_highlight_hover_01.js]
[browser_markupview_highlight_hover_02.js]
[browser_markupview_highlight_hover_03.js]
[browser_markupview_html_edit_01.js]
[browser_markupview_html_edit_02.js]
[browser_markupview_html_edit_03.js]

View File

@ -0,0 +1,54 @@
/* vim: set ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Test that once a node has been hovered over and marked as such, if it is
// navigated away using the keyboard, the highlighter moves to the new node, and
// if it is then navigated back to, it is briefly highlighted again
const TEST_PAGE = "data:text/html;charset=utf-8," +
"<p id=\"one\">one</p><p id=\"two\">two</p>";
let test = asyncTest(function*() {
let {inspector} = yield addTab(TEST_PAGE).then(openInspector);
info("Making sure the markup-view frame is focused");
inspector.markup._frame.focus();
// Mock the highlighter to easily track which node gets highlighted.
// We don't need to test here that the highlighter is actually visible, we
// just care about whether the markup-view asks it to be shown
let highlightedNode = null;
inspector.toolbox._highlighter.showBoxModel = function(nodeFront) {
highlightedNode = nodeFront;
return promise.resolve();
};
inspector.toolbox._highlighter.hideBoxModel = function() {
return promise.resolve();
};
function isHighlighting(node, desc) {
is(highlightedNode, getContainerForRawNode(node, inspector).node, desc);
}
info("Hover over <p#one> line in the markup-view");
yield hoverContainer("#one", inspector);
isHighlighting(getNode("#one"), "<p#one> is highlighted");
info("Navigate to <p#two> with the keyboard");
let onUpdated = inspector.once("inspector-updated");
EventUtils.synthesizeKey("VK_DOWN", {});
yield onUpdated;
let onUpdated = inspector.once("inspector-updated");
EventUtils.synthesizeKey("VK_DOWN", {});
yield onUpdated;
isHighlighting(getNode("#two"), "<p#two> is highlighted");
info("Navigate back to <p#one> with the keyboard");
let onUpdated = inspector.once("inspector-updated");
EventUtils.synthesizeKey("VK_UP", {});
yield onUpdated;
isHighlighting(getNode("#one"), "<p#one> is highlighted again");
});

View File

@ -539,7 +539,7 @@ NetworkEventsHandler.prototype = {
let { actor, startedDateTime, method, url, isXHR } = aPacket.eventActor;
NetMonitorView.RequestsMenu.addRequest(actor, startedDateTime, method, url, isXHR);
window.emit(EVENTS.NETWORK_EVENT);
window.emit(EVENTS.NETWORK_EVENT, actor);
},
/**
@ -560,23 +560,23 @@ NetworkEventsHandler.prototype = {
switch (aPacket.updateType) {
case "requestHeaders":
this.webConsoleClient.getRequestHeaders(actor, this._onRequestHeaders);
window.emit(EVENTS.UPDATING_REQUEST_HEADERS);
window.emit(EVENTS.UPDATING_REQUEST_HEADERS, actor);
break;
case "requestCookies":
this.webConsoleClient.getRequestCookies(actor, this._onRequestCookies);
window.emit(EVENTS.UPDATING_REQUEST_COOKIES);
window.emit(EVENTS.UPDATING_REQUEST_COOKIES, actor);
break;
case "requestPostData":
this.webConsoleClient.getRequestPostData(actor, this._onRequestPostData);
window.emit(EVENTS.UPDATING_REQUEST_POST_DATA);
window.emit(EVENTS.UPDATING_REQUEST_POST_DATA, actor);
break;
case "responseHeaders":
this.webConsoleClient.getResponseHeaders(actor, this._onResponseHeaders);
window.emit(EVENTS.UPDATING_RESPONSE_HEADERS);
window.emit(EVENTS.UPDATING_RESPONSE_HEADERS, actor);
break;
case "responseCookies":
this.webConsoleClient.getResponseCookies(actor, this._onResponseCookies);
window.emit(EVENTS.UPDATING_RESPONSE_COOKIES);
window.emit(EVENTS.UPDATING_RESPONSE_COOKIES, actor);
break;
case "responseStart":
NetMonitorView.RequestsMenu.updateRequest(aPacket.from, {
@ -585,7 +585,7 @@ NetworkEventsHandler.prototype = {
statusText: aPacket.response.statusText,
headersSize: aPacket.response.headersSize
});
window.emit(EVENTS.STARTED_RECEIVING_RESPONSE);
window.emit(EVENTS.STARTED_RECEIVING_RESPONSE, actor);
break;
case "responseContent":
NetMonitorView.RequestsMenu.updateRequest(aPacket.from, {
@ -593,14 +593,14 @@ NetworkEventsHandler.prototype = {
mimeType: aPacket.mimeType
});
this.webConsoleClient.getResponseContent(actor, this._onResponseContent);
window.emit(EVENTS.UPDATING_RESPONSE_CONTENT);
window.emit(EVENTS.UPDATING_RESPONSE_CONTENT, actor);
break;
case "eventTimings":
NetMonitorView.RequestsMenu.updateRequest(aPacket.from, {
totalTime: aPacket.totalTime
});
this.webConsoleClient.getEventTimings(actor, this._onEventTimings);
window.emit(EVENTS.UPDATING_EVENT_TIMINGS);
window.emit(EVENTS.UPDATING_EVENT_TIMINGS, actor);
break;
}
},
@ -615,7 +615,7 @@ NetworkEventsHandler.prototype = {
NetMonitorView.RequestsMenu.updateRequest(aResponse.from, {
requestHeaders: aResponse
});
window.emit(EVENTS.RECEIVED_REQUEST_HEADERS);
window.emit(EVENTS.RECEIVED_REQUEST_HEADERS, aResponse.from);
},
/**
@ -628,7 +628,7 @@ NetworkEventsHandler.prototype = {
NetMonitorView.RequestsMenu.updateRequest(aResponse.from, {
requestCookies: aResponse
});
window.emit(EVENTS.RECEIVED_REQUEST_COOKIES);
window.emit(EVENTS.RECEIVED_REQUEST_COOKIES, aResponse.from);
},
/**
@ -641,7 +641,7 @@ NetworkEventsHandler.prototype = {
NetMonitorView.RequestsMenu.updateRequest(aResponse.from, {
requestPostData: aResponse
});
window.emit(EVENTS.RECEIVED_REQUEST_POST_DATA);
window.emit(EVENTS.RECEIVED_REQUEST_POST_DATA, aResponse.from);
},
/**
@ -654,7 +654,7 @@ NetworkEventsHandler.prototype = {
NetMonitorView.RequestsMenu.updateRequest(aResponse.from, {
responseHeaders: aResponse
});
window.emit(EVENTS.RECEIVED_RESPONSE_HEADERS);
window.emit(EVENTS.RECEIVED_RESPONSE_HEADERS, aResponse.from);
},
/**
@ -667,7 +667,7 @@ NetworkEventsHandler.prototype = {
NetMonitorView.RequestsMenu.updateRequest(aResponse.from, {
responseCookies: aResponse
});
window.emit(EVENTS.RECEIVED_RESPONSE_COOKIES);
window.emit(EVENTS.RECEIVED_RESPONSE_COOKIES, aResponse.from);
},
/**
@ -680,7 +680,7 @@ NetworkEventsHandler.prototype = {
NetMonitorView.RequestsMenu.updateRequest(aResponse.from, {
responseContent: aResponse
});
window.emit(EVENTS.RECEIVED_RESPONSE_CONTENT);
window.emit(EVENTS.RECEIVED_RESPONSE_CONTENT, aResponse.from);
},
/**
@ -693,7 +693,7 @@ NetworkEventsHandler.prototype = {
NetMonitorView.RequestsMenu.updateRequest(aResponse.from, {
eventTimings: aResponse
});
window.emit(EVENTS.RECEIVED_EVENT_TIMINGS);
window.emit(EVENTS.RECEIVED_EVENT_TIMINGS, aResponse.from);
},
/**

View File

@ -172,65 +172,74 @@ function waitForNetworkEvents(aMonitor, aGetRequests, aPostRequests = 0) {
let deferred = promise.defer();
let panel = aMonitor.panelWin;
let events = panel.EVENTS;
let menu = panel.NetMonitorView.RequestsMenu;
let progress = {};
let genericEvents = 0;
let postEvents = 0;
function onGenericEvent() {
let awaitedEventsToListeners = [
["UPDATING_REQUEST_HEADERS", onGenericEvent],
["RECEIVED_REQUEST_HEADERS", onGenericEvent],
["UPDATING_REQUEST_COOKIES", onGenericEvent],
["RECEIVED_REQUEST_COOKIES", onGenericEvent],
["UPDATING_REQUEST_POST_DATA", onPostEvent],
["RECEIVED_REQUEST_POST_DATA", onPostEvent],
["UPDATING_RESPONSE_HEADERS", onGenericEvent],
["RECEIVED_RESPONSE_HEADERS", onGenericEvent],
["UPDATING_RESPONSE_COOKIES", onGenericEvent],
["RECEIVED_RESPONSE_COOKIES", onGenericEvent],
["STARTED_RECEIVING_RESPONSE", onGenericEvent],
["UPDATING_RESPONSE_CONTENT", onGenericEvent],
["RECEIVED_RESPONSE_CONTENT", onGenericEvent],
["UPDATING_EVENT_TIMINGS", onGenericEvent],
["RECEIVED_EVENT_TIMINGS", onGenericEvent]
];
function initProgressForURL(url) {
if (progress[url]) return;
progress[url] = {};
awaitedEventsToListeners.forEach(([e]) => progress[url][e] = 0);
}
function updateProgressForURL(url, event) {
initProgressForURL(url);
progress[url][Object.keys(events).find(e => events[e] == event)] = 1;
}
function onGenericEvent(event, actor) {
genericEvents++;
maybeResolve();
maybeResolve(event, actor);
}
function onPostEvent() {
function onPostEvent(event, actor) {
postEvents++;
maybeResolve();
maybeResolve(event, actor);
}
function maybeResolve() {
function maybeResolve(event, actor) {
info("> Network events progress: " +
genericEvents + "/" + ((aGetRequests + aPostRequests) * 13) + ", " +
postEvents + "/" + (aPostRequests * 2));
postEvents + "/" + (aPostRequests * 2) + ", " +
"got " + event + " for " + actor);
let url = menu.getItemByValue(actor).attachment.url;
updateProgressForURL(url, event);
info("> Current state: " + JSON.stringify(progress, null, 2));
// There are 15 updates which need to be fired for a request to be
// considered finished. RequestPostData isn't fired for non-POST requests.
// considered finished. The "requestPostData" packet isn't fired for
// non-POST requests.
if (genericEvents == (aGetRequests + aPostRequests) * 13 &&
postEvents == aPostRequests * 2) {
panel.off(panel.EVENTS.UPDATING_REQUEST_HEADERS, onGenericEvent);
panel.off(panel.EVENTS.RECEIVED_REQUEST_HEADERS, onGenericEvent);
panel.off(panel.EVENTS.UPDATING_REQUEST_COOKIES, onGenericEvent);
panel.off(panel.EVENTS.RECEIVED_REQUEST_COOKIES, onGenericEvent);
panel.off(panel.EVENTS.UPDATING_REQUEST_POST_DATA, onPostEvent);
panel.off(panel.EVENTS.RECEIVED_REQUEST_POST_DATA, onPostEvent);
panel.off(panel.EVENTS.UPDATING_RESPONSE_HEADERS, onGenericEvent);
panel.off(panel.EVENTS.RECEIVED_RESPONSE_HEADERS, onGenericEvent);
panel.off(panel.EVENTS.UPDATING_RESPONSE_COOKIES, onGenericEvent);
panel.off(panel.EVENTS.RECEIVED_RESPONSE_COOKIES, onGenericEvent);
panel.off(panel.EVENTS.STARTED_RECEIVING_RESPONSE, onGenericEvent);
panel.off(panel.EVENTS.UPDATING_RESPONSE_CONTENT, onGenericEvent);
panel.off(panel.EVENTS.RECEIVED_RESPONSE_CONTENT, onGenericEvent);
panel.off(panel.EVENTS.UPDATING_EVENT_TIMINGS, onGenericEvent);
panel.off(panel.EVENTS.RECEIVED_EVENT_TIMINGS, onGenericEvent);
awaitedEventsToListeners.forEach(([e, l]) => panel.off(events[e], l));
executeSoon(deferred.resolve);
}
}
panel.on(panel.EVENTS.UPDATING_REQUEST_HEADERS, onGenericEvent);
panel.on(panel.EVENTS.RECEIVED_REQUEST_HEADERS, onGenericEvent);
panel.on(panel.EVENTS.UPDATING_REQUEST_COOKIES, onGenericEvent);
panel.on(panel.EVENTS.RECEIVED_REQUEST_COOKIES, onGenericEvent);
panel.on(panel.EVENTS.UPDATING_REQUEST_POST_DATA, onPostEvent);
panel.on(panel.EVENTS.RECEIVED_REQUEST_POST_DATA, onPostEvent);
panel.on(panel.EVENTS.UPDATING_RESPONSE_HEADERS, onGenericEvent);
panel.on(panel.EVENTS.RECEIVED_RESPONSE_HEADERS, onGenericEvent);
panel.on(panel.EVENTS.UPDATING_RESPONSE_COOKIES, onGenericEvent);
panel.on(panel.EVENTS.RECEIVED_RESPONSE_COOKIES, onGenericEvent);
panel.on(panel.EVENTS.STARTED_RECEIVING_RESPONSE, onGenericEvent);
panel.on(panel.EVENTS.UPDATING_RESPONSE_CONTENT, onGenericEvent);
panel.on(panel.EVENTS.RECEIVED_RESPONSE_CONTENT, onGenericEvent);
panel.on(panel.EVENTS.UPDATING_EVENT_TIMINGS, onGenericEvent);
panel.on(panel.EVENTS.RECEIVED_EVENT_TIMINGS, onGenericEvent);
awaitedEventsToListeners.forEach(([e, l]) => panel.on(events[e], l));
return deferred.promise;
}

View File

@ -64,8 +64,8 @@
<deck id="main-deck" flex="1">
<vbox flex="1" id="source-deckitem">
<hbox id="sources-body" flex="1">
<vbox width="250">
<vbox id="sources" flex="1">
<vbox width="250" id="sources">
<vbox flex="1">
</vbox>
<toolbar id="project-toolbar" class="devtools-toolbar" hidden="true"></toolbar>
</vbox>

View File

@ -186,6 +186,9 @@ var TextEditor = Class({
resource.load(),
this.appended
]).then(([resourceContents])=> {
if (!this.editor) {
return;
}
this.editor.setText(resourceContents);
this.editor.setClean();
this.emit("load");

View File

@ -0,0 +1,33 @@
/* -*- Mode: Javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* This file contains helper functions for showing user prompts.
* See https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIPromptService
*/
const { Cu, Cc, Ci } = require("chrome");
const { getLocalizedString } = require("projecteditor/helpers/l10n");
const prompts = Cc["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Ci.nsIPromptService);
/**
* Show a prompt.
*
* @param string title
* The title to the dialog
* @param string message
* The message to display
*
* @return bool
* Whether the user has confirmed the action
*/
function confirm(title, message) {
var result = prompts.confirm(null, title || "Title of this Dialog", message || "Are you sure?");
return result;
}
exports.confirm = confirm;

View File

@ -6,10 +6,12 @@
const { Class } = require("sdk/core/heritage");
const { registerPlugin, Plugin } = require("projecteditor/plugins/core");
const { confirm } = require("projecteditor/helpers/prompts");
const { getLocalizedString } = require("projecteditor/helpers/l10n");
var DeletePlugin = Class({
extends: Plugin,
shouldConfirm: true,
init: function(host) {
this.host.addCommand({
@ -22,14 +24,28 @@ var DeletePlugin = Class({
});
},
confirmDelete: function(resource) {
let deletePromptMessage = resource.isDir ?
getLocalizedString("projecteditor.deleteFolderPromptMessage") :
getLocalizedString("projecteditor.deleteFilePromptMessage");
return !this.shouldConfirm || confirm(
getLocalizedString("projecteditor.deletePromptTitle"),
deletePromptMessage
);
},
onCommand: function(cmd) {
if (cmd === "cmd-delete") {
let tree = this.host.projectTree;
let resource = tree.getSelectedResource();
let parent = resource.parent;
if (!this.confirmDelete(resource)) {
return;
}
resource.delete().then(() => {
this.host.project.refresh();
})
});
}
}
});

View File

@ -24,6 +24,14 @@ const gEncoder = new TextEncoder();
* A Project keeps track of the opened folders using LocalStore
* objects. Resources are generally requested from the project,
* even though the Store is actually keeping track of them.
*
*
* This object emits the following events:
* - "refresh-complete": After all stores have been refreshed from disk.
* - "store-added": When a store has been added to the project.
* - "store-removed": When a store has been removed from the project.
* - "resource-added": When a resource has been added to one of the stores.
* - "resource-removed": When a resource has been removed from one of the stores.
*/
var Project = Class({
extends: EventTarget,
@ -88,6 +96,7 @@ var Project = Class({
for (let [path, store] of this.localStores) {
yield store.refresh();
}
emit(this, "refresh-complete");
}.bind(this));
},

View File

@ -171,7 +171,7 @@ var ProjectEditor = Class({
on(this, this.projectTree, "selection", this._onTreeSelected);
on(this, this.projectTree, "resource-removed", this._onTreeResourceRemoved);
let sourcesBox = this.document.querySelector("#sources");
let sourcesBox = this.document.querySelector("#sources > vbox");
sourcesBox.appendChild(this.projectTree.elt);
},

View File

@ -25,15 +25,6 @@ let test = asyncTest(function*() {
return defer.promise;
}
function onPopupHide(contextMenu) {
let defer = promise.defer();
contextMenu.addEventListener("popuphidden", function popuphidden() {
contextMenu.removeEventListener("popuphidden", popuphidden);
defer.resolve();
});
return defer.promise;
}
function openContextMenuOn(node) {
EventUtils.synthesizeMouseAtCenter(
node,
@ -55,9 +46,13 @@ let test = asyncTest(function*() {
is (deleteCommand.getAttribute("hidden"), "", "Delete command is visible");
is (deleteCommand.getAttribute("disabled"), "", "Delete command is enabled");
onPopupHide(popup).then(() => {
ok (true, "Popup has been hidden, waiting for project refresh");
projecteditor.project.refresh().then(() => {
function onConfirmShown(aSubject) {
info("confirm dialog observed as expected");
Services.obs.removeObserver(onConfirmShown, "common-dialog-loaded");
Services.obs.removeObserver(onConfirmShown, "tabmodal-dialog-loaded");
projecteditor.project.on("refresh-complete", function refreshComplete() {
projecteditor.project.off("refresh-complete", refreshComplete);
OS.File.stat(resource.path).then(() => {
ok (false, "The file was not deleted");
defer.resolve();
@ -66,7 +61,13 @@ let test = asyncTest(function*() {
defer.resolve();
});
});
});
// Click the 'OK' button
aSubject.Dialog.ui.button0.click();
}
Services.obs.addObserver(onConfirmShown, "common-dialog-loaded", false);
Services.obs.addObserver(onConfirmShown, "tabmodal-dialog-loaded", false);
deleteCommand.click();
popup.hidePopup();
@ -76,5 +77,4 @@ let test = asyncTest(function*() {
return defer.promise;
}
});

View File

@ -38,11 +38,40 @@ function testGraph(graph) {
is(graph.getSelection().end, graph._regions[0].end,
"The first region is now selected (2).");
let min = map(graph.getSelection().start, 0, graph.width, 112, 4180);
let max = map(graph.getSelection().end, 0, graph.width, 112, 4180);
is(graph.getMappedSelection().min, min,
"The mapped selection's min value is correct (1).");
is(graph.getMappedSelection().max, max,
"The mapped selection's max value is correct (2).");
click(graph, (graph._regions[1].start + graph._regions[1].end) / 2);
is(graph.getSelection().start, graph._regions[1].start,
"The second region is now selected (1).");
is(graph.getSelection().end, graph._regions[1].end,
"The second region is now selected (2).");
min = map(graph.getSelection().start, 0, graph.width, 112, 4180);
max = map(graph.getSelection().end, 0, graph.width, 112, 4180);
is(graph.getMappedSelection().min, min,
"The mapped selection's min value is correct (3).");
is(graph.getMappedSelection().max, max,
"The mapped selection's max value is correct (4).");
graph.setSelection({ start: graph.width, end: 0 });
min = map(0, 0, graph.width, 112, 4180);
max = map(graph.width, 0, graph.width, 112, 4180);
is(graph.getMappedSelection().min, min,
"The mapped selection's min value is correct (5).");
is(graph.getMappedSelection().max, max,
"The mapped selection's max value is correct (6).");
}
/**
* Maps a value from one range to another.
*/
function map(value, istart, istop, ostart, ostop) {
return ostart + (ostop - ostart) * ((value - istart) / (istop - istart));
}
// EventUtils just doesn't work!

View File

@ -377,6 +377,38 @@ AbstractCanvasGraph.prototype = {
return { start: null, end: null };
},
/**
* Gets the selection bounds, scaled to correlate with the data source ranges,
* such that a [0, max width] selection maps to [first value, last value].
*
* @param function unpack [optional]
* Invoked when retrieving the numbers in the data source representing
* the first and last values, on the X axis. Currently, all graphs
* store this in a "delta" property for all entries, but in the future
* this may change as new graphs with different data source format
* requirements are implemented.
* @return object
* The mapped selection's { min, max } values.
*/
getMappedSelection: function(unpack = e => e.delta) {
if (!this.hasData() || !this.hasSelection()) {
return { start: null, end: null };
}
let selection = this.getSelection();
let totalTicks = this._data.length;
let firstTick = unpack(this._data[0]);
let lastTick = unpack(this._data[totalTicks - 1]);
// The selection's start and end values are not guaranteed to be ascending.
// This can happen, for example, when click & dragging from right to left.
let min = Math.min(selection.start, selection.end);
let max = Math.max(selection.start, selection.end);
min = map(min, 0, this._width, firstTick, lastTick);
max = map(max, 0, this._width, firstTick, lastTick);
return { min: min, max: max };
},
/**
* Removes the selection.
*/
@ -1150,13 +1182,6 @@ LineGraphWidget.prototype = Heritage.extend(AbstractCanvasGraph.prototype, {
this._avgTooltip.querySelector("[text=value]").textContent = avgValue|0;
this._minTooltip.querySelector("[text=value]").textContent = minValue|0;
/**
* Maps a value from one range to another.
*/
function map(value, istart, istop, ostart, ostop) {
return ostart + (ostop - ostart) * ((value - istart) / (istop - istart));
}
/**
* Constrains a value to a range.
*/
@ -1603,3 +1628,10 @@ this.CanvasGraphUtils = {
});
}
};
/**
* Maps a value from one range to another.
*/
function map(value, istart, istop, ostart, ostop) {
return ostart + (ostop - ostart) * ((value - istart) / (istop - istart));
}

View File

@ -5,7 +5,7 @@ code, and optionally help with indentation.
# Upgrade
Currently used version is 4.0.3. To upgrade, download a new version of
Currently used version is 4.2.0. To upgrade, download a new version of
CodeMirror from the project's page [1] and replace all JavaScript and
CSS files inside the codemirror directory [2].
@ -46,29 +46,36 @@ in the LICENSE file:
* codemirror.css
* codemirror.js
* comment.js
* comment/comment.js
* comment/continue-comment.js
* activeline.js
* dialog/dialog.css
* dialog/dialog.js
* keymap/emacs.js
* keymap/sublime.js
* keymap/vim.js
* edit/closebrackets.js
* edit/closetag.js
* edit/continuelist.js
* edit/matchbrackets.js
* edit/matchtags.js
* edit/trailingspace.js
* fold/foldcode.js
* fold/brace-fold.js
* fold/comment-fold.js
* fold/xml-fold.js
* fold/foldgutter.js
* xml.js
* css.js
* javascript.js
* clike.js
* htmlmixed.js
* matchbrackets.js
* closebrackets.js
* trailingspace.js
* hint/show-hint.js
* keymap/emacs.js
* keymap/sublime.js
* keymap/vim.js
* mode/xml.js
* mode/css.js
* mode/javascript.js
* mode/clike.js
* mode/htmlmixed.js
* search/match-highlighter.js
* search/search.js
* search/searchcursor.js
* tern/tern.js
* tern/tern.css
* test/codemirror.html
* test/cm_comment_test.js
* test/cm_doc_test.js

View File

@ -70,11 +70,12 @@ div.CodeMirror-overwrite div.CodeMirror-cursor {}
.cm-s-default .cm-atom {color: #219;}
.cm-s-default .cm-number {color: #164;}
.cm-s-default .cm-def {color: #00f;}
.cm-s-default .cm-variable {color: black;}
.cm-s-default .cm-variable,
.cm-s-default .cm-punctuation,
.cm-s-default .cm-property,
.cm-s-default .cm-operator {}
.cm-s-default .cm-variable-2 {color: #05a;}
.cm-s-default .cm-variable-3 {color: #085;}
.cm-s-default .cm-property {color: black;}
.cm-s-default .cm-operator {color: black;}
.cm-s-default .cm-comment {color: #a50;}
.cm-s-default .cm-string {color: #a11;}
.cm-s-default .cm-string-2 {color: #f50;}
@ -250,6 +251,7 @@ div.CodeMirror-cursors {
.CodeMirror-selected { background: #d9d9d9; }
.CodeMirror-focused .CodeMirror-selected { background: #d7d4f0; }
.CodeMirror-crosshair { cursor: crosshair; }
.cm-searching {
background: #ffa;

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,6 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));

View File

@ -0,0 +1,85 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
var modes = ["clike", "css", "javascript"];
for (var i = 0; i < modes.length; ++i)
CodeMirror.extendMode(modes[i], {blockCommentContinue: " * "});
function continueComment(cm) {
if (cm.getOption("disableInput")) return CodeMirror.Pass;
var ranges = cm.listSelections(), mode, inserts = [];
for (var i = 0; i < ranges.length; i++) {
var pos = ranges[i].head, token = cm.getTokenAt(pos);
if (token.type != "comment") return CodeMirror.Pass;
var modeHere = CodeMirror.innerMode(cm.getMode(), token.state).mode;
if (!mode) mode = modeHere;
else if (mode != modeHere) return CodeMirror.Pass;
var insert = null;
if (mode.blockCommentStart && mode.blockCommentContinue) {
var end = token.string.indexOf(mode.blockCommentEnd);
var full = cm.getRange(CodeMirror.Pos(pos.line, 0), CodeMirror.Pos(pos.line, token.end)), found;
if (end != -1 && end == token.string.length - mode.blockCommentEnd.length && pos.ch >= end) {
// Comment ended, don't continue it
} else if (token.string.indexOf(mode.blockCommentStart) == 0) {
insert = full.slice(0, token.start);
if (!/^\s*$/.test(insert)) {
insert = "";
for (var j = 0; j < token.start; ++j) insert += " ";
}
} else if ((found = full.indexOf(mode.blockCommentContinue)) != -1 &&
found + mode.blockCommentContinue.length > token.start &&
/^\s*$/.test(full.slice(0, found))) {
insert = full.slice(0, found);
}
if (insert != null) insert += mode.blockCommentContinue;
}
if (insert == null && mode.lineComment && continueLineCommentEnabled(cm)) {
var line = cm.getLine(pos.line), found = line.indexOf(mode.lineComment);
if (found > -1) {
insert = line.slice(0, found);
if (/\S/.test(insert)) insert = null;
else insert += mode.lineComment + line.slice(found + mode.lineComment.length).match(/^\s*/)[0];
}
}
if (insert == null) return CodeMirror.Pass;
inserts[i] = "\n" + insert;
}
cm.operation(function() {
for (var i = ranges.length - 1; i >= 0; i--)
cm.replaceRange(inserts[i], ranges[i].from(), ranges[i].to(), "+insert");
});
}
function continueLineCommentEnabled(cm) {
var opt = cm.getOption("continueComments");
if (opt && typeof opt == "object")
return opt.continueLineComment !== false;
return true;
}
CodeMirror.defineOption("continueComments", null, function(cm, val, prev) {
if (prev && prev != CodeMirror.Init)
cm.removeKeyMap("continueComment");
if (val) {
var key = "Enter";
if (typeof val == "string")
key = val;
else if (typeof val == "object" && val.key)
key = val.key;
var map = {name: "continueComment"};
map[key] = continueComment;
cm.addKeyMap(map);
}
});
});

View File

@ -1,3 +1,6 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
// Open simple dialogs on top of an editor. Relies on dialog.css.
(function(mod) {

View File

@ -1,3 +1,6 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
@ -10,6 +13,8 @@
var DEFAULT_EXPLODE_ON_ENTER = "[]{}";
var SPACE_CHAR_REGEX = /\s/;
var Pos = CodeMirror.Pos;
CodeMirror.defineOption("autoCloseBrackets", false, function(cm, val, old) {
if (old != CodeMirror.Init && old)
cm.removeKeyMap("autoCloseBrackets");
@ -26,8 +31,8 @@
});
function charsAround(cm, pos) {
var str = cm.getRange(CodeMirror.Pos(pos.line, pos.ch - 1),
CodeMirror.Pos(pos.line, pos.ch + 1));
var str = cm.getRange(Pos(pos.line, pos.ch - 1),
Pos(pos.line, pos.ch + 1));
return str.length == 2 ? str : null;
}
@ -44,7 +49,7 @@
}
for (var i = ranges.length - 1; i >= 0; i--) {
var cur = ranges[i].head;
cm.replaceRange("", CodeMirror.Pos(cur.line, cur.ch - 1), CodeMirror.Pos(cur.line, cur.ch + 1));
cm.replaceRange("", Pos(cur.line, cur.ch - 1), Pos(cur.line, cur.ch + 1));
}
}
};
@ -58,11 +63,18 @@
var range = ranges[i], cur = range.head, curType;
if (left == "'" && cm.getTokenTypeAt(cur) == "comment")
return CodeMirror.Pass;
var next = cm.getRange(cur, CodeMirror.Pos(cur.line, cur.ch + 1));
var next = cm.getRange(cur, Pos(cur.line, cur.ch + 1));
if (!range.empty())
curType = "surround";
else if (left == right && next == right)
curType = "skip";
else if (left == right && next == right) {
if (cm.getRange(cur, Pos(cur.line, cur.ch + 3)) == left + left + left)
curType = "skipThree";
else
curType = "skip";
} else if (left == right && cur.ch > 1 &&
cm.getRange(Pos(cur.line, cur.ch - 2), cur) == left + left &&
(cur.ch <= 2 || cm.getRange(Pos(cur.line, cur.ch - 3), Pos(cur.line, cur.ch - 2)) != left))
curType = "addFour";
else if (left == right && CodeMirror.isWordChar(next))
return CodeMirror.Pass;
else if (cm.getLine(cur.line).length == cur.ch || closingBrackets.indexOf(next) >= 0 || SPACE_CHAR_REGEX.test(next))
@ -73,24 +85,32 @@
else if (type != curType) return CodeMirror.Pass;
}
if (type == "skip") {
cm.execCommand("goCharRight");
} else if (type == "surround") {
var sels = cm.getSelections();
for (var i = 0; i < sels.length; i++)
sels[i] = left + sels[i] + right;
cm.replaceSelections(sels, "around");
} else if (type == "both") {
cm.replaceSelection(left + right, null);
cm.execCommand("goCharLeft");
}
cm.operation(function() {
if (type == "skip") {
cm.execCommand("goCharRight");
} else if (type == "skipThree") {
for (var i = 0; i < 3; i++)
cm.execCommand("goCharRight");
} else if (type == "surround") {
var sels = cm.getSelections();
for (var i = 0; i < sels.length; i++)
sels[i] = left + sels[i] + right;
cm.replaceSelections(sels, "around");
} else if (type == "both") {
cm.replaceSelection(left + right, null);
cm.execCommand("goCharLeft");
} else if (type == "addFour") {
cm.replaceSelection(left + left + left + left, "before");
cm.execCommand("goCharRight");
}
});
};
if (left != right) map["'" + right + "'"] = function(cm) {
var ranges = cm.listSelections();
for (var i = 0; i < ranges.length; i++) {
var range = ranges[i];
if (!range.empty() ||
cm.getRange(range.head, CodeMirror.Pos(range.head.line, range.head.ch + 1)) != right)
cm.getRange(range.head, Pos(range.head.line, range.head.ch + 1)) != right)
return CodeMirror.Pass;
}
cm.execCommand("goCharRight");

View File

@ -0,0 +1,141 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
/**
* Tag-closer extension for CodeMirror.
*
* This extension adds an "autoCloseTags" option that can be set to
* either true to get the default behavior, or an object to further
* configure its behavior.
*
* These are supported options:
*
* `whenClosing` (default true)
* Whether to autoclose when the '/' of a closing tag is typed.
* `whenOpening` (default true)
* Whether to autoclose the tag when the final '>' of an opening
* tag is typed.
* `dontCloseTags` (default is empty tags for HTML, none for XML)
* An array of tag names that should not be autoclosed.
* `indentTags` (default is block tags for HTML, none for XML)
* An array of tag names that should, when opened, cause a
* blank line to be added inside the tag, and the blank line and
* closing line to be indented.
*
* See demos/closetag.html for a usage example.
*/
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"), require("../fold/xml-fold"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror", "../fold/xml-fold"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
CodeMirror.defineOption("autoCloseTags", false, function(cm, val, old) {
if (old != CodeMirror.Init && old)
cm.removeKeyMap("autoCloseTags");
if (!val) return;
var map = {name: "autoCloseTags"};
if (typeof val != "object" || val.whenClosing)
map["'/'"] = function(cm) { return autoCloseSlash(cm); };
if (typeof val != "object" || val.whenOpening)
map["'>'"] = function(cm) { return autoCloseGT(cm); };
cm.addKeyMap(map);
});
var htmlDontClose = ["area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param",
"source", "track", "wbr"];
var htmlIndent = ["applet", "blockquote", "body", "button", "div", "dl", "fieldset", "form", "frameset", "h1", "h2", "h3", "h4",
"h5", "h6", "head", "html", "iframe", "layer", "legend", "object", "ol", "p", "select", "table", "ul"];
function autoCloseGT(cm) {
if (cm.getOption("disableInput")) return CodeMirror.Pass;
var ranges = cm.listSelections(), replacements = [];
for (var i = 0; i < ranges.length; i++) {
if (!ranges[i].empty()) return CodeMirror.Pass;
var pos = ranges[i].head, tok = cm.getTokenAt(pos);
var inner = CodeMirror.innerMode(cm.getMode(), tok.state), state = inner.state;
if (inner.mode.name != "xml" || !state.tagName) return CodeMirror.Pass;
var opt = cm.getOption("autoCloseTags"), html = inner.mode.configuration == "html";
var dontCloseTags = (typeof opt == "object" && opt.dontCloseTags) || (html && htmlDontClose);
var indentTags = (typeof opt == "object" && opt.indentTags) || (html && htmlIndent);
var tagName = state.tagName;
if (tok.end > pos.ch) tagName = tagName.slice(0, tagName.length - tok.end + pos.ch);
var lowerTagName = tagName.toLowerCase();
// Don't process the '>' at the end of an end-tag or self-closing tag
if (!tagName ||
tok.type == "string" && (tok.end != pos.ch || !/[\"\']/.test(tok.string.charAt(tok.string.length - 1)) || tok.string.length == 1) ||
tok.type == "tag" && state.type == "closeTag" ||
tok.string.indexOf("/") == (tok.string.length - 1) || // match something like <someTagName />
dontCloseTags && indexOf(dontCloseTags, lowerTagName) > -1 ||
closingTagExists(cm, tagName, pos, state, true))
return CodeMirror.Pass;
var indent = indentTags && indexOf(indentTags, lowerTagName) > -1;
replacements[i] = {indent: indent,
text: ">" + (indent ? "\n\n" : "") + "</" + tagName + ">",
newPos: indent ? CodeMirror.Pos(pos.line + 1, 0) : CodeMirror.Pos(pos.line, pos.ch + 1)};
}
for (var i = ranges.length - 1; i >= 0; i--) {
var info = replacements[i];
cm.replaceRange(info.text, ranges[i].head, ranges[i].anchor, "+insert");
var sel = cm.listSelections().slice(0);
sel[i] = {head: info.newPos, anchor: info.newPos};
cm.setSelections(sel);
if (info.indent) {
cm.indentLine(info.newPos.line, null, true);
cm.indentLine(info.newPos.line + 1, null, true);
}
}
}
function autoCloseSlash(cm) {
if (cm.getOption("disableInput")) return CodeMirror.Pass;
var ranges = cm.listSelections(), replacements = [];
for (var i = 0; i < ranges.length; i++) {
if (!ranges[i].empty()) return CodeMirror.Pass;
var pos = ranges[i].head, tok = cm.getTokenAt(pos);
var inner = CodeMirror.innerMode(cm.getMode(), tok.state), state = inner.state;
if (tok.type == "string" || tok.string.charAt(0) != "<" ||
tok.start != pos.ch - 1 || inner.mode.name != "xml" ||
!state.context || !state.context.tagName ||
closingTagExists(cm, state.context.tagName, pos, state))
return CodeMirror.Pass;
replacements[i] = "/" + state.context.tagName + ">";
}
cm.replaceSelections(replacements);
}
function indexOf(collection, elt) {
if (collection.indexOf) return collection.indexOf(elt);
for (var i = 0, e = collection.length; i < e; ++i)
if (collection[i] == elt) return i;
return -1;
}
// If xml-fold is loaded, we use its functionality to try and verify
// whether a given tag is actually unclosed.
function closingTagExists(cm, tagName, pos, state, newTag) {
if (!CodeMirror.scanForClosingTag) return false;
var end = Math.min(cm.lastLine() + 1, pos.line + 500);
var nextClose = CodeMirror.scanForClosingTag(cm, pos, null, end);
if (!nextClose || nextClose.tag != tagName) return false;
var cx = state.context;
// If the immediate wrapping context contains onCx instances of
// the same tag, a closing tag only exists if there are at least
// that many closing tags of that type following.
for (var onCx = newTag ? 1 : 0; cx && cx.tagName == tagName; cx = cx.prev) ++onCx;
pos = nextClose.to;
for (var i = 1; i < onCx; i++) {
var next = CodeMirror.scanForClosingTag(cm, pos, null, end);
if (!next || next.tag != tagName) return false;
pos = next.to;
}
return true;
}
});

View File

@ -0,0 +1,38 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
var listRE = /^(\s*)([*+-]|(\d+)\.)(\s*)/,
unorderedBullets = "*+-";
CodeMirror.commands.newlineAndIndentContinueMarkdownList = function(cm) {
if (cm.getOption("disableInput")) return CodeMirror.Pass;
var ranges = cm.listSelections(), replacements = [];
for (var i = 0; i < ranges.length; i++) {
var pos = ranges[i].head, match;
var inList = cm.getStateAfter(pos.line).list !== false;
if (!ranges[i].empty() || !inList || !(match = cm.getLine(pos.line).match(listRE))) {
cm.execCommand("newlineAndIndent");
return;
}
var indent = match[1], after = match[4];
var bullet = unorderedBullets.indexOf(match[2]) >= 0
? match[2]
: (parseInt(match[3], 10) + 1) + ".";
replacements[i] = "\n" + indent + bullet + after;
}
cm.replaceSelections(replacements);
};
});

View File

@ -1,3 +1,6 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
@ -22,15 +25,24 @@
var style = cm.getTokenTypeAt(Pos(where.line, pos + 1));
var found = scanForBracket(cm, Pos(where.line, pos + (dir > 0 ? 1 : 0)), dir, style || null, config);
if (found == null) return null;
return {from: Pos(where.line, pos), to: found && found.pos,
match: found && found.ch == match.charAt(0), forward: dir > 0};
}
// bracketRegex is used to specify which type of bracket to scan
// should be a regexp, e.g. /[[\]]/
//
// Note: If "where" is on an open bracket, then this bracket is ignored.
//
// Returns false when no bracket was found, null when it reached
// maxScanLines and gave up
function scanForBracket(cm, where, dir, style, config) {
var maxScanLen = (config && config.maxScanLineLength) || 10000;
var maxScanLines = (config && config.maxScanLines) || 500;
var maxScanLines = (config && config.maxScanLines) || 1000;
var stack = [], re = /[(){}[\]]/;
var stack = [];
var re = config && config.bracketRegex ? config.bracketRegex : /[(){}[\]]/;
var lineEnd = dir > 0 ? Math.min(where.line + maxScanLines, cm.lastLine() + 1)
: Math.max(cm.firstLine() - 1, where.line - maxScanLines);
for (var lineNo = where.line; lineNo != lineEnd; lineNo += dir) {
@ -49,6 +61,7 @@
}
}
}
return lineNo - dir == (dir > 0 ? cm.lastLine() : cm.firstLine()) ? false : null;
}
function matchBrackets(cm, autoclear, config) {
@ -57,11 +70,10 @@
var marks = [], ranges = cm.listSelections();
for (var i = 0; i < ranges.length; i++) {
var match = ranges[i].empty() && findMatchingBracket(cm, ranges[i].head, false, config);
if (match && cm.getLine(match.from.line).length <= maxHighlightLen &&
match.to && cm.getLine(match.to.line).length <= maxHighlightLen) {
if (match && cm.getLine(match.from.line).length <= maxHighlightLen) {
var style = match.match ? "CodeMirror-matchingbracket" : "CodeMirror-nonmatchingbracket";
marks.push(cm.markText(match.from, Pos(match.from.line, match.from.ch + 1), {className: style}));
if (match.to)
if (match.to && cm.getLine(match.to.line).length <= maxHighlightLen)
marks.push(cm.markText(match.to, Pos(match.to.line, match.to.ch + 1), {className: style}));
}
}
@ -99,10 +111,10 @@
});
CodeMirror.defineExtension("matchBrackets", function() {matchBrackets(this, true);});
CodeMirror.defineExtension("findMatchingBracket", function(pos, strict){
return findMatchingBracket(this, pos, strict);
CodeMirror.defineExtension("findMatchingBracket", function(pos, strict, config){
return findMatchingBracket(this, pos, strict, config);
});
CodeMirror.defineExtension("scanForBracket", function(pos, dir, style){
return scanForBracket(this, pos, dir, style);
CodeMirror.defineExtension("scanForBracket", function(pos, dir, style, config){
return scanForBracket(this, pos, dir, style, config);
});
});

View File

@ -0,0 +1,66 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"), require("../fold/xml-fold"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror", "../fold/xml-fold"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
CodeMirror.defineOption("matchTags", false, function(cm, val, old) {
if (old && old != CodeMirror.Init) {
cm.off("cursorActivity", doMatchTags);
cm.off("viewportChange", maybeUpdateMatch);
clear(cm);
}
if (val) {
cm.state.matchBothTags = typeof val == "object" && val.bothTags;
cm.on("cursorActivity", doMatchTags);
cm.on("viewportChange", maybeUpdateMatch);
doMatchTags(cm);
}
});
function clear(cm) {
if (cm.state.tagHit) cm.state.tagHit.clear();
if (cm.state.tagOther) cm.state.tagOther.clear();
cm.state.tagHit = cm.state.tagOther = null;
}
function doMatchTags(cm) {
cm.state.failedTagMatch = false;
cm.operation(function() {
clear(cm);
if (cm.somethingSelected()) return;
var cur = cm.getCursor(), range = cm.getViewport();
range.from = Math.min(range.from, cur.line); range.to = Math.max(cur.line + 1, range.to);
var match = CodeMirror.findMatchingTag(cm, cur, range);
if (!match) return;
if (cm.state.matchBothTags) {
var hit = match.at == "open" ? match.open : match.close;
if (hit) cm.state.tagHit = cm.markText(hit.from, hit.to, {className: "CodeMirror-matchingtag"});
}
var other = match.at == "close" ? match.open : match.close;
if (other)
cm.state.tagOther = cm.markText(other.from, other.to, {className: "CodeMirror-matchingtag"});
else
cm.state.failedTagMatch = true;
});
}
function maybeUpdateMatch(cm) {
if (cm.state.failedTagMatch) doMatchTags(cm);
}
CodeMirror.commands.toMatchingTag = function(cm) {
var found = CodeMirror.findMatchingTag(cm, cm.getCursor());
if (found) {
var other = found.at == "close" ? found.open : found.close;
if (other) cm.extendSelection(other.to, other.from);
}
};
});

View File

@ -1,3 +1,6 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));

View File

@ -1,3 +1,16 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
CodeMirror.registerHelper("fold", "brace", function(cm, start) {
var line = start.line, lineText = cm.getLine(line);
var startCh, tokenType;
@ -45,7 +58,6 @@ CodeMirror.registerHelper("fold", "brace", function(cm, start) {
return {from: CodeMirror.Pos(line, startCh),
to: CodeMirror.Pos(end, endCh)};
});
CodeMirror.braceRangeFinder = CodeMirror.fold.brace; // deprecated
CodeMirror.registerHelper("fold", "import", function(cm, start) {
function hasImport(line) {
@ -70,7 +82,6 @@ CodeMirror.registerHelper("fold", "import", function(cm, start) {
}
return {from: cm.clipPos(CodeMirror.Pos(start, has.startCh + 1)), to: end};
});
CodeMirror.importRangeFinder = CodeMirror.fold["import"]; // deprecated
CodeMirror.registerHelper("fold", "include", function(cm, start) {
function hasInclude(line) {
@ -90,4 +101,5 @@ CodeMirror.registerHelper("fold", "include", function(cm, start) {
return {from: CodeMirror.Pos(start, has + 1),
to: cm.clipPos(CodeMirror.Pos(end))};
});
CodeMirror.includeRangeFinder = CodeMirror.fold.include; // deprecated
});

View File

@ -1,3 +1,16 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
CodeMirror.registerGlobalHelper("fold", "comment", function(mode) {
return mode.blockCommentStart && mode.blockCommentEnd;
}, function(cm, start) {
@ -40,3 +53,5 @@ CodeMirror.registerGlobalHelper("fold", "comment", function(mode) {
return {from: CodeMirror.Pos(line, startCh),
to: CodeMirror.Pos(end, endCh)};
});
});

View File

@ -1,11 +1,25 @@
(function() {
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
function doFold(cm, pos, options, force) {
var finder = options && (options.call ? options : options.rangeFinder);
if (!finder) finder = CodeMirror.fold.auto;
if (options && options.call) {
var finder = options;
options = null;
} else {
var finder = getOption(cm, options, "rangeFinder");
}
if (typeof pos == "number") pos = CodeMirror.Pos(pos, 0);
var minSize = options && options.minFoldSize || 0;
var minSize = getOption(cm, options, "minFoldSize");
function getRange(allowFolded) {
var range = finder(cm, pos);
@ -22,14 +36,17 @@
}
var range = getRange(true);
if (options && options.scanUp) while (!range && pos.line > cm.firstLine()) {
if (getOption(cm, options, "scanUp")) while (!range && pos.line > cm.firstLine()) {
pos = CodeMirror.Pos(pos.line - 1, 0);
range = getRange(false);
}
if (!range || range.cleared || force === "unfold") return;
var myWidget = makeWidget(options);
CodeMirror.on(myWidget, "mousedown", function() { myRange.clear(); });
var myWidget = makeWidget(cm, options);
CodeMirror.on(myWidget, "mousedown", function(e) {
myRange.clear();
CodeMirror.e_preventDefault(e);
});
var myRange = cm.markText(range.from, range.to, {
replacedWith: myWidget,
clearOnEnter: true,
@ -41,8 +58,8 @@
CodeMirror.signal(cm, "fold", cm, range.from, range.to);
}
function makeWidget(options) {
var widget = (options && options.widget) || "\u2194";
function makeWidget(cm, options) {
var widget = getOption(cm, options, "widget");
if (typeof widget == "string") {
var text = document.createTextNode(widget);
widget = document.createElement("span");
@ -62,9 +79,33 @@
doFold(this, pos, options, force);
});
CodeMirror.commands.fold = function(cm) {
CodeMirror.defineExtension("isFolded", function(pos) {
var marks = this.findMarksAt(pos);
for (var i = 0; i < marks.length; ++i)
if (marks[i].__isFold) return true;
});
CodeMirror.commands.toggleFold = function(cm) {
cm.foldCode(cm.getCursor());
};
CodeMirror.commands.fold = function(cm) {
cm.foldCode(cm.getCursor(), null, "fold");
};
CodeMirror.commands.unfold = function(cm) {
cm.foldCode(cm.getCursor(), null, "unfold");
};
CodeMirror.commands.foldAll = function(cm) {
cm.operation(function() {
for (var i = cm.firstLine(), e = cm.lastLine(); i <= e; i++)
cm.foldCode(CodeMirror.Pos(i, 0), null, "fold");
});
};
CodeMirror.commands.unfoldAll = function(cm) {
cm.operation(function() {
for (var i = cm.firstLine(), e = cm.lastLine(); i <= e; i++)
cm.foldCode(CodeMirror.Pos(i, 0), null, "unfold");
});
};
CodeMirror.registerHelper("fold", "combine", function() {
var funcs = Array.prototype.slice.call(arguments, 0);
@ -83,4 +124,22 @@
if (cur) return cur;
}
});
})();
var defaultOptions = {
rangeFinder: CodeMirror.fold.auto,
widget: "\u2194",
minFoldSize: 0,
scanUp: false
};
CodeMirror.defineOption("foldOptions", null);
function getOption(cm, options, name) {
if (options && options[name] !== undefined)
return options[name];
var editorOptions = cm.options.foldOptions;
if (editorOptions && editorOptions[name] !== undefined)
return editorOptions[name];
return defaultOptions[name];
}
});

View File

@ -0,0 +1,21 @@
.CodeMirror-foldmarker {
color: blue;
text-shadow: #b9f 1px 1px 2px, #b9f -1px -1px 2px, #b9f 1px -1px 2px, #b9f -1px 1px 2px;
font-family: arial;
line-height: .3;
cursor: pointer;
}
.CodeMirror-foldgutter {
width: .7em;
}
.CodeMirror-foldgutter-open,
.CodeMirror-foldgutter-folded {
color: #555;
cursor: pointer;
}
.CodeMirror-foldgutter-open:after {
content: "\25BE";
}
.CodeMirror-foldgutter-folded:after {
content: "\25B8";
}

View File

@ -1,4 +1,14 @@
(function() {
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"), require("./foldcode"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror", "./foldcode"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
CodeMirror.defineOption("foldGutter", false, function(cm, val, old) {
@ -121,4 +131,4 @@
if (line >= state.from && line < state.to)
updateFoldInfo(cm, line, line + 1);
}
})();
});

View File

@ -0,0 +1,44 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
CodeMirror.registerHelper("fold", "indent", function(cm, start) {
var tabSize = cm.getOption("tabSize"), firstLine = cm.getLine(start.line);
if (!/\S/.test(firstLine)) return;
var getIndent = function(line) {
return CodeMirror.countColumn(line, null, tabSize);
};
var myIndent = getIndent(firstLine);
var lastLineInFold = null;
// Go through lines until we find a line that definitely doesn't belong in
// the block we're folding, or to the end.
for (var i = start.line + 1, end = cm.lastLine(); i <= end; ++i) {
var curLine = cm.getLine(i);
var curIndent = getIndent(curLine);
if (curIndent > myIndent) {
// Lines with a greater indent are considered part of the block.
lastLineInFold = i;
} else if (!/\S/.test(curLine)) {
// Empty lines might be breaks within the block we're trying to fold.
} else {
// A non-empty line at an indent equal to or less than ours marks the
// start of another block.
break;
}
}
if (lastLineInFold) return {
from: CodeMirror.Pos(start.line, firstLine.length),
to: CodeMirror.Pos(lastLineInFold, cm.getLine(lastLineInFold).length)
};
});
});

View File

@ -0,0 +1,49 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
CodeMirror.registerHelper("fold", "markdown", function(cm, start) {
var maxDepth = 100;
function isHeader(lineNo) {
var tokentype = cm.getTokenTypeAt(CodeMirror.Pos(lineNo, 0));
return tokentype && /\bheader\b/.test(tokentype);
}
function headerLevel(lineNo, line, nextLine) {
var match = line && line.match(/^#+/);
if (match && isHeader(lineNo)) return match[0].length;
match = nextLine && nextLine.match(/^[=\-]+\s*$/);
if (match && isHeader(lineNo + 1)) return nextLine[0] == "=" ? 1 : 2;
return maxDepth;
}
var firstLine = cm.getLine(start.line), nextLine = cm.getLine(start.line + 1);
var level = headerLevel(start.line, firstLine, nextLine);
if (level === maxDepth) return undefined;
var lastLineNo = cm.lastLine();
var end = start.line, nextNextLine = cm.getLine(end + 2);
while (end < lastLineNo) {
if (headerLevel(end + 1, nextLine, nextNextLine) <= level) break;
++end;
nextLine = nextNextLine;
nextNextLine = cm.getLine(end + 2);
}
return {
from: CodeMirror.Pos(start.line, firstLine.length),
to: CodeMirror.Pos(end, cm.getLine(end).length)
};
});
});

View File

@ -1,4 +1,14 @@
(function() {
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
var Pos = CodeMirror.Pos;
@ -136,8 +146,6 @@
}
}
});
CodeMirror.tagRangeFinder = CodeMirror.fold.xml; // deprecated
CodeMirror.findMatchingTag = function(cm, pos, range) {
var iter = new Iter(cm, pos.line, pos.ch, range);
if (iter.text.indexOf(">") == -1 && iter.text.indexOf("<") == -1) return;
@ -168,6 +176,6 @@
// Used by addon/edit/closetag.js
CodeMirror.scanForClosingTag = function(cm, pos, name, end) {
var iter = new Iter(cm, pos.line, pos.ch, end ? {from: 0, to: end} : null);
return !!findMatchingClose(iter, name);
return findMatchingClose(iter, name);
};
})();
});

View File

@ -1,31 +1,48 @@
(function() {
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
var HINT_ELEMENT_CLASS = "CodeMirror-hint";
var ACTIVE_HINT_ELEMENT_CLASS = "CodeMirror-hint-active";
// This is the old interface, kept around for now to stay
// backwards-compatible.
CodeMirror.showHint = function(cm, getHints, options) {
// We want a single cursor position.
if (cm.somethingSelected()) return;
if (getHints == null) {
if (options && options.async) return;
else getHints = CodeMirror.hint.auto;
}
if (cm.state.completionActive) cm.state.completionActive.close();
var completion = cm.state.completionActive = new Completion(cm, getHints, options || {});
CodeMirror.signal(cm, "startCompletion", cm);
if (completion.options.async)
getHints(cm, function(hints) { completion.showHints(hints); }, completion.options);
else
return completion.showHints(getHints(cm, completion.options));
if (!getHints) return cm.showHint(options);
if (options && options.async) getHints.async = true;
var newOpts = {hint: getHints};
if (options) for (var prop in options) newOpts[prop] = options[prop];
return cm.showHint(newOpts);
};
function Completion(cm, getHints, options) {
CodeMirror.defineExtension("showHint", function(options) {
// We want a single cursor position.
if (this.listSelections().length > 1 || this.somethingSelected()) return;
if (this.state.completionActive) this.state.completionActive.close();
var completion = this.state.completionActive = new Completion(this, options);
var getHints = completion.options.hint;
if (!getHints) return;
CodeMirror.signal(this, "startCompletion", this);
if (getHints.async)
getHints(this, function(hints) { completion.showHints(hints); }, completion.options);
else
return completion.showHints(getHints(this, completion.options));
});
function Completion(cm, options) {
this.cm = cm;
this.getHints = getHints;
this.options = options;
this.options = this.buildOptions(options);
this.widget = this.onClose = null;
}
@ -46,7 +63,8 @@
pick: function(data, i) {
var completion = data.list[i];
if (completion.hint) completion.hint(this.cm, data, completion);
else this.cm.replaceRange(getText(completion), data.from, data.to);
else this.cm.replaceRange(getText(completion), completion.from || data.from,
completion.to || data.to, "complete");
CodeMirror.signal(data, "pick", completion);
this.close();
},
@ -54,7 +72,7 @@
showHints: function(data) {
if (!data || !data.list.length || !this.active()) return this.close();
if (this.options.completeSingle != false && data.list.length == 1)
if (this.options.completeSingle && data.list.length == 1)
this.pick(data, 0);
else
this.showWidget(data);
@ -65,7 +83,7 @@
CodeMirror.signal(data, "shown");
var debounce = 0, completion = this, finished;
var closeOn = this.options.closeCharacters || /[\s()\[\]{};:>,]/;
var closeOn = this.options.closeCharacters;
var startPos = this.cm.getCursor(), startLen = this.cm.getLine(startPos.line).length;
var requestAnimationFrame = window.requestAnimationFrame || function(fn) {
@ -84,15 +102,17 @@
function update() {
if (finished) return;
CodeMirror.signal(data, "update");
if (completion.options.async)
completion.getHints(completion.cm, finishUpdate, completion.options);
var getHints = completion.options.hint;
if (getHints.async)
getHints(completion.cm, finishUpdate, completion.options);
else
finishUpdate(completion.getHints(completion.cm, completion.options));
finishUpdate(getHints(completion.cm, completion.options));
}
function finishUpdate(data_) {
data = data_;
if (finished) return;
if (!data || !data.list.length) return done();
if (completion.widget) completion.widget.close();
completion.widget = new Widget(completion, data);
}
@ -117,6 +137,17 @@
}
this.cm.on("cursorActivity", activity);
this.onClose = done;
},
buildOptions: function(options) {
var editor = this.cm.options.hintOptions;
var out = {};
for (var prop in defaultOptions) out[prop] = defaultOptions[prop];
if (editor) for (var prop in editor)
if (editor[prop] !== undefined) out[prop] = editor[prop];
if (options) for (var prop in options)
if (options[prop] !== undefined) out[prop] = options[prop];
return out;
}
};
@ -125,7 +156,7 @@
else return completion.text;
}
function buildKeyMap(options, handle) {
function buildKeyMap(completion, handle) {
var baseMap = {
Up: function() {handle.moveFocus(-1);},
Down: function() {handle.moveFocus(1);},
@ -137,7 +168,8 @@
Tab: handle.pick,
Esc: handle.close
};
var ourMap = options.customKeys ? {} : baseMap;
var custom = completion.options.customKeys;
var ourMap = custom ? {} : baseMap;
function addBinding(key, val) {
var bound;
if (typeof val != "string")
@ -149,12 +181,13 @@
bound = val;
ourMap[key] = bound;
}
if (options.customKeys)
for (var key in options.customKeys) if (options.customKeys.hasOwnProperty(key))
addBinding(key, options.customKeys[key]);
if (options.extraKeys)
for (var key in options.extraKeys) if (options.extraKeys.hasOwnProperty(key))
addBinding(key, options.extraKeys[key]);
if (custom)
for (var key in custom) if (custom.hasOwnProperty(key))
addBinding(key, custom[key]);
var extra = completion.options.extraKeys;
if (extra)
for (var key in extra) if (extra.hasOwnProperty(key))
addBinding(key, extra[key]);
return ourMap;
}
@ -168,11 +201,11 @@
function Widget(completion, data) {
this.completion = completion;
this.data = data;
var widget = this, cm = completion.cm, options = completion.options;
var widget = this, cm = completion.cm;
var hints = this.hints = document.createElement("ul");
hints.className = "CodeMirror-hints";
this.selectedHint = options.getDefaultSelection ? options.getDefaultSelection(cm,options,data) : 0;
this.selectedHint = data.selectedHint || 0;
var completions = data.list;
for (var i = 0; i < completions.length; ++i) {
@ -185,14 +218,14 @@
elt.hintId = i;
}
var pos = cm.cursorCoords(options.alignWithWord !== false ? data.from : null);
var pos = cm.cursorCoords(completion.options.alignWithWord ? data.from : null);
var left = pos.left, top = pos.bottom, below = true;
hints.style.left = left + "px";
hints.style.top = top + "px";
// If we're at the edge of the screen, then we want the menu to appear on the left of the cursor.
var winW = window.innerWidth || Math.max(document.body.offsetWidth, document.documentElement.offsetWidth);
var winH = window.innerHeight || Math.max(document.body.offsetHeight, document.documentElement.offsetHeight);
(options.container || document.body).appendChild(hints);
(completion.options.container || document.body).appendChild(hints);
var box = hints.getBoundingClientRect(), overlapY = box.bottom - winH;
if (overlapY > 0) {
var height = box.bottom - box.top, curTop = box.top - (pos.bottom - pos.top);
@ -219,7 +252,7 @@
hints.style.left = (left = pos.left - overlapX) + "px";
}
cm.addKeyMap(this.keyMap = buildKeyMap(options, {
cm.addKeyMap(this.keyMap = buildKeyMap(completion, {
moveFocus: function(n, avoidWrap) { widget.changeActive(widget.selectedHint + n, avoidWrap); },
setFocus: function(n) { widget.changeActive(n); },
menuSize: function() { return widget.screenAmount(); },
@ -229,7 +262,7 @@
data: data
}));
if (options.closeOnUnfocus !== false) {
if (completion.options.closeOnUnfocus) {
var closingOnBlur;
cm.on("blur", this.onBlur = function() { closingOnBlur = setTimeout(function() { completion.close(); }, 100); });
cm.on("focus", this.onFocus = function() { clearTimeout(closingOnBlur); });
@ -255,7 +288,7 @@
var t = getHintElement(hints, e.target || e.srcElement);
if (t && t.hintId != null) {
widget.changeActive(t.hintId);
if (options.completeOnSingleClick) widget.pick();
if (completion.options.completeOnSingleClick) widget.pick();
}
});
@ -275,7 +308,7 @@
this.completion.cm.removeKeyMap(this.keyMap);
var cm = this.completion.cm;
if (this.completion.options.closeOnUnfocus !== false) {
if (this.completion.options.closeOnUnfocus) {
cm.off("blur", this.onBlur);
cm.off("focus", this.onFocus);
}
@ -309,15 +342,16 @@
};
CodeMirror.registerHelper("hint", "auto", function(cm, options) {
var helpers = cm.getHelpers(cm.getCursor(), "hint");
var helpers = cm.getHelpers(cm.getCursor(), "hint"), words;
if (helpers.length) {
for (var i = 0; i < helpers.length; i++) {
var cur = helpers[i](cm, options);
if (cur && cur.list.length) return cur;
}
} else {
var words = cm.getHelper(cm.getCursor(), "hintWords");
} else if (words = cm.getHelper(cm.getCursor(), "hintWords")) {
if (words) return CodeMirror.hint.fromList(cm, {words: words});
} else if (CodeMirror.hint.anyword) {
return CodeMirror.hint.anyword(cm, options);
}
});
@ -338,4 +372,18 @@
});
CodeMirror.commands.autocomplete = CodeMirror.showHint;
})();
var defaultOptions = {
hint: CodeMirror.hint.auto,
completeSingle: true,
alignWithWord: true,
closeCharacters: /[\s()\[\]{};:>,]/,
closeOnUnfocus: true,
completeOnSingleClick: false,
container: null,
customKeys: null,
extraKeys: null
};
CodeMirror.defineOption("hintOptions", null);
});

View File

@ -1,3 +1,6 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../lib/codemirror"));
@ -324,13 +327,7 @@
},
"Ctrl-O": repeated(function(cm) { cm.replaceSelection("\n", "start"); }),
"Ctrl-T": repeated(function(cm) {
var pos = cm.getCursor();
if (pos.ch < cm.getLine(pos.line).length) pos = Pos(pos.line, pos.ch + 1);
var from = cm.findPosH(pos, -2, "char");
var range = cm.getRange(from, pos);
if (range.length != 2) return;
cm.setSelection(from, pos);
cm.replaceSelection(range.charAt(1) + range.charAt(0), null, "+transpose");
cm.execCommand("transposeChars");
}),
"Alt-C": repeated(function(cm) {

View File

@ -1,3 +1,6 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
// A rough approximation of Sublime Text's keybindings
// Depends on addon/search/searchcursor.js and optionally addon/dialog/dialogs.js
@ -52,10 +55,22 @@
cmds[map["Alt-Right"] = "goSubwordRight"] = function(cm) { moveSubword(cm, 1); };
cmds[map[ctrl + "Up"] = "scrollLineUp"] = function(cm) {
cm.scrollTo(null, cm.getScrollInfo().top - cm.defaultTextHeight());
var info = cm.getScrollInfo();
if (!cm.somethingSelected()) {
var visibleBottomLine = cm.lineAtHeight(info.top + info.clientHeight, "local");
if (cm.getCursor().line >= visibleBottomLine)
cm.execCommand("goLineUp");
}
cm.scrollTo(null, info.top - cm.defaultTextHeight());
};
cmds[map[ctrl + "Down"] = "scrollLineDown"] = function(cm) {
cm.scrollTo(null, cm.getScrollInfo().top + cm.defaultTextHeight());
var info = cm.getScrollInfo();
if (!cm.somethingSelected()) {
var visibleTopLine = cm.lineAtHeight(info.top, "local")+1;
if (cm.getCursor().line <= visibleTopLine)
cm.execCommand("goLineDown");
}
cm.scrollTo(null, info.top + cm.defaultTextHeight());
};
cmds[map["Shift-" + ctrl + "L"] = "splitSelectionByLine"] = function(cm) {
@ -172,9 +187,12 @@
};
cmds[map["Shift-" + ctrl + "Up"] = "swapLineUp"] = function(cm) {
var ranges = cm.listSelections(), linesToMove = [], at = cm.firstLine() - 1;
var ranges = cm.listSelections(), linesToMove = [], at = cm.firstLine() - 1, newSels = [];
for (var i = 0; i < ranges.length; i++) {
var range = ranges[i], from = range.from().line - 1, to = range.to().line;
newSels.push({anchor: Pos(range.anchor.line - 1, range.anchor.ch),
head: Pos(range.head.line - 1, range.head.ch)});
if (range.to().ch == 0 && !range.empty()) --to;
if (from > at) linesToMove.push(from, to);
else if (linesToMove.length) linesToMove[linesToMove.length - 1] = to;
at = to;
@ -184,16 +202,12 @@
var from = linesToMove[i], to = linesToMove[i + 1];
var line = cm.getLine(from);
cm.replaceRange("", Pos(from, 0), Pos(from + 1, 0), "+swapLine");
if (to > cm.lastLine()) {
if (to > cm.lastLine())
cm.replaceRange("\n" + line, Pos(cm.lastLine()), null, "+swapLine");
var sels = cm.listSelections(), last = sels[sels.length - 1];
var head = last.head.line == to ? Pos(to - 1) : last.head;
var anchor = last.anchor.line == to ? Pos(to - 1) : last.anchor;
cm.setSelections(sels.slice(0, sels.length - 1).concat([{head: head, anchor: anchor}]));
} else {
else
cm.replaceRange(line + "\n", Pos(to, 0), null, "+swapLine");
}
}
cm.setSelections(newSels);
cm.scrollIntoView();
});
};
@ -202,6 +216,7 @@
var ranges = cm.listSelections(), linesToMove = [], at = cm.lastLine() + 1;
for (var i = ranges.length - 1; i >= 0; i--) {
var range = ranges[i], from = range.to().line + 1, to = range.from().line;
if (range.to().ch == 0 && !range.empty()) from--;
if (from < at) linesToMove.push(from, to);
else if (linesToMove.length) linesToMove[linesToMove.length - 1] = to;
at = to;

View File

@ -1,3 +1,6 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
/**
* Supported keybindings:
*
@ -58,9 +61,9 @@
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../lib/codemirror"), require("../addon/search/searchcursor"), require("../addon/dialog/dialog"));
mod(require("../lib/codemirror"), require("../addon/search/searchcursor"), require("../addon/dialog/dialog"), require("../addon/edit/matchbrackets.js"));
else if (typeof define == "function" && define.amd) // AMD
define(["../lib/codemirror", "../addon/search/searchcursor", "../addon/dialog/dialog"], mod);
define(["../lib/codemirror", "../addon/search/searchcursor", "../addon/dialog/dialog", "../addon/edit/matchbrackets"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
@ -201,13 +204,18 @@
{ keys: [','], type: 'motion', motion: 'repeatLastCharacterSearch',
motionArgs: { forward: false }},
{ keys: ['\'', 'character'], type: 'motion', motion: 'goToMark',
motionArgs: {toJumplist: true}},
motionArgs: {toJumplist: true, linewise: true}},
{ keys: ['`', 'character'], type: 'motion', motion: 'goToMark',
motionArgs: {toJumplist: true}},
{ keys: [']', '`'], type: 'motion', motion: 'jumpToMark', motionArgs: { forward: true } },
{ keys: ['[', '`'], type: 'motion', motion: 'jumpToMark', motionArgs: { forward: false } },
{ keys: [']', '\''], type: 'motion', motion: 'jumpToMark', motionArgs: { forward: true, linewise: true } },
{ keys: ['[', '\''], type: 'motion', motion: 'jumpToMark', motionArgs: { forward: false, linewise: true } },
// the next two aren't motions but must come before more general motion declarations
{ keys: [']', 'p'], type: 'action', action: 'paste', isEdit: true,
actionArgs: { after: true, isEdit: true, matchIndent: true}},
{ keys: ['[', 'p'], type: 'action', action: 'paste', isEdit: true,
actionArgs: { after: false, isEdit: true, matchIndent: true}},
{ keys: [']', 'character'], type: 'motion',
motion: 'moveToSymbol',
motionArgs: { forward: true, toJumplist: true}},
@ -266,6 +274,7 @@
actionArgs: { insertAt: 'charAfter' }},
{ keys: ['A'], type: 'action', action: 'enterInsertMode', isEdit: true,
actionArgs: { insertAt: 'eol' }},
{ keys: ['A'], type: 'action', action: 'enterInsertMode', isEdit: true, actionArgs: { insertAt: 'endOfSelectedArea' }, context: 'visual' },
{ keys: ['i'], type: 'action', action: 'enterInsertMode', isEdit: true,
actionArgs: { insertAt: 'inplace' }},
{ keys: ['I'], type: 'action', action: 'enterInsertMode', isEdit: true,
@ -292,6 +301,8 @@
{ keys: ['R'], type: 'action', action: 'enterInsertMode', isEdit: true,
actionArgs: { replace: true }},
{ keys: ['u'], type: 'action', action: 'undo' },
{ keys: ['u'], type: 'action', action: 'changeCase', actionArgs: {toLower: true}, context: 'visual', isEdit: true },
{ keys: ['U'],type: 'action', action: 'changeCase', actionArgs: {toLower: false}, context: 'visual', isEdit: true },
{ keys: ['<C-r>'], type: 'action', action: 'redo' },
{ keys: ['m', 'character'], type: 'action', action: 'setMark' },
{ keys: ['"', 'character'], type: 'action', action: 'setRegister' },
@ -329,9 +340,11 @@
{ keys: ['?'], type: 'search',
searchArgs: { forward: false, querySrc: 'prompt', toJumplist: true }},
{ keys: ['*'], type: 'search',
searchArgs: { forward: true, querySrc: 'wordUnderCursor', toJumplist: true }},
searchArgs: { forward: true, querySrc: 'wordUnderCursor', wholeWordOnly: true, toJumplist: true }},
{ keys: ['#'], type: 'search',
searchArgs: { forward: false, querySrc: 'wordUnderCursor', toJumplist: true }},
searchArgs: { forward: false, querySrc: 'wordUnderCursor', wholeWordOnly: true, toJumplist: true }},
{ keys: ['g', '*'], type: 'search', searchArgs: { forward: true, querySrc: 'wordUnderCursor', toJumplist: true }},
{ keys: ['g', '#'], type: 'search', searchArgs: { forward: false, querySrc: 'wordUnderCursor', toJumplist: true }},
// Ex command
{ keys: [':'], type: 'ex' }
];
@ -345,12 +358,14 @@
cm.setOption('disableInput', true);
CodeMirror.signal(cm, "vim-mode-change", {mode: "normal"});
cm.on('beforeSelectionChange', beforeSelectionChange);
cm.on('cursorActivity', onCursorActivity);
maybeInitVimState(cm);
CodeMirror.on(cm.getInputField(), 'paste', getOnPasteFn(cm));
} else if (cm.state.vim) {
cm.setOption('keyMap', 'default');
cm.setOption('disableInput', false);
cm.off('beforeSelectionChange', beforeSelectionChange);
cm.off('cursorActivity', onCursorActivity);
CodeMirror.off(cm.getInputField(), 'paste', getOnPasteFn(cm));
cm.state.vim = null;
}
@ -396,7 +411,7 @@
var specialKeys = ['Left', 'Right', 'Up', 'Down', 'Space', 'Backspace',
'Esc', 'Home', 'End', 'PageUp', 'PageDown', 'Enter'];
var validMarks = [].concat(upperCaseAlphabet, lowerCaseAlphabet, numbers, ['<', '>']);
var validRegisters = [].concat(upperCaseAlphabet, lowerCaseAlphabet, numbers, ['-', '"']);
var validRegisters = [].concat(upperCaseAlphabet, lowerCaseAlphabet, numbers, ['-', '"', '.', ':']);
function isLine(cm, line) {
return line >= cm.firstLine() && line <= cm.lastLine();
@ -549,6 +564,7 @@
this.latestRegister = undefined;
this.isPlaying = false;
this.isRecording = false;
this.replaySearchQueries = [];
this.onRecordingDone = undefined;
this.lastInsertModeChanges = createInsertModeChanges();
}
@ -614,6 +630,8 @@
searchQuery: null,
// Whether we are searching backwards.
searchIsReversed: false,
// Replace part of the last substituted pattern
lastSubstituteReplacePart: undefined,
jumpList: createCircularJumpList(),
macroModeState: new MacroModeState,
// Recording latest f, t, F or T motion command.
@ -670,13 +688,13 @@
if (macroModeState.isRecording) {
if (key == 'q') {
macroModeState.exitMacroRecordMode();
vim.inputState = new InputState();
clearInputState(cm);
return;
}
}
if (key == '<Esc>') {
// Clear input state and get back to normal mode.
vim.inputState = new InputState();
clearInputState(cm);
if (vim.visualMode) {
exitVisualMode(cm);
}
@ -754,6 +772,11 @@
return repeat;
};
function clearInputState(cm, reason) {
cm.state.vim.inputState = new InputState();
CodeMirror.signal(cm, 'vim-command-done', reason);
}
/*
* Register stores information about copy and paste registers. Besides
* text, a register must store whether it is linewise (i.e., when it is
@ -764,6 +787,7 @@
this.clear();
this.keyBuffer = [text || ''];
this.insertModeChanges = [];
this.searchQueries = [];
this.linewise = !!linewise;
}
Register.prototype = {
@ -773,8 +797,10 @@
},
pushText: function(text, linewise) {
// if this register has ever been set to linewise, use linewise.
if (linewise || this.linewise) {
this.keyBuffer.push('\n');
if (linewise) {
if (!this.linewise) {
this.keyBuffer.push('\n');
}
this.linewise = true;
}
this.keyBuffer.push(text);
@ -782,9 +808,13 @@
pushInsertModeChanges: function(changes) {
this.insertModeChanges.push(createInsertModeChanges(changes));
},
pushSearchQuery: function(query) {
this.searchQueries.push(query);
},
clear: function() {
this.keyBuffer = [];
this.insertModeChanges = [];
this.searchQueries = [];
this.linewise = false;
},
toString: function() {
@ -803,6 +833,8 @@
function RegisterController(registers) {
this.registers = registers;
this.unnamedRegister = registers['"'] = new Register();
registers['.'] = new Register();
registers[':'] = new Register();
}
RegisterController.prototype = {
pushText: function(registerName, operator, text, linewise) {
@ -845,14 +877,13 @@
// If we've gotten to this point, we've actually specified a register
var append = isUpperCase(registerName);
if (append) {
register.append(text, linewise);
// The unnamed register always has the same value as the last used
// register.
this.unnamedRegister.append(text, linewise);
register.pushText(text, linewise);
} else {
register.setText(text, linewise);
this.unnamedRegister.setText(text, linewise);
}
// The unnamed register always has the same value as the last used
// register.
this.unnamedRegister.setText(register.toString(), linewise);
},
// Gets the register named @name. If one of @name doesn't already exist,
// create it. If @name is invalid, return the unnamedRegister.
@ -998,7 +1029,7 @@
return;
} else {
// 2 different operators in a row doesn't make sense.
vim.inputState = new InputState();
clearInputState(cm);
}
}
inputState.operator = command.operator;
@ -1043,7 +1074,7 @@
actionArgs.repeat = repeat || 1;
actionArgs.repeatIsExplicit = repeatIsExplicit;
actionArgs.registerName = inputState.registerName;
vim.inputState = new InputState();
clearInputState(cm);
vim.lastMotion = null;
if (command.isEdit) {
this.recordLastEdit(vim, inputState, command);
@ -1056,6 +1087,7 @@
return;
}
var forward = command.searchArgs.forward;
var wholeWordOnly = command.searchArgs.wholeWordOnly;
getSearchState(cm).setReversed(!forward);
var promptPrefix = (forward) ? '/' : '?';
var originalQuery = getSearchState(cm).getQuery();
@ -1076,6 +1108,10 @@
function onPromptClose(query) {
cm.scrollTo(originalScrollPos.left, originalScrollPos.top);
handleQuery(query, true /** ignoreCase */, true /** smartCase */);
var macroModeState = vimGlobalState.macroModeState;
if (macroModeState.isRecording) {
logSearchQuery(macroModeState, query);
}
}
function onPromptKeyUp(_e, query) {
var parsedQuery;
@ -1106,13 +1142,19 @@
}
switch (command.searchArgs.querySrc) {
case 'prompt':
showPrompt(cm, {
onClose: onPromptClose,
prefix: promptPrefix,
desc: searchPromptDesc,
onKeyUp: onPromptKeyUp,
onKeyDown: onPromptKeyDown
});
var macroModeState = vimGlobalState.macroModeState;
if (macroModeState.isPlaying) {
var query = macroModeState.replaySearchQueries.shift();
handleQuery(query, true /** ignoreCase */, false /** smartCase */);
} else {
showPrompt(cm, {
onClose: onPromptClose,
prefix: promptPrefix,
desc: searchPromptDesc,
onKeyUp: onPromptKeyUp,
onKeyDown: onPromptKeyDown
});
}
break;
case 'wordUnderCursor':
var word = expandWordUnderCursor(cm, false /** inclusive */,
@ -1130,8 +1172,8 @@
}
var query = cm.getLine(word.start.line).substring(word.start.ch,
word.end.ch);
if (isKeyword) {
query = '\\b' + query + '\\b';
if (isKeyword && wholeWordOnly) {
query = '\\b' + query + '\\b';
} else {
query = escapeRegex(query);
}
@ -1213,7 +1255,7 @@
inputState.selectedCharacter;
}
motionArgs.repeat = repeat;
vim.inputState = new InputState();
clearInputState(cm);
if (motion) {
var motionResult = motions[motion](cm, motionArgs, vim);
vim.lastMotion = motions[motion];
@ -1295,19 +1337,34 @@
motionArgs.inclusive = true;
}
// Swap start and end if motion was backward.
if (cursorIsBefore(curEnd, curStart)) {
if (curEnd && cursorIsBefore(curEnd, curStart)) {
var tmp = curStart;
curStart = curEnd;
curEnd = tmp;
inverted = true;
} else if (!curEnd) {
curEnd = copyCursor(curStart);
}
if (motionArgs.inclusive && !(vim.visualMode && inverted)) {
// Move the selection end one to the right to include the last
// character.
curEnd.ch++;
}
if (operatorArgs.selOffset) {
// Replaying a visual mode operation
curEnd.line = curStart.line + operatorArgs.selOffset.line;
if (operatorArgs.selOffset.line) {curEnd.ch = operatorArgs.selOffset.ch; }
else { curEnd.ch = curStart.ch + operatorArgs.selOffset.ch; }
} else if (vim.visualMode) {
var selOffset = Pos();
selOffset.line = curEnd.line - curStart.line;
if (selOffset.line) { selOffset.ch = curEnd.ch; }
else { selOffset.ch = curEnd.ch - curStart.ch; }
operatorArgs.selOffset = selOffset;
}
var linewise = motionArgs.linewise ||
(vim.visualMode && vim.visualLine);
(vim.visualMode && vim.visualLine) ||
operatorArgs.linewise;
if (linewise) {
// Expand selection to entire line.
expandSelectionToLine(cm, curStart, curEnd);
@ -1372,10 +1429,11 @@
highlightSearchMatches(cm, query);
return findNext(cm, prev/** prev */, query, motionArgs.repeat);
},
goToMark: function(_cm, motionArgs, vim) {
goToMark: function(cm, motionArgs, vim) {
var mark = vim.marks[motionArgs.selectedCharacter];
if (mark) {
return mark.find();
var pos = mark.find();
return motionArgs.linewise ? { line: pos.line, ch: findFirstNonWhiteSpaceCharacter(cm.getLine(pos.line)) } : pos;
}
return null;
},
@ -1503,10 +1561,7 @@
// will move the cursor to where it should be in the end.
var curStart = cm.getCursor();
var repeat = motionArgs.repeat;
cm.moveV((motionArgs.forward ? repeat : -repeat), 'page');
var curEnd = cm.getCursor();
cm.setCursor(curStart);
return curEnd;
return cm.findPosV(curStart, (motionArgs.forward ? repeat : -repeat), 'page');
},
moveByParagraph: function(cm, motionArgs) {
var line = cm.getCursor().line;
@ -1595,20 +1650,18 @@
var ch = cursor.ch;
var lineText = cm.getLine(line);
var symbol;
var startContext = cm.getTokenAt(cursor).type;
var startCtxLevel = getContextLevel(startContext);
do {
symbol = lineText.charAt(ch++);
if (symbol && isMatchableSymbol(symbol)) {
var endContext = cm.getTokenAt(Pos(line, ch)).type;
var endCtxLevel = getContextLevel(endContext);
if (startCtxLevel >= endCtxLevel) {
var style = cm.getTokenTypeAt(Pos(line, ch));
if (style !== "string" && style !== "comment") {
break;
}
}
} while (symbol);
if (symbol) {
return findMatchedSymbol(cm, Pos(line, ch-1), symbol);
var matched = cm.findMatchingBracket(Pos(line, ch));
return matched.to;
} else {
return cursor;
}
@ -1637,6 +1690,13 @@
var selfPaired = {'\'': true, '"': true};
var character = motionArgs.selectedCharacter;
// 'b' refers to '()' block.
// 'B' refers to '{}' block.
if (character == 'b') {
character = '(';
} else if (character == 'B') {
character = '{';
}
// Inclusive is the difference between a and i
// TODO: Instead of using the additional text object map to perform text
@ -1647,7 +1707,7 @@
var tmp;
if (mirroredPairs[character]) {
tmp = selectCompanionObject(cm, mirroredPairs[character], inclusive);
tmp = selectCompanionObject(cm, character, inclusive);
} else if (selfPaired[character]) {
tmp = findBeginningAndEnd(cm, character, inclusive);
} else if (character === 'W') {
@ -1863,6 +1923,12 @@
cm.setCursor(offsetCursor(cm.getCursor(), 0, 1));
} else if (insertAt == 'firstNonBlank') {
cm.setCursor(motions.moveToFirstNonWhiteSpaceCharacter(cm));
} else if (insertAt == 'endOfSelectedArea') {
var selectionEnd = cm.getCursor('head');
var selectionStart = cm.getCursor('anchor');
selectionEnd = cursorIsBefore(selectionStart, selectionEnd) ? Pos(selectionEnd.line, selectionEnd.ch+1) : (selectionEnd.line < selectionStart.line ? Pos(selectionStart.line, 0) : selectionEnd);
cm.setCursor(selectionEnd);
exitVisualMode(cm);
}
cm.setOption('keyMap', 'vim-insert');
cm.setOption('disableInput', false);
@ -1878,7 +1944,6 @@
if (!vimGlobalState.macroModeState.isPlaying) {
// Only record if not replaying.
cm.on('change', onChange);
cm.on('cursorActivity', onCursorActivity);
CodeMirror.on(cm.getInputField(), 'keydown', onKeyEventTargetKeyDown);
}
},
@ -2001,7 +2066,7 @@
}
this.enterInsertMode(cm, { repeat: actionArgs.repeat }, vim);
},
paste: function(cm, actionArgs) {
paste: function(cm, actionArgs, vim) {
var cur = copyCursor(cm.getCursor());
var register = vimGlobalState.registerController.getRegister(
actionArgs.registerName);
@ -2009,12 +2074,42 @@
if (!text) {
return;
}
if (actionArgs.matchIndent) {
// length that considers tabs and cm.options.tabSize
var whitespaceLength = function(str) {
var tabs = (str.split("\t").length - 1);
var spaces = (str.split(" ").length - 1);
return tabs * cm.options.tabSize + spaces * 1;
};
var currentLine = cm.getLine(cm.getCursor().line);
var indent = whitespaceLength(currentLine.match(/^\s*/)[0]);
// chomp last newline b/c don't want it to match /^\s*/gm
var chompedText = text.replace(/\n$/, '');
var wasChomped = text !== chompedText;
var firstIndent = whitespaceLength(text.match(/^\s*/)[0]);
var text = chompedText.replace(/^\s*/gm, function(wspace) {
var newIndent = indent + (whitespaceLength(wspace) - firstIndent);
if (newIndent < 0) {
return "";
}
else if (cm.options.indentWithTabs) {
var quotient = Math.floor(newIndent / cm.options.tabSize);
return Array(quotient + 1).join('\t');
}
else {
return Array(newIndent + 1).join(' ');
}
});
text += wasChomped ? "\n" : "";
}
if (actionArgs.repeat > 1) {
var text = Array(actionArgs.repeat + 1).join(text);
}
var linewise = register.linewise;
if (linewise) {
if (actionArgs.after) {
if(vim.visualMode) {
text = vim.visualLine ? text.slice(0, -1) : '\n' + text.slice(0, text.length - 1) + '\n';
} else if (actionArgs.after) {
// Move the newline at the end to the start instead, and paste just
// before the newline character of the line we are on right now.
text = '\n' + text.slice(0, text.length - 1);
@ -2025,24 +2120,35 @@
} else {
cur.ch += actionArgs.after ? 1 : 0;
}
cm.replaceRange(text, cur);
// Now fine tune the cursor to where we want it.
var curPosFinal;
var idx;
if (linewise && actionArgs.after) {
curPosFinal = Pos(
cur.line + 1,
findFirstNonWhiteSpaceCharacter(cm.getLine(cur.line + 1)));
} else if (linewise && !actionArgs.after) {
curPosFinal = Pos(
cur.line,
findFirstNonWhiteSpaceCharacter(cm.getLine(cur.line)));
} else if (!linewise && actionArgs.after) {
idx = cm.indexFromPos(cur);
curPosFinal = cm.posFromIndex(idx + text.length - 1);
if (vim.visualMode) {
var selectedArea = getSelectedAreaRange(cm, vim);
var selectionStart = selectedArea[0];
var selectionEnd = selectedArea[1];
// push the previously selected text to unnamed register
vimGlobalState.registerController.unnamedRegister.setText(cm.getRange(selectionStart, selectionEnd));
cm.replaceRange(text, selectionStart, selectionEnd);
curPosFinal = cm.posFromIndex(cm.indexFromPos(selectionStart) + text.length - 1);
if(linewise)curPosFinal.ch=0;
} else {
idx = cm.indexFromPos(cur);
curPosFinal = cm.posFromIndex(idx + text.length);
cm.replaceRange(text, cur);
// Now fine tune the cursor to where we want it.
if (linewise && actionArgs.after) {
curPosFinal = Pos(
cur.line + 1,
findFirstNonWhiteSpaceCharacter(cm.getLine(cur.line + 1)));
} else if (linewise && !actionArgs.after) {
curPosFinal = Pos(
cur.line,
findFirstNonWhiteSpaceCharacter(cm.getLine(cur.line)));
} else if (!linewise && actionArgs.after) {
idx = cm.indexFromPos(cur);
curPosFinal = cm.posFromIndex(idx + text.length - 1);
} else {
idx = cm.indexFromPos(cur);
curPosFinal = cm.posFromIndex(idx + text.length);
}
}
cm.setCursor(curPosFinal);
},
@ -2136,6 +2242,15 @@
repeat = vim.lastEditInputState.repeatOverride || repeat;
}
repeatLastEdit(cm, vim, repeat, false /** repeatForInsert */);
},
changeCase: function(cm, actionArgs, vim) {
var selectedAreaRange = getSelectedAreaRange(cm, vim);
var selectionStart = selectedAreaRange[0];
var selectionEnd = selectedAreaRange[1];
var toLower = actionArgs.toLower;
var text = cm.getRange(selectionStart, selectionEnd);
cm.replaceRange(toLower ? text.toLowerCase() : text.toUpperCase(), selectionStart, selectionEnd);
cm.setCursor(selectionStart);
}
};
@ -2218,6 +2333,29 @@
function escapeRegex(s) {
return s.replace(/([.?*+$\[\]\/\\(){}|\-])/g, '\\$1');
}
function getSelectedAreaRange(cm, vim) {
var selectionStart = cm.getCursor('anchor');
var selectionEnd = cm.getCursor('head');
var lastSelection = vim.lastSelection;
if (!vim.visualMode) {
var line = lastSelection.curEnd.line - lastSelection.curStart.line;
var ch = line ? lastSelection.curEnd.ch : lastSelection.curEnd.ch - lastSelection.curStart.ch;
selectionEnd = {line: selectionEnd.line + line, ch: line ? selectionEnd.ch : ch + selectionEnd.ch};
if (lastSelection.visualLine) {
return [{line: selectionStart.line, ch: 0}, {line: selectionEnd.line, ch: lineLength(cm, selectionEnd.line)}];
}
} else {
if (cursorIsBefore(selectionEnd, selectionStart)) {
var tmp = selectionStart;
selectionStart = selectionEnd;
selectionEnd = tmp;
} else {
selectionEnd = cm.clipPos(Pos(selectionEnd.line, selectionEnd.ch+1));
}
exitVisualMode(cm);
}
return [selectionStart, selectionEnd];
}
function exitVisualMode(cm) {
cm.off('mousedown', exitVisualMode);
@ -2670,74 +2808,33 @@
return idx;
}
function getContextLevel(ctx) {
return (ctx === 'string' || ctx === 'comment') ? 1 : 0;
}
function findMatchedSymbol(cm, cur, symb) {
var line = cur.line;
var ch = cur.ch;
symb = symb ? symb : cm.getLine(line).charAt(ch);
var symbContext = cm.getTokenAt(Pos(line, ch + 1)).type;
var symbCtxLevel = getContextLevel(symbContext);
var reverseSymb = ({
'(': ')', ')': '(',
'[': ']', ']': '[',
'{': '}', '}': '{'})[symb];
// Couldn't find a matching symbol, abort
if (!reverseSymb) {
return cur;
}
// set our increment to move forward (+1) or backwards (-1)
// depending on which bracket we're matching
var increment = ({'(': 1, '{': 1, '[': 1})[symb] || -1;
var endLine = increment === 1 ? cm.lineCount() : -1;
var depth = 1, nextCh = symb, index = ch, lineText = cm.getLine(line);
// Simple search for closing paren--just count openings and closings till
// we find our match
// TODO: use info from CodeMirror to ignore closing brackets in comments
// and quotes, etc.
while (line !== endLine && depth > 0) {
index += increment;
nextCh = lineText.charAt(index);
if (!nextCh) {
line += increment;
lineText = cm.getLine(line) || '';
if (increment > 0) {
index = 0;
} else {
var lineLen = lineText.length;
index = (lineLen > 0) ? (lineLen-1) : 0;
}
nextCh = lineText.charAt(index);
}
var revSymbContext = cm.getTokenAt(Pos(line, index + 1)).type;
var revSymbCtxLevel = getContextLevel(revSymbContext);
if (symbCtxLevel >= revSymbCtxLevel) {
if (nextCh === symb) {
depth++;
} else if (nextCh === reverseSymb) {
depth--;
}
}
}
if (nextCh) {
return Pos(line, index);
}
return cur;
}
// TODO: perhaps this finagling of start and end positions belonds
// in codmirror/replaceRange?
function selectCompanionObject(cm, revSymb, inclusive) {
var cur = copyCursor(cm.getCursor());
var end = findMatchedSymbol(cm, cur, revSymb);
var start = findMatchedSymbol(cm, end);
function selectCompanionObject(cm, symb, inclusive) {
var cur = cm.getCursor(), start, end;
var bracketRegexp = ({
'(': /[()]/, ')': /[()]/,
'[': /[[\]]/, ']': /[[\]]/,
'{': /[{}]/, '}': /[{}]/})[symb];
var openSym = ({
'(': '(', ')': '(',
'[': '[', ']': '[',
'{': '{', '}': '{'})[symb];
var curChar = cm.getLine(cur.line).charAt(cur.ch);
// Due to the behavior of scanForBracket, we need to add an offset if the
// cursor is on a matching open bracket.
var offset = curChar === openSym ? 1 : 0;
start = cm.scanForBracket(Pos(cur.line, cur.ch + offset), -1, null, {'bracketRegex': bracketRegexp});
end = cm.scanForBracket(Pos(cur.line, cur.ch + offset), 1, null, {'bracketRegex': bracketRegexp});
if (!start || !end) {
return { start: cur, end: cur };
}
start = start.pos;
end = end.pos;
if ((start.line == end.line && start.ch > end.ch)
|| (start.line > end.line)) {
@ -2869,15 +2966,15 @@
// Translates a search string from ex (vim) syntax into javascript form.
function translateRegex(str) {
// When these match, add a '\' if unescaped or remove one if escaped.
var specials = ['|', '(', ')', '{'];
var specials = '|(){';
// Remove, but never add, a '\' for these.
var unescape = ['}'];
var unescape = '}';
var escapeNextChar = false;
var out = [];
for (var i = -1; i < str.length; i++) {
var c = str.charAt(i) || '';
var n = str.charAt(i+1) || '';
var specialComesNext = (specials.indexOf(n) != -1);
var specialComesNext = (n && specials.indexOf(n) != -1);
if (escapeNextChar) {
if (c !== '\\' || !specialComesNext) {
out.push(c);
@ -2887,7 +2984,7 @@
if (c === '\\') {
escapeNextChar = true;
// Treat the unescape list as special for removing, but not adding '\'.
if (unescape.indexOf(n) != -1) {
if (n && unescape.indexOf(n) != -1) {
specialComesNext = true;
}
// Not passing this test means removing a '\'.
@ -3188,7 +3285,7 @@
{ name: 'substitute', shortName: 's' },
{ name: 'nohlsearch', shortName: 'noh' },
{ name: 'delmarks', shortName: 'delm' },
{ name: 'registers', shortName: 'reg' }
{ name: 'registers', shortName: 'reg', excludeFromCommandHistory: true }
];
Vim.ExCommandDispatcher = function() {
this.buildCommandMap_();
@ -3196,10 +3293,14 @@
Vim.ExCommandDispatcher.prototype = {
processCommand: function(cm, input) {
var vim = cm.state.vim;
var commandHistoryRegister = vimGlobalState.registerController.getRegister(':');
var previousCommand = commandHistoryRegister.toString();
if (vim.visualMode) {
exitVisualMode(cm);
}
var inputStream = new CodeMirror.StringStream(input);
// update ": with the latest command whether valid or invalid
commandHistoryRegister.setText(input);
var params = {};
params.input = input;
try {
@ -3218,6 +3319,9 @@
var command = this.matchCommand_(params.commandName);
if (command) {
commandName = command.name;
if (command.excludeFromCommandHistory) {
commandHistoryRegister.setText(previousCommand);
}
this.parseCommandArgs_(inputStream, params, command);
if (command.type == 'exToKey') {
// Handle Ex to Key mapping.
@ -3509,7 +3613,7 @@
continue;
}
var register = registers[registerName] || new Register();
regInfo += '"' + registerName + ' ' + register.text + '<br>';
regInfo += '"' + registerName + ' ' + register.toString() + '<br>';
}
}
showConfirm(cm, regInfo);
@ -3595,38 +3699,41 @@
'any other getSearchCursor implementation.');
}
var argString = params.argString;
var slashes = findUnescapedSlashes(argString);
if (slashes[0] !== 0) {
showConfirm(cm, 'Substitutions should be of the form ' +
':s/pattern/replace/');
return;
}
var regexPart = argString.substring(slashes[0] + 1, slashes[1]);
var slashes = argString ? findUnescapedSlashes(argString) : [];
var replacePart = '';
var flagsPart;
var count;
var confirm = false; // Whether to confirm each replace.
if (slashes[1]) {
replacePart = argString.substring(slashes[1] + 1, slashes[2]);
if (getOption('pcre')) {
replacePart = unescapeRegexReplace(replacePart);
} else {
replacePart = translateRegexReplace(replacePart);
if (slashes.length) {
if (slashes[0] !== 0) {
showConfirm(cm, 'Substitutions should be of the form ' +
':s/pattern/replace/');
return;
}
}
if (slashes[2]) {
// After the 3rd slash, we can have flags followed by a space followed
// by count.
var trailing = argString.substring(slashes[2] + 1).split(' ');
flagsPart = trailing[0];
count = parseInt(trailing[1]);
}
if (flagsPart) {
if (flagsPart.indexOf('c') != -1) {
confirm = true;
flagsPart.replace('c', '');
var regexPart = argString.substring(slashes[0] + 1, slashes[1]);
var flagsPart;
var count;
var confirm = false; // Whether to confirm each replace.
if (slashes[1]) {
replacePart = argString.substring(slashes[1] + 1, slashes[2]);
if (getOption('pcre')) {
replacePart = unescapeRegexReplace(replacePart);
} else {
replacePart = translateRegexReplace(replacePart);
}
vimGlobalState.lastSubstituteReplacePart = replacePart;
}
if (slashes[2]) {
// After the 3rd slash, we can have flags followed by a space followed
// by count.
var trailing = argString.substring(slashes[2] + 1).split(' ');
flagsPart = trailing[0];
count = parseInt(trailing[1]);
}
if (flagsPart) {
if (flagsPart.indexOf('c') != -1) {
confirm = true;
flagsPart.replace('c', '');
}
regexPart = regexPart + '/' + flagsPart;
}
regexPart = regexPart + '/' + flagsPart;
}
if (regexPart) {
// If regex part is empty, then use the previous query. Otherwise use
@ -3639,6 +3746,11 @@
return;
}
}
replacePart = replacePart || vimGlobalState.lastSubstituteReplacePart;
if (replacePart === undefined) {
showConfirm(cm, 'No previous substitute regular expression');
return;
}
var state = getSearchState(cm);
var query = state.getQuery();
var lineStart = (params.line !== undefined) ? params.line : cm.getCursor().line;
@ -3847,6 +3959,7 @@
// Closure to bind CodeMirror, key, modifier.
function keyMapper(vimKey) {
return function(cm) {
CodeMirror.signal(cm, 'vim-keypress', vimKey);
CodeMirror.Vim.handleKey(cm, vimKey);
};
}
@ -3884,10 +3997,10 @@
function exitInsertMode(cm) {
var vim = cm.state.vim;
var macroModeState = vimGlobalState.macroModeState;
var insertModeChangeRegister = vimGlobalState.registerController.getRegister('.');
var isPlaying = macroModeState.isPlaying;
if (!isPlaying) {
cm.off('change', onChange);
cm.off('cursorActivity', onCursorActivity);
CodeMirror.off(cm.getInputField(), 'keydown', onKeyEventTargetKeyDown);
}
if (!isPlaying && vim.insertModeRepeat > 1) {
@ -3897,11 +4010,13 @@
vim.lastEditInputState.repeatOverride = vim.insertModeRepeat;
}
delete vim.insertModeRepeat;
cm.setCursor(cm.getCursor().line, cm.getCursor().ch-1);
vim.insertMode = false;
cm.setCursor(cm.getCursor().line, cm.getCursor().ch-1);
cm.setOption('keyMap', 'vim');
cm.setOption('disableInput', true);
cm.toggleOverwrite(false); // exit replace mode if we were in it.
// update the ". register before exiting insert mode
insertModeChangeRegister.setText(macroModeState.lastInsertModeChanges.changes.join(''));
CodeMirror.signal(cm, "vim-mode-change", {mode: "normal"});
if (macroModeState.isRecording) {
logInsertModeChange(macroModeState);
@ -3934,6 +4049,7 @@
var keyBuffer = register.keyBuffer;
var imc = 0;
macroModeState.isPlaying = true;
macroModeState.replaySearchQueries = register.searchQueries.slice(0);
for (var i = 0; i < keyBuffer.length; i++) {
var text = keyBuffer[i];
var match, key;
@ -3972,6 +4088,15 @@
}
}
function logSearchQuery(macroModeState, query) {
if (macroModeState.isPlaying) { return; }
var registerName = macroModeState.latestRegister;
var register = vimGlobalState.registerController.getRegister(registerName);
if (register) {
register.pushSearchQuery(query);
}
}
/**
* Listens for changes made in insert mode.
* Should only be active in insert mode.
@ -3995,18 +4120,23 @@
/**
* Listens for any kind of cursor activity on CodeMirror.
* - For tracking cursor activity in insert mode.
* - Should only be active in insert mode.
*/
function onCursorActivity() {
var macroModeState = vimGlobalState.macroModeState;
if (macroModeState.isPlaying) { return; }
var lastChange = macroModeState.lastInsertModeChanges;
if (lastChange.expectCursorActivityForChange) {
lastChange.expectCursorActivityForChange = false;
} else {
// Cursor moved outside the context of an edit. Reset the change.
lastChange.changes = [];
function onCursorActivity(cm) {
var vim = cm.state.vim;
if (vim.insertMode) {
// Tracking cursor activity in insert mode (for macro support).
var macroModeState = vimGlobalState.macroModeState;
if (macroModeState.isPlaying) { return; }
var lastChange = macroModeState.lastInsertModeChanges;
if (lastChange.expectCursorActivityForChange) {
lastChange.expectCursorActivityForChange = false;
} else {
// Cursor moved outside the context of an edit. Reset the change.
lastChange.changes = [];
}
} else if (cm.doc.history.lastSelOrigin == '*mouse') {
// Reset lastHPos if mouse click was done in normal mode.
vim.lastHPos = cm.doc.getCursor().ch;
}
}

View File

@ -1,3 +1,6 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
@ -173,7 +176,6 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
};
});
(function() {
function words(str) {
var obj = {}, words = str.split(" ");
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
@ -251,6 +253,7 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
}
function def(mimes, mode) {
if (typeof mimes == "string") mimes = [mimes];
var words = [];
function add(obj) {
if (obj) for (var prop in obj) if (obj.hasOwnProperty(prop))
@ -295,7 +298,7 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
},
modeProps: {fold: ["brace", "include"]}
});
CodeMirror.defineMIME("text/x-java", {
def("text/x-java", {
name: "clike",
keywords: words("abstract assert boolean break byte case catch char class const continue default " +
"do double else enum extends final finally float for goto if implements import " +
@ -312,7 +315,7 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
},
modeProps: {fold: ["brace", "import"]}
});
CodeMirror.defineMIME("text/x-csharp", {
def("text/x-csharp", {
name: "clike",
keywords: words("abstract as base break case catch checked class const continue" +
" default delegate do else enum event explicit extern finally fixed for" +
@ -338,7 +341,7 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
}
}
});
CodeMirror.defineMIME("text/x-scala", {
def("text/x-scala", {
name: "clike",
keywords: words(
@ -432,6 +435,5 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
hooks: {"#": cppHook},
modeProps: {fold: ["brace", "include"]}
});
}());
});

View File

@ -0,0 +1,717 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
CodeMirror.defineMode("css", function(config, parserConfig) {
if (!parserConfig.propertyKeywords) parserConfig = CodeMirror.resolveMode("text/css");
var indentUnit = config.indentUnit,
tokenHooks = parserConfig.tokenHooks,
mediaTypes = parserConfig.mediaTypes || {},
mediaFeatures = parserConfig.mediaFeatures || {},
propertyKeywords = parserConfig.propertyKeywords || {},
nonStandardPropertyKeywords = parserConfig.nonStandardPropertyKeywords || {},
colorKeywords = parserConfig.colorKeywords || {},
valueKeywords = parserConfig.valueKeywords || {},
fontProperties = parserConfig.fontProperties || {},
allowNested = parserConfig.allowNested;
var type, override;
function ret(style, tp) { type = tp; return style; }
// Tokenizers
function tokenBase(stream, state) {
var ch = stream.next();
if (tokenHooks[ch]) {
var result = tokenHooks[ch](stream, state);
if (result !== false) return result;
}
if (ch == "@") {
stream.eatWhile(/[\w\\\-]/);
return ret("def", stream.current());
} else if (ch == "=" || (ch == "~" || ch == "|") && stream.eat("=")) {
return ret(null, "compare");
} else if (ch == "\"" || ch == "'") {
state.tokenize = tokenString(ch);
return state.tokenize(stream, state);
} else if (ch == "#") {
stream.eatWhile(/[\w\\\-]/);
return ret("atom", "hash");
} else if (ch == "!") {
stream.match(/^\s*\w*/);
return ret("keyword", "important");
} else if (/\d/.test(ch) || ch == "." && stream.eat(/\d/)) {
stream.eatWhile(/[\w.%]/);
return ret("number", "unit");
} else if (ch === "-") {
if (/[\d.]/.test(stream.peek())) {
stream.eatWhile(/[\w.%]/);
return ret("number", "unit");
} else if (stream.match(/^\w+-/)) {
return ret("meta", "meta");
}
} else if (/[,+>*\/]/.test(ch)) {
return ret(null, "select-op");
} else if (ch == "." && stream.match(/^-?[_a-z][_a-z0-9-]*/i)) {
return ret("qualifier", "qualifier");
} else if (/[:;{}\[\]\(\)]/.test(ch)) {
return ret(null, ch);
} else if (ch == "u" && stream.match("rl(")) {
stream.backUp(1);
state.tokenize = tokenParenthesized;
return ret("property", "word");
} else if (/[\w\\\-]/.test(ch)) {
stream.eatWhile(/[\w\\\-]/);
return ret("property", "word");
} else {
return ret(null, null);
}
}
function tokenString(quote) {
return function(stream, state) {
var escaped = false, ch;
while ((ch = stream.next()) != null) {
if (ch == quote && !escaped) {
if (quote == ")") stream.backUp(1);
break;
}
escaped = !escaped && ch == "\\";
}
if (ch == quote || !escaped && quote != ")") state.tokenize = null;
return ret("string", "string");
};
}
function tokenParenthesized(stream, state) {
stream.next(); // Must be '('
if (!stream.match(/\s*[\"\')]/, false))
state.tokenize = tokenString(")");
else
state.tokenize = null;
return ret(null, "(");
}
// Context management
function Context(type, indent, prev) {
this.type = type;
this.indent = indent;
this.prev = prev;
}
function pushContext(state, stream, type) {
state.context = new Context(type, stream.indentation() + indentUnit, state.context);
return type;
}
function popContext(state) {
state.context = state.context.prev;
return state.context.type;
}
function pass(type, stream, state) {
return states[state.context.type](type, stream, state);
}
function popAndPass(type, stream, state, n) {
for (var i = n || 1; i > 0; i--)
state.context = state.context.prev;
return pass(type, stream, state);
}
// Parser
function wordAsValue(stream) {
var word = stream.current().toLowerCase();
if (valueKeywords.hasOwnProperty(word))
override = "atom";
else if (colorKeywords.hasOwnProperty(word))
override = "keyword";
else
override = "variable";
}
var states = {};
states.top = function(type, stream, state) {
if (type == "{") {
return pushContext(state, stream, "block");
} else if (type == "}" && state.context.prev) {
return popContext(state);
} else if (type == "@media") {
return pushContext(state, stream, "media");
} else if (type == "@font-face") {
return "font_face_before";
} else if (/^@(-(moz|ms|o|webkit)-)?keyframes$/.test(type)) {
return "keyframes";
} else if (type && type.charAt(0) == "@") {
return pushContext(state, stream, "at");
} else if (type == "hash") {
override = "builtin";
} else if (type == "word") {
override = "tag";
} else if (type == "variable-definition") {
return "maybeprop";
} else if (type == "interpolation") {
return pushContext(state, stream, "interpolation");
} else if (type == ":") {
return "pseudo";
} else if (allowNested && type == "(") {
return pushContext(state, stream, "parens");
}
return state.context.type;
};
states.block = function(type, stream, state) {
if (type == "word") {
var word = stream.current().toLowerCase();
if (propertyKeywords.hasOwnProperty(word)) {
override = "property";
return "maybeprop";
} else if (nonStandardPropertyKeywords.hasOwnProperty(word)) {
override = "string-2";
return "maybeprop";
} else if (allowNested) {
override = stream.match(/^\s*:/, false) ? "property" : "tag";
return "block";
} else {
override += " error";
return "maybeprop";
}
} else if (type == "meta") {
return "block";
} else if (!allowNested && (type == "hash" || type == "qualifier")) {
override = "error";
return "block";
} else {
return states.top(type, stream, state);
}
};
states.maybeprop = function(type, stream, state) {
if (type == ":") return pushContext(state, stream, "prop");
return pass(type, stream, state);
};
states.prop = function(type, stream, state) {
if (type == ";") return popContext(state);
if (type == "{" && allowNested) return pushContext(state, stream, "propBlock");
if (type == "}" || type == "{") return popAndPass(type, stream, state);
if (type == "(") return pushContext(state, stream, "parens");
if (type == "hash" && !/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(stream.current())) {
override += " error";
} else if (type == "word") {
wordAsValue(stream);
} else if (type == "interpolation") {
return pushContext(state, stream, "interpolation");
}
return "prop";
};
states.propBlock = function(type, _stream, state) {
if (type == "}") return popContext(state);
if (type == "word") { override = "property"; return "maybeprop"; }
return state.context.type;
};
states.parens = function(type, stream, state) {
if (type == "{" || type == "}") return popAndPass(type, stream, state);
if (type == ")") return popContext(state);
if (type == "(") return pushContext(state, stream, "parens");
if (type == "word") wordAsValue(stream);
return "parens";
};
states.pseudo = function(type, stream, state) {
if (type == "word") {
override = "variable-3";
return state.context.type;
}
return pass(type, stream, state);
};
states.media = function(type, stream, state) {
if (type == "(") return pushContext(state, stream, "media_parens");
if (type == "}") return popAndPass(type, stream, state);
if (type == "{") return popContext(state) && pushContext(state, stream, allowNested ? "block" : "top");
if (type == "word") {
var word = stream.current().toLowerCase();
if (word == "only" || word == "not" || word == "and")
override = "keyword";
else if (mediaTypes.hasOwnProperty(word))
override = "attribute";
else if (mediaFeatures.hasOwnProperty(word))
override = "property";
else
override = "error";
}
return state.context.type;
};
states.media_parens = function(type, stream, state) {
if (type == ")") return popContext(state);
if (type == "{" || type == "}") return popAndPass(type, stream, state, 2);
return states.media(type, stream, state);
};
states.font_face_before = function(type, stream, state) {
if (type == "{")
return pushContext(state, stream, "font_face");
return pass(type, stream, state);
};
states.font_face = function(type, stream, state) {
if (type == "}") return popContext(state);
if (type == "word") {
if (!fontProperties.hasOwnProperty(stream.current().toLowerCase()))
override = "error";
else
override = "property";
return "maybeprop";
}
return "font_face";
};
states.keyframes = function(type, stream, state) {
if (type == "word") { override = "variable"; return "keyframes"; }
if (type == "{") return pushContext(state, stream, "top");
return pass(type, stream, state);
};
states.at = function(type, stream, state) {
if (type == ";") return popContext(state);
if (type == "{" || type == "}") return popAndPass(type, stream, state);
if (type == "word") override = "tag";
else if (type == "hash") override = "builtin";
return "at";
};
states.interpolation = function(type, stream, state) {
if (type == "}") return popContext(state);
if (type == "{" || type == ";") return popAndPass(type, stream, state);
if (type != "variable") override = "error";
return "interpolation";
};
return {
startState: function(base) {
return {tokenize: null,
state: "top",
context: new Context("top", base || 0, null)};
},
token: function(stream, state) {
if (!state.tokenize && stream.eatSpace()) return null;
var style = (state.tokenize || tokenBase)(stream, state);
if (style && typeof style == "object") {
type = style[1];
style = style[0];
}
override = style;
state.state = states[state.state](type, stream, state);
return override;
},
indent: function(state, textAfter) {
var cx = state.context, ch = textAfter && textAfter.charAt(0);
var indent = cx.indent;
if (cx.type == "prop" && (ch == "}" || ch == ")")) cx = cx.prev;
if (cx.prev &&
(ch == "}" && (cx.type == "block" || cx.type == "top" || cx.type == "interpolation" || cx.type == "font_face") ||
ch == ")" && (cx.type == "parens" || cx.type == "media_parens") ||
ch == "{" && (cx.type == "at" || cx.type == "media"))) {
indent = cx.indent - indentUnit;
cx = cx.prev;
}
return indent;
},
electricChars: "}",
blockCommentStart: "/*",
blockCommentEnd: "*/",
fold: "brace"
};
});
function keySet(array) {
var keys = {};
for (var i = 0; i < array.length; ++i) {
keys[array[i]] = true;
}
return keys;
}
var mediaTypes_ = [
"all", "aural", "braille", "handheld", "print", "projection", "screen",
"tty", "tv", "embossed"
], mediaTypes = keySet(mediaTypes_);
var mediaFeatures_ = [
"width", "min-width", "max-width", "height", "min-height", "max-height",
"device-width", "min-device-width", "max-device-width", "device-height",
"min-device-height", "max-device-height", "aspect-ratio",
"min-aspect-ratio", "max-aspect-ratio", "device-aspect-ratio",
"min-device-aspect-ratio", "max-device-aspect-ratio", "color", "min-color",
"max-color", "color-index", "min-color-index", "max-color-index",
"monochrome", "min-monochrome", "max-monochrome", "resolution",
"min-resolution", "max-resolution", "scan", "grid"
], mediaFeatures = keySet(mediaFeatures_);
var propertyKeywords_ = [
"align-content", "align-items", "align-self", "alignment-adjust",
"alignment-baseline", "anchor-point", "animation", "animation-delay",
"animation-direction", "animation-duration", "animation-fill-mode",
"animation-iteration-count", "animation-name", "animation-play-state",
"animation-timing-function", "appearance", "azimuth", "backface-visibility",
"background", "background-attachment", "background-clip", "background-color",
"background-image", "background-origin", "background-position",
"background-repeat", "background-size", "baseline-shift", "binding",
"bleed", "bookmark-label", "bookmark-level", "bookmark-state",
"bookmark-target", "border", "border-bottom", "border-bottom-color",
"border-bottom-left-radius", "border-bottom-right-radius",
"border-bottom-style", "border-bottom-width", "border-collapse",
"border-color", "border-image", "border-image-outset",
"border-image-repeat", "border-image-slice", "border-image-source",
"border-image-width", "border-left", "border-left-color",
"border-left-style", "border-left-width", "border-radius", "border-right",
"border-right-color", "border-right-style", "border-right-width",
"border-spacing", "border-style", "border-top", "border-top-color",
"border-top-left-radius", "border-top-right-radius", "border-top-style",
"border-top-width", "border-width", "bottom", "box-decoration-break",
"box-shadow", "box-sizing", "break-after", "break-before", "break-inside",
"caption-side", "clear", "clip", "color", "color-profile", "column-count",
"column-fill", "column-gap", "column-rule", "column-rule-color",
"column-rule-style", "column-rule-width", "column-span", "column-width",
"columns", "content", "counter-increment", "counter-reset", "crop", "cue",
"cue-after", "cue-before", "cursor", "direction", "display",
"dominant-baseline", "drop-initial-after-adjust",
"drop-initial-after-align", "drop-initial-before-adjust",
"drop-initial-before-align", "drop-initial-size", "drop-initial-value",
"elevation", "empty-cells", "fit", "fit-position", "flex", "flex-basis",
"flex-direction", "flex-flow", "flex-grow", "flex-shrink", "flex-wrap",
"float", "float-offset", "flow-from", "flow-into", "font", "font-feature-settings",
"font-family", "font-kerning", "font-language-override", "font-size", "font-size-adjust",
"font-stretch", "font-style", "font-synthesis", "font-variant",
"font-variant-alternates", "font-variant-caps", "font-variant-east-asian",
"font-variant-ligatures", "font-variant-numeric", "font-variant-position",
"font-weight", "grid", "grid-area", "grid-auto-columns", "grid-auto-flow",
"grid-auto-position", "grid-auto-rows", "grid-column", "grid-column-end",
"grid-column-start", "grid-row", "grid-row-end", "grid-row-start",
"grid-template", "grid-template-areas", "grid-template-columns",
"grid-template-rows", "hanging-punctuation", "height", "hyphens",
"icon", "image-orientation", "image-rendering", "image-resolution",
"inline-box-align", "justify-content", "left", "letter-spacing",
"line-break", "line-height", "line-stacking", "line-stacking-ruby",
"line-stacking-shift", "line-stacking-strategy", "list-style",
"list-style-image", "list-style-position", "list-style-type", "margin",
"margin-bottom", "margin-left", "margin-right", "margin-top",
"marker-offset", "marks", "marquee-direction", "marquee-loop",
"marquee-play-count", "marquee-speed", "marquee-style", "max-height",
"max-width", "min-height", "min-width", "move-to", "nav-down", "nav-index",
"nav-left", "nav-right", "nav-up", "object-fit", "object-position",
"opacity", "order", "orphans", "outline",
"outline-color", "outline-offset", "outline-style", "outline-width",
"overflow", "overflow-style", "overflow-wrap", "overflow-x", "overflow-y",
"padding", "padding-bottom", "padding-left", "padding-right", "padding-top",
"page", "page-break-after", "page-break-before", "page-break-inside",
"page-policy", "pause", "pause-after", "pause-before", "perspective",
"perspective-origin", "pitch", "pitch-range", "play-during", "position",
"presentation-level", "punctuation-trim", "quotes", "region-break-after",
"region-break-before", "region-break-inside", "region-fragment",
"rendering-intent", "resize", "rest", "rest-after", "rest-before", "richness",
"right", "rotation", "rotation-point", "ruby-align", "ruby-overhang",
"ruby-position", "ruby-span", "shape-image-threshold", "shape-inside", "shape-margin",
"shape-outside", "size", "speak", "speak-as", "speak-header",
"speak-numeral", "speak-punctuation", "speech-rate", "stress", "string-set",
"tab-size", "table-layout", "target", "target-name", "target-new",
"target-position", "text-align", "text-align-last", "text-decoration",
"text-decoration-color", "text-decoration-line", "text-decoration-skip",
"text-decoration-style", "text-emphasis", "text-emphasis-color",
"text-emphasis-position", "text-emphasis-style", "text-height",
"text-indent", "text-justify", "text-outline", "text-overflow", "text-shadow",
"text-size-adjust", "text-space-collapse", "text-transform", "text-underline-position",
"text-wrap", "top", "transform", "transform-origin", "transform-style",
"transition", "transition-delay", "transition-duration",
"transition-property", "transition-timing-function", "unicode-bidi",
"vertical-align", "visibility", "voice-balance", "voice-duration",
"voice-family", "voice-pitch", "voice-range", "voice-rate", "voice-stress",
"voice-volume", "volume", "white-space", "widows", "width", "word-break",
"word-spacing", "word-wrap", "z-index",
// SVG-specific
"clip-path", "clip-rule", "mask", "enable-background", "filter", "flood-color",
"flood-opacity", "lighting-color", "stop-color", "stop-opacity", "pointer-events",
"color-interpolation", "color-interpolation-filters",
"color-rendering", "fill", "fill-opacity", "fill-rule", "image-rendering",
"marker", "marker-end", "marker-mid", "marker-start", "shape-rendering", "stroke",
"stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin",
"stroke-miterlimit", "stroke-opacity", "stroke-width", "text-rendering",
"baseline-shift", "dominant-baseline", "glyph-orientation-horizontal",
"glyph-orientation-vertical", "text-anchor", "writing-mode"
], propertyKeywords = keySet(propertyKeywords_);
var nonStandardPropertyKeywords = [
"scrollbar-arrow-color", "scrollbar-base-color", "scrollbar-dark-shadow-color",
"scrollbar-face-color", "scrollbar-highlight-color", "scrollbar-shadow-color",
"scrollbar-3d-light-color", "scrollbar-track-color", "shape-inside",
"searchfield-cancel-button", "searchfield-decoration", "searchfield-results-button",
"searchfield-results-decoration", "zoom"
], nonStandardPropertyKeywords = keySet(nonStandardPropertyKeywords);
var colorKeywords_ = [
"aliceblue", "antiquewhite", "aqua", "aquamarine", "azure", "beige",
"bisque", "black", "blanchedalmond", "blue", "blueviolet", "brown",
"burlywood", "cadetblue", "chartreuse", "chocolate", "coral", "cornflowerblue",
"cornsilk", "crimson", "cyan", "darkblue", "darkcyan", "darkgoldenrod",
"darkgray", "darkgreen", "darkkhaki", "darkmagenta", "darkolivegreen",
"darkorange", "darkorchid", "darkred", "darksalmon", "darkseagreen",
"darkslateblue", "darkslategray", "darkturquoise", "darkviolet",
"deeppink", "deepskyblue", "dimgray", "dodgerblue", "firebrick",
"floralwhite", "forestgreen", "fuchsia", "gainsboro", "ghostwhite",
"gold", "goldenrod", "gray", "grey", "green", "greenyellow", "honeydew",
"hotpink", "indianred", "indigo", "ivory", "khaki", "lavender",
"lavenderblush", "lawngreen", "lemonchiffon", "lightblue", "lightcoral",
"lightcyan", "lightgoldenrodyellow", "lightgray", "lightgreen", "lightpink",
"lightsalmon", "lightseagreen", "lightskyblue", "lightslategray",
"lightsteelblue", "lightyellow", "lime", "limegreen", "linen", "magenta",
"maroon", "mediumaquamarine", "mediumblue", "mediumorchid", "mediumpurple",
"mediumseagreen", "mediumslateblue", "mediumspringgreen", "mediumturquoise",
"mediumvioletred", "midnightblue", "mintcream", "mistyrose", "moccasin",
"navajowhite", "navy", "oldlace", "olive", "olivedrab", "orange", "orangered",
"orchid", "palegoldenrod", "palegreen", "paleturquoise", "palevioletred",
"papayawhip", "peachpuff", "peru", "pink", "plum", "powderblue",
"purple", "red", "rosybrown", "royalblue", "saddlebrown", "salmon",
"sandybrown", "seagreen", "seashell", "sienna", "silver", "skyblue",
"slateblue", "slategray", "snow", "springgreen", "steelblue", "tan",
"teal", "thistle", "tomato", "turquoise", "violet", "wheat", "white",
"whitesmoke", "yellow", "yellowgreen"
], colorKeywords = keySet(colorKeywords_);
var valueKeywords_ = [
"above", "absolute", "activeborder", "activecaption", "afar",
"after-white-space", "ahead", "alias", "all", "all-scroll", "alternate",
"always", "amharic", "amharic-abegede", "antialiased", "appworkspace",
"arabic-indic", "armenian", "asterisks", "auto", "avoid", "avoid-column", "avoid-page",
"avoid-region", "background", "backwards", "baseline", "below", "bidi-override", "binary",
"bengali", "blink", "block", "block-axis", "bold", "bolder", "border", "border-box",
"both", "bottom", "break", "break-all", "break-word", "button", "button-bevel",
"buttonface", "buttonhighlight", "buttonshadow", "buttontext", "cambodian",
"capitalize", "caps-lock-indicator", "caption", "captiontext", "caret",
"cell", "center", "checkbox", "circle", "cjk-earthly-branch",
"cjk-heavenly-stem", "cjk-ideographic", "clear", "clip", "close-quote",
"col-resize", "collapse", "column", "compact", "condensed", "contain", "content",
"content-box", "context-menu", "continuous", "copy", "cover", "crop",
"cross", "crosshair", "currentcolor", "cursive", "dashed", "decimal",
"decimal-leading-zero", "default", "default-button", "destination-atop",
"destination-in", "destination-out", "destination-over", "devanagari",
"disc", "discard", "document", "dot-dash", "dot-dot-dash", "dotted",
"double", "down", "e-resize", "ease", "ease-in", "ease-in-out", "ease-out",
"element", "ellipse", "ellipsis", "embed", "end", "ethiopic", "ethiopic-abegede",
"ethiopic-abegede-am-et", "ethiopic-abegede-gez", "ethiopic-abegede-ti-er",
"ethiopic-abegede-ti-et", "ethiopic-halehame-aa-er",
"ethiopic-halehame-aa-et", "ethiopic-halehame-am-et",
"ethiopic-halehame-gez", "ethiopic-halehame-om-et",
"ethiopic-halehame-sid-et", "ethiopic-halehame-so-et",
"ethiopic-halehame-ti-er", "ethiopic-halehame-ti-et",
"ethiopic-halehame-tig", "ew-resize", "expanded", "extra-condensed",
"extra-expanded", "fantasy", "fast", "fill", "fixed", "flat", "footnotes",
"forwards", "from", "geometricPrecision", "georgian", "graytext", "groove",
"gujarati", "gurmukhi", "hand", "hangul", "hangul-consonant", "hebrew",
"help", "hidden", "hide", "higher", "highlight", "highlighttext",
"hiragana", "hiragana-iroha", "horizontal", "hsl", "hsla", "icon", "ignore",
"inactiveborder", "inactivecaption", "inactivecaptiontext", "infinite",
"infobackground", "infotext", "inherit", "initial", "inline", "inline-axis",
"inline-block", "inline-table", "inset", "inside", "intrinsic", "invert",
"italic", "justify", "kannada", "katakana", "katakana-iroha", "keep-all", "khmer",
"landscape", "lao", "large", "larger", "left", "level", "lighter",
"line-through", "linear", "lines", "list-item", "listbox", "listitem",
"local", "logical", "loud", "lower", "lower-alpha", "lower-armenian",
"lower-greek", "lower-hexadecimal", "lower-latin", "lower-norwegian",
"lower-roman", "lowercase", "ltr", "malayalam", "match",
"media-controls-background", "media-current-time-display",
"media-fullscreen-button", "media-mute-button", "media-play-button",
"media-return-to-realtime-button", "media-rewind-button",
"media-seek-back-button", "media-seek-forward-button", "media-slider",
"media-sliderthumb", "media-time-remaining-display", "media-volume-slider",
"media-volume-slider-container", "media-volume-sliderthumb", "medium",
"menu", "menulist", "menulist-button", "menulist-text",
"menulist-textfield", "menutext", "message-box", "middle", "min-intrinsic",
"mix", "mongolian", "monospace", "move", "multiple", "myanmar", "n-resize",
"narrower", "ne-resize", "nesw-resize", "no-close-quote", "no-drop",
"no-open-quote", "no-repeat", "none", "normal", "not-allowed", "nowrap",
"ns-resize", "nw-resize", "nwse-resize", "oblique", "octal", "open-quote",
"optimizeLegibility", "optimizeSpeed", "oriya", "oromo", "outset",
"outside", "outside-shape", "overlay", "overline", "padding", "padding-box",
"painted", "page", "paused", "persian", "plus-darker", "plus-lighter", "pointer",
"polygon", "portrait", "pre", "pre-line", "pre-wrap", "preserve-3d", "progress", "push-button",
"radio", "read-only", "read-write", "read-write-plaintext-only", "rectangle", "region",
"relative", "repeat", "repeat-x", "repeat-y", "reset", "reverse", "rgb", "rgba",
"ridge", "right", "round", "row-resize", "rtl", "run-in", "running",
"s-resize", "sans-serif", "scroll", "scrollbar", "se-resize", "searchfield",
"searchfield-cancel-button", "searchfield-decoration",
"searchfield-results-button", "searchfield-results-decoration",
"semi-condensed", "semi-expanded", "separate", "serif", "show", "sidama",
"single", "skip-white-space", "slide", "slider-horizontal",
"slider-vertical", "sliderthumb-horizontal", "sliderthumb-vertical", "slow",
"small", "small-caps", "small-caption", "smaller", "solid", "somali",
"source-atop", "source-in", "source-out", "source-over", "space", "square",
"square-button", "start", "static", "status-bar", "stretch", "stroke",
"sub", "subpixel-antialiased", "super", "sw-resize", "table",
"table-caption", "table-cell", "table-column", "table-column-group",
"table-footer-group", "table-header-group", "table-row", "table-row-group",
"telugu", "text", "text-bottom", "text-top", "textarea", "textfield", "thai",
"thick", "thin", "threeddarkshadow", "threedface", "threedhighlight",
"threedlightshadow", "threedshadow", "tibetan", "tigre", "tigrinya-er",
"tigrinya-er-abegede", "tigrinya-et", "tigrinya-et-abegede", "to", "top",
"transparent", "ultra-condensed", "ultra-expanded", "underline", "up",
"upper-alpha", "upper-armenian", "upper-greek", "upper-hexadecimal",
"upper-latin", "upper-norwegian", "upper-roman", "uppercase", "urdu", "url",
"vertical", "vertical-text", "visible", "visibleFill", "visiblePainted",
"visibleStroke", "visual", "w-resize", "wait", "wave", "wider",
"window", "windowframe", "windowtext", "x-large", "x-small", "xor",
"xx-large", "xx-small"
], valueKeywords = keySet(valueKeywords_);
var fontProperties_ = [
"font-family", "src", "unicode-range", "font-variant", "font-feature-settings",
"font-stretch", "font-weight", "font-style"
], fontProperties = keySet(fontProperties_);
var allWords = mediaTypes_.concat(mediaFeatures_).concat(propertyKeywords_)
.concat(nonStandardPropertyKeywords).concat(colorKeywords_).concat(valueKeywords_);
CodeMirror.registerHelper("hintWords", "css", allWords);
function tokenCComment(stream, state) {
var maybeEnd = false, ch;
while ((ch = stream.next()) != null) {
if (maybeEnd && ch == "/") {
state.tokenize = null;
break;
}
maybeEnd = (ch == "*");
}
return ["comment", "comment"];
}
function tokenSGMLComment(stream, state) {
if (stream.skipTo("-->")) {
stream.match("-->");
state.tokenize = null;
} else {
stream.skipToEnd();
}
return ["comment", "comment"];
}
CodeMirror.defineMIME("text/css", {
mediaTypes: mediaTypes,
mediaFeatures: mediaFeatures,
propertyKeywords: propertyKeywords,
nonStandardPropertyKeywords: nonStandardPropertyKeywords,
colorKeywords: colorKeywords,
valueKeywords: valueKeywords,
fontProperties: fontProperties,
tokenHooks: {
"<": function(stream, state) {
if (!stream.match("!--")) return false;
state.tokenize = tokenSGMLComment;
return tokenSGMLComment(stream, state);
},
"/": function(stream, state) {
if (!stream.eat("*")) return false;
state.tokenize = tokenCComment;
return tokenCComment(stream, state);
}
},
name: "css"
});
CodeMirror.defineMIME("text/x-scss", {
mediaTypes: mediaTypes,
mediaFeatures: mediaFeatures,
propertyKeywords: propertyKeywords,
nonStandardPropertyKeywords: nonStandardPropertyKeywords,
colorKeywords: colorKeywords,
valueKeywords: valueKeywords,
fontProperties: fontProperties,
allowNested: true,
tokenHooks: {
"/": function(stream, state) {
if (stream.eat("/")) {
stream.skipToEnd();
return ["comment", "comment"];
} else if (stream.eat("*")) {
state.tokenize = tokenCComment;
return tokenCComment(stream, state);
} else {
return ["operator", "operator"];
}
},
":": function(stream) {
if (stream.match(/\s*{/))
return [null, "{"];
return false;
},
"$": function(stream) {
stream.match(/^[\w-]+/);
if (stream.match(/^\s*:/, false))
return ["variable-2", "variable-definition"];
return ["variable-2", "variable"];
},
"#": function(stream) {
if (!stream.eat("{")) return false;
return [null, "interpolation"];
}
},
name: "css",
helperType: "scss"
});
CodeMirror.defineMIME("text/x-less", {
mediaTypes: mediaTypes,
mediaFeatures: mediaFeatures,
propertyKeywords: propertyKeywords,
nonStandardPropertyKeywords: nonStandardPropertyKeywords,
colorKeywords: colorKeywords,
valueKeywords: valueKeywords,
fontProperties: fontProperties,
allowNested: true,
tokenHooks: {
"/": function(stream, state) {
if (stream.eat("/")) {
stream.skipToEnd();
return ["comment", "comment"];
} else if (stream.eat("*")) {
state.tokenize = tokenCComment;
return tokenCComment(stream, state);
} else {
return ["operator", "operator"];
}
},
"@": function(stream) {
if (stream.match(/^(charset|document|font-face|import|(-(moz|ms|o|webkit)-)?keyframes|media|namespace|page|supports)\b/, false)) return false;
stream.eatWhile(/[\w\\\-]/);
if (stream.match(/^\s*:/, false))
return ["variable-2", "variable-definition"];
return ["variable-2", "variable"];
},
"&": function() {
return ["atom", "atom"];
}
},
name: "css",
helperType: "less"
});
});

View File

@ -1,3 +1,6 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"), require("../xml/xml"), require("../javascript/javascript"), require("../css/css"));

View File

@ -1,3 +1,6 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
// TODO actually recognize syntax of TypeScript constructs
(function(mod) {
@ -325,7 +328,11 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
if (type == "keyword b") return cont(pushlex("form"), statement, poplex);
if (type == "{") return cont(pushlex("}"), block, poplex);
if (type == ";") return cont();
if (type == "if") return cont(pushlex("form"), expression, statement, poplex, maybeelse);
if (type == "if") {
if (cx.state.lexical.info == "else" && cx.state.cc[cx.state.cc.length - 1] == poplex)
cx.state.cc.pop()();
return cont(pushlex("form"), expression, statement, poplex, maybeelse);
}
if (type == "function") return cont(functiondef);
if (type == "for") return cont(pushlex("form"), forspec, statement, poplex);
if (type == "variable") return cont(pushlex("stat"), maybelabel);
@ -356,12 +363,13 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
var maybeop = noComma ? maybeoperatorNoComma : maybeoperatorComma;
if (atomicTypes.hasOwnProperty(type)) return cont(maybeop);
if (type == "function") return cont(functiondef);
if (type == "function") return cont(functiondef, maybeop);
if (type == "keyword c") return cont(noComma ? maybeexpressionNoComma : maybeexpression);
if (type == "(") return cont(pushlex(")"), maybeexpression, comprehension, expect(")"), poplex, maybeop);
if (type == "operator" || type == "spread") return cont(noComma ? expressionNoComma : expression);
if (type == "[") return cont(pushlex("]"), arrayLiteral, poplex, maybeop);
if (type == "{") return contCommasep(objprop, "}", null, maybeop);
if (type == "quasi") { return pass(quasi, maybeop); }
return cont();
}
function maybeexpression(type) {
@ -386,21 +394,22 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
if (value == "?") return cont(expression, expect(":"), expr);
return cont(expr);
}
if (type == "quasi") { cx.cc.push(me); return quasi(value); }
if (type == "quasi") { return pass(quasi, me); }
if (type == ";") return;
if (type == "(") return contCommasep(expressionNoComma, ")", "call", me);
if (type == ".") return cont(property, me);
if (type == "[") return cont(pushlex("]"), maybeexpression, expect("]"), poplex, me);
}
function quasi(value) {
if (value.slice(value.length - 2) != "${") return cont();
function quasi(type, value) {
if (type != "quasi") return pass();
if (value.slice(value.length - 2) != "${") return cont(quasi);
return cont(expression, continueQuasi);
}
function continueQuasi(type) {
if (type == "}") {
cx.marked = "string-2";
cx.state.tokenize = tokenQuasi;
return cont();
return cont(quasi);
}
}
function arrowBody(type) {
@ -493,7 +502,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
if (type == ",") return cont(vardef);
}
function maybeelse(type, value) {
if (type == "keyword b" && value == "else") return cont(pushlex("form"), statement, poplex);
if (type == "keyword b" && value == "else") return cont(pushlex("form", "else"), statement, poplex);
}
function forspec(type) {
if (type == "(") return cont(pushlex(")"), forspec1, expect(")"), poplex);
@ -606,7 +615,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
if (state.tokenize != tokenBase) return 0;
var firstChar = textAfter && textAfter.charAt(0), lexical = state.lexical;
// Kludge to prevent 'maybelse' from blocking lexical scope pops
for (var i = state.cc.length - 1; i >= 0; --i) {
if (!/^\s*else\b/.test(textAfter)) for (var i = state.cc.length - 1; i >= 0; --i) {
var c = state.cc[i];
if (c == poplex) lexical = lexical.prev;
else if (c != maybeelse) break;
@ -639,6 +648,8 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
};
});
CodeMirror.registerHelper("wordChars", "javascript", /[\\w$]/);
CodeMirror.defineMIME("text/javascript", "javascript");
CodeMirror.defineMIME("text/ecmascript", "javascript");
CodeMirror.defineMIME("application/javascript", "javascript");

View File

@ -1,3 +1,6 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
@ -58,7 +61,7 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
var alignCDATA = parserConfig.alignCDATA;
// Return variables for tokenizers
var tagName, type, setStyle;
var type, setStyle;
function inText(stream, state) {
function chain(parser) {
@ -85,15 +88,9 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
state.tokenize = inBlock("meta", "?>");
return "meta";
} else {
var isClose = stream.eat("/");
tagName = "";
var c;
while ((c = stream.eat(/[^\s\u00a0=<>\"\'\/?]/))) tagName += c;
if (Kludges.caseFold) tagName = tagName.toLowerCase();
if (!tagName) return "tag error";
type = isClose ? "closeTag" : "openTag";
type = stream.eat("/") ? "closeTag" : "openTag";
state.tokenize = inTag;
return "tag";
return "tag bracket";
}
} else if (ch == "&") {
var ok;
@ -118,7 +115,7 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
if (ch == ">" || (ch == "/" && stream.eat(">"))) {
state.tokenize = inText;
type = ch == ">" ? "endTag" : "selfcloseTag";
return "tag";
return "tag bracket";
} else if (ch == "=") {
type = "equals";
return null;
@ -127,13 +124,13 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
state.state = baseState;
state.tagName = state.tagStart = null;
var next = state.tokenize(stream, state);
return next ? next + " error" : "error";
return next ? next + " tag error" : "tag error";
} else if (/[\'\"]/.test(ch)) {
state.tokenize = inAttribute(ch);
state.stringStartCol = stream.column();
return state.tokenize(stream, state);
} else {
stream.eatWhile(/[^\s\u00a0=<>\"\']/);
stream.match(/^[^\s\u00a0=<>\"\']*[^\s\u00a0=<>\"\'\/]/);
return "word";
}
}
@ -213,26 +210,42 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
function baseState(type, stream, state) {
if (type == "openTag") {
state.tagName = tagName;
state.tagStart = stream.column();
return attrState;
return tagNameState;
} else if (type == "closeTag") {
var err = false;
if (state.context) {
if (state.context.tagName != tagName) {
if (Kludges.implicitlyClosed.hasOwnProperty(state.context.tagName))
popContext(state);
err = !state.context || state.context.tagName != tagName;
}
} else {
err = true;
}
if (err) setStyle = "error";
return err ? closeStateErr : closeState;
return closeTagNameState;
} else {
return baseState;
}
}
function tagNameState(type, stream, state) {
if (type == "word") {
state.tagName = stream.current();
setStyle = "tag";
return attrState;
} else {
setStyle = "error";
return tagNameState;
}
}
function closeTagNameState(type, stream, state) {
if (type == "word") {
var tagName = stream.current();
if (state.context && state.context.tagName != tagName &&
Kludges.implicitlyClosed.hasOwnProperty(state.context.tagName))
popContext(state);
if (state.context && state.context.tagName == tagName) {
setStyle = "tag";
return closeState;
} else {
setStyle = "tag error";
return closeStateErr;
}
} else {
setStyle = "error";
return closeStateErr;
}
}
function closeState(type, _stream, state) {
if (type != "endTag") {
@ -296,7 +309,7 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
state.indented = stream.indentation();
if (stream.eatSpace()) return null;
tagName = type = null;
type = null;
var style = state.tokenize(stream, state);
if ((style || type) && style != "comment") {
setStyle = null;
@ -311,7 +324,10 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
var context = state.context;
// Indent multi-line strings (e.g. css).
if (state.tokenize.isInAttribute) {
return state.stringStartCol + 1;
if (state.tagStart == state.indented)
return state.stringStartCol + 1;
else
return state.indented + indentUnit;
}
if (context && context.noIndent) return CodeMirror.Pass;
if (state.tokenize != inTag && state.tokenize != inText)
@ -324,15 +340,34 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
return state.tagStart + indentUnit * multilineTagIndentFactor;
}
if (alignCDATA && /<!\[CDATA\[/.test(textAfter)) return 0;
if (context && /^<\//.test(textAfter))
context = context.prev;
var tagAfter = textAfter && /^<(\/)?([\w_:\.-]*)/.exec(textAfter);
if (tagAfter && tagAfter[1]) { // Closing tag spotted
while (context) {
if (context.tagName == tagAfter[2]) {
context = context.prev;
break;
} else if (Kludges.implicitlyClosed.hasOwnProperty(context.tagName)) {
context = context.prev;
} else {
break;
}
}
} else if (tagAfter) { // Opening tag spotted
while (context) {
var grabbers = Kludges.contextGrabbers[context.tagName];
if (grabbers && grabbers.hasOwnProperty(tagAfter[2]))
context = context.prev;
else
break;
}
}
while (context && !context.startOfLine)
context = context.prev;
if (context) return context.indent + indentUnit;
else return 0;
},
electricChars: "/",
electricInput: /<\/[\s\w:]+>$/,
blockCommentStart: "<!--",
blockCommentEnd: "-->",

View File

@ -1,3 +1,6 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
// Highlighting text that matches the selection
//
// Defines an option highlightSelectionMatches, which, when enabled,
@ -76,8 +79,9 @@
cm.addOverlay(state.overlay = makeOverlay(line.slice(start, end), re, state.style));
return;
}
if (cm.getCursor("head").line != cm.getCursor("anchor").line) return;
var selection = cm.getSelections()[0].replace(/^\s+|\s+$/g, "");
var from = cm.getCursor("from"), to = cm.getCursor("to");
if (from.line != to.line) return;
var selection = cm.getRange(from, to).replace(/^\s+|\s+$/g, "");
if (selection.length >= state.minChars)
cm.addOverlay(state.overlay = makeOverlay(selection, false, state.style));
});

View File

@ -1,3 +1,6 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
// Define search commands. Depends on dialog.js or another
// implementation of the openDialog method.
@ -16,21 +19,21 @@
})(function(CodeMirror) {
"use strict";
function searchOverlay(query, caseInsensitive) {
var startChar;
if (typeof query == "string") {
startChar = query.charAt(0);
query = new RegExp("^" + query.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"),
caseInsensitive ? "i" : "");
} else {
query = new RegExp("^(?:" + query.source + ")", query.ignoreCase ? "i" : "");
}
if (typeof query == "string")
query = new RegExp(query.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"), caseInsensitive ? "gi" : "g");
else if (!query.global)
query = new RegExp(query.source, query.ignoreCase ? "gi" : "g");
return {token: function(stream) {
if (stream.match(query)) return "searching";
while (!stream.eol()) {
stream.next();
if (startChar && !caseInsensitive)
stream.skipTo(startChar) || stream.skipToEnd();
if (stream.match(query, false)) break;
query.lastIndex = stream.pos;
var match = query.exec(stream.string);
if (match && match.index == stream.pos) {
stream.pos += match[0].length;
return "searching";
} else if (match) {
stream.pos = match.index;
} else {
stream.skipToEnd();
}
}};
}

View File

@ -1,3 +1,6 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));

View File

@ -1,3 +1,6 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
// Because sometimes you need to style the cursor's line.
//
// Adds an option 'styleActiveLine' which, when enabled, gives the

View File

@ -0,0 +1,118 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
// Because sometimes you need to mark the selected *text*.
//
// Adds an option 'styleSelectedText' which, when enabled, gives
// selected text the CSS class given as option value, or
// "CodeMirror-selectedtext" when the value is not a string.
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
CodeMirror.defineOption("styleSelectedText", false, function(cm, val, old) {
var prev = old && old != CodeMirror.Init;
if (val && !prev) {
cm.state.markedSelection = [];
cm.state.markedSelectionStyle = typeof val == "string" ? val : "CodeMirror-selectedtext";
reset(cm);
cm.on("cursorActivity", onCursorActivity);
cm.on("change", onChange);
} else if (!val && prev) {
cm.off("cursorActivity", onCursorActivity);
cm.off("change", onChange);
clear(cm);
cm.state.markedSelection = cm.state.markedSelectionStyle = null;
}
});
function onCursorActivity(cm) {
cm.operation(function() { update(cm); });
}
function onChange(cm) {
if (cm.state.markedSelection.length)
cm.operation(function() { clear(cm); });
}
var CHUNK_SIZE = 8;
var Pos = CodeMirror.Pos;
var cmp = CodeMirror.cmpPos;
function coverRange(cm, from, to, addAt) {
if (cmp(from, to) == 0) return;
var array = cm.state.markedSelection;
var cls = cm.state.markedSelectionStyle;
for (var line = from.line;;) {
var start = line == from.line ? from : Pos(line, 0);
var endLine = line + CHUNK_SIZE, atEnd = endLine >= to.line;
var end = atEnd ? to : Pos(endLine, 0);
var mark = cm.markText(start, end, {className: cls});
if (addAt == null) array.push(mark);
else array.splice(addAt++, 0, mark);
if (atEnd) break;
line = endLine;
}
}
function clear(cm) {
var array = cm.state.markedSelection;
for (var i = 0; i < array.length; ++i) array[i].clear();
array.length = 0;
}
function reset(cm) {
clear(cm);
var ranges = cm.listSelections();
for (var i = 0; i < ranges.length; i++)
coverRange(cm, ranges[i].from(), ranges[i].to());
}
function update(cm) {
if (!cm.somethingSelected()) return clear(cm);
if (cm.listSelections().length > 1) return reset(cm);
var from = cm.getCursor("start"), to = cm.getCursor("end");
var array = cm.state.markedSelection;
if (!array.length) return coverRange(cm, from, to);
var coverStart = array[0].find(), coverEnd = array[array.length - 1].find();
if (!coverStart || !coverEnd || to.line - from.line < CHUNK_SIZE ||
cmp(from, coverEnd.to) >= 0 || cmp(to, coverStart.from) <= 0)
return reset(cm);
while (cmp(from, coverStart.from) > 0) {
array.shift().clear();
coverStart = array[0].find();
}
if (cmp(from, coverStart.from) < 0) {
if (coverStart.to.line - from.line < CHUNK_SIZE) {
array.shift().clear();
coverRange(cm, from, coverStart.to, 0);
} else {
coverRange(cm, from, coverStart.from, 0);
}
}
while (cmp(to, coverEnd.to) < 0) {
array.pop().clear();
coverEnd = array[array.length - 1].find();
}
if (cmp(to, coverEnd.to) > 0) {
if (to.line - coverEnd.from.line < CHUNK_SIZE) {
array.pop().clear();
coverRange(cm, coverEnd.from, to);
} else {
coverRange(cm, coverEnd.to, to);
}
}
}
});

View File

@ -0,0 +1,86 @@
.CodeMirror-Tern-completion {
padding-left: 22px;
position: relative;
}
.CodeMirror-Tern-completion:before {
position: absolute;
left: 2px;
bottom: 2px;
border-radius: 50%;
font-size: 12px;
font-weight: bold;
height: 15px;
width: 15px;
line-height: 16px;
text-align: center;
color: white;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.CodeMirror-Tern-completion-unknown:before {
content: "?";
background: #4bb;
}
.CodeMirror-Tern-completion-object:before {
content: "O";
background: #77c;
}
.CodeMirror-Tern-completion-fn:before {
content: "F";
background: #7c7;
}
.CodeMirror-Tern-completion-array:before {
content: "A";
background: #c66;
}
.CodeMirror-Tern-completion-number:before {
content: "1";
background: #999;
}
.CodeMirror-Tern-completion-string:before {
content: "S";
background: #999;
}
.CodeMirror-Tern-completion-bool:before {
content: "B";
background: #999;
}
.CodeMirror-Tern-completion-guess {
color: #999;
}
.CodeMirror-Tern-tooltip {
border: 1px solid silver;
border-radius: 3px;
color: #444;
padding: 2px 5px;
font-size: 90%;
font-family: monospace;
background-color: white;
white-space: pre-wrap;
max-width: 40em;
position: absolute;
z-index: 10;
-webkit-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
-moz-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
box-shadow: 2px 3px 5px rgba(0,0,0,.2);
transition: opacity 1s;
-moz-transition: opacity 1s;
-webkit-transition: opacity 1s;
-o-transition: opacity 1s;
-ms-transition: opacity 1s;
}
.CodeMirror-Tern-hint-doc {
max-width: 25em;
margin-top: -3px;
}
.CodeMirror-Tern-fname { color: black; }
.CodeMirror-Tern-farg { color: #70a; }
.CodeMirror-Tern-farg-current { text-decoration: underline; }
.CodeMirror-Tern-type { color: #07c; }
.CodeMirror-Tern-fhint-guess { opacity: .7; }

View File

@ -1,3 +1,6 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
// Glue code between CodeMirror and Tern.
//
// Create a CodeMirror.TernServer to wrap an actual Tern server,
@ -14,7 +17,7 @@
// indicate that a file is not available.
// * fileFilter: A function(value, docName, doc) that will be applied
// to documents before passing them on to Tern.
// * switchToDoc: A function(name) that should, when providing a
// * switchToDoc: A function(name, doc) that should, when providing a
// multi-file view, switch the view or focus to the named file.
// * showError: A function(editor, message) that can be used to
// override the way errors are displayed.
@ -40,7 +43,14 @@
// load. Or, if you minified those into a single script and included
// them in the workerScript, simply leave this undefined.
(function() {
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
// declare global: tern
@ -65,6 +75,9 @@
this.cachedArgHints = null;
this.activeArgHints = null;
this.jumpStack = [];
this.getHint = function(cm, c) { return hint(self, cm, c); };
this.getHint.async = true;
};
CodeMirror.TernServer.prototype = {
@ -75,28 +88,25 @@
return this.docs[name] = data;
},
delDoc: function(name) {
var found = this.docs[name];
delDoc: function(id) {
var found = resolveDoc(this, id);
if (!found) return;
CodeMirror.off(found.doc, "change", this.trackChange);
delete this.docs[name];
this.server.delFile(name);
delete this.docs[found.name];
this.server.delFile(found.name);
},
hideDoc: function(name) {
hideDoc: function(id) {
closeArgHints(this);
var found = this.docs[name];
var found = resolveDoc(this, id);
if (found && found.changed) sendDoc(this, found);
},
complete: function(cm) {
var self = this;
CodeMirror.showHint(cm, function(cm, c) { return hint(self, cm, c); }, {async: true});
cm.showHint({hint: this.getHint});
},
getHint: function(cm, c) { return hint(this, cm, c); },
showType: function(cm, pos, c) { showType(this, cm, pos, c); },
showType: function(cm, pos, cb) { showType(this, cm, pos, cb); },
updateArgHints: function(cm) { updateArgHints(this, cm); },
@ -106,6 +116,8 @@
rename: function(cm) { rename(this, cm); },
selectName: function(cm) { selectName(this, cm); },
request: function (cm, query, c, pos) {
var self = this;
var doc = findDoc(this, cm.getDoc());
@ -145,6 +157,12 @@
return ts.addDoc(name, doc);
}
function resolveDoc(ts, id) {
if (typeof id == "string") return ts.docs[id];
if (id instanceof CodeMirror) id = id.getDoc();
if (id instanceof CodeMirror.Doc) return findDoc(ts, id);
}
function trackChange(ts, doc, change) {
var data = findDoc(ts, doc);
@ -167,7 +185,7 @@
function sendDoc(ts, doc) {
ts.server.request({files: [{type: "full", name: doc.name, text: docValue(ts, doc)}]}, function(error) {
if (error) console.error(error);
if (error) window.console.error(error);
else doc.changed = null;
});
}
@ -221,13 +239,13 @@
// Type queries
function showType(ts, cm, pos, c) {
function showType(ts, cm, pos, cb) {
ts.request(cm, "type", function(error, data) {
if (error) return showError(ts, cm, error);
if (ts.options.typeTip) {
var tip = ts.options.typeTip(data);
} else {
var tip = elt("span", cls + "information", elt("strong", null, data.type || "not found"));
var tip = elt("span", null, elt("strong", null, data.type || "not found"));
if (data.doc)
tip.appendChild(document.createTextNode(" — " + data.doc));
if (data.url) {
@ -236,7 +254,7 @@
}
}
tempTooltip(cm, tip);
c && c(tip);
if (cb) cb();
}, pos);
}
@ -373,10 +391,10 @@
}
function moveTo(ts, curDoc, doc, start, end) {
doc.doc.setSelection(end, start);
doc.doc.setSelection(start, end);
if (curDoc != doc && ts.options.switchToDoc) {
closeArgHints(ts);
ts.options.switchToDoc(doc.name);
ts.options.switchToDoc(doc.name, doc.doc);
}
}
@ -421,7 +439,7 @@
function rename(ts, cm) {
var token = cm.getTokenAt(cm.getCursor());
if (!/\w/.test(token.string)) showError(ts, cm, "Not at a variable");
if (!/\w/.test(token.string)) return showError(ts, cm, "Not at a variable");
dialog(cm, "New name for " + token.string, function(newName) {
ts.request(cm, {type: "rename", newName: newName, fullDocs: true}, function(error, data) {
if (error) return showError(ts, cm, error);
@ -430,6 +448,23 @@
});
}
function selectName(ts, cm) {
var name = findDoc(ts, cm.doc).name;
ts.request(cm, {type: "refs"}, function(error, data) {
if (error) return showError(ts, cm, error);
var ranges = [], cur = 0;
for (var i = 0; i < data.refs.length; i++) {
var ref = data.refs[i];
if (ref.file == name) {
ranges.push({anchor: ref.start, head: ref.end});
if (cmpPos(cur, ref.start) >= 0 && cmpPos(cur, ref.end) <= 0)
cur = ranges.length - 1;
}
}
cm.setSelections(ranges, cur);
});
}
var nextChangeOrig = 0;
function applyChanges(ts, changes) {
var perFile = Object.create(null);
@ -522,7 +557,7 @@
// Generic utilities
function cmpPos(a, b) { return a.line - b.line || a.ch - b.ch; }
var cmpPos = CodeMirror.cmpPos;
function elt(tagname, cls /*, ... elts*/) {
var e = document.createElement(tagname);
@ -615,7 +650,7 @@
send({type: "getFile", err: String(err), text: text, id: data.id});
});
} else if (data.type == "debug") {
console.log(data.message);
window.console.log(data.message);
} else if (data.id && pending[data.id]) {
pending[data.id](data.err, data.body);
delete pending[data.id];
@ -630,4 +665,4 @@
this.delFile = function(name) { send({type: "del", name: name}); };
this.request = function(body, c) { send({type: "req", body: body}, c); };
}
})();
});

View File

@ -28,13 +28,13 @@ namespace = "comment_";
cm.uncomment(Pos(0, 0), Pos(2, 1));
}, simpleProg, simpleProg);
// test("fallbackToBlock", "css", function(cm) {
// cm.lineComment(Pos(0, 0), Pos(2, 1));
// }, "html {\n border: none;\n}", "/* html {\n border: none;\n} */");
test("fallbackToBlock", "css", function(cm) {
cm.lineComment(Pos(0, 0), Pos(2, 1));
}, "html {\n border: none;\n}", "/* html {\n border: none;\n} */");
// test("fallbackToLine", "ruby", function(cm) {
// cm.blockComment(Pos(0, 0), Pos(1));
// }, "def blah()\n return hah\n", "# def blah()\n# return hah\n");
test("fallbackToLine", "ruby", function(cm) {
cm.blockComment(Pos(0, 0), Pos(1));
}, "def blah()\n return hah\n", "# def blah()\n# return hah\n");
test("commentRange", "javascript", function(cm) {
cm.blockComment(Pos(1, 2), Pos(1, 13), {fullLines: false});

View File

@ -320,6 +320,29 @@
eq(cleared, 1);
});
testDoc("sharedMarkerCopy", "A='abcde'", function(a) {
var shared = a.markText(Pos(0, 1), Pos(0, 3), {shared: true});
var b = a.linkedDoc();
var found = b.findMarksAt(Pos(0, 2));
eq(found.length, 1);
eq(found[0], shared);
shared.clear();
eq(b.findMarksAt(Pos(0, 2)), 0);
});
testDoc("sharedMarkerDetach", "A='abcde' B<A C<B", function(a, b, c) {
var shared = a.markText(Pos(0, 1), Pos(0, 3), {shared: true});
a.unlinkDoc(b);
var inB = b.findMarksAt(Pos(0, 2));
eq(inB.length, 1);
is(inB[0] != shared);
var inC = c.findMarksAt(Pos(0, 2));
eq(inC.length, 1);
is(inC[0] != shared);
inC[0].clear();
is(shared.find());
});
testDoc("sharedBookmark", "A='ab\ncd\nef\ngh' B<A C<~A/1-2", function(a, b, c) {
var mark = b.setBookmark(Pos(1, 1), {shared: true});
var found = a.findMarksAt(Pos(1, 1));

View File

@ -108,10 +108,10 @@
sim("openLine", "foo bar", "Alt-F", "Ctrl-O", txt("foo\n bar"))
sim("transposeChar", "abcd\n\ne",
"Ctrl-F", "Ctrl-T", "Ctrl-T", txt("bcad\n\ne"), at(0, 3),
"Ctrl-F", "Ctrl-T", "Ctrl-T", "Ctrl-T", txt("bcda\n\ne"), at(0, 4),
"Ctrl-F", "Ctrl-T", txt("bcd\na\ne"), at(1, 1));
sim("transposeChar", "abcd\ne",
"Ctrl-F", "Ctrl-T", "Ctrl-T", txt("bcad\ne"), at(0, 3),
"Ctrl-F", "Ctrl-T", "Ctrl-T", "Ctrl-T", txt("bcda\ne"), at(0, 4),
"Ctrl-F", "Ctrl-T", txt("bcde\na"), at(1, 0));
sim("manipWordCase", "foo BAR bAZ",
"Alt-C", "Alt-L", "Alt-U", txt("Foo bar BAZ"),

View File

@ -8,3 +8,16 @@
.mt-output .mt-style {
font-size: x-small;
}
.mt-output .mt-state {
font-size: x-small;
vertical-align: top;
}
.mt-output .mt-state-row {
display: none;
}
.mt-state-unhide .mt-output .mt-state-row {
display: table-row;
}

View File

@ -52,7 +52,7 @@
pos = end;
}
text = text.replace(/\[\[|\]\]/g, function(s) {return s.charAt(0);});
tokens.push(style, text);
tokens.push({style: style, text: text});
plain += text;
}
}
@ -67,16 +67,17 @@
};
function esc(str) {
return str.replace('&', '&amp;').replace('<', '&lt;');
return str.replace('&', '&amp;').replace('<', '&lt;').replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
;
}
function compare(text, expected, mode) {
var expectedOutput = [];
for (var i = 0; i < expected.length; i += 2) {
var sty = expected[i];
for (var i = 0; i < expected.length; ++i) {
var sty = expected[i].style;
if (sty && sty.indexOf(" ")) sty = sty.split(' ').sort().join(' ');
expectedOutput.push(sty, expected[i + 1]);
expectedOutput.push({style: sty, text: expected[i].text});
}
var observedOutput = highlight(text, mode);
@ -89,7 +90,7 @@
s += '<div class="cm-s-default">';
s += 'expected:';
s += prettyPrintOutputTable(expectedOutput, diff);
s += 'observed:';
s += 'observed: [<a onclick="this.parentElement.className+=\' mt-state-unhide\'">display states</a>]';
s += prettyPrintOutputTable(observedOutput, diff);
s += '</div>';
s += '</div>';
@ -101,8 +102,21 @@
if (s) throw new Failure(s);
}
function stringify(obj) {
function replacer(key, obj) {
if (typeof obj == "function") {
var m = obj.toString().match(/function\s*[^\s(]*/);
return m ? m[0] : "function";
}
return obj;
}
if (window.JSON && JSON.stringify)
return JSON.stringify(obj, replacer, 2);
return "[unsupported]"; // Fail safely if no native JSON.
}
function highlight(string, mode) {
var state = mode.startState()
var state = mode.startState();
var lines = string.replace(/\r\n/g,'\n').split('\n');
var st = [], pos = 0;
@ -119,17 +133,21 @@
if (line == "" && mode.blankLine) mode.blankLine(state);
/* Start copied code from CodeMirror.highlight */
while (!stream.eol()) {
var compare = mode.token(stream, state), substr = stream.current();
for (var j = 0; j < 10 && stream.start >= stream.pos; j++)
var compare = mode.token(stream, state);
if (j == 10)
throw new Failure("Failed to advance the stream." + stream.string + " " + stream.pos);
var substr = stream.current();
if (compare && compare.indexOf(" ") > -1) compare = compare.split(' ').sort().join(' ');
stream.start = stream.pos;
if (pos && st[pos-2] == compare && !newLine) {
st[pos-1] += substr;
if (pos && st[pos-1].style == compare && !newLine) {
st[pos-1].text += substr;
} else if (substr) {
st[pos++] = compare; st[pos++] = substr;
st[pos++] = {style: compare, text: substr, state: stringify(state)};
}
// Give up when line is ridiculously long
if (stream.pos > 5000) {
st[pos++] = null; st[pos++] = this.text.slice(stream.pos);
st[pos++] = {style: null, text: this.text.slice(stream.pos)};
break;
}
newLine = false;
@ -142,27 +160,33 @@
function highlightOutputsDifferent(o1, o2) {
var minLen = Math.min(o1.length, o2.length);
for (var i = 0; i < minLen; ++i)
if (o1[i] != o2[i]) return i >> 1;
if (o1[i].style != o2[i].style || o1[i].text != o2[i].text) return i;
if (o1.length > minLen || o2.length > minLen) return minLen;
}
function prettyPrintOutputTable(output, diffAt) {
var s = '<table class="mt-output">';
s += '<tr>';
for (var i = 0; i < output.length; i += 2) {
var style = output[i], val = output[i+1];
for (var i = 0; i < output.length; ++i) {
var style = output[i].style, val = output[i].text;
s +=
'<td class="mt-token"' + (i == diffAt * 2 ? " style='background: pink'" : "") + '>' +
'<span class="cm-' + esc(String(style)) + '">' +
esc(val.replace(/ /g,'\xb7')) +
esc(val.replace(/ /g,'\xb7')) + // · MIDDLE DOT
'</span>' +
'</td>';
}
s += '</tr><tr>';
for (var i = 0; i < output.length; i += 2) {
s += '<td class="mt-style"><span>' + (output[i] || null) + '</span></td>';
for (var i = 0; i < output.length; ++i) {
s += '<td class="mt-style"><span>' + (output[i].style || null) + '</span></td>';
}
s += '</table>';
if(output[0].state) {
s += '</tr><tr class="mt-state-row" title="State AFTER each token">';
for (var i = 0; i < output.length; ++i) {
s += '<td class="mt-state"><pre>' + esc(output[i].state) + '</pre></td>';
}
}
s += '</tr></table>';
return s;
}
})();

View File

@ -178,6 +178,12 @@
1, 0, 2, 0,
2, 2, 2, 2));
stTest("swapLineEmptyBottomSel", "1\n2\n3",
setSel(0, 1, 1, 0),
"swapLineDown", val("2\n1\n3"), hasSel(1, 1, 2, 0),
"swapLineUp", val("1\n2\n3"), hasSel(0, 1, 1, 0),
"swapLineUp", val("1\n2\n3"), hasSel(0, 0, 0, 0));
stTest("swapLineUpFromEnd", "a\nb\nc",
Pos(2, 1), "swapLineUp",
hasSel(1, 1, 1, 1), val("a\nc\nb"));

View File

@ -1548,6 +1548,19 @@ testCM("atomicMarker", function(cm) {
eq(cm.getValue().length, 53, "del chunk");
});
testCM("selectionBias", function(cm) {
cm.markText(Pos(0, 1), Pos(0, 3), {atomic: true});
cm.setCursor(Pos(0, 2));
eqPos(cm.getCursor(), Pos(0, 3));
cm.setCursor(Pos(0, 2));
eqPos(cm.getCursor(), Pos(0, 1));
cm.setCursor(Pos(0, 2), null, {bias: -1});
eqPos(cm.getCursor(), Pos(0, 1));
cm.setCursor(Pos(0, 4));
cm.setCursor(Pos(0, 2), null, {bias: 1});
eqPos(cm.getCursor(), Pos(0, 3), "A");
}, {value: "12345"});
testCM("readOnlyMarker", function(cm) {
function mark(ll, cl, lr, cr, at) {
return cm.markText(Pos(ll, cl), Pos(lr, cr),
@ -1776,6 +1789,20 @@ testCM("lineStyleFromMode", function(cm) {
is(/^\s*cm-span\s*$/.test(spanElts[0].className));
}, {value: "line1: [br] [br]\nline2: (par) (par)\nline3: <tag> <tag>"});
testCM("lineStyleFromBlankLine", function(cm) {
CodeMirror.defineMode("lineStyleFromBlankLine_mode", function() {
return {token: function(stream) { stream.skipToEnd(); return "comment"; },
blankLine: function() { return "line-blank"; }};
});
cm.setOption("mode", "lineStyleFromBlankLine_mode");
var blankElts = byClassName(cm.getWrapperElement(), "blank");
eq(blankElts.length, 1);
eq(blankElts[0].nodeName, "PRE");
cm.replaceRange("x", Pos(1, 0));
blankElts = byClassName(cm.getWrapperElement(), "blank");
eq(blankElts.length, 0);
}, {value: "foo\n\nbar"});
CodeMirror.registerHelper("xxx", "a", "A");
CodeMirror.registerHelper("xxx", "b", "B");
CodeMirror.defineMode("yyy", function() {
@ -1876,3 +1903,16 @@ testCM("alwaysMergeSelEventWithChangeOrigin", function(cm) {
cm.undoSelection();
eq(cm.getValue(), "Va");
}, {value: "a"});
testCM("getTokenTypeAt", function(cm) {
eq(cm.getTokenTypeAt(Pos(0, 0)), "number");
eq(cm.getTokenTypeAt(Pos(0, 6)), "string");
cm.addOverlay({
token: function(stream) {
if (stream.match("foo")) return "foo";
else stream.next();
}
});
eq(byClassName(cm.getWrapperElement(), "cm-foo").length, 1);
eq(cm.getTokenTypeAt(Pos(0, 6)), "string");
}, {value: "1 + 'foo'", mode: "javascript"});

View File

@ -98,7 +98,7 @@ function copyCursor(cur) {
function forEach(arr, func) {
for (var i = 0; i < arr.length; i++) {
func(arr[i]);
func(arr[i], i, arr);
}
}
@ -258,7 +258,7 @@ testJumplist('jumplist_gg', ['g', 'g', '<C-o>'], [5,2], [5,2]);
testJumplist('jumplist_%', ['%', '<C-o>'], [1,5], [1,5]);
testJumplist('jumplist_{', ['{', '<C-o>'], [1,5], [1,5]);
testJumplist('jumplist_}', ['}', '<C-o>'], [1,5], [1,5]);
testJumplist('jumplist_\'', ['m', 'a', 'h', '\'', 'a', 'h', '<C-i>'], [1,5], [1,5]);
testJumplist('jumplist_\'', ['m', 'a', 'h', '\'', 'a', 'h', '<C-i>'], [1,0], [1,5]);
testJumplist('jumplist_`', ['m', 'a', 'h', '`', 'a', 'h', '<C-i>'], [1,5], [1,5]);
testJumplist('jumplist_*_cachedCursor', ['*', '<C-o>'], [1,3], [1,3]);
testJumplist('jumplist_#_cachedCursor', ['#', '<C-o>'], [1,3], [1,3]);
@ -1015,6 +1015,7 @@ testEdit('daW_end_punct', 'foo \tbAr.', /A/, 'daW', 'foo');
// Open and close on same line
testEdit('di(_open_spc', 'foo (bAr) baz', /\(/, 'di(', 'foo () baz');
testEdit('di)_open_spc', 'foo (bAr) baz', /\(/, 'di)', 'foo () baz');
testEdit('dib_open_spc', 'foo (bAr) baz', /\(/, 'dib', 'foo () baz');
testEdit('da(_open_spc', 'foo (bAr) baz', /\(/, 'da(', 'foo baz');
testEdit('da)_open_spc', 'foo (bAr) baz', /\(/, 'da)', 'foo baz');
@ -1028,11 +1029,26 @@ testEdit('di)_close_spc', 'foo (bAr) baz', /\)/, 'di)', 'foo () baz');
testEdit('da(_close_spc', 'foo (bAr) baz', /\)/, 'da(', 'foo baz');
testEdit('da)_close_spc', 'foo (bAr) baz', /\)/, 'da)', 'foo baz');
// delete around and inner b.
testEdit('dab_on_(_should_delete_around_()block', 'o( in(abc) )', /\(a/, 'dab', 'o( in )');
// delete around and inner B.
testEdit('daB_on_{_should_delete_around_{}block', 'o{ in{abc} }', /{a/, 'daB', 'o{ in }');
testEdit('diB_on_{_should_delete_inner_{}block', 'o{ in{abc} }', /{a/, 'diB', 'o{ in{} }');
testEdit('da{_on_{_should_delete_inner_block', 'o{ in{abc} }', /{a/, 'da{', 'o{ in }');
testEdit('di[_on_(_should_not_delete', 'foo (bAr) baz', /\(/, 'di[', 'foo (bAr) baz');
testEdit('di[_on_)_should_not_delete', 'foo (bAr) baz', /\)/, 'di[', 'foo (bAr) baz');
testEdit('da[_on_(_should_not_delete', 'foo (bAr) baz', /\(/, 'da[', 'foo (bAr) baz');
testEdit('da[_on_)_should_not_delete', 'foo (bAr) baz', /\)/, 'da[', 'foo (bAr) baz');
testMotion('di(_outside_should_stay', ['d', 'i', '('], { line: 0, ch: 0}, { line: 0, ch: 0});
// Open and close on different lines, equally indented
testEdit('di{_middle_spc', 'a{\n\tbar\n}b', /r/, 'di{', 'a{}b');
testEdit('di}_middle_spc', 'a{\n\tbar\n}b', /r/, 'di}', 'a{}b');
testEdit('da{_middle_spc', 'a{\n\tbar\n}b', /r/, 'da{', 'ab');
testEdit('da}_middle_spc', 'a{\n\tbar\n}b', /r/, 'da}', 'ab');
testEdit('daB_middle_spc', 'a{\n\tbar\n}b', /r/, 'daB', 'ab');
// open and close on diff lines, open indented less than close
testEdit('di{_middle_spc', 'a{\n\tbar\n\t}b', /r/, 'di{', 'a{}b');
@ -1125,6 +1141,13 @@ testVim('a_eol', function(cm, vim, helpers) {
helpers.assertCursorAt(0, lines[0].length);
eq('vim-insert', cm.getOption('keyMap'));
});
testVim('a_endOfSelectedArea', function(cm, vim, helpers) {
cm.setCursor(0, 0);
helpers.doKeys('v', 'j', 'l');
helpers.doKeys('A');
helpers.assertCursorAt(1, 2);
eq('vim-insert', cm.getOption('keyMap'));
}, {value: 'foo\nbar'});
testVim('i', function(cm, vim, helpers) {
cm.setCursor(0, 1);
helpers.doKeys('i');
@ -1236,6 +1259,31 @@ testVim('p_lastline', function(cm, vim, helpers) {
eq('___\n a\nd\n a\nd', cm.getValue());
helpers.assertCursorAt(1, 2);
}, { value: '___' });
testVim(']p_first_indent_is_smaller', function(cm, vim, helpers) {
helpers.getRegisterController().pushText('"', 'yank', ' abc\n def\n', true);
helpers.doKeys(']', 'p');
eq(' ___\n abc\n def', cm.getValue());
}, { value: ' ___' });
testVim(']p_first_indent_is_larger', function(cm, vim, helpers) {
helpers.getRegisterController().pushText('"', 'yank', ' abc\n def\n', true);
helpers.doKeys(']', 'p');
eq(' ___\n abc\ndef', cm.getValue());
}, { value: ' ___' });
testVim(']p_with_tab_indents', function(cm, vim, helpers) {
helpers.getRegisterController().pushText('"', 'yank', '\t\tabc\n\t\t\tdef\n', true);
helpers.doKeys(']', 'p');
eq('\t___\n\tabc\n\t\tdef', cm.getValue());
}, { value: '\t___', indentWithTabs: true});
testVim(']p_with_spaces_translated_to_tabs', function(cm, vim, helpers) {
helpers.getRegisterController().pushText('"', 'yank', ' abc\n def\n', true);
helpers.doKeys(']', 'p');
eq('\t___\n\tabc\n\t\tdef', cm.getValue());
}, { value: '\t___', indentWithTabs: true, tabSize: 2 });
testVim('[p', function(cm, vim, helpers) {
helpers.getRegisterController().pushText('"', 'yank', ' abc\n def\n', true);
helpers.doKeys('[', 'p');
eq(' abc\n def\n ___', cm.getValue());
}, { value: ' ___' });
testVim('P', function(cm, vim, helpers) {
cm.setCursor(0, 1);
helpers.getRegisterController().pushText('"', 'yank', 'abc\ndef', false);
@ -1270,11 +1318,13 @@ testVim('mark', function(cm, vim, helpers) {
cm.setCursor(2, 2);
helpers.doKeys('m', 't');
cm.setCursor(0, 0);
helpers.doKeys('\'', 't');
helpers.assertCursorAt(2, 2);
cm.setCursor(0, 0);
helpers.doKeys('`', 't');
helpers.assertCursorAt(2, 2);
cm.setCursor(2, 0);
cm.replaceRange(' h', cm.getCursor());
cm.setCursor(0, 0);
helpers.doKeys('\'', 't');
helpers.assertCursorAt(2, 3);
});
testVim('jumpToMark_next', function(cm, vim, helpers) {
cm.setCursor(2, 2);
@ -1524,13 +1574,13 @@ testVim('visual_line', function(cm, vim, helpers) {
eq(' 4\n 5', cm.getValue());
}, { value: ' 1\n 2\n 3\n 4\n 5' });
testVim('visual_marks', function(cm, vim, helpers) {
helpers.doKeys('l', 'v', 'l', 'l', 'v');
helpers.doKeys('l', 'v', 'l', 'l', 'j', 'j', 'v');
// Test visual mode marks
cm.setCursor(0, 0);
cm.setCursor(2, 1);
helpers.doKeys('\'', '<');
helpers.assertCursorAt(0, 1);
helpers.doKeys('\'', '>');
helpers.assertCursorAt(0, 3);
helpers.assertCursorAt(2, 0);
});
testVim('visual_join', function(cm, vim, helpers) {
helpers.doKeys('l', 'V', 'l', 'j', 'j', 'J');
@ -1577,7 +1627,50 @@ testVim('o_visual', function(cm,vim,helpers) {
helpers.doKeys('d');
eq('p',cm.getValue());
}, { value: 'abcd\nefgh\nijkl\nmnop'});
testVim('uppercase/lowercase_visual', function(cm, vim, helpers) {
cm.setCursor(0, 0);
helpers.doKeys('v', 'l', 'l');
helpers.doKeys('U');
helpers.assertCursorAt(0, 0);
helpers.doKeys('v', 'l', 'l');
helpers.doKeys('u');
helpers.assertCursorAt(0, 0);
helpers.doKeys('l', 'l', 'l', '.');
helpers.assertCursorAt(0, 3);
cm.setCursor(0, 0);
helpers.doKeys('q', 'a', 'v', 'j', 'U', 'q');
helpers.assertCursorAt(0, 0);
helpers.doKeys('j', '@', 'a');
helpers.assertCursorAt(1, 0);
cm.setCursor(3, 0);
helpers.doKeys('V', 'U', 'j', '.');
eq('ABCDEF\nGHIJKL\nMnopq\nSHORT LINE\nLONG LINE OF TEXT', cm.getValue());
}, { value: 'abcdef\nghijkl\nmnopq\nshort line\nlong line of text'});
testVim('visual_paste', function(cm, vim, helpers) {
cm.setCursor(0, 0);
helpers.doKeys('v', 'l', 'l', 'y', 'j', 'v', 'l', 'p');
helpers.assertCursorAt(1, 4);
eq('this is a\nunthi test for visual paste', cm.getValue());
cm.setCursor(0, 0);
// in case of pasting whole line
helpers.doKeys('y', 'y');
cm.setCursor(1, 6);
helpers.doKeys('v', 'l', 'l', 'l', 'p');
helpers.assertCursorAt(2, 0);
eq('this is a\nunthi \nthis is a\n for visual paste', cm.getValue());
}, { value: 'this is a\nunit test for visual paste'});
// This checks the contents of the register used to paste the text
testVim('v_paste_from_register', function(cm, vim, helpers) {
cm.setCursor(0, 0);
helpers.doKeys('"', 'a', 'y', 'w');
cm.setCursor(1, 0);
helpers.doKeys('v', 'p');
cm.openDialog = helpers.fakeOpenDialog('registers');
cm.openNotification = helpers.fakeOpenNotification(function(text) {
is(/a\s+register/.test(text));
});
}, { value: 'register contents\nare not erased'});
testVim('S_normal', function(cm, vim, helpers) {
cm.setCursor(0, 1);
helpers.doKeys('j', 'S');
@ -1750,6 +1843,22 @@ testVim('#', function(cm, vim, helpers) {
helpers.doKeys('#');
helpers.assertCursorAt(1, 8);
}, { value: ' := match nomatch match \nnomatch Match' });
testVim('g*', function(cm, vim, helpers) {
cm.setCursor(0, 8);
helpers.doKeys('g', '*');
helpers.assertCursorAt(0, 18);
cm.setCursor(0, 8);
helpers.doKeys('3', 'g', '*');
helpers.assertCursorAt(1, 8);
}, { value: 'matches match alsoMatch\nmatchme matching' });
testVim('g#', function(cm, vim, helpers) {
cm.setCursor(0, 8);
helpers.doKeys('g', '#');
helpers.assertCursorAt(0, 0);
cm.setCursor(0, 8);
helpers.doKeys('3', 'g', '#');
helpers.assertCursorAt(1, 0);
}, { value: 'matches match alsoMatch\nmatchme matching' });
testVim('macro_insert', function(cm, vim, helpers) {
cm.setCursor(0, 0);
helpers.doKeys('q', 'a', '0', 'i');
@ -1769,6 +1878,46 @@ testVim('macro_space', function(cm, vim, helpers) {
helpers.doKeys('@', 'a');
helpers.assertCursorAt(0, 8);
}, { value: 'one line of text.'});
testVim('macro_t_search', function(cm, vim, helpers) {
cm.setCursor(0, 0);
helpers.doKeys('q', 'a', 't', 'e', 'q');
helpers.assertCursorAt(0, 1);
helpers.doKeys('l', '@', 'a');
helpers.assertCursorAt(0, 6);
helpers.doKeys('l', ';');
helpers.assertCursorAt(0, 12);
}, { value: 'one line of text.'});
testVim('macro_f_search', function(cm, vim, helpers) {
cm.setCursor(0, 0);
helpers.doKeys('q', 'b', 'f', 'e', 'q');
helpers.assertCursorAt(0, 2);
helpers.doKeys('@', 'b');
helpers.assertCursorAt(0, 7);
helpers.doKeys(';');
helpers.assertCursorAt(0, 13);
}, { value: 'one line of text.'});
testVim('macro_slash_search', function(cm, vim, helpers) {
cm.setCursor(0, 0);
helpers.doKeys('q', 'c');
cm.openDialog = helpers.fakeOpenDialog('e');
helpers.doKeys('/', 'q');
helpers.assertCursorAt(0, 2);
helpers.doKeys('@', 'c');
helpers.assertCursorAt(0, 7);
helpers.doKeys('n');
helpers.assertCursorAt(0, 13);
}, { value: 'one line of text.'});
testVim('macro_multislash_search', function(cm, vim, helpers) {
cm.setCursor(0, 0);
helpers.doKeys('q', 'd');
cm.openDialog = helpers.fakeOpenDialog('e');
helpers.doKeys('/');
cm.openDialog = helpers.fakeOpenDialog('t');
helpers.doKeys('/', 'q');
helpers.assertCursorAt(0, 12);
helpers.doKeys('@', 'd');
helpers.assertCursorAt(0, 15);
}, { value: 'one line of text to rule them all.'});
testVim('macro_parens', function(cm, vim, helpers) {
cm.setCursor(0, 0);
helpers.doKeys('q', 'z', 'i');
@ -1827,6 +1976,50 @@ testVim('yank_register', function(cm, vim, helpers) {
});
helpers.doKeys(':');
}, { value: 'foo\nbar'});
testVim('yank_append_line_to_line_register', function(cm, vim, helpers) {
cm.setCursor(0, 0);
helpers.doKeys('"', 'a', 'y', 'y');
helpers.doKeys('j', '"', 'A', 'y', 'y');
cm.openDialog = helpers.fakeOpenDialog('registers');
cm.openNotification = helpers.fakeOpenNotification(function(text) {
is(/a\s+foo\nbar/.test(text));
is(/"\s+foo\nbar/.test(text));
});
helpers.doKeys(':');
}, { value: 'foo\nbar'});
testVim('yank_append_word_to_word_register', function(cm, vim, helpers) {
cm.setCursor(0, 0);
helpers.doKeys('"', 'a', 'y', 'w');
helpers.doKeys('j', '"', 'A', 'y', 'w');
cm.openDialog = helpers.fakeOpenDialog('registers');
cm.openNotification = helpers.fakeOpenNotification(function(text) {
is(/a\s+foobar/.test(text));
is(/"\s+foobar/.test(text));
});
helpers.doKeys(':');
}, { value: 'foo\nbar'});
testVim('yank_append_line_to_word_register', function(cm, vim, helpers) {
cm.setCursor(0, 0);
helpers.doKeys('"', 'a', 'y', 'w');
helpers.doKeys('j', '"', 'A', 'y', 'y');
cm.openDialog = helpers.fakeOpenDialog('registers');
cm.openNotification = helpers.fakeOpenNotification(function(text) {
is(/a\s+foo\nbar/.test(text));
is(/"\s+foo\nbar/.test(text));
});
helpers.doKeys(':');
}, { value: 'foo\nbar'});
testVim('yank_append_word_to_line_register', function(cm, vim, helpers) {
cm.setCursor(0, 0);
helpers.doKeys('"', 'a', 'y', 'y');
helpers.doKeys('j', '"', 'A', 'y', 'w');
cm.openDialog = helpers.fakeOpenDialog('registers');
cm.openNotification = helpers.fakeOpenNotification(function(text) {
is(/a\s+foo\nbar/.test(text));
is(/"\s+foo\nbar/.test(text));
});
helpers.doKeys(':');
}, { value: 'foo\nbar'});
testVim('macro_register', function(cm, vim, helpers) {
cm.setCursor(0, 0);
helpers.doKeys('q', 'a', 'i');
@ -1844,6 +2037,25 @@ testVim('macro_register', function(cm, vim, helpers) {
});
helpers.doKeys(':');
}, { value: ''});
testVim('._register', function(cm,vim,helpers) {
cm.setCursor(0,0);
helpers.doKeys('i');
cm.replaceRange('foo',cm.getCursor());
helpers.doInsertModeKeys('Esc');
cm.openDialog = helpers.fakeOpenDialog('registers');
cm.openNotification = helpers.fakeOpenNotification(function(text) {
is(/\.\s+foo/.test(text));
});
helpers.doKeys(':');
}, {value: ''});
testVim(':_register', function(cm,vim,helpers) {
helpers.doEx('bar');
cm.openDialog = helpers.fakeOpenDialog('registers');
cm.openNotification = helpers.fakeOpenNotification(function(text) {
is(/:\s+bar/.test(text));
});
helpers.doKeys(':');
}, {value: ''});
testVim('.', function(cm, vim, helpers) {
cm.setCursor(0, 0);
helpers.doKeys('2', 'd', 'w');
@ -1947,6 +2159,14 @@ testVim('._delete_repeat', function(cm, vim, helpers) {
eq('zzce', cm.getValue());
helpers.assertCursorAt(0, 1);
}, { value: 'zzabcde'});
testVim('._visual_>', function(cm, vim, helpers) {
cm.setCursor(0, 0);
helpers.doKeys('V', 'j', '>');
cm.setCursor(2, 0)
helpers.doKeys('.');
eq(' 1\n 2\n 3\n 4', cm.getValue());
helpers.assertCursorAt(2, 2);
}, { value: '1\n2\n3\n4'});
testVim('f;', function(cm, vim, helpers) {
cm.setCursor(0, 0);
helpers.doKeys('f', 'x');
@ -2155,7 +2375,8 @@ testVim('HML', function(cm, vim, helpers) {
return upper + lower;
})()});
var zVals = ['zb','zz','zt','z-','z.','z<CR>'].map(function(e, idx){
var zVals = [];
forEach(['zb','zz','zt','z-','z.','z<CR>'], function(e, idx){
var lineNum = 250;
var lines = 35;
testVim(e, function(cm, vim, helpers) {
@ -2496,6 +2717,13 @@ testVim('ex_substitute_javascript', function(cm, vim, helpers) {
helpers.doEx('s/\\(\\d+\\)/$$ $\' $` $& \\1/')
eq('a $$ $\' $` $& 0 b', cm.getValue());
}, { value: 'a 0 b' });
testVim('ex_substitute_empty_arguments', function(cm,vim,helpers) {
cm.setCursor(0, 0);
helpers.doEx('s/a/b');
cm.setCursor(1, 0);
helpers.doEx('s');
eq('b b\nb b', cm.getValue());
}, {value: 'a a\na a'});
// More complex substitute tests that test both pcre and nopcre options.
function testSubstitute(name, options) {
@ -2857,3 +3085,5 @@ testVim('beforeSelectionChange', function(cm, vim, helpers) {
cm.setCursor(0, 100);
eqPos(cm.getCursor('head'), cm.getCursor('anchor'));
}, { value: 'abc' });

View File

@ -7,6 +7,7 @@ support-files =
doc_simple-node-creation.html
doc_buffer-and-array.html
doc_media-node-creation.html
doc_destroy-nodes.html
440hz_sine.ogg
head.js
@ -17,6 +18,7 @@ support-files =
[browser_audionode-actor-get-param-flags.js]
[browser_audionode-actor-is-source.js]
[browser_webaudio-actor-simple.js]
[browser_webaudio-actor-destroy-node.js]
[browser_wa_first-run.js]
[browser_wa_reset-01.js]

View File

@ -0,0 +1,41 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* Test `destroy-node` event on WebAudioActor.
*/
function spawnTest () {
let [target, debuggee, front] = yield initBackend(DESTROY_NODES_URL);
let waitUntilDestroyed = getN(front, "destroy-node", 10);
let [_, _, created] = yield Promise.all([
front.setup({ reload: true }),
once(front, "start-context"),
// Should create 1 destination node and 10 disposable buffer nodes
getN(front, "create-node", 13)
]);
// Force CC so we can ensure it's run to clear out dead AudioNodes
forceCC();
let destroyed = yield waitUntilDestroyed;
let destroyedTypes = yield Promise.all(destroyed.map(actor => actor.getType()));
destroyedTypes.forEach((type, i) => {
ok(type, "AudioBufferSourceNode", "Only buffer nodes are destroyed");
ok(actorIsInList(created, destroyed[i]),
"`destroy-node` called only on AudioNodes in current document.");
});
yield removeTab(target.tab);
finish();
}
function actorIsInList (list, actor) {
for (let i = 0; i < list.length; i++) {
if (list[i].actorID === actor.actorID)
return list[i];
}
return null;
}

View File

@ -0,0 +1,32 @@
<!-- Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ -->
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title>Web Audio Editor test page</title>
</head>
<body>
<script type="text/javascript;version=1.8">
"use strict";
(function () {
let ctx = new AudioContext();
let osc = ctx.createOscillator();
let gain = ctx.createGain();
for (let i = 0; i < 10; i++) {
ctx.createBufferSource();
}
osc.connect(gain);
gain.connect(ctx.destination);
gain.gain.value = 0;
osc.start();
})();
</script>
</body>
</html>

View File

@ -26,6 +26,7 @@ const COMPLEX_CONTEXT_URL = EXAMPLE_URL + "doc_complex-context.html";
const SIMPLE_NODES_URL = EXAMPLE_URL + "doc_simple-node-creation.html";
const MEDIA_NODES_URL = EXAMPLE_URL + "doc_media-node-creation.html";
const BUFFER_AND_ARRAY_URL = EXAMPLE_URL + "doc_buffer-and-array.html";
const DESTROY_NODES_URL = EXAMPLE_URL + "doc_destroy-nodes.html";
// All tests are asynchronous.
waitForExplicitFinish();
@ -372,6 +373,15 @@ function countGraphObjects (win) {
}
}
/**
* Forces cycle collection and GC, used in AudioNode destruction tests.
*/
function forceCC () {
SpecialPowers.DOMWindowUtils.cycleCollect();
SpecialPowers.DOMWindowUtils.garbageCollect();
SpecialPowers.DOMWindowUtils.garbageCollect();
}
/**
* List of audio node properties to test against expectations of the AudioNode actor
*/

View File

@ -44,7 +44,7 @@
<command id="cmd_showAddons" oncommand="Cmds.showAddons()"/>
<command id="cmd_showTroubleShooting" oncommand="Cmds.showTroubleShooting()"/>
<command id="cmd_play" oncommand="Cmds.play()"/>
<command id="cmd_stop" oncommand="Cmds.stop()"/>
<command id="cmd_stop" oncommand="Cmds.stop()" label="&projectMenu_stop_label;"/>
<command id="cmd_toggleToolbox" oncommand="Cmds.toggleToolbox()"/>
</commandset>
</commandset>
@ -58,7 +58,7 @@
<menuitem command="cmd_showProjectPanel" key="key_showProjectPanel" label="&projectMenu_selectApp_label;" accesskey="&projectMenu_selectApp_accessley;"/>
<menuseparator/>
<menuitem command="cmd_play" key="key_play" label="&projectMenu_play_label;" accesskey="&projectMenu_play_accesskey;"/>
<menuitem command="cmd_stop" key="key_stop" label="&projectMenu_stop_label;" accesskey="&projectMenu_stop_accesskey;"/>
<menuitem command="cmd_stop" accesskey="&projectMenu_stop_accesskey;"/>
<menuitem command="cmd_toggleToolbox" key="key_toggleToolbox" label="&projectMenu_debug_label;" accesskey="&projectMenu_debug_accesskey;"/>
<menuseparator/>
<menuitem command="cmd_removeProject" accesskey="&projectMenu_remove_accesskey;"/>
@ -88,7 +88,6 @@
<key key="&key_quit;" id="key_quit" command="cmd_quit" modifiers="accel"/>
<key key="&key_showProjectPanel;" id="key_showProjectPanel" command="cmd_showProjectPanel" modifiers="accel"/>
<key key="&key_play;" id="key_play" command="cmd_play" modifiers="accel"/>
<key key="&key_stop;" id="key_stop" command="cmd_stop" modifiers="accel"/>
<key key="&key_toggleEditor;" id="key_toggleEditor" command="cmd_toggleEditor" modifiers="accel"/>
<key keycode="&key_toggleToolbox;" id="key_toggleToolbox" command="cmd_toggleToolbox"/>
</keyset>

View File

@ -2,7 +2,7 @@
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<!ENTITY windowTitle "Firefox App Manager">
<!ENTITY windowTitle "Firefox WebIDE">
<!ENTITY projectMenu_label "Project">
<!ENTITY projectMenu_accesskey "P">
@ -46,13 +46,11 @@
<!-- We try to repicate Firefox' bindings: -->
<!-- quit app -->
<!ENTITY key_quit "Q">
<!ENTITY key_quit "W">
<!-- open menu -->
<!ENTITY key_showProjectPanel "O">
<!-- reload app -->
<!ENTITY key_play "R">
<!-- close app -->
<!ENTITY key_stop "W">
<!-- show toolbox -->
<!ENTITY key_toggleToolbox "VK_F12">
<!-- toggle sidebar -->

View File

@ -2,8 +2,8 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
title_noApp=Firefox App Manager
title_app=Firefox App Manager: %S
title_noApp=Firefox WebIDE
title_app=Firefox WebIDE: %S
runtimeButton_label=Select Runtime
projectButton_label=Open App

View File

@ -259,6 +259,8 @@ These should match what Safari and other Apple applications use on OS X Lion. --
<!ENTITY devToolbarMenu.accesskey "v">
<!ENTITY devAppMgrMenu.label "App Manager">
<!ENTITY devAppMgrMenu.accesskey "A">
<!ENTITY webide.label "WebIDE">
<!ENTITY webide.accesskey "W">
<!ENTITY devToolbar.keycode "VK_F2">
<!ENTITY devToolbar.keytext "F2">
<!ENTITY devToolboxMenuItem.label "Toggle Tools">

View File

@ -1400,3 +1400,20 @@ injectManual2=Inject common libraries into the content of the page which can als
injectLibraryDesc=Select the library to inject or enter a valid script URI to inject
injectLoaded=%1$S loaded
injectFailed=Failed to load %1$S - Invalid URI
# LOCALIZATION NOTE (folderDesc, folderOpenDesc, folderOpenDir,
# folderOpenProfileDesc) These strings describe the 'folder' commands and
# all available parameters.
folderDesc=Open folders
folderOpenDesc=Open folder path
folderOpenDir=Directory Path
folderOpenProfileDesc=Open profile directory
# LOCALIZATION NOTE (folderInvalidPath) A string displayed as the result
# of the 'folder open' command with an invalid folder path.
folderInvalidPath=Please enter a valid path
# LOCALIZATION NOTE (folderOpenDirResult) A very short string used to
# describe the result of the 'folder open' command.
# The argument (%1$S) is the folder path.
folderOpenDirResult=Opened %1$S

View File

@ -13,37 +13,52 @@
# LOCALIZATION NOTE (projecteditor.deleteLabel):
# This string is displayed as a context menu item for allowing the selected
# file / folder to be deleted
# file / folder to be deleted.
projecteditor.deleteLabel=Delete
# LOCALIZATION NOTE (projecteditor.deletePromptTitle):
# This string is displayed as as the title of the confirm prompt that checks
# to make sure if a file or folder should be removed.
projecteditor.deletePromptTitle=Delete
# LOCALIZATION NOTE (projecteditor.deleteFolderPromptMessage):
# This string is displayed as as the message of the confirm prompt that checks
# to make sure if a folder should be removed.
projecteditor.deleteFolderPromptMessage=Are you sure you want to delete this folder?
# LOCALIZATION NOTE (projecteditor.deleteFilePromptMessage):
# This string is displayed as as the message of the confirm prompt that checks
# to make sure if a file should be removed.
projecteditor.deleteFilePromptMessage=Are you sure you want to delete this file?
# LOCALIZATION NOTE (projecteditor.newLabel):
# This string is displayed as a context menu item for adding a new file to
# the directory
# the directory.
projecteditor.newLabel=New…
# LOCALIZATION NOTE (projecteditor.selectFileLabel):
# This string is displayed as the title on the file picker when saving a file
# This string is displayed as the title on the file picker when saving a file.
projecteditor.selectFileLabel=Select a File
# LOCALIZATION NOTE (projecteditor.openFolderLabel):
# This string is displayed as the title on the file picker when opening a folder
# This string is displayed as the title on the file picker when opening a folder.
projecteditor.openFolderLabel=Select a Folder
# LOCALIZATION NOTE (projecteditor.openFileLabel):
# This string is displayed as the title on the file picker when opening a file
# This string is displayed as the title on the file picker when opening a file.
projecteditor.openFileLabel=Open a File
# LOCALIZATION NOTE (projecteditor.find.commandkey): This is the key to use in
# conjunction with accel (Command on Mac or Ctrl on other platforms) to search
# text in the files
# text in the files.
projecteditor.find.commandkey=F
# LOCALIZATION NOTE (projecteditor.save.commandkey): This is the key to use in
# conjunction with accel (Command on Mac or Ctrl on other platforms) to
# save the file. It is used with accel+shift to "save as"
# save the file. It is used with accel+shift to "save as".
projecteditor.save.commandkey=S
# LOCALIZATION NOTE (projecteditor.new.commandkey): This is the key to use in
# conjunction with accel (Command on Mac or Ctrl on other platforms) to
# create a new file
# create a new file.
projecteditor.new.commandkey=N

View File

@ -39,6 +39,10 @@
background: rgb(237, 237, 237);
}
#sources {
overflow: auto;
}
.sources-tree {
overflow:auto;
overflow-x: hidden;

View File

@ -36,17 +36,20 @@ AlarmDB.prototype = {
this.initDBHelper(ALARMDB_NAME, ALARMDB_VERSION, [ALARMSTORE_NAME]);
},
upgradeSchema: function upgradeSchema(aTransaction, aDb, aOldVersion, aNewVersion) {
upgradeSchema: function upgradeSchema(aTransaction, aDb,
aOldVersion, aNewVersion) {
debug("upgradeSchema()");
let objectStore = aDb.createObjectStore(ALARMSTORE_NAME, { keyPath: "id", autoIncrement: true });
let objStore =
aDb.createObjectStore(ALARMSTORE_NAME,
{ keyPath: "id", autoIncrement: true });
objectStore.createIndex("date", "date", { unique: false });
objectStore.createIndex("ignoreTimezone", "ignoreTimezone", { unique: false });
objectStore.createIndex("timezoneOffset", "timezoneOffset", { unique: false });
objectStore.createIndex("data", "data", { unique: false });
objectStore.createIndex("pageURL", "pageURL", { unique: false });
objectStore.createIndex("manifestURL", "manifestURL", { unique: false });
objStore.createIndex("date", "date", { unique: false });
objStore.createIndex("ignoreTimezone", "ignoreTimezone", { unique: false });
objStore.createIndex("timezoneOffset", "timezoneOffset", { unique: false });
objStore.createIndex("data", "data", { unique: false });
objStore.createIndex("pageURL", "pageURL", { unique: false });
objStore.createIndex("manifestURL", "manifestURL", { unique: false });
debug("Created object stores and indexes");
},
@ -62,19 +65,13 @@ AlarmDB.prototype = {
add: function add(aAlarm, aSuccessCb, aErrorCb) {
debug("add()");
this.newTxn(
"readwrite",
ALARMSTORE_NAME,
function txnCb(aTxn, aStore) {
debug("Going to add " + JSON.stringify(aAlarm));
aStore.put(aAlarm).onsuccess = function setTxnResult(aEvent) {
aTxn.result = aEvent.target.result;
debug("Request successful. New record ID: " + aTxn.result);
};
},
aSuccessCb,
aErrorCb
);
this.newTxn("readwrite", ALARMSTORE_NAME, function txnCb(aTxn, aStore) {
debug("Going to add " + JSON.stringify(aAlarm));
aStore.put(aAlarm).onsuccess = function setTxnResult(aEvent) {
aTxn.result = aEvent.target.result;
debug("Request successful. New record ID: " + aTxn.result);
};
}, aSuccessCb, aErrorCb);
},
/**
@ -92,33 +89,27 @@ AlarmDB.prototype = {
remove: function remove(aId, aManifestURL, aSuccessCb, aErrorCb) {
debug("remove()");
this.newTxn(
"readwrite",
ALARMSTORE_NAME,
function txnCb(aTxn, aStore) {
debug("Going to remove " + aId);
this.newTxn("readwrite", ALARMSTORE_NAME, function txnCb(aTxn, aStore) {
debug("Going to remove " + aId);
// Look up the existing record and compare the manifestURL
// to see if the alarm to be removed belongs to this app.
aStore.get(aId).onsuccess = function doRemove(aEvent) {
let alarm = aEvent.target.result;
// Look up the existing record and compare the manifestURL
// to see if the alarm to be removed belongs to this app.
aStore.get(aId).onsuccess = function doRemove(aEvent) {
let alarm = aEvent.target.result;
if (!alarm) {
debug("Alarm doesn't exist. No need to remove it.");
return;
}
if (!alarm) {
debug("Alarm doesn't exist. No need to remove it.");
return;
}
if (aManifestURL && aManifestURL != alarm.manifestURL) {
debug("Cannot remove the alarm added by other apps.");
return;
}
if (aManifestURL && aManifestURL != alarm.manifestURL) {
debug("Cannot remove the alarm added by other apps.");
return;
}
aStore.delete(aId);
};
},
aSuccessCb,
aErrorCb
);
aStore.delete(aId);
};
}, aSuccessCb, aErrorCb);
},
/**
@ -134,22 +125,16 @@ AlarmDB.prototype = {
getAll: function getAll(aManifestURL, aSuccessCb, aErrorCb) {
debug("getAll()");
this.newTxn(
"readonly",
ALARMSTORE_NAME,
function txnCb(aTxn, aStore) {
if (!aTxn.result) {
aTxn.result = [];
}
this.newTxn("readonly", ALARMSTORE_NAME, function txnCb(aTxn, aStore) {
if (!aTxn.result) {
aTxn.result = [];
}
let index = aStore.index("manifestURL");
index.mozGetAll(aManifestURL).onsuccess = function setTxnResult(aEvent) {
aTxn.result = aEvent.target.result;
debug("Request successful. Record count: " + aTxn.result.length);
};
},
aSuccessCb,
aErrorCb
);
let index = aStore.index("manifestURL");
index.mozGetAll(aManifestURL).onsuccess = function setTxnResult(aEvent) {
aTxn.result = aEvent.target.result;
debug("Request successful. Record count: " + aTxn.result.length);
};
}, aSuccessCb, aErrorCb);
}
};

View File

@ -29,11 +29,13 @@ XPCOMUtils.defineLazyServiceGetter(this, "ppmm",
"nsIMessageListenerManager");
XPCOMUtils.defineLazyGetter(this, "messenger", function() {
return Cc["@mozilla.org/system-message-internal;1"].getService(Ci.nsISystemMessagesInternal);
return Cc["@mozilla.org/system-message-internal;1"]
.getService(Ci.nsISystemMessagesInternal);
});
XPCOMUtils.defineLazyGetter(this, "powerManagerService", function() {
return Cc["@mozilla.org/power/powermanagerservice;1"].getService(Ci.nsIPowerManagerService);
return Cc["@mozilla.org/power/powermanagerservice;1"]
.getService(Ci.nsIPowerManagerService);
});
/**
@ -50,14 +52,14 @@ XPCOMUtils.defineLazyGetter(this, "powerManagerService", function() {
this.AlarmService = {
init: function init() {
debug("init()");
Services.obs.addObserver(this, "profile-change-teardown", false);
Services.obs.addObserver(this, "webapps-clear-data",false);
this._currentTimezoneOffset = (new Date()).getTimezoneOffset();
let alarmHalService =
this._alarmHalService = Cc["@mozilla.org/alarmHalService;1"]
.getService(Ci.nsIAlarmHalService);
let alarmHalService = this._alarmHalService =
Cc["@mozilla.org/alarmHalService;1"].getService(Ci.nsIAlarmHalService);
alarmHalService.setAlarmFiredCb(this._onAlarmFired.bind(this));
alarmHalService.setTimezoneChangedCb(this._onTimezoneChanged.bind(this));
@ -109,6 +111,7 @@ this.AlarmService = {
debug("Got message from a child process with no 'alarms' permission.");
return null;
}
if (!aMessage.target.assertContainApp(json.manifestURL)) {
debug("Got message from a child process containing illegal manifest URL.");
return null;
@ -116,37 +119,34 @@ this.AlarmService = {
}
let mm = aMessage.target.QueryInterface(Ci.nsIMessageSender);
switch (aMessage.name) {
case "AlarmsManager:GetAll":
this._db.getAll(
json.manifestURL,
this._db.getAll(json.manifestURL,
function getAllSuccessCb(aAlarms) {
debug("Callback after getting alarms from database: " +
JSON.stringify(aAlarms));
this._sendAsyncMessage(mm, "GetAll", true, json.requestId, aAlarms);
}.bind(this),
function getAllErrorCb(aErrorMsg) {
this._sendAsyncMessage(mm, "GetAll", false, json.requestId, aErrorMsg);
}.bind(this)
);
}.bind(this));
break;
case "AlarmsManager:Add":
// Prepare a record for the new alarm to be added.
let newAlarm = {
date: json.date,
ignoreTimezone: json.ignoreTimezone,
data: json.data,
pageURL: json.pageURL,
manifestURL: json.manifestURL
};
let newAlarm = { date: json.date,
ignoreTimezone: json.ignoreTimezone,
data: json.data,
pageURL: json.pageURL,
manifestURL: json.manifestURL };
this.add(newAlarm, null,
// Receives the alarm ID as the last argument.
this._sendAsyncMessage.bind(this, mm, "Add", true, json.requestId),
// Receives the error message as the last argument.
this._sendAsyncMessage.bind(this, mm, "Add", false, json.requestId)
);
this._sendAsyncMessage.bind(this, mm, "Add", false, json.requestId));
break;
case "AlarmsManager:Remove":
@ -169,8 +169,7 @@ this.AlarmService = {
}
let json = null;
switch (aMessageName)
{
switch (aMessageName) {
case "Add":
json = aSuccess ?
{ requestId: aRequestId, id: aData } :
@ -189,7 +188,8 @@ this.AlarmService = {
}
aMessageManager.sendAsyncMessage("AlarmsManager:" + aMessageName +
":Return:" + (aSuccess ? "OK" : "KO"), json);
":Return:" + (aSuccess ? "OK" : "KO"),
json);
},
_removeAlarmFromDb: function _removeAlarmFromDb(aId, aManifestURL,
@ -204,14 +204,10 @@ this.AlarmService = {
};
}
this._db.remove(
aId,
aManifestURL,
aRemoveSuccessCb,
function removeErrorCb(aErrorMsg) {
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
}
);
this._db.remove(aId, aManifestURL, aRemoveSuccessCb,
function removeErrorCb(aErrorMsg) {
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
});
},
/**
@ -220,13 +216,11 @@ this.AlarmService = {
* boolean |ignoreTimezone| field.
*/
_publicAlarm: function _publicAlarm(aAlarm) {
let alarm = {
"id": aAlarm.id,
"date": aAlarm.date,
"respectTimezone": aAlarm.ignoreTimezone ?
"ignoreTimezone" : "honorTimezone",
"data": aAlarm.data
};
let alarm = { "id": aAlarm.id,
"date": aAlarm.date,
"respectTimezone": aAlarm.ignoreTimezone ?
"ignoreTimezone" : "honorTimezone",
"data": aAlarm.data };
return alarm;
},
@ -237,8 +231,10 @@ this.AlarmService = {
let manifestURI = Services.io.newURI(aAlarm.manifestURL, null, null);
let pageURI = Services.io.newURI(aAlarm.pageURL, null, null);
messenger.sendMessage("alarm", this._publicAlarm(aAlarm),
pageURI, manifestURI);
messenger.sendMessage("alarm",
this._publicAlarm(aAlarm),
pageURI,
manifestURI);
},
_notifyAlarmObserver: function _notifyAlarmObserver(aAlarm) {
@ -276,6 +272,7 @@ this.AlarmService = {
break;
}
}
this._debugCurrentAlarm();
},
@ -289,8 +286,7 @@ this.AlarmService = {
_restoreAlarmsFromDb: function _restoreAlarmsFromDb() {
debug("_restoreAlarmsFromDb()");
this._db.getAll(
null,
this._db.getAll(null,
function getAllSuccessCb(aAlarms) {
debug("Callback after getting alarms from database: " +
JSON.stringify(aAlarms));
@ -311,7 +307,7 @@ this.AlarmService = {
}
}.bind(this));
// Set the next alarm from queue.
// Set the next alarm from the queue.
if (alarmQueue.length) {
alarmQueue.sort(this._sortAlarmByTimeStamps.bind(this));
this._currentAlarm = alarmQueue.shift();
@ -321,8 +317,7 @@ this.AlarmService = {
}.bind(this),
function getAllErrorCb(aErrorMsg) {
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
}
);
});
},
_getAlarmTime: function _getAlarmTime(aAlarm) {
@ -341,7 +336,8 @@ this.AlarmService = {
// is located at Paris. We can adjust the alarm UTC time by calculating
// the difference of the orginal timezone and the current timezone.
if (aAlarm.ignoreTimezone) {
alarmTime += (this._currentTimezoneOffset - aAlarm.timezoneOffset) * 60000;
alarmTime +=
(this._currentTimezoneOffset - aAlarm.timezoneOffset) * 60000;
}
return alarmTime;
},
@ -402,8 +398,7 @@ this.AlarmService = {
aNewAlarm['timezoneOffset'] = this._currentTimezoneOffset;
this._db.add(
aNewAlarm,
this._db.add(aNewAlarm,
function addSuccessCb(aNewId) {
debug("Callback after adding alarm in database.");
@ -422,7 +417,7 @@ this.AlarmService = {
}
// If the new alarm is earlier than the current alarm, swap them and
// push the previous alarm back to queue.
// push the previous alarm back to the queue.
let alarmQueue = this._alarmQueue;
let aNewAlarmTime = this._getAlarmTime(aNewAlarm);
let currentAlarmTime = this._getAlarmTime(this._currentAlarm);
@ -442,8 +437,7 @@ this.AlarmService = {
}.bind(this),
function addErrorCb(aErrorMsg) {
aErrorCb(aErrorMsg);
}.bind(this)
);
}.bind(this));
},
/*
@ -457,9 +451,8 @@ this.AlarmService = {
*/
remove: function(aAlarmId, aManifestURL) {
debug("remove(" + aAlarmId + ", " + aManifestURL + ")");
this._removeAlarmFromDb(
aAlarmId,
aManifestURL,
this._removeAlarmFromDb(aAlarmId, aManifestURL,
function removeSuccessCb() {
debug("Callback after removing alarm from database.");
@ -488,7 +481,7 @@ this.AlarmService = {
}
// The alarm to be removed is the current alarm reset the next alarm
// from queue if any.
// from the queue if any.
if (alarmQueue.length) {
this._currentAlarm = alarmQueue.shift();
this._debugCurrentAlarm();
@ -498,15 +491,17 @@ this.AlarmService = {
// No alarm waiting to be set in the queue.
this._currentAlarm = null;
this._debugCurrentAlarm();
}.bind(this)
);
}.bind(this));
},
observe: function(aSubject, aTopic, aData) {
debug("observe(): " + aTopic);
switch (aTopic) {
case "profile-change-teardown":
this.uninit();
break;
case "webapps-clear-data":
let params =
aSubject.QueryInterface(Ci.mozIApplicationClearPrivateDataParams);
@ -526,8 +521,7 @@ this.AlarmService = {
return;
}
this._db.getAll(
manifestURL,
this._db.getAll(manifestURL,
function getAllSuccessCb(aAlarms) {
aAlarms.forEach(function removeAlarm(aAlarm) {
this.remove(aAlarm.id, manifestURL);
@ -535,14 +529,14 @@ this.AlarmService = {
}.bind(this),
function getAllErrorCb(aErrorMsg) {
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
}
);
});
break;
}
},
uninit: function uninit() {
debug("uninit()");
Services.obs.removeObserver(this, "profile-change-teardown");
Services.obs.removeObserver(this, "webapps-clear-data");

View File

@ -18,13 +18,11 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/DOMRequestHelper.jsm");
function AlarmsManager()
{
function AlarmsManager() {
debug("Constructor");
}
AlarmsManager.prototype = {
__proto__: DOMRequestIpcHelper.prototype,
contractID : "@mozilla.org/alarmsManager;1",
@ -48,6 +46,7 @@ AlarmsManager.prototype = {
}
let isIgnoreTimezone = true;
switch (aRespectTimezone) {
case "honorTimezone":
isIgnoreTimezone = false;
@ -63,35 +62,30 @@ AlarmsManager.prototype = {
}
let request = this.createRequest();
this._cpmm.sendAsyncMessage(
"AlarmsManager:Add",
{ requestId: this.getRequestId(request),
date: aDate,
ignoreTimezone: isIgnoreTimezone,
data: aData,
pageURL: this._pageURL,
manifestURL: this._manifestURL }
);
this._cpmm.sendAsyncMessage("AlarmsManager:Add",
{ requestId: this.getRequestId(request),
date: aDate,
ignoreTimezone: isIgnoreTimezone,
data: aData,
pageURL: this._pageURL,
manifestURL: this._manifestURL });
return request;
},
remove: function remove(aId) {
debug("remove()");
this._cpmm.sendAsyncMessage(
"AlarmsManager:Remove",
{ id: aId, manifestURL: this._manifestURL }
);
this._cpmm.sendAsyncMessage("AlarmsManager:Remove",
{ id: aId, manifestURL: this._manifestURL });
},
getAll: function getAll() {
debug("getAll()");
let request = this.createRequest();
this._cpmm.sendAsyncMessage(
"AlarmsManager:GetAll",
{ requestId: this.getRequestId(request), manifestURL: this._manifestURL }
);
this._cpmm.sendAsyncMessage("AlarmsManager:GetAll",
{ requestId: this.getRequestId(request),
manifestURL: this._manifestURL });
return request;
},
@ -115,13 +109,14 @@ AlarmsManager.prototype = {
// We don't need to expose everything to the web content.
let alarms = [];
json.alarms.forEach(function trimAlarmInfo(aAlarm) {
let alarm = { "id": aAlarm.id,
"date": aAlarm.date,
let alarm = { "id": aAlarm.id,
"date": aAlarm.date,
"respectTimezone": aAlarm.ignoreTimezone ?
"ignoreTimezone" : "honorTimezone",
"data": aAlarm.data };
"data": aAlarm.data };
alarms.push(alarm);
});
Services.DOMRequest.fireSuccess(request,
Cu.cloneInto(alarms, this._window));
break;
@ -138,6 +133,7 @@ AlarmsManager.prototype = {
debug("Wrong message: " + aMessage.name);
break;
}
this.removeRequest(json.requestId);
},

View File

@ -11,9 +11,14 @@ interface nsIDOMMozCellBroadcastEtwsInfo;
* MozCellBroadcastMessage encapsulates Cell Broadcast short message service
* (CBS) messages.
*/
[scriptable, uuid(701e74a9-5fc4-4e2d-a324-9b7693395159)]
[scriptable, uuid(dc729df4-f1d8-11e3-b00d-d3332542c557)]
interface nsIDOMMozCellBroadcastMessage : nsISupports
{
/**
* The Service Id in the device where the message is received from.
*/
readonly attribute unsigned long serviceId;
/**
* Indication of the geographical area over which the Message Code is unique,
* and the display mode.

View File

@ -0,0 +1,229 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
const {Cc: Cc, Ci: Ci, Cr: Cr, Cu: Cu} = SpecialPowers;
let Promise = Cu.import("resource://gre/modules/Promise.jsm").Promise;
/**
* Push required permissions and test if |navigator.mozCellBroadcast| exists.
* Resolve if it does, reject otherwise.
*
* Fulfill params:
* cbManager -- an reference to navigator.mozCellBroadcast.
*
* Reject params: (none)
*
* @return A deferred promise.
*/
let cbManager;
function ensureCellBroadcast() {
let deferred = Promise.defer();
let permissions = [{
"type": "cellbroadcast",
"allow": 1,
"context": document,
}];
SpecialPowers.pushPermissions(permissions, function() {
ok(true, "permissions pushed: " + JSON.stringify(permissions));
cbManager = window.navigator.mozCellBroadcast;
if (cbManager) {
log("navigator.mozCellBroadcast is instance of " + cbManager.constructor);
} else {
log("navigator.mozCellBroadcast is undefined.");
}
if (cbManager instanceof window.MozCellBroadcast) {
deferred.resolve(cbManager);
} else {
deferred.reject();
}
});
return deferred.promise;
}
/**
* Send emulator command with safe guard.
*
* We should only call |finish()| after all emulator command transactions
* end, so here comes with the pending counter. Resolve when the emulator
* gives positive response, and reject otherwise.
*
* Fulfill params:
* result -- an array of emulator response lines.
*
* Reject params:
* result -- an array of emulator response lines.
*
* @return A deferred promise.
*/
let pendingEmulatorCmdCount = 0;
function runEmulatorCmdSafe(aCommand) {
let deferred = Promise.defer();
++pendingEmulatorCmdCount;
runEmulatorCmd(aCommand, function(aResult) {
--pendingEmulatorCmdCount;
ok(true, "Emulator response: " + JSON.stringify(aResult));
if (Array.isArray(aResult) && aResult[aResult.length - 1] === "OK") {
deferred.resolve(aResult);
} else {
deferred.reject(aResult);
}
});
return deferred.promise;
}
/**
* Send raw CBS PDU to emulator.
*
* @param: aPdu
* A hex string representing the whole CBS PDU.
*
* Fulfill params:
* result -- an array of emulator response lines.
*
* Reject params:
* result -- an array of emulator response lines.
*
* @return A deferred promise.
*/
function sendRawCbsToEmulator(aPdu) {
let command = "cbs pdu " + aPdu;
return runEmulatorCmdSafe(command);
}
/**
* Wait for one named Cellbroadcast event.
*
* Resolve if that named event occurs. Never reject.
*
* Fulfill params: the DOMEvent passed.
*
* @param aEventName
* A string event name.
*
* @return A deferred promise.
*/
function waitForManagerEvent(aEventName) {
let deferred = Promise.defer();
cbManager.addEventListener(aEventName, function onevent(aEvent) {
cbManager.removeEventListener(aEventName, onevent);
ok(true, "Cellbroadcast event '" + aEventName + "' got.");
deferred.resolve(aEvent);
});
return deferred.promise;
}
/**
* Send multiple raw CB PDU to emulator and wait
*
* @param: aPdus
* A array of hex strings. Each represents a CB PDU.
* These PDUs are expected to be concatenated into single CB Message.
*
* Fulfill params:
* result -- array of resolved Promise, where
* result[0].message representing the received message.
* result[1-n] represents the response of sent emulator command.
*
* Reject params:
* result -- an array of emulator response lines.
*
* @return A deferred promise.
*/
function sendMultipleRawCbsToEmulatorAndWait(aPdus) {
let promises = [];
promises.push(waitForManagerEvent("received"));
for (let pdu of aPdus) {
promises.push(sendRawCbsToEmulator(pdu));
}
return Promise.all(promises);
}
/**
* Flush permission settings and call |finish()|.
*/
function cleanUp() {
waitFor(function() {
SpecialPowers.flushPermissions(function() {
// Use ok here so that we have at least one test run.
ok(true, "permissions flushed");
finish();
});
}, function() {
return pendingEmulatorCmdCount === 0;
});
}
/**
* Switch modem for receving upcoming emulator commands.
*
* @param: aServiceId
* The id of the modem to be switched to.
*
* Fulfill params:
* result -- an array of emulator response lines.
*
* Reject params:
* result -- an array of emulator response lines.
*
* @return A deferred promise.
*/
function selectModem(aServiceId) {
let command = "mux modem " + aServiceId;
return runEmulatorCmdSafe(command);
}
/**
* Helper to run the test case only needed in Multi-SIM environment.
*
* @param aTest
* A function which will be invoked w/o parameter.
* @return a Promise object.
*/
function runIfMultiSIM(aTest) {
let numRIL;
try {
numRIL = SpecialPowers.getIntPref("ril.numRadioInterfaces");
} catch (ex) {
numRIL = 1; // Pref not set.
}
if (numRIL > 1) {
return aTest();
} else {
log("Not a Multi-SIM environment. Test is skipped.");
return Promise.resolve();
}
}
/**
* Common test routine helper for cell broadcast tests.
*
* This function ensures global |cbManager| variable is available during the
* process and performs clean-ups as well.
*
* @param aTestCaseMain
* A function that takes no parameter.
*/
function startTestCommon(aTestCaseMain) {
Promise.resolve()
.then(ensureCellBroadcast)
.then(aTestCaseMain)
.then(cleanUp, function() {
ok(false, 'promise rejects during test.');
cleanUp();
});
}

View File

@ -5,3 +5,4 @@ qemu = true
[test_cellbroadcast_etws.js]
[test_cellbroadcast_gsm.js]
[test_cellbroadcast_multi_sim.js]

View File

@ -0,0 +1,34 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
MARIONETTE_TIMEOUT = 60000;
MARIONETTE_HEAD_JS = 'head.js';
const BODY_7BITS = "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
+ "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
+ "@@@@@@@@@@@@@"; // 93 ascii chars.
const CB_PDU_SIZE = 88;
function testReceivingMultiSIM() {
let CB_PDU = "";
while (CB_PDU.length < CB_PDU_SIZE * 2) {
CB_PDU += "00";
}
let verifyCBMessage = (aMessage, aServiceId) => {
log("Verify CB message received from serviceId: " + aServiceId);
is(aMessage.body, BODY_7BITS, "Checking message body.");
is(aMessage.serviceId, aServiceId, "Checking serviceId.");
};
return selectModem(1)
.then(() => sendMultipleRawCbsToEmulatorAndWait([CB_PDU]))
.then((results) => verifyCBMessage(results[0].message, 1))
.then(() => selectModem(0))
.then(() => sendMultipleRawCbsToEmulatorAndWait([CB_PDU]))
.then((results) => verifyCBMessage(results[0].message, 0));
}
startTestCommon(function testCaseMain() {
return runIfMultiSIM(testReceivingMultiSIM);
});

View File

@ -574,7 +574,7 @@ MozInputContext.prototype = {
contextId: self._contextId,
requestId: resolverId,
text: text,
cursor: cursor || text.length,
cursor: (typeof cursor !== 'undefined') ? cursor : text.length,
clauses: clauses || null
});
});

View File

@ -305,7 +305,8 @@ MobileCallForwardingInfo.prototype = {
serviceClass: 'r'}
};
function CellBroadcastMessage(pdu) {
function CellBroadcastMessage(clientId, pdu) {
this.serviceId = clientId;
this.gsmGeographicalScope = RIL.CB_GSM_GEOGRAPHICAL_SCOPE_NAMES[pdu.geographicalScope];
this.messageCode = pdu.messageCode;
this.messageId = pdu.messageId;
@ -331,6 +332,7 @@ CellBroadcastMessage.prototype = {
}),
// nsIDOMMozCellBroadcastMessage
serviceId: -1,
gsmGeographicalScope: null,
messageCode: null,
@ -1544,13 +1546,17 @@ RILContentHelper.prototype = {
registerCellBroadcastMsg: function(listener) {
if (DEBUG) debug("Registering for Cell Broadcast related messages");
//TODO: Bug 921326 - Cellbroadcast API: support multiple sim cards
// Instead of registering multiple listeners for Multi-SIM, we reuse
// clientId 0 to route all CBS messages to single listener and provide the
// |clientId| info by |CellBroadcastMessage.serviceId|.
this.registerListener("_cellBroadcastListeners", 0, listener);
cpmm.sendAsyncMessage("RIL:RegisterCellBroadcastMsg");
},
unregisterCellBroadcastMsg: function(listener) {
//TODO: Bug 921326 - Cellbroadcast API: support multiple sim cards
// Instead of unregistering multiple listeners for Multi-SIM, we reuse
// clientId 0 to route all CBS messages to single listener and provide the
// |clientId| info by |CellBroadcastMessage.serviceId|.
this.unregisterListener("_cellBroadcastListeners", 0, listener);
},
@ -1824,8 +1830,10 @@ RILContentHelper.prototype = {
this.handleSimpleRequest(data.requestId, data.errorMsg, null);
break;
case "RIL:CellBroadcastReceived": {
let message = new CellBroadcastMessage(data);
this._deliverEvent(clientId,
// All CBS messages are to routed the listener for clientId 0 and
// provide the |clientId| info by |CellBroadcastMessage.serviceId|.
let message = new CellBroadcastMessage(clientId, data);
this._deliverEvent(0, // route to clientId 0.
"_cellBroadcastListeners",
"notifyMessageReceived",
[message]);

Some files were not shown because too many files have changed in this diff Show More