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

Commit 25be547

Browse files
committed
Merge pull request #6777 from WebsiteDeveloper/overwrite
Overwrite mode improvements
2 parents 531d0d3 + 280864e commit 25be547

File tree

6 files changed

+92
-35
lines changed

6 files changed

+92
-35
lines changed

src/editor/Editor.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,8 @@ define(function (require, exports, module) {
400400
whenOpening: true,
401401
whenClosing: true,
402402
indentTags: []
403-
}
403+
},
404+
cursorScrollMargin: 3
404405
});
405406

406407
// Can't get CodeMirror's focused state without searching for
@@ -710,6 +711,9 @@ define(function (require, exports, module) {
710711
this._codeMirror.on("update", function (instance) {
711712
$(self).triggerHandler("update", [self]);
712713
});
714+
this._codeMirror.on("overwriteToggle", function (instance, newstate) {
715+
$(self).triggerHandler("overwriteToggle", [self, newstate]);
716+
});
713717
};
714718

715719
/**
@@ -920,6 +924,15 @@ define(function (require, exports, module) {
920924
}
921925
};
922926

927+
/**
928+
* Sets the editors overwrite mode state. If null is passed, the state is toggled.
929+
*
930+
* @param {?boolean} start
931+
*/
932+
Editor.prototype.toggleOverwrite = function (state) {
933+
this._codeMirror.toggleOverwrite(state);
934+
};
935+
923936
/**
924937
* Selects word that the given pos lies within or adjacent to. If pos isn't touching a word
925938
* (e.g. within a token like "//"), moves the cursor to pos without selecting a range.

src/editor/EditorStatusBar.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ define(function (require, exports, module) {
3333

3434
// Load dependent modules
3535
var AppInit = require("utils/AppInit"),
36+
AnimationUtils = require("utils/AnimationUtils"),
3637
EditorManager = require("editor/EditorManager"),
3738
Editor = require("editor/Editor").Editor,
3839
KeyEvent = require("utils/KeyEvent"),
@@ -46,7 +47,8 @@ define(function (require, exports, module) {
4647
$fileInfo,
4748
$indentType,
4849
$indentWidthLabel,
49-
$indentWidthInput;
50+
$indentWidthInput,
51+
$statusOverwrite;
5052

5153

5254
function _formatCountable(number, singularStr, pluralStr) {
@@ -141,6 +143,22 @@ define(function (require, exports, module) {
141143
_updateCursorInfo();
142144
}
143145

146+
function _updateOverwriteLabel(event, editor, newstate) {
147+
$statusOverwrite.text(newstate ? Strings.STATUSBAR_OVERWRITE : Strings.STATUSBAR_INSERT);
148+
149+
AnimationUtils.animateUsingClass($statusOverwrite[0], "flash");
150+
}
151+
152+
function _updateEditorOverwriteMode() {
153+
var editor = EditorManager.getActiveEditor();
154+
155+
editor.toggleOverwrite(null);
156+
}
157+
158+
function _initOverwriteMode(currentEditor) {
159+
currentEditor.toggleOverwrite($statusOverwrite.text() === Strings.STATUSBAR_OVERWRITE);
160+
}
161+
144162
function _onActiveEditorChange(event, current, previous) {
145163
if (previous) {
146164
$(previous).off(".statusbar");
@@ -162,13 +180,15 @@ define(function (require, exports, module) {
162180
// async update to keep typing speed smooth
163181
window.setTimeout(function () { _updateFileInfo(current); }, 0);
164182
});
183+
$(current).on("overwriteToggle.statusbar", _updateOverwriteLabel);
165184

166185
current.document.addRef();
167186
$(current.document).on("languageChanged.statusbar", function () { _updateLanguageInfo(current); });
168187

169188
_updateCursorInfo(null, current);
170189
_updateLanguageInfo(current);
171190
_updateFileInfo(current);
191+
_initOverwriteMode(current);
172192
_updateIndentType();
173193
_updateIndentSize();
174194
}
@@ -181,6 +201,7 @@ define(function (require, exports, module) {
181201
$indentType = $("#indent-type");
182202
$indentWidthLabel = $("#indent-width-label");
183203
$indentWidthInput = $("#indent-width-input");
204+
$statusOverwrite = $("#status-overwrite");
184205

185206
// indentation event handlers
186207
$indentType.on("click", _toggleIndentType);
@@ -208,6 +229,8 @@ define(function (require, exports, module) {
208229

209230
$indentWidthInput.focus(function () { $indentWidthInput.select(); });
210231

232+
$statusOverwrite.on("click", _updateEditorOverwriteMode);
233+
211234
_onActiveEditorChange(null, EditorManager.getActiveEditor(), null);
212235
}
213236

src/nls/root/strings.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ define({
198198
"STATUSBAR_LINE_COUNT_SINGULAR" : "\u2014 {0} Line",
199199
"STATUSBAR_LINE_COUNT_PLURAL" : "\u2014 {0} Lines",
200200
"STATUSBAR_USER_EXTENSIONS_DISABLED" : "Extensions Disabled",
201+
"STATUSBAR_INSERT" : "INS",
202+
"STATUSBAR_OVERWRITE" : "OVR",
201203

202204
// CodeInspection: errors/warnings
203205
"ERRORS_PANEL_TITLE_MULTIPLE" : "{0} Problems",

src/styles/brackets.less

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,19 @@ a, img {
224224
margin: 0;
225225
}
226226

227+
#status-overwrite {
228+
transition: background-color 3s;
229+
background-color: rgba(120, 178, 242, 0);
230+
color: rgb(69, 69, 69);
231+
cursor: pointer;
232+
}
233+
234+
#status-overwrite.flash {
235+
transition: background-color 1s;
236+
background-color: rgb(120, 178, 242);
237+
}
238+
239+
227240
#editor-holder {
228241
position: relative;
229242

@@ -257,15 +270,15 @@ a, img {
257270
font-weight: @font-weight-semibold;
258271
}
259272
}
260-
273+
261274
#image-holder:before {
262275
content: '';
263276
display: inline-block;
264277
height: 100%;
265278
margin-right: -0.25em; /* Adjusts for spacing */
266279
vertical-align: middle;
267280
}
268-
281+
269282
#img-preview {
270283
background: url(images/preview_bg.png);
271284
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.36);
@@ -278,25 +291,25 @@ a, img {
278291
height: 38px;
279292
margin-bottom: 15px;
280293
}
281-
294+
282295
#img-data,
283296
#img-path {
284297
text-align: left;
285298
.user-select(text);
286299
white-space: nowrap;
287300
text-overflow: ellipsis;
288-
overflow: hidden;
301+
overflow: hidden;
289302
}
290-
303+
291304
#img-data::selection,
292305
#img-path::selection {
293306
background: @selection-color-focused;
294307
}
295-
308+
296309
#img {
297310
position: relative;
298311
}
299-
312+
300313
.img-guide,
301314
#img-preview {
302315
cursor: none;
@@ -314,7 +327,7 @@ a, img {
314327
border-radius: 3px;
315328
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
316329
}
317-
330+
318331
#img-tip {
319332
display: block;
320333
position: absolute;
@@ -329,16 +342,16 @@ a, img {
329342
border-radius: 3px;
330343
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.24);
331344
}
332-
345+
333346
#x-value,
334347
#y-value {
335348
text-align: right;
336349
}
337-
350+
338351
.tip-container {
339352
border: 0;
340353
}
341-
354+
342355
#horiz-guide {
343356
background-image: url("images/horizontal-dash.svg");
344357
background-repeat: repeat-x;
@@ -352,7 +365,7 @@ a, img {
352365
width: 1px;
353366
height: 8px;
354367
}
355-
368+
356369
#horiz-guide,
357370
#vert-guide {
358371
position: absolute;
@@ -736,7 +749,7 @@ a, img {
736749
background-color: @tc-lighter-gray;
737750
min-width: 250px;
738751
cursor: default;
739-
752+
740753
&.animating {
741754
// Make the animation use the GPU--especially important for retina.
742755
-webkit-transform: translateZ(0);
@@ -780,7 +793,7 @@ a, img {
780793
}
781794
}
782795
}
783-
796+
784797
.shadow {
785798
display: block;
786799
height: 4px;
@@ -830,7 +843,7 @@ a, img {
830843
max-width: 50%;
831844
overflow: hidden;
832845
background: @inline-background-color-2;
833-
846+
834847
// Without this, the "New Rule" button shows on top of the rule list if you resize
835848
// the window narrow enough. No idea why, since there's no z-index on the button, and
836849
// the other items in the header go behind the rule list.
@@ -887,7 +900,7 @@ a, img {
887900
padding: 2px 0px 2px 15px;
888901
text-overflow: ellipsis;
889902
white-space: nowrap;
890-
903+
891904
.related-file {
892905
color: @tc-input-placeholder-text;
893906
}
@@ -1018,20 +1031,20 @@ a, img {
10181031
// Separator line between us and the HTML menu/titlebar above
10191032
border-top: 1px solid darken(@background-color-3, @bc-color-step-size);
10201033
}
1021-
1034+
10221035
&.popout {
10231036
position: absolute;
10241037
left: 0;
10251038
right: 0;
10261039
top: 0;
10271040
}
1028-
1041+
10291042
&.offscreen {
10301043
-webkit-transform: translate(0, -44px);
10311044
transform: translate(0, -44px);
10321045
transition: -webkit-transform 266ms cubic-bezier(0, 0.56, 0, 1);
10331046
transition: transform 266ms cubic-bezier(0, 0.56, 0, 1);
1034-
1047+
10351048
body:not(.has-appshell-menus) & {
10361049
top: 37px;
10371050
}
@@ -1049,29 +1062,29 @@ a, img {
10491062
box-shadow: inset 0 1px 0 rgba(0, 0, 0, 0.12), 0 0 0 2px rgba(255, 0, 120, 0.5);
10501063
}
10511064
}
1052-
1065+
10531066
#find-what, #replace-with {
10541067
width: 295px;
10551068
}
10561069

10571070
.search-input-container {
10581071
position: relative;
10591072
display: inline;
1060-
1073+
10611074
.error { // "popup" that hangs below search field
10621075
position: absolute;
10631076
left: 5px;
10641077
top: 24px;
10651078
min-width: 291px + 2px; // to align with search field above it
1066-
1079+
10671080
background-color: #f74687;
10681081
color: @bc-white;
10691082
font-size: 12px;
10701083
padding: 3px 8px;
10711084
border-radius: 0 0 3px 3px;
10721085
box-shadow: @tc-small-shadow-bottom;
10731086
}
1074-
1087+
10751088
#find-what {
10761089
padding-right: 62px; // room for #find-counter overlay
10771090
width: 295px - (62px - 6px); // maintain width, accounting for differing padding
@@ -1084,16 +1097,16 @@ a, img {
10841097
font-size: 12px;
10851098
}
10861099
}
1087-
1100+
10881101
#find-group, #replace-group {
10891102
display: inline-block;
10901103
white-space: nowrap;
10911104
}
1092-
1105+
10931106
.message, .no-results-message {
10941107
display: inline-block;
10951108
}
1096-
1109+
10971110
#find-case-sensitive, #find-regexp {
10981111
padding: 1px 5px;
10991112
}
@@ -1125,7 +1138,7 @@ a, img {
11251138
border-bottom-right-radius: 0;
11261139
margin-left: 5px;
11271140
}
1128-
1141+
11291142
// Make button pairs snug
11301143
#find-prev, #replace-yes, #find-case-sensitive {
11311144
border-right: none;
@@ -1136,7 +1149,7 @@ a, img {
11361149
border-bottom-left-radius: 0;
11371150
margin-left: 0;
11381151
}
1139-
1152+
11401153
// Make find field snug with options buttons
11411154
// & replace snug with replace commands
11421155
#find-what, #replace-with {
@@ -1191,11 +1204,10 @@ a, img {
11911204
width: 12px;
11921205
z-index: @z-index-cm-max;
11931206
pointer-events: none;
1194-
1207+
11951208
.tickmark {
11961209
position: absolute;
11971210
width: 12px;
1198-
11991211
height: 1px;
12001212
background-color: #eddd23;
12011213
border-top: 1px solid #e0d123;
@@ -1250,11 +1262,11 @@ a, img {
12501262
list-style: none;
12511263
cursor: default;
12521264
padding: 6px 10px;
1253-
1265+
12541266
&:nth-child(odd) {
12551267
background-color: @tc-lighter-gray;
12561268
}
1257-
1269+
12581270
&:hover {
12591271
background-color: @tc-hover-highlight;
12601272
}

src/styles/brackets_codemirror_override.less

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,12 @@
177177
other than a vanilla .CodeMirror)
178178
*/
179179
.CodeMirror {
180+
div.CodeMirror-cursor.CodeMirror-overwrite {
181+
border-left: none !important;
182+
border-bottom: 1px solid black !important;
183+
width: 1.2ex;
184+
}
185+
180186
.CodeMirror {
181187
background: transparent;
182188
}

0 commit comments

Comments
 (0)