Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions menus/darwin.cson
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
{ label: 'Copy Path', command: 'editor:copy-path' }
{ label: 'Paste', command: 'core:paste' }
{ label: 'Paste Without Reformatting', command: 'editor:paste-without-reformatting' }
{ label: 'Paste Without Reindenting', command: 'editor:paste-without-reindenting' }
{ label: 'Select All', command: 'core:select-all' }
{ type: 'separator' }
{ label: 'Toggle Comments', command: 'editor:toggle-line-comments' }
Expand Down
1 change: 1 addition & 0 deletions menus/linux.cson
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
{ label: 'Copy Pat&h', command: 'editor:copy-path' }
{ label: '&Paste', command: 'core:paste' }
{ label: 'Paste Without Reformatting', command: 'editor:paste-without-reformatting' }
{ label: 'Paste Without Reindenting', command: 'editor:paste-without-reindenting' }
{ label: 'Select &All', command: 'core:select-all' }
{ type: 'separator' }
{ label: '&Toggle Comments', command: 'editor:toggle-line-comments' }
Expand Down
1 change: 1 addition & 0 deletions menus/win32.cson
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
{ label: 'Copy Pat&h', command: 'editor:copy-path' }
{ label: '&Paste', command: 'core:paste' }
{ label: 'Paste Without Reformatting', command: 'editor:paste-without-reformatting' }
{ label: 'Paste Without Reindenting', command: 'editor:paste-without-reindenting' }
{ label: 'Select &All', command: 'core:select-all' }
{ type: 'separator' }
{ label: '&Toggle Comments', command: 'editor:toggle-line-comments' }
Expand Down
21 changes: 21 additions & 0 deletions spec/clipboard-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,26 @@ describe('Clipboard', () => {
Object.defineProperty(process, 'platform', { value: originalPlatform });
});
}

it('does not convert line endings when the setting is off', () => {
atom.config.set('editor.convertLineEndingOnCopy', 'off');
atom.clipboard.write('next\ndone\r\n\n');
expect(atom.clipboard.read()).toEqual('next\ndone\r\n\n');
});

it('converts line endings to LF when the setting is LF', () => {
atom.config.set('editor.convertLineEndingOnCopy', 'LF');
atom.clipboard.write('next\ndone\r\n\n');
expect(atom.clipboard.read()).toEqual('next\ndone\n\n');
});

it('converts line endings to CRLF when the setting is CRLF', () => {
atom.config.set('editor.convertLineEndingOnCopy', 'CRLF');
atom.clipboard.write('next\ndone\r\n\n');
expect(atom.clipboard.read()).toEqual('next\r\ndone\r\n\r\n');

// Cleanup: Back to the default setting
atom.config.set('editor.convertLineEndingOnCopy', 'system');
});
});
});
11 changes: 10 additions & 1 deletion src/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,16 @@ module.exports = class Clipboard {
// * `text` The {String} to store.
// * `metadata` (optional) The additional info to associate with the text.
write(text, metadata) {
text = text.replace(/\r?\n/g, process.platform === 'win32' ? '\r\n' : '\n');
const lineEndingOption = atom.config.get('editor.convertLineEndingOnCopy');
if (lineEndingOption !== "off") {
text = text.replace(
/\r?\n/g,
lineEndingOption === "CRLF" ||
(lineEndingOption === "system" && process.platform === 'win32')
? '\r\n'
: '\n'
);
}

this.signatureForMetadata = this.md5(text);
this.metadata = metadata;
Expand Down
13 changes: 10 additions & 3 deletions src/config-schema.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This is loaded by atom-environment.coffee. See
// https://atom.io/docs/api/latest/Config for more information about config TODO: Link to Pulsar API site when documented
// schemas.
// This is loaded by atom-environment.js.
// See https://atom.io/docs/api/latest/Config for more information about config schemas.
// TODO: Link to Pulsar API site when documented
const configSchema = {
core: {
type: 'object',
Expand Down Expand Up @@ -496,6 +496,13 @@ const configSchema = {
description:
'Automatically indent pasted text based on the indentation of the previous line.'
},
convertLineEndingOnCopy: {
type: 'string',
default: 'system',
enum: ['system', 'off', 'LF', 'CRLF'],
description:
'Changes how newlines are converted when text is copied. When set to "system", newlines are changed to CRLF on Windows and LF on Unix. When set to "off", newlines are copied as-is.'
},
nonWordCharacters: {
type: 'string',
default: '/\\()"\':,.;<>~!@#$%^&*|+=[]{}`?-…',
Expand Down
11 changes: 11 additions & 0 deletions src/pane-element.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const path = require('path');
const { CompositeDisposable } = require('event-kit');

// The HTMLElement corresponding to a {Pane}.
class PaneElement extends HTMLElement {
constructor() {
super();
Expand Down Expand Up @@ -72,6 +73,16 @@ class PaneElement extends HTMLElement {
this.addEventListener('drop', handleDrop);
}

// Sets up callbacks when PaneElement initializes
//
// Only called in {Pane::getElement} as of February 2025.
//
// * `model` The container {Pane}.
// * An {Object} with the following keys:
// * `views` A {ViewRegistry} used to hide and show pane items.
// * `applicationDelegate` An {ApplicationDelegate} used to open file paths.
//
// Returns this {PaneElement}.
initialize(model, { views, applicationDelegate }) {
this.model = model;
this.views = views;
Expand Down
5 changes: 5 additions & 0 deletions src/register-default-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,11 @@ module.exports = function({commandRegistry, commandInstaller, config, notificati
'core:paste': function() {
return this.pasteText();
},
'editor:paste-without-reindenting': function() {
return this.pasteText({
autoIndent: false
});
},
'editor:paste-without-reformatting': function() {
return this.pasteText({
normalizeLineEndings: false,
Expand Down
4 changes: 2 additions & 2 deletions src/view-registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const AnyConstructor = Symbol('any-constructor');

// Essential: `ViewRegistry` handles the association between model and view
// types in Pulsar. We call this association a View Provider. As in, for a given
// model, this class can provide a view via {::getView}, as long as the
// model/view association was registered via {::addViewProvider}
// model, this class can provide a view (a DOMElement) via {::getView}, as long
// as the model/view association was registered via {::addViewProvider}
//
// If you're adding your own kind of pane item, a good strategy for all but the
// simplest items is to separate the model and the view. The model handles
Expand Down
Loading