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

Add Status bar Indicator for Overwrite mode #6670

Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,9 @@ define(function (require, exports, module) {
this._codeMirror.on("update", function (instance) {
$(self).triggerHandler("update", [self]);
});
this._codeMirror.on("overwriteToggle", function (instance, newstate) {
$(self).triggerHandler("overwriteToggle", [self, newstate]);
});
};

/**
Expand Down
27 changes: 26 additions & 1 deletion src/editor/EditorStatusBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ define(function (require, exports, module) {
$fileInfo,
$indentType,
$indentWidthLabel,
$indentWidthInput;
$indentWidthInput,
$statusOverwrite;


function _formatCountable(number, singularStr, pluralStr) {
Expand Down Expand Up @@ -141,6 +142,25 @@ define(function (require, exports, module) {
_updateCursorInfo();
}

function _updateOverwriteLabel(event, editor, newstate) {
if (!newstate) {
$statusOverwrite.addClass("active");
$statusOverwrite.text(Strings.STATUSBAR_INSERT);
} else {
$statusOverwrite.addClass("active");
$statusOverwrite.text(Strings.STATUSBAR_OVERWRITE);
}
window.setTimeout(function () {
$statusOverwrite.removeClass("active");
}, 1000);
}

function _updateEditorOverwriteMode() {
var editor = EditorManager.getActiveEditor();

editor._codeMirror.toggleOverwrite(null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make a new Editor.toggleOverwrite method which just does this._codeMirror.toggleOverwrite(value), so that we don't access the private member _codeMirror?

}

function _onActiveEditorChange(event, current, previous) {
if (previous) {
$(previous).off(".statusbar");
Expand All @@ -151,6 +171,7 @@ define(function (require, exports, module) {
if (!current) {
StatusBar.hide(); // calls resizeEditor() if needed
} else {
current._codeMirror.toggleOverwrite($statusOverwrite.hasClass("active"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can't be used any more.

StatusBar.show(); // calls resizeEditor() if needed

$(current).on("cursorActivity.statusbar", _updateCursorInfo);
Expand All @@ -162,6 +183,7 @@ define(function (require, exports, module) {
// async update to keep typing speed smooth
window.setTimeout(function () { _updateFileInfo(current); }, 0);
});
$(current).on("overwriteToggle.statusbar", _updateOverwriteLabel);

current.document.addRef();
$(current.document).on("languageChanged.statusbar", function () { _updateLanguageInfo(current); });
Expand All @@ -181,6 +203,7 @@ define(function (require, exports, module) {
$indentType = $("#indent-type");
$indentWidthLabel = $("#indent-width-label");
$indentWidthInput = $("#indent-width-input");
$statusOverwrite = $("#status-overwrite");

// indentation event handlers
$indentType.on("click", _toggleIndentType);
Expand Down Expand Up @@ -208,6 +231,8 @@ define(function (require, exports, module) {

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

$statusOverwrite.on("click", _updateEditorOverwriteMode);

_onActiveEditorChange(null, EditorManager.getActiveEditor(), null);
}

Expand Down
2 changes: 2 additions & 0 deletions src/nls/root/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ define({
"STATUSBAR_LINE_COUNT_SINGULAR" : "\u2014 {0} Line",
"STATUSBAR_LINE_COUNT_PLURAL" : "\u2014 {0} Lines",
"STATUSBAR_USER_EXTENSIONS_DISABLED" : "Extensions Disabled",
"STATUSBAR_INSERT" : "INS",
"STATUSBAR_OVERWRITE" : "OVR",

// CodeInspection: errors/warnings
"ERRORS_PANEL_TITLE_MULTIPLE" : "{0} Problems",
Expand Down
13 changes: 13 additions & 0 deletions src/styles/brackets.less
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,19 @@ a, img {
margin: 0;
}

#status-overwrite {
transition: color 1s, background-color 3s;
background-color: rgba(120, 178, 242, 0);
color: rgb(69, 69, 69);
}

#status-overwrite.active {
transition: color 0.1s, background-color 1s;
background-color: rgb(120, 178, 242);
color: #efefef;
}


#editor-holder {
position: relative;

Expand Down
3 changes: 2 additions & 1 deletion src/widgets/StatusBar.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
<div id="indent-type"></div>
<div id="indent-width-label"></div>
<input id="indent-width-input" type="number" min="1" max="10" maxlength="2" size="2" class="hidden">
</div>
</div>
<div id="status-language"></div>
<div id="status-overwrite">{{STATUSBAR_INSERT}}</div>
<div class="spinner"></div>
</div>
</div>