-
Notifications
You must be signed in to change notification settings - Fork 7.6k
adding lineEndings UI in statusbar for documents #13152
base: master
Are you sure you want to change the base?
Changes from 4 commits
fec7267
3300abf
3cedf6d
ac3df87
3be830b
a7f903f
7de2a4c
a7ab934
5ba75de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,7 +49,8 @@ define(function (require, exports, module) { | |
$indentType, | ||
$indentWidthLabel, | ||
$indentWidthInput, | ||
$statusOverwrite; | ||
$statusOverwrite, | ||
$statusLineEndings; | ||
|
||
/** Special list item for the 'set as default' gesture in language switcher dropdown */ | ||
var LANGUAGE_SET_AS_DEFAULT = {}; | ||
|
@@ -216,7 +217,7 @@ define(function (require, exports, module) { | |
if (!doNotAnimate) { | ||
AnimationUtils.animateUsingClass($statusOverwrite[0], "flash", 1500); | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: trailing whitespace |
||
|
||
/** | ||
* Update insert/overwrite indicator | ||
|
@@ -231,6 +232,29 @@ define(function (require, exports, module) { | |
editor.toggleOverwrite(newstate); | ||
} | ||
|
||
/** | ||
* Update LineEndings indicator | ||
* @param {Event} event (unused) | ||
*/ | ||
function _updateLineEndings(event) { | ||
var editor = EditorManager.getActiveEditor(), | ||
document = editor.document, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assignment to a window global, change to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assignment to window global There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, we should really make ESLint catch this. |
||
currentLineEndings; | ||
|
||
// update label | ||
if($statusLineEndings.text() === Strings.STATUSBAR_LINE_ENDINGS_CRLF) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: space between |
||
$statusLineEndings.text(Strings.STATUSBAR_LINE_ENDINGS_LF); | ||
currentLineEndings = FileUtils.LINE_ENDINGS_LF; | ||
} else { | ||
$statusLineEndings.text(Strings.STATUSBAR_LINE_ENDINGS_CRLF); | ||
currentLineEndings = FileUtils.LINE_ENDINGS_CRLF; | ||
} | ||
// Update the line ending in the document if needed. | ||
if(document.getLineEndings() !== currentLineEndings) { | ||
document.setLineEndings(currentLineEndings); | ||
} | ||
} | ||
|
||
/** | ||
* Initialize insert/overwrite indicator | ||
* @param {Editor} currentEditor Current editor | ||
|
@@ -240,6 +264,15 @@ define(function (require, exports, module) { | |
$statusOverwrite.attr("title", Strings.STATUSBAR_INSOVR_TOOLTIP); | ||
} | ||
|
||
/** | ||
* Initialize line endings indicator | ||
* @param {Editor} currentEditor Current editor | ||
*/ | ||
function _initLineEndings(currentEditor) { | ||
$statusLineEndings.text(currentEditor.document.getLineEndings()); | ||
$statusLineEndings.attr("title", Strings.STATUSBAR_LINE_ENDINGS_TOOLTIP); | ||
} | ||
|
||
/** | ||
* Handle active editor change event | ||
* @param {Event} event (unused) | ||
|
@@ -279,6 +312,7 @@ define(function (require, exports, module) { | |
_updateLanguageInfo(current); | ||
_updateFileInfo(current); | ||
_initOverwriteMode(current); | ||
_initLineEndings(current); | ||
_updateIndentType(fullPath); | ||
_updateIndentSize(fullPath); | ||
} | ||
|
@@ -316,7 +350,8 @@ define(function (require, exports, module) { | |
$indentWidthLabel = $("#indent-width-label"); | ||
$indentWidthInput = $("#indent-width-input"); | ||
$statusOverwrite = $("#status-overwrite"); | ||
|
||
$statusLineEndings = $("#status-line-endings"); | ||
|
||
languageSelect = new DropdownButton("", [], function (item, index) { | ||
var document = EditorManager.getActiveEditor().document, | ||
defaultLang = LanguageManager.getLanguageForPath(document.file.fullPath, true); | ||
|
@@ -389,6 +424,8 @@ define(function (require, exports, module) { | |
} | ||
}); | ||
|
||
$statusLineEndings.on("click", _updateLineEndings); | ||
|
||
$statusOverwrite.on("click", _updateEditorOverwriteMode); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is toggled twice, the document is effectively in unedited state and hence should not throw a save/don't save prompt while closing the file.
Other thing is should the change of line ending be part of undo stack?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tryed Notepad++ with a txt file. When you change the line ending, the first time goes in edited state, if you change back to the previous line ending it remains in an edited state.
So, to me, the prompt is expected.
As stated above, the line ending changes should be part of the history but requires to add custom entry in CodeMirror. If someone at Adobe could do the courtesy it would be great.