Skip to content

Commit bd97790

Browse files
authored
Merge branch 'phcode-dev:main' into main
2 parents 15b0858 + 86a70ba commit bd97790

File tree

10 files changed

+659
-193
lines changed

10 files changed

+659
-193
lines changed

src/extensions/default/DebugCommands/MacroRunner.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -498,10 +498,12 @@ define(function (require, exports, module) {
498498
/**
499499
* Opens a file in the first pane (left/top)
500500
* @param {string} filePath - Project relative or absolute file path
501+
* @param {boolean} [addToWorkingSet] - true to add to working set
501502
* @returns {Promise} A promise that resolves when the file is opened
502503
*/
503-
openFileInFirstPane: function(filePath) {
504-
return jsPromise(CommandManager.execute(Commands.FILE_OPEN, {
504+
openFileInFirstPane: function(filePath, addToWorkingSet) {
505+
const command = addToWorkingSet ? Commands.CMD_ADD_TO_WORKINGSET_AND_OPEN : Commands.FILE_OPEN;
506+
return jsPromise(CommandManager.execute(command, {
505507
fullPath: _getFullPath(filePath),
506508
paneId: "first-pane"
507509
}));
@@ -510,10 +512,12 @@ define(function (require, exports, module) {
510512
/**
511513
* Opens a file in the second pane (right/bottom)
512514
* @param {string} filePath - Project relative or absolute file path
515+
* @param {boolean} addToWorkingSet - true to add to working set
513516
* @returns {Promise} A promise that resolves when the file is opened
514517
*/
515-
openFileInSecondPane: function(filePath) {
516-
return jsPromise(CommandManager.execute(Commands.FILE_OPEN, {
518+
openFileInSecondPane: function(filePath, addToWorkingSet) {
519+
const command = addToWorkingSet ? Commands.CMD_ADD_TO_WORKINGSET_AND_OPEN : Commands.FILE_OPEN;
520+
return jsPromise(CommandManager.execute(command, {
517521
fullPath: _getFullPath(filePath),
518522
paneId: "second-pane"
519523
}));
@@ -772,7 +776,8 @@ define(function (require, exports, module) {
772776
closeFile, closeAll, undo, redo, setPreference, getPreference, validateEqual, validateNotEqual, execCommand,
773777
saveActiveFile,
774778
awaitsFor, waitForModalDialog, waitForModalDialogClosed, clickDialogButtonID, clickDialogButton,
775-
EDITING, $, Commands, Dialogs
779+
EDITING, // contains apis like splitVertical, openFileInFirstPane. focus pane etc...
780+
$, Commands, Dialogs
776781
};
777782

778783
async function runMacro(macroText) {

src/extensions/default/Git/src/GutterManager.js

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ define(function (require, exports) {
88
CommandManager = brackets.getModule("command/CommandManager"),
99
DocumentManager = brackets.getModule("document/DocumentManager"),
1010
EditorManager = brackets.getModule("editor/EditorManager"),
11+
ScrollTrackMarkers = brackets.getModule("search/ScrollTrackMarkers"),
1112
MainViewManager = brackets.getModule("view/MainViewManager"),
1213
ErrorHandler = require("src/ErrorHandler"),
1314
Events = require("src/Events"),
@@ -16,6 +17,8 @@ define(function (require, exports) {
1617
Preferences = require("./Preferences"),
1718
Strings = brackets.getModule("strings");
1819

20+
const GIT_SCROLL_MARKS = "git_marks";
21+
1922
var gitAvailable = false,
2023
gutterName = "brackets-git-gutter",
2124
editorsWithGutters = [],
@@ -125,7 +128,7 @@ define(function (require, exports) {
125128
}
126129
}
127130

128-
function showGutters(editor, _results) {
131+
function _showGutters(editor, _results) {
129132
prepareGutter(editor);
130133

131134
var cm = editor._codeMirror;
@@ -137,8 +140,8 @@ define(function (require, exports) {
137140
cm.clearGutter(gutterName);
138141
cm.gitGutters.forEach(function (obj) {
139142
var $marker = $("<div>")
140-
.addClass(gutterName + "-" + obj.type + " gitline-" + (obj.line + 1))
141-
.html("&nbsp;");
143+
.addClass(gutterName + "-" + obj.type + " gitline-" + (obj.line + 1))
144+
.html("&nbsp;");
142145
cm.setGutterMarker(obj.line, gutterName, $marker[0]);
143146
});
144147
_cursorActivity(null, editor);
@@ -214,6 +217,48 @@ define(function (require, exports) {
214217
return doc && doc._masterEditor;
215218
}
216219

220+
function hasVerticalScrollbar(editor) {
221+
const cm = editor._codeMirror;
222+
const scrollEl = cm.getScrollerElement();
223+
return scrollEl.scrollHeight > scrollEl.clientHeight;
224+
}
225+
226+
227+
function _markScrollbar(editor, allChanges) {
228+
ScrollTrackMarkers.clear(editor, GIT_SCROLL_MARKS);
229+
if(!hasVerticalScrollbar(editor)){
230+
return;
231+
}
232+
const added = allChanges
233+
.filter(item => item.type === "added")
234+
.map(({ line }) => ({ line, ch: 0 }));
235+
236+
const removed = allChanges
237+
.filter(item => item.type === "removed")
238+
.map(({ line }) => ({ line, ch: 0 }));
239+
240+
const modified = allChanges
241+
.filter(item => item.type === "modified")
242+
.map(({ line }) => ({ line, ch: 0 }));
243+
244+
const trackers = [
245+
{arr: added, css: "brackets-git-added"},
246+
{arr: removed, css: "brackets-git-removed"},
247+
{arr: modified, css: "brackets-git-modified"}
248+
];
249+
for(let tracker of trackers) {
250+
if( !tracker.arr.length ){
251+
continue;
252+
}
253+
let posArray = tracker.arr.map(item => ({ line: item.line, ch: 0 }));
254+
ScrollTrackMarkers.addTickmarks(editor, posArray, {
255+
trackStyle: ScrollTrackMarkers.TRACK_STYLES.ON_LEFT,
256+
name: GIT_SCROLL_MARKS,
257+
cssColorClass: tracker.css
258+
});
259+
}
260+
}
261+
217262
function processDiffResults(editor, diff) {
218263
var added = [],
219264
removed = [],
@@ -239,9 +284,9 @@ define(function (require, exports) {
239284
type: "removed",
240285
line: lineRemovedFrom,
241286
content: str.split("\n")
242-
.filter(function (l) { return l.indexOf("-") === 0; })
243-
.map(function (l) { return l.substring(1); })
244-
.join("\n")
287+
.filter(function (l) { return l.indexOf("-") === 0; })
288+
.map(function (l) { return l.substring(1); })
289+
.join("\n")
245290
});
246291
}
247292

@@ -279,7 +324,9 @@ define(function (require, exports) {
279324
o.line = o.line + 1;
280325
});
281326

282-
showGutters(editor, [].concat(added, removed, modified));
327+
const allChanges = [].concat(added, removed, modified);
328+
_showGutters(editor, allChanges);
329+
_markScrollbar(editor, allChanges);
283330
}
284331

285332
function refresh() {

src/extensions/default/Git/styles/git-styles.less

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,29 @@
292292
// codemirror
293293
// main: brackets-git.less
294294

295+
.tickmark-track {
296+
.brackets-git-added {
297+
--mark-color: @git-green;
298+
.dark & {
299+
--mark-color: @dark-git-green;
300+
}
301+
}
302+
303+
.brackets-git-modified {
304+
--mark-color: @git-orange;
305+
.dark & {
306+
--mark-color: @dark-git-orange;
307+
}
308+
}
309+
310+
.brackets-git-removed {
311+
--mark-color: @git-red;
312+
.dark & {
313+
--mark-color: @dark-git-red;
314+
}
315+
}
316+
}
317+
295318
.CodeMirror {
296319
.brackets-git-gutter {
297320
pointer-events: auto;

src/search/FindReplace.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -393,10 +393,10 @@ define(function (require, exports, module) {
393393
}
394394

395395
/** Removes the current-match highlight, leaving all matches marked in the generic highlight style */
396-
function clearCurrentMatchHighlight(cm, state) {
396+
function clearCurrentMatchHighlight(editor, state) {
397397
if (state.markedCurrent) {
398398
state.markedCurrent.clear();
399-
ScrollTrackMarkers.markCurrent(-1);
399+
ScrollTrackMarkers.markCurrent(-1, editor);
400400
}
401401
}
402402

@@ -405,7 +405,7 @@ define(function (require, exports, module) {
405405
const pos = editor.getCursorPos(false, "start");
406406
cm.operation(function () {
407407
var state = getSearchState(cm);
408-
clearCurrentMatchHighlight(cm, state);
408+
clearCurrentMatchHighlight(editor, state);
409409

410410
let curIndex = editor.indexFromPos(pos);
411411
curIndex = curIndex >= 1 ? curIndex-- : 0;
@@ -424,7 +424,7 @@ define(function (require, exports, module) {
424424
{from: thisMatch.start, to: thisMatch.end}, false);
425425
// Update current-tickmark indicator - only if highlighting enabled (disabled if FIND_HIGHLIGHT_MAX threshold hit)
426426
if (state.marked.length) {
427-
ScrollTrackMarkers.markCurrent(state.matchIndex); // _updateFindBarWithMatchInfo() has updated this index
427+
ScrollTrackMarkers.markCurrent(state.matchIndex, editor); // _updateFindBarWithMatchInfo() has updated this index
428428
}
429429
}
430430

@@ -454,7 +454,7 @@ define(function (require, exports, module) {
454454
var cm = editor._codeMirror;
455455
cm.operation(function () {
456456
var state = getSearchState(cm);
457-
clearCurrentMatchHighlight(cm, state);
457+
clearCurrentMatchHighlight(editor, state);
458458

459459
var nextMatch = _getNextMatch(editor, searchBackwards, pos);
460460
if (nextMatch) {
@@ -464,7 +464,7 @@ define(function (require, exports, module) {
464464
{from: nextMatch.start, to: nextMatch.end}, searchBackwards);
465465
// Update current-tickmark indicator - only if highlighting enabled (disabled if FIND_HIGHLIGHT_MAX threshold hit)
466466
if (state.marked.length) {
467-
ScrollTrackMarkers.markCurrent(state.matchIndex); // _updateFindBarWithMatchInfo() has updated this index
467+
ScrollTrackMarkers.markCurrent(state.matchIndex, editor); // _updateFindBarWithMatchInfo() has updated this index
468468
}
469469
}
470470

@@ -485,31 +485,33 @@ define(function (require, exports, module) {
485485
}
486486

487487
/** Clears all match highlights, including the current match */
488-
function clearHighlights(cm, state) {
488+
function clearHighlights(editor, state) {
489+
const cm = editor._codeMirror;
489490
cm.operation(function () {
490491
state.marked.forEach(function (markedRange) {
491492
markedRange.clear();
492493
});
493-
clearCurrentMatchHighlight(cm, state);
494+
clearCurrentMatchHighlight(editor, state);
494495
});
495496
state.marked.length = 0;
496497
state.markedCurrent = null;
497498

498-
ScrollTrackMarkers.clear();
499+
ScrollTrackMarkers.clear(editor);
499500

500501
state.resultSet = [];
501502
state.matchIndex = -1;
502503
}
503504

504-
function clearSearch(cm) {
505+
function clearSearch(editor) {
506+
const cm = editor._codeMirror;
505507
cm.operation(function () {
506508
var state = getSearchState(cm);
507509
if (!state.parsedQuery) {
508510
return;
509511
}
510512
setQueryInfo(state, null);
511513

512-
clearHighlights(cm, state);
514+
clearHighlights(editor, state);
513515
});
514516
}
515517

@@ -544,7 +546,7 @@ define(function (require, exports, module) {
544546
cm.operation(function () {
545547
// Clear old highlights
546548
if (state.marked) {
547-
clearHighlights(cm, state);
549+
clearHighlights(editor, state);
548550
}
549551

550552
if (!state.parsedQuery) {
@@ -676,7 +678,7 @@ define(function (require, exports, module) {
676678
.on("close.FindReplace", function (e) {
677679
editor.lastParsedQuery = state.parsedQuery;
678680
// Clear highlights but leave search state in place so Find Next/Previous work after closing
679-
clearHighlights(cm, state);
681+
clearHighlights(editor, state);
680682

681683
// Dispose highlighting UI (important to restore normal selection color as soon as focus goes back to the editor)
682684
toggleHighlighting(editor, false);
@@ -770,7 +772,7 @@ define(function (require, exports, module) {
770772

771773
if (editor) {
772774
// Create a new instance of the search bar UI
773-
clearSearch(editor._codeMirror);
775+
clearSearch(editor);
774776
doSearch(editor, false);
775777
}
776778
}

0 commit comments

Comments
 (0)