-
Notifications
You must be signed in to change notification settings - Fork 7.6k
adding lineEndings UI in statusbar for documents #10346
base: master
Are you sure you want to change the base?
Conversation
Looks like travis failed because of CLA agreement. I had once signed long time back. Not sure if it was changed. I have re signed it now. Please restart if possible. |
@sriram-dev After changing line endings, it loses the cursor position. It would be nice if it retain cursor position. |
Yes. I will make one more commit to the PR to preserve cursor position and scroll position while modifying lineEndings. |
*/ | ||
Document.prototype.setLineEndings = function (lineEndings) { | ||
this._lineEndings = lineEndings; | ||
this.setText(FileUtils.translateLineEndings(this.getText(true), lineEndings)); |
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.
You don't need this line -- the document model's text uses normalized line endings, so this is a no-ope anyway. Removing this line should fix the cursor/scroll position issues too.
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 we avoid this, the new lineEndings is not set to the existing file text. And document is left unmodified. With this change, file gets dirty(with new lineending added) and once we save, the new line endings is saved to file. It doesnt happen otherwise.
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.
That's just a side-effect: a no-op change still marks the document dirty, and you can only save documents when they're dirty. If you remove this line, it will still work fine if you make any edits to the document (marking it dirty) before saving.
It does sound like this needs to be integrated with the dirty flag to have intuitive behavior, since it'd definitely be confusing if even explicitly saving wouldn't persist the change. I don't think this is the right way to achieve that though.
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.
Setting document.isDirty flag to true on Document.prototype.setLineEndings is a proper way ? It works.
One last thought: should toggling line endings mark the document as dirty? It could be confusing if a user toggles line endings, then closes the document, then discovers later that it still has the old line-ending type. OTOH, it could be architecturally a little tricky (or messy) to have this affect the dirty flag. |
If it marks the doc dirty, it should also be possible to undo using |
Making it undoable as @marcelgerber suggested is likely to be pretty tricky -- e.g. pushing some kind of custom entry onto the CodeMirror history stack. I don't feel we need to go that far, though. One simple way we could mark it dirty: when changing line endings, set |
|
@sriram-dev The |
@peterflynn Got the reasoning now. Thanks for the clarification. |
The reason I suggested |
I see currently none of the options in the status bar is affected by ctrl+z(ins/ovr, tab/spaces etc). Anyways can someone please confirm if we need it affected by ctrl+z or if the changes are fine for the PR ? |
The difference is, options like INS/OVR and tab/spaces don't directly change the document. They change how you interact with them, but they don't touch the content itself, while CRLF/LF does. |
@marcelgerber Sounds like the right thing to do :) |
@peterflynn @marcelgerber If we want the line endings to be part of Ctrl+z, can you guys provide some pointers on the code changes needed for that ? |
Can someone please update on the next steps for this ? |
I apologize if this is the wrong place to ask, but is there any chance this will be included in the next release? |
@sriram-dev @rhbecker |
Related: http://discuss.codemirror.net/t/custom-entries-in-undo-history/304 |
This didn't quite work out well, but after a CM update, we could make use of the newly added option |
@sriram-dev @marcelgerber what is the status of this? |
Given this discussion the |
Fix for #10106 and #10594
Tests Done
Let me know if any unit tests needs to be added for the change. I couldn't find any added for other status bar options available.