Skip to content

Commit ae5e808

Browse files
committed
fix: cursor not seen if line is empty and no git gutter marker in line in git projects
This was caused by fractional .7em rendering of git gutter. The css pixel approximation will hide the 1px cursor line in certain window widths, so we should not use fractional em in the gutter. if was to use a 1em gutter and set a fractional em inset border so that gutter width not fractional also added hover style so that when user hovers over 1em gutter, it expands to 2 em to have the user not work with needle threading precision to click git gutter. the green git-added-lines gutter will not expand as there is currently no action associated with it.
1 parent 36e551c commit ae5e808

File tree

4 files changed

+88
-13
lines changed

4 files changed

+88
-13
lines changed

src/LiveDevelopment/LiveDevMultiBrowser.js

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

589589
// reload the page if the given document is a JS file related
590590
// to the current live document.
591-
if (_liveDocument.isRelated(absolutePath)) {
591+
if (_liveDocument.isRelated && _liveDocument.isRelated(absolutePath)) {
592592
if (doc.getLanguage().getId() === "javascript") {
593593
_setStatus(STATUS_RELOADING);
594594
_protocol.reload();
@@ -610,7 +610,7 @@ define(function (require, exports, module) {
610610

611611
var absolutePath = doc.file.fullPath;
612612

613-
if (_liveDocument.isRelated(absolutePath)) {
613+
if (_liveDocument.isRelated && _liveDocument.isRelated(absolutePath)) {
614614
// Set status to out of sync if dirty. Otherwise, set it to active status.
615615
_setStatus(_docIsOutOfSync(doc) ? STATUS_OUT_OF_SYNC : STATUS_ACTIVE);
616616
}

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

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,45 @@ define(function (require, exports) {
2121
editorsWithGutters = [],
2222
openWidgets = [];
2323

24+
/**
25+
* Checks if there's already a gutter marker on the given line;
26+
* if not, inserts a blank <div> to prevent an empty gutter spot.
27+
*/
28+
function _addDummyGutterMarkerIfNotExist(cm, line) {
29+
var lineInfo = cm.lineInfo(line);
30+
if (!lineInfo) {
31+
return; // If line is out of range or doc is empty
32+
}
33+
var gutters = cm.getOption("gutters").slice(0),
34+
gutterEnabled = gutters.indexOf(gutterName);
35+
if(gutterEnabled === -1){
36+
return;
37+
}
38+
var gutterMarkers = lineInfo.gutterMarkers;
39+
var existingMarker = gutterMarkers && gutterMarkers[gutterName];
40+
if (!existingMarker) {
41+
var dummy = document.createElement("div");
42+
dummy.className = "CodeMirror-gitGutter-none";
43+
cm.setGutterMarker(line, gutterName, dummy);
44+
}
45+
}
46+
47+
function _cursorActivity(_evt, editor){
48+
// this is to prevent a gutter gap in the active line if there is no color on this line.
49+
_addDummyGutterMarkerIfNotExist(editor._codeMirror, editor.getCursorPos().line);
50+
}
51+
52+
EditorManager.on("activeEditorChange", function (event, newEditor, oldEditor) {
53+
if(newEditor){
54+
newEditor.off("cursorActivity.gitGutter");
55+
newEditor.on("cursorActivity.gitGutter", _cursorActivity);
56+
_cursorActivity(null, newEditor);
57+
}
58+
if(oldEditor){
59+
oldEditor.off("cursorActivity.gitGutter");
60+
}
61+
});
62+
2463
function clearWidgets() {
2564
var lines = openWidgets.map(function (mark) {
2665
var w = mark.lineWidget;
@@ -102,7 +141,7 @@ define(function (require, exports) {
102141
.html("&nbsp;");
103142
cm.setGutterMarker(obj.line, gutterName, $marker[0]);
104143
});
105-
144+
_cursorActivity(null, editor);
106145
// reopen widgets that were opened before refresh
107146
openBefore.forEach(function (obj) {
108147
gutterClick(obj.cm, obj.line, gutterName);
@@ -373,7 +412,18 @@ define(function (require, exports) {
373412
}
374413
});
375414

415+
function init() {
416+
const editor = EditorManager.getActiveEditor();
417+
if(!editor){
418+
return;
419+
}
420+
editor.off("cursorActivity.gitGutter");
421+
editor.on("cursorActivity.gitGutter", _cursorActivity);
422+
_cursorActivity(null, editor);
423+
}
424+
376425
// API
426+
exports.init = init;
377427
exports.goToPrev = goToPrev;
378428
exports.goToNext = goToNext;
379429
});

src/extensions/default/Git/src/Panel.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@ define(function (require, exports) {
10831083
if ($this.attr("x-status") === Git.FILE_STATUS.DELETED) {
10841084
return;
10851085
}
1086-
FileViewController.addToWorkingSetAndSelect(Preferences.get("currentGitRoot") + $this.attr("x-file"));
1086+
FileViewController.openFileAndAddToWorkingSet(Preferences.get("currentGitRoot") + $this.attr("x-file"));
10871087
});
10881088

10891089
}
@@ -1316,6 +1316,7 @@ define(function (require, exports) {
13161316
toggle(true);
13171317
}
13181318
_panelResized();
1319+
GutterManager.init();
13191320
} // function init() {
13201321

13211322
function enable() {

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

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
// common
44
@git-moreDarkGrey: #868888;
55
@git-green: #91CC41;
6+
@dark-git-green: #78A336;
67
@git-red: #F74687;
8+
@dark-git-red: #D03A6F;
79
@git-red-text: #F74687;
810
@git-blue-text: #1976DD;
911
@git-dark-blue-text: #51c0ff;
1012
@git-orange: #E3B551;
13+
@dark-git-orange: #C29844;
1114
@git-orange-text: #e28200;
1215

1316
// Diff colors ('d' for 'dark', `l` for "light")
@@ -291,41 +294,58 @@
291294

292295
.CodeMirror {
293296
.brackets-git-gutter {
297+
pointer-events: auto;
294298
width: @gutterWidth;
295-
margin-left: 1px;
296299
}
297300
.brackets-git-gutter-added,
298301
.brackets-git-gutter-modified,
299302
.brackets-git-gutter-removed {
303+
pointer-events: auto;
300304
background-size: @gutterWidth @gutterWidth;
301305
background-repeat: no-repeat;
302-
font-size: 1em;
303-
font-weight: bold;
304306
color: @bc-menu-bg;
305307

308+
border-left: 0.4em solid transparent;
309+
transition: border-left-width 0.2s ease;
306310
.dark & {
307311
color: @dark-bc-menu-bg;
312+
border-left-width: 0.3em;
308313
}
309314
}
310315
.brackets-git-gutter-added {
311-
background-color: @git-green;
316+
border-left-color: @git-green;
317+
.dark & {
318+
border-left-color: @dark-git-green;
319+
}
312320
}
313321

314322
.brackets-git-gutter-modified {
315-
background-color: @git-orange;
323+
border-left-color: @git-orange;
324+
&:hover {
325+
border-left-width: 2em;
326+
}
327+
.dark & {
328+
border-left-color: @dark-git-orange;
329+
}
316330
}
317331

318332
.brackets-git-gutter-removed {
319-
background-color: @git-red;
333+
border-left-color: @git-red;
334+
&:hover {
335+
border-left-width: 2em;
336+
}
337+
.dark & {
338+
border-left-color: @dark-git-red;
339+
}
320340
}
321341

322342
.brackets-git-gutter-deleted-lines {
323343
color: @bc-text;
324-
background-color: lighten(@git-red, 25%);
344+
border-left-color: lighten(@git-red, 25%);
325345
.selectable-text();
326346

327347
.dark & {
328-
background-color: darken(@git-red, 25%);
348+
border-left-color: darken(@dark-git-red, 25%);
329349
color: @dark-bc-text;
330350
}
331351

@@ -338,6 +358,10 @@
338358
height: 1.2em;
339359
line-height: 0.5em;
340360
}
361+
362+
&:hover {
363+
border-left-width: 1em;
364+
}
341365
}
342366
}
343367

@@ -814,7 +838,7 @@
814838

815839
// main
816840

817-
@gutterWidth: 0.65em; // using ems so that it'll be scalable on cmd +/-
841+
@gutterWidth: 1em; // using ems so that it'll be scalable on cmd +/-
818842

819843
#editor-holder {
820844
.git.spinner {

0 commit comments

Comments
 (0)