Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
Merge pull request #7179 from adobe/cmv4
Browse files Browse the repository at this point in the history
Integrate CodeMirror v4 and implement multiple selections
  • Loading branch information
njx committed Mar 12, 2014
2 parents e4c289f + bb4a634 commit 098d360
Show file tree
Hide file tree
Showing 55 changed files with 4,896 additions and 1,054 deletions.
22 changes: 17 additions & 5 deletions src/LiveDevelopment/Agents/HighlightAgent.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ define(function HighlightAgent(require, exports, module) {
var DOMAgent = require("LiveDevelopment/Agents/DOMAgent"),
Inspector = require("LiveDevelopment/Inspector/Inspector"),
LiveDevelopment = require("LiveDevelopment/LiveDevelopment"),
RemoteAgent = require("LiveDevelopment/Agents/RemoteAgent");
RemoteAgent = require("LiveDevelopment/Agents/RemoteAgent"),
_ = require("thirdparty/lodash");

var _highlight = {}; // active highlight

Expand Down Expand Up @@ -108,11 +109,22 @@ define(function HighlightAgent(require, exports, module) {
}

/** Highlight all nodes with 'data-brackets-id' value
* that matches id.
* @param {string} value of the 'data-brackets-id' to match
* that matches id, or if id is an array, matches any of the given ids.
* @param {string|Array<string>} value of the 'data-brackets-id' to match,
* or an array of such.
*/
function domElement(id) {
rule("[data-brackets-id='" + id + "']");
function domElement(ids) {
var selector = "";
if (!Array.isArray(ids)) {
ids = [ids];
}
_.each(ids, function (id) {
if (selector !== "") {
selector += ",";
}
selector += "[data-brackets-id='" + id + "']";
});
rule(selector);
}

/**
Expand Down
15 changes: 11 additions & 4 deletions src/LiveDevelopment/Documents/CSSDocument.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,17 @@ define(function CSSDocumentModule(require, exports, module) {

CSSDocument.prototype.updateHighlight = function () {
if (Inspector.config.highlight && this.editor) {
var codeMirror = this.editor._codeMirror;
var selector = CSSUtils.findSelectorAtDocumentPos(this.editor, codeMirror.getCursor());
if (selector) {
HighlightAgent.rule(selector);
var editor = this.editor,
codeMirror = editor._codeMirror,
selectors = [];
_.each(this.editor.getSelections(), function (sel) {
var selector = CSSUtils.findSelectorAtDocumentPos(editor, (sel.reversed ? sel.end : sel.start));
if (selector) {
selectors.push(selector);
}
});
if (selectors.length) {
HighlightAgent.rule(selectors.join(","));
} else {
HighlightAgent.hide();
}
Expand Down
24 changes: 16 additions & 8 deletions src/LiveDevelopment/Documents/HTMLDocument.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ define(function HTMLDocumentModule(require, exports, module) {
LiveDevelopment = require("LiveDevelopment/LiveDevelopment"),
PerfUtils = require("utils/PerfUtils"),
RemoteAgent = require("LiveDevelopment/Agents/RemoteAgent"),
StringUtils = require("utils/StringUtils");
StringUtils = require("utils/StringUtils"),
_ = require("thirdparty/lodash");

/**
* Constructor
Expand Down Expand Up @@ -140,17 +141,24 @@ define(function HTMLDocumentModule(require, exports, module) {

/** Update the highlight */
HTMLDocument.prototype.updateHighlight = function () {
var codeMirror = this.editor._codeMirror;
var editor = this.editor,
codeMirror = editor._codeMirror,
ids = [];
if (Inspector.config.highlight) {
var tagID = HTMLInstrumentation._getTagIDAtDocumentPos(
this.editor,
codeMirror.getCursor()
);
_.each(this.editor.getSelections(), function (sel) {
var tagID = HTMLInstrumentation._getTagIDAtDocumentPos(
editor,
sel.reversed ? sel.end : sel.start
);
if (tagID !== -1) {
ids.push(tagID);
}
});

if (tagID === -1) {
if (!ids.length) {
HighlightAgent.hide();
} else {
HighlightAgent.domElement(tagID);
HighlightAgent.domElement(ids);
}
}
};
Expand Down
34 changes: 34 additions & 0 deletions src/base-config/keyboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@
"platform": "mac"
}
],
"edit.splitSelIntoLines": [
"Ctrl-Alt-L"
],
"edit.addPrevLineToSel": [
{
"key": "Shift-Alt-Up",
"displayKey": "Shift-Alt-↑"
}
],
"edit.addNextLineToSel": [
{
"key": "Shift-Alt-Down",
"displayKey": "Shift-Alt-↓"
}
],
"edit.find": [
"Ctrl-F"
],
Expand All @@ -89,6 +104,25 @@
"platform": "mac"
}
],
"edit.findAllAndSelect": [
{
"key": "Alt-F3"
},
{
"key": "Cmd-Ctrl-G",
"platform": "mac"
}
],
"edit.addNextMatch": [
{
"key": "Ctrl-B"
}
],
"edit.skipCurrentMatch": [
{
"key": "Ctrl-Shift-B"
}
],
"edit.replace": [
{
"key": "Ctrl-H"
Expand Down
12 changes: 12 additions & 0 deletions src/brackets.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ define(function (require, exports, module) {
require("widgets/bootstrap-twipsy-mod");
require("thirdparty/path-utils/path-utils.min");
require("thirdparty/smart-auto-complete-local/jquery.smart_autocomplete");

// Load CodeMirror add-ons--these attach themselves to the CodeMirror module
require("thirdparty/CodeMirror2/addon/fold/xml-fold");
require("thirdparty/CodeMirror2/addon/edit/matchtags");
require("thirdparty/CodeMirror2/addon/edit/matchbrackets");
require("thirdparty/CodeMirror2/addon/edit/closebrackets");
require("thirdparty/CodeMirror2/addon/edit/closetag");
require("thirdparty/CodeMirror2/addon/selection/active-line");
require("thirdparty/CodeMirror2/addon/mode/multiplex");
require("thirdparty/CodeMirror2/addon/mode/overlay");
require("thirdparty/CodeMirror2/addon/search/searchcursor");
require("thirdparty/CodeMirror2/keymap/sublime");

// Load dependent modules
var Global = require("utils/Global"),
Expand Down
8 changes: 7 additions & 1 deletion src/command/Commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,20 @@ define(function (require, exports, module) {
exports.EDIT_SELECT_ALL = "edit.selectAll"; // EditorCommandHandlers.js _handleSelectAll()

exports.EDIT_SELECT_LINE = "edit.selectLine"; // EditorCommandHandlers.js selectLine()
exports.EDIT_SPLIT_SEL_INTO_LINES = "edit.splitSelIntoLines"; // EditorCommandHandlers.js splitSelIntoLines()
exports.EDIT_ADD_NEXT_LINE_TO_SEL = "edit.addNextLineToSel"; // EditorCommandHandlers.js addNextLineToSel()
exports.EDIT_ADD_PREV_LINE_TO_SEL = "edit.addPrevLineToSel"; // EditorCommandHandlers.js addPrevLineToSel()
exports.EDIT_FIND = "edit.find"; // FindReplace.js _launchFind()
exports.EDIT_FIND_IN_FILES = "edit.findInFiles"; // FindInFiles.js _doFindInFiles()
exports.EDIT_FIND_IN_SUBTREE = "edit.findInSubtree"; // FindInFiles.js _doFindInSubtree()
exports.EDIT_FIND_NEXT = "edit.findNext"; // FindReplace.js _findNext()
exports.EDIT_FIND_PREVIOUS = "edit.findPrevious"; // FindReplace.js _findPrevious()
exports.EDIT_FIND_ALL_AND_SELECT = "edit.findAllAndSelect"; // FindReplace.js _findAllAndSelect()
exports.EDIT_ADD_NEXT_MATCH = "edit.addNextMatch"; // FindReplace.js _expandAndAddNextToSelection()
exports.EDIT_SKIP_CURRENT_MATCH = "edit.skipCurrentMatch"; // FindReplace.js _skipCurrentMatch()
exports.EDIT_REPLACE = "edit.replace"; // FindReplace.js _replace()
exports.EDIT_INDENT = "edit.indent"; // EditorCommandHandlers.js indentText()
exports.EDIT_UNINDENT = "edit.unindent"; // EditorCommandHandlers.js unidentText()
exports.EDIT_UNINDENT = "edit.unindent"; // EditorCommandHandlers.js unindentText()
exports.EDIT_DUPLICATE = "edit.duplicate"; // EditorCommandHandlers.js duplicateText()
exports.EDIT_DELETE_LINES = "edit.deletelines"; // EditorCommandHandlers.js deleteCurrentLines()
exports.EDIT_LINE_COMMENT = "edit.lineComment"; // EditorCommandHandlers.js lineComment()
Expand Down
7 changes: 6 additions & 1 deletion src/command/DefaultMenus.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,17 @@ define(function (require, exports, module) {
menu.addMenuDivider();
menu.addMenuItem(Commands.EDIT_SELECT_ALL);
menu.addMenuItem(Commands.EDIT_SELECT_LINE);
menu.addMenuItem(Commands.EDIT_SPLIT_SEL_INTO_LINES);
menu.addMenuItem(Commands.EDIT_ADD_PREV_LINE_TO_SEL);
menu.addMenuItem(Commands.EDIT_ADD_NEXT_LINE_TO_SEL);
menu.addMenuDivider();
menu.addMenuItem(Commands.EDIT_FIND);
menu.addMenuItem(Commands.EDIT_FIND_IN_FILES);
menu.addMenuItem(Commands.EDIT_FIND_NEXT);

menu.addMenuItem(Commands.EDIT_FIND_PREVIOUS);
menu.addMenuItem(Commands.EDIT_FIND_ALL_AND_SELECT);
menu.addMenuItem(Commands.EDIT_ADD_NEXT_MATCH);
menu.addMenuItem(Commands.EDIT_SKIP_CURRENT_MATCH);

menu.addMenuDivider();
menu.addMenuItem(Commands.EDIT_REPLACE);
Expand Down
2 changes: 1 addition & 1 deletion src/dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

window.setTimeout(function () {
"use strict";
var deps = { "Mustache": window.Mustache, "jQuery": window.$, "CodeMirror": window.CodeMirror, "RequireJS": window.require };
var deps = { "Mustache": window.Mustache, "jQuery": window.$, "RequireJS": window.require };
var key, missingDeps = [];
for (key in deps) {
if (deps.hasOwnProperty(key) && !deps[key]) {
Expand Down
Loading

0 comments on commit 098d360

Please sign in to comment.