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

Commit 943e23a

Browse files
committed
Merge branch 'master' into alf_localization
2 parents 378b879 + 252b40a commit 943e23a

File tree

10 files changed

+76
-46
lines changed

10 files changed

+76
-46
lines changed

src/LiveDevelopment/Agents/GotoAgent.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ define(function GotoAgent(require, exports, module) {
3333

3434
require("utils/Global");
3535

36-
var Inspector = require("LiveDevelopment/Inspector/Inspector");
37-
var DOMAgent = require("LiveDevelopment/Agents/DOMAgent");
38-
var ScriptAgent = require("LiveDevelopment/Agents/ScriptAgent");
39-
var RemoteAgent = require("LiveDevelopment/Agents/RemoteAgent");
40-
41-
var DocumentManager = require("document/DocumentManager");
42-
var EditorManager = require("editor/EditorManager");
43-
var MainViewManager = require("view/MainViewManager");
36+
var Inspector = require("LiveDevelopment/Inspector/Inspector"),
37+
DOMAgent = require("LiveDevelopment/Agents/DOMAgent"),
38+
ScriptAgent = require("LiveDevelopment/Agents/ScriptAgent"),
39+
RemoteAgent = require("LiveDevelopment/Agents/RemoteAgent"),
40+
EditorManager = require("editor/EditorManager"),
41+
CommandManager = require("command/CommandManager"),
42+
Commands = require("command/Commands");
43+
4444

4545
/** Return the URL without the query string
4646
* @param {string} URL
@@ -168,9 +168,8 @@ define(function GotoAgent(require, exports, module) {
168168
var path = url.slice(brackets.platform === "win" ? 8 : 7);
169169
// URL-decode the path ('%20' => ' ')
170170
path = decodeURI(path);
171-
var promise = DocumentManager.getDocumentForPath(path);
171+
var promise = CommandManager.execute(Commands.FILE_OPEN, {fullPath: path});
172172
promise.done(function onDone(doc) {
173-
MainViewManager._edit(MainViewManager.ACTIVE_PANE, doc);
174173
if (location) {
175174
openLocation(location, noFlash);
176175
}

src/command/KeyBindingManager.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ define(function (require, exports, module) {
10431043
function _undoPriorUserKeyBindings() {
10441044
_.forEach(_customKeyMapCache, function (commandID, key) {
10451045
var normalizedKey = normalizeKeyDescriptorString(key),
1046-
defaults = KeyboardPrefs[commandID],
1046+
defaults = _.find(_.toArray(_defaultKeyMap), { "commandID": commandID }),
10471047
defaultCommand = _defaultKeyMap[normalizedKey];
10481048

10491049
// We didn't modified this before, so skip it.
@@ -1057,11 +1057,11 @@ define(function (require, exports, module) {
10571057
// Unassign the key from any command. e.g. "Cmd-W": "file.open" in _customKeyMapCache
10581058
// will require us to remove Cmd-W shortcut from file.open command.
10591059
removeBinding(normalizedKey);
1060-
1060+
10611061
// Reassign the default key binding. e.g. "Cmd-W": "file.open" in _customKeyMapCache
10621062
// will require us to reassign Cmd-O shortcut to file.open command.
1063-
if (defaults.length) {
1064-
addBinding(commandID, defaults);
1063+
if (defaults) {
1064+
addBinding(commandID, defaults, brackets.platform);
10651065
}
10661066

10671067
// Reassign the default key binding of the previously modified command.
@@ -1149,9 +1149,7 @@ define(function (require, exports, module) {
11491149
function _loadUserKeyMap() {
11501150
_readUserKeyMap()
11511151
.then(function (keyMap) {
1152-
if (_.size(_customKeyMap)) {
1153-
_customKeyMapCache = _.cloneDeep(_customKeyMap);
1154-
}
1152+
_customKeyMapCache = _.cloneDeep(_customKeyMap);
11551153
_customKeyMap = keyMap;
11561154
_undoPriorUserKeyBindings();
11571155
_applyUserKeyBindings();

src/document/DocumentManager.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,24 @@ define(function (require, exports, module) {
586586
$(exports).triggerHandler("dirtyFlagChange", doc);
587587
if (doc.isDirty) {
588588
MainViewManager.addToWorkingSet(MainViewManager.ACTIVE_PANE, doc.file);
589+
590+
// We just dirtied a doc and added it to the active working set
591+
// this may have come from an internal dirtying so if it was
592+
// added to a working set that had no active document then
593+
// open the document
594+
//
595+
// See: https://github.com/adobe/brackets/issues/9569
596+
//
597+
// NOTE: Adding a file to the active working set may not actually add
598+
// it to the active working set (e.g. the document was already
599+
// opened to the inactive working set.)
600+
//
601+
// Check that it was actually added to the active working set
602+
603+
if (!MainViewManager.getCurrentlyViewedFile() &&
604+
MainViewManager.findInWorkingSet(MainViewManager.ACTIVE_PANE, doc.file.fullPath) !== -1) {
605+
CommandManager.execute(Commands.FILE_OPEN, {fullPath: doc.file.fullPath});
606+
}
589607
}
590608
})
591609
.on("_documentSaved", function (event, doc) {

src/extensions/default/DebugCommands/keyboard.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"key": "Shift-F5"
2323
},
2424
{
25-
"key": "Cmd-Shift-R",
25+
"key": "Cmd-Ctrl-R",
2626
"platform": "mac"
2727
}
2828
]

src/extensions/default/QuickOpenCSS/main.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ define(function (require, exports, module) {
3232
var EditorManager = brackets.getModule("editor/EditorManager"),
3333
QuickOpen = brackets.getModule("search/QuickOpen"),
3434
CSSUtils = brackets.getModule("language/CSSUtils"),
35-
DocumentManager = brackets.getModule("document/DocumentManager");
35+
DocumentManager = brackets.getModule("document/DocumentManager"),
36+
StringMatch = brackets.getModule("utils/StringMatch");
3637

3738

3839
/**
@@ -73,7 +74,7 @@ define(function (require, exports, module) {
7374
});
7475

7576
// Sort based on ranking & basic alphabetical order
76-
QuickOpen.basicMatchSort(filteredList);
77+
StringMatch.basicMatchSort(filteredList);
7778

7879
return filteredList;
7980
}

src/extensions/default/QuickOpenHTML/main.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ define(function (require, exports, module) {
3131

3232
var EditorManager = brackets.getModule("editor/EditorManager"),
3333
QuickOpen = brackets.getModule("search/QuickOpen"),
34-
DocumentManager = brackets.getModule("document/DocumentManager");
34+
DocumentManager = brackets.getModule("document/DocumentManager"),
35+
StringMatch = brackets.getModule("utils/StringMatch");
3536

3637

3738
/**
@@ -107,7 +108,7 @@ define(function (require, exports, module) {
107108
});
108109

109110
// Sort based on ranking & basic alphabetical order
110-
QuickOpen.basicMatchSort(filteredList);
111+
StringMatch.basicMatchSort(filteredList);
111112

112113
return filteredList;
113114
}

src/extensions/default/QuickOpenJavaScript/main.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ define(function (require, exports, module) {
3232
var EditorManager = brackets.getModule("editor/EditorManager"),
3333
QuickOpen = brackets.getModule("search/QuickOpen"),
3434
JSUtils = brackets.getModule("language/JSUtils"),
35-
DocumentManager = brackets.getModule("document/DocumentManager");
35+
DocumentManager = brackets.getModule("document/DocumentManager"),
36+
StringMatch = brackets.getModule("utils/StringMatch");
3637

3738

3839
/**
@@ -100,7 +101,7 @@ define(function (require, exports, module) {
100101
});
101102

102103
// Sort based on ranking & basic alphabetical order
103-
QuickOpen.basicMatchSort(filteredList);
104+
StringMatch.basicMatchSort(filteredList);
104105

105106
return filteredList;
106107
}

src/search/FindUtils.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,16 @@ define(function (require, exports, module) {
276276
var newDoc = DocumentManager.getOpenDocumentForPath(firstPath);
277277
// newDoc might be null if the replacement failed.
278278
if (newDoc) {
279+
// @todo change the `_edit` call to this:
280+
//
281+
/// CommandManager.execute(Commands.FILE_OPEN, {fullPath: firstPath});
282+
//
283+
// The problem with doing that is that the promise returned by this
284+
// function has already been resolved by `Async.doInParallel()` and
285+
// `CommandManager.execute` is an asynchronous operation.
286+
// An asynchronous open can't be waited on (since the promise has been
287+
// resolved already) so use the synchronous version so that the next `done`
288+
// handler is blocked until the open completes
279289
MainViewManager._edit(MainViewManager.ACTIVE_PANE, newDoc);
280290
}
281291
}

src/view/MainViewManager.js

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,28 +1120,20 @@ define(function (require, exports, module) {
11201120

11211121
/**
11221122
* Edits a document in the specified pane.
1123-
* This function is only used by Unit Tests (which construct Mock Documents),
1124-
* The Deprecated API "setCurrentDocument" and by File > New
1125-
* because there is yet to be an established File object for the Document which is required
1126-
* for the open API.
1127-
* Do not use this API unless you have a document object without a file object
1123+
* This function is only used by:
1124+
* - Unit Tests (which construct Mock Document objects),
1125+
* - by File > New because there is yet to be an established File object
1126+
* - by Find In Files which needs to open documents synchronously in some cases
1127+
* Do not use this API it is for internal use only
11281128
* @param {!string} paneId - id of the pane in which to open the document
11291129
* @param {!Document} doc - document to edit
1130-
* @param {{noPaneActivate:boolean=, noPaneRedundancyCheck:boolean=}=} optionsIn - options
1130+
* @param {{noPaneActivate:boolean=}=} optionsIn - options
11311131
* @private
11321132
*/
11331133
function _edit(paneId, doc, optionsIn) {
11341134
var options = optionsIn || {},
1135-
currentPaneId;
1135+
currentPaneId = _getPaneIdForPath(doc.file.fullPath);
11361136

1137-
if (options.noPaneRedundancyCheck) {
1138-
// This flag is for internal use only to improve performance
1139-
// Don't check for the file to have been opened in another pane pane which could be time
1140-
// consuming. should only be used when passing an actual paneId (not a special paneId)
1141-
// and the caller has already done a redundancy check.
1142-
currentPaneId = _getPaneIdForPath(doc.file.fullPath);
1143-
}
1144-
11451137
if (currentPaneId) {
11461138
// If the doc is open in another pane then switch to that pane and call open document
11471139
// which will really just show the view as it has always done we could just
@@ -1172,7 +1164,7 @@ define(function (require, exports, module) {
11721164
* or a document for editing. If it's a document for editing, edit is called on the document
11731165
* @param {!string} paneId - id of the pane in which to open the document
11741166
* @param {!File} file - file to open
1175-
* @param {{noPaneActivate:boolean=, noPaneRedundancyCheck:boolean=}=} optionsIn - options
1167+
* @param {{noPaneActivate:boolean=}=} optionsIn - options
11761168
* @return {jQuery.Promise} promise that resolves to a File object or
11771169
* rejects with a File error or string
11781170
*/
@@ -1250,8 +1242,7 @@ define(function (require, exports, module) {
12501242
DocumentManager.getDocumentForPath(file.fullPath)
12511243
.done(function (doc) {
12521244
_edit(paneId, doc, $.extend({}, options, {
1253-
noPaneActivate: true,
1254-
noPaneRedundancyCheck: true
1245+
noPaneActivate: true
12551246
}));
12561247
doPostOpenActivation();
12571248
result.resolve(doc.file);

test/spec/FindInFiles-test.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,20 +1636,31 @@ define(function (require, exports, module) {
16361636
it("should select the first modified file in the working set if replacements are done in memory and no editor was open", function () {
16371637
openTestProjectCopy(defaultSourcePath);
16381638

1639+
var testFiles = ["/css/foo.css", "/foo.html", "/foo.js"];
1640+
16391641
doInMemoryTest({
16401642
queryInfo: {query: "foo"},
16411643
numMatches: 14,
16421644
replaceText: "bar",
16431645
knownGoodFolder: "unchanged",
16441646
forceFilesOpen: true,
1645-
inMemoryFiles: ["/css/foo.css", "/foo.html", "/foo.js"],
1647+
inMemoryFiles: testFiles,
16461648
inMemoryKGFolder: "simple-case-insensitive"
16471649
});
16481650

1651+
16491652
runs(function () {
1650-
var expectedFile = testPath + "/foo.html";
1651-
expect(DocumentManager.getCurrentDocument().file.fullPath).toBe(expectedFile);
1652-
expect(MainViewManager.findInWorkingSet(MainViewManager.ACTIVE_PANE, expectedFile)).not.toBe(-1);
1653+
// since nothing was opened prior to doing the
1654+
// replacements then the first file modified will be opened.
1655+
// This may not be the first item in the array above
1656+
// since the files are sorted differently in performReplacements
1657+
// and the replace is performed asynchronously.
1658+
// So, just ensure that *something* was opened
1659+
expect(DocumentManager.getCurrentDocument().file.fullPath).toBeTruthy();
1660+
1661+
testFiles.forEach(function (relPath) {
1662+
expect(MainViewManager.findInWorkingSet(MainViewManager.ACTIVE_PANE, testPath + relPath)).not.toBe(-1);
1663+
});
16531664
});
16541665
});
16551666

0 commit comments

Comments
 (0)