This repository has been archived by the owner on Sep 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
adding lineEndings UI in statusbar for documents #13152
Open
zaggino
wants to merge
9
commits into
master
Choose a base branch
from
pull-10346
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
fec7267
adding lineEndings UI in statusbar for documents
sriram-dev 3300abf
lineEndings changes
sriram-dev 3cedf6d
Further Modifications for adding LineEndings
sriram-dev ac3df87
Merge remote-tracking branch 'sriram-dev/10106-lineEndings' into pull…
zaggino 3be830b
refactor
zaggino a7f903f
fix can't read property file of undefined
zaggino 7de2a4c
fire _handleEditorChange so the dirty flag would change
zaggino a7ab934
do not fire, when set to equal value
zaggino 5ba75de
fix assignment to global document
zaggino File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ define(function (require, exports, module) { | |
AppInit = require("utils/AppInit"), | ||
DropdownButton = require("widgets/DropdownButton").DropdownButton, | ||
EditorManager = require("editor/EditorManager"), | ||
FileUtils = require("file/FileUtils"), | ||
MainViewManager = require("view/MainViewManager"), | ||
Editor = require("editor/Editor").Editor, | ||
KeyEvent = require("utils/KeyEvent"), | ||
|
@@ -49,7 +50,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 = {}; | ||
|
@@ -231,6 +233,23 @@ define(function (require, exports, module) { | |
editor.toggleOverwrite(newstate); | ||
} | ||
|
||
/** | ||
* Update LineEndings indicator | ||
* @param {Event} event (unused) | ||
*/ | ||
function _toggleLineEndings(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. |
||
oldLineEndings = document.getLineEndings(), | ||
newLineEndings = oldLineEndings === FileUtils.LINE_ENDINGS_LF ? | ||
FileUtils.LINE_ENDINGS_CRLF : | ||
FileUtils.LINE_ENDINGS_LF; | ||
|
||
// update the line endings in document & status bar | ||
document.setLineEndings(newLineEndings); | ||
$statusLineEndings.text(newLineEndings); | ||
} | ||
|
||
/** | ||
* Initialize insert/overwrite indicator | ||
* @param {Editor} currentEditor Current editor | ||
|
@@ -240,6 +259,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 +307,7 @@ define(function (require, exports, module) { | |
_updateLanguageInfo(current); | ||
_updateFileInfo(current); | ||
_initOverwriteMode(current); | ||
_initLineEndings(current); | ||
_updateIndentType(fullPath); | ||
_updateIndentSize(fullPath); | ||
} | ||
|
@@ -316,6 +345,7 @@ 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, | ||
|
@@ -389,6 +419,8 @@ define(function (require, exports, module) { | |
} | ||
}); | ||
|
||
$statusLineEndings.on("click", _toggleLineEndings); | ||
|
||
$statusOverwrite.on("click", _updateEditorOverwriteMode); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.