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

Commit 098d360

Browse files
author
Narciso Jaramillo
committed
Merge pull request #7179 from adobe/cmv4
Integrate CodeMirror v4 and implement multiple selections
2 parents e4c289f + bb4a634 commit 098d360

55 files changed

Lines changed: 4896 additions & 1054 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/LiveDevelopment/Agents/HighlightAgent.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ define(function HighlightAgent(require, exports, module) {
3737
var DOMAgent = require("LiveDevelopment/Agents/DOMAgent"),
3838
Inspector = require("LiveDevelopment/Inspector/Inspector"),
3939
LiveDevelopment = require("LiveDevelopment/LiveDevelopment"),
40-
RemoteAgent = require("LiveDevelopment/Agents/RemoteAgent");
40+
RemoteAgent = require("LiveDevelopment/Agents/RemoteAgent"),
41+
_ = require("thirdparty/lodash");
4142

4243
var _highlight = {}; // active highlight
4344

@@ -108,11 +109,22 @@ define(function HighlightAgent(require, exports, module) {
108109
}
109110

110111
/** Highlight all nodes with 'data-brackets-id' value
111-
* that matches id.
112-
* @param {string} value of the 'data-brackets-id' to match
112+
* that matches id, or if id is an array, matches any of the given ids.
113+
* @param {string|Array<string>} value of the 'data-brackets-id' to match,
114+
* or an array of such.
113115
*/
114-
function domElement(id) {
115-
rule("[data-brackets-id='" + id + "']");
116+
function domElement(ids) {
117+
var selector = "";
118+
if (!Array.isArray(ids)) {
119+
ids = [ids];
120+
}
121+
_.each(ids, function (id) {
122+
if (selector !== "") {
123+
selector += ",";
124+
}
125+
selector += "[data-brackets-id='" + id + "']";
126+
});
127+
rule(selector);
116128
}
117129

118130
/**

src/LiveDevelopment/Documents/CSSDocument.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,17 @@ define(function CSSDocumentModule(require, exports, module) {
159159

160160
CSSDocument.prototype.updateHighlight = function () {
161161
if (Inspector.config.highlight && this.editor) {
162-
var codeMirror = this.editor._codeMirror;
163-
var selector = CSSUtils.findSelectorAtDocumentPos(this.editor, codeMirror.getCursor());
164-
if (selector) {
165-
HighlightAgent.rule(selector);
162+
var editor = this.editor,
163+
codeMirror = editor._codeMirror,
164+
selectors = [];
165+
_.each(this.editor.getSelections(), function (sel) {
166+
var selector = CSSUtils.findSelectorAtDocumentPos(editor, (sel.reversed ? sel.end : sel.start));
167+
if (selector) {
168+
selectors.push(selector);
169+
}
170+
});
171+
if (selectors.length) {
172+
HighlightAgent.rule(selectors.join(","));
166173
} else {
167174
HighlightAgent.hide();
168175
}

src/LiveDevelopment/Documents/HTMLDocument.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ define(function HTMLDocumentModule(require, exports, module) {
5252
LiveDevelopment = require("LiveDevelopment/LiveDevelopment"),
5353
PerfUtils = require("utils/PerfUtils"),
5454
RemoteAgent = require("LiveDevelopment/Agents/RemoteAgent"),
55-
StringUtils = require("utils/StringUtils");
55+
StringUtils = require("utils/StringUtils"),
56+
_ = require("thirdparty/lodash");
5657

5758
/**
5859
* Constructor
@@ -140,17 +141,24 @@ define(function HTMLDocumentModule(require, exports, module) {
140141

141142
/** Update the highlight */
142143
HTMLDocument.prototype.updateHighlight = function () {
143-
var codeMirror = this.editor._codeMirror;
144+
var editor = this.editor,
145+
codeMirror = editor._codeMirror,
146+
ids = [];
144147
if (Inspector.config.highlight) {
145-
var tagID = HTMLInstrumentation._getTagIDAtDocumentPos(
146-
this.editor,
147-
codeMirror.getCursor()
148-
);
148+
_.each(this.editor.getSelections(), function (sel) {
149+
var tagID = HTMLInstrumentation._getTagIDAtDocumentPos(
150+
editor,
151+
sel.reversed ? sel.end : sel.start
152+
);
153+
if (tagID !== -1) {
154+
ids.push(tagID);
155+
}
156+
});
149157

150-
if (tagID === -1) {
158+
if (!ids.length) {
151159
HighlightAgent.hide();
152160
} else {
153-
HighlightAgent.domElement(tagID);
161+
HighlightAgent.domElement(ids);
154162
}
155163
}
156164
};

src/base-config/keyboard.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,21 @@
6565
"platform": "mac"
6666
}
6767
],
68+
"edit.splitSelIntoLines": [
69+
"Ctrl-Alt-L"
70+
],
71+
"edit.addPrevLineToSel": [
72+
{
73+
"key": "Shift-Alt-Up",
74+
"displayKey": "Shift-Alt-↑"
75+
}
76+
],
77+
"edit.addNextLineToSel": [
78+
{
79+
"key": "Shift-Alt-Down",
80+
"displayKey": "Shift-Alt-↓"
81+
}
82+
],
6883
"edit.find": [
6984
"Ctrl-F"
7085
],
@@ -89,6 +104,25 @@
89104
"platform": "mac"
90105
}
91106
],
107+
"edit.findAllAndSelect": [
108+
{
109+
"key": "Alt-F3"
110+
},
111+
{
112+
"key": "Cmd-Ctrl-G",
113+
"platform": "mac"
114+
}
115+
],
116+
"edit.addNextMatch": [
117+
{
118+
"key": "Ctrl-B"
119+
}
120+
],
121+
"edit.skipCurrentMatch": [
122+
{
123+
"key": "Ctrl-Shift-B"
124+
}
125+
],
92126
"edit.replace": [
93127
{
94128
"key": "Ctrl-H"

src/brackets.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ define(function (require, exports, module) {
4444
require("widgets/bootstrap-twipsy-mod");
4545
require("thirdparty/path-utils/path-utils.min");
4646
require("thirdparty/smart-auto-complete-local/jquery.smart_autocomplete");
47+
48+
// Load CodeMirror add-ons--these attach themselves to the CodeMirror module
49+
require("thirdparty/CodeMirror2/addon/fold/xml-fold");
50+
require("thirdparty/CodeMirror2/addon/edit/matchtags");
51+
require("thirdparty/CodeMirror2/addon/edit/matchbrackets");
52+
require("thirdparty/CodeMirror2/addon/edit/closebrackets");
53+
require("thirdparty/CodeMirror2/addon/edit/closetag");
54+
require("thirdparty/CodeMirror2/addon/selection/active-line");
55+
require("thirdparty/CodeMirror2/addon/mode/multiplex");
56+
require("thirdparty/CodeMirror2/addon/mode/overlay");
57+
require("thirdparty/CodeMirror2/addon/search/searchcursor");
58+
require("thirdparty/CodeMirror2/keymap/sublime");
4759

4860
// Load dependent modules
4961
var Global = require("utils/Global"),

src/command/Commands.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,20 @@ define(function (require, exports, module) {
6969
exports.EDIT_SELECT_ALL = "edit.selectAll"; // EditorCommandHandlers.js _handleSelectAll()
7070

7171
exports.EDIT_SELECT_LINE = "edit.selectLine"; // EditorCommandHandlers.js selectLine()
72+
exports.EDIT_SPLIT_SEL_INTO_LINES = "edit.splitSelIntoLines"; // EditorCommandHandlers.js splitSelIntoLines()
73+
exports.EDIT_ADD_NEXT_LINE_TO_SEL = "edit.addNextLineToSel"; // EditorCommandHandlers.js addNextLineToSel()
74+
exports.EDIT_ADD_PREV_LINE_TO_SEL = "edit.addPrevLineToSel"; // EditorCommandHandlers.js addPrevLineToSel()
7275
exports.EDIT_FIND = "edit.find"; // FindReplace.js _launchFind()
7376
exports.EDIT_FIND_IN_FILES = "edit.findInFiles"; // FindInFiles.js _doFindInFiles()
7477
exports.EDIT_FIND_IN_SUBTREE = "edit.findInSubtree"; // FindInFiles.js _doFindInSubtree()
7578
exports.EDIT_FIND_NEXT = "edit.findNext"; // FindReplace.js _findNext()
7679
exports.EDIT_FIND_PREVIOUS = "edit.findPrevious"; // FindReplace.js _findPrevious()
80+
exports.EDIT_FIND_ALL_AND_SELECT = "edit.findAllAndSelect"; // FindReplace.js _findAllAndSelect()
81+
exports.EDIT_ADD_NEXT_MATCH = "edit.addNextMatch"; // FindReplace.js _expandAndAddNextToSelection()
82+
exports.EDIT_SKIP_CURRENT_MATCH = "edit.skipCurrentMatch"; // FindReplace.js _skipCurrentMatch()
7783
exports.EDIT_REPLACE = "edit.replace"; // FindReplace.js _replace()
7884
exports.EDIT_INDENT = "edit.indent"; // EditorCommandHandlers.js indentText()
79-
exports.EDIT_UNINDENT = "edit.unindent"; // EditorCommandHandlers.js unidentText()
85+
exports.EDIT_UNINDENT = "edit.unindent"; // EditorCommandHandlers.js unindentText()
8086
exports.EDIT_DUPLICATE = "edit.duplicate"; // EditorCommandHandlers.js duplicateText()
8187
exports.EDIT_DELETE_LINES = "edit.deletelines"; // EditorCommandHandlers.js deleteCurrentLines()
8288
exports.EDIT_LINE_COMMENT = "edit.lineComment"; // EditorCommandHandlers.js lineComment()

src/command/DefaultMenus.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,17 @@ define(function (require, exports, module) {
7878
menu.addMenuDivider();
7979
menu.addMenuItem(Commands.EDIT_SELECT_ALL);
8080
menu.addMenuItem(Commands.EDIT_SELECT_LINE);
81+
menu.addMenuItem(Commands.EDIT_SPLIT_SEL_INTO_LINES);
82+
menu.addMenuItem(Commands.EDIT_ADD_PREV_LINE_TO_SEL);
83+
menu.addMenuItem(Commands.EDIT_ADD_NEXT_LINE_TO_SEL);
8184
menu.addMenuDivider();
8285
menu.addMenuItem(Commands.EDIT_FIND);
8386
menu.addMenuItem(Commands.EDIT_FIND_IN_FILES);
8487
menu.addMenuItem(Commands.EDIT_FIND_NEXT);
85-
8688
menu.addMenuItem(Commands.EDIT_FIND_PREVIOUS);
89+
menu.addMenuItem(Commands.EDIT_FIND_ALL_AND_SELECT);
90+
menu.addMenuItem(Commands.EDIT_ADD_NEXT_MATCH);
91+
menu.addMenuItem(Commands.EDIT_SKIP_CURRENT_MATCH);
8792

8893
menu.addMenuDivider();
8994
menu.addMenuItem(Commands.EDIT_REPLACE);

src/dependencies.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
window.setTimeout(function () {
2828
"use strict";
29-
var deps = { "Mustache": window.Mustache, "jQuery": window.$, "CodeMirror": window.CodeMirror, "RequireJS": window.require };
29+
var deps = { "Mustache": window.Mustache, "jQuery": window.$, "RequireJS": window.require };
3030
var key, missingDeps = [];
3131
for (key in deps) {
3232
if (deps.hasOwnProperty(key) && !deps[key]) {

0 commit comments

Comments
 (0)