From e6565f6561121b6c22c8961f39038f97542b36cf Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 24 Jan 2014 17:52:54 -0800 Subject: [PATCH 01/14] Return object from Pasteboard::read Closes #1465 --- spec/editor-spec.coffee | 4 ++-- spec/editor-view-spec.coffee | 2 +- spec/pasteboard-spec.coffee | 7 ++++--- src/editor.coffee | 2 +- src/pasteboard.coffee | 15 ++++++++++----- src/selection.coffee | 3 +-- 6 files changed, 19 insertions(+), 14 deletions(-) diff --git a/spec/editor-spec.coffee b/spec/editor-spec.coffee index ecd6e6d7a..7339c3dda 100644 --- a/spec/editor-spec.coffee +++ b/spec/editor-spec.coffee @@ -1885,7 +1885,7 @@ describe "Editor", -> editor.cutToEndOfLine() expect(buffer.lineForRow(2)).toBe ' if (items.length' expect(buffer.lineForRow(3)).toBe ' var pivot = item' - expect(atom.pasteboard.read()[0]).toBe ' <= 1) return items;\ns.shift(), current, left = [], right = [];' + expect(atom.pasteboard.read().text).toBe ' <= 1) return items;\ns.shift(), current, left = [], right = [];' describe "when text is selected", -> it "only cuts the selected text, not to the end of the line", -> @@ -1895,7 +1895,7 @@ describe "Editor", -> expect(buffer.lineForRow(2)).toBe ' if (items.lengthurn items;' expect(buffer.lineForRow(3)).toBe ' var pivot = item' - expect(atom.pasteboard.read()[0]).toBe ' <= 1) ret\ns.shift(), current, left = [], right = [];' + expect(atom.pasteboard.read().text).toBe ' <= 1) ret\ns.shift(), current, left = [], right = [];' describe ".copySelectedText()", -> it "copies selected text onto the clipboard", -> diff --git a/spec/editor-view-spec.coffee b/spec/editor-view-spec.coffee index 23804de70..329e12e5b 100644 --- a/spec/editor-view-spec.coffee +++ b/spec/editor-view-spec.coffee @@ -2517,7 +2517,7 @@ describe "EditorView", -> describe "when editor:copy-path is triggered", -> it "copies the absolute path to the editor view's file to the pasteboard", -> editorView.trigger 'editor:copy-path' - expect(atom.pasteboard.read()[0]).toBe editor.getPath() + expect(atom.pasteboard.read().text).toBe editor.getPath() describe "when editor:move-line-up is triggered", -> describe "when there is no selection", -> diff --git a/spec/pasteboard-spec.coffee b/spec/pasteboard-spec.coffee index 467418204..f52779a37 100644 --- a/spec/pasteboard-spec.coffee +++ b/spec/pasteboard-spec.coffee @@ -1,10 +1,11 @@ describe "Pasteboard", -> describe "write(text, metadata) and read()", -> it "writes and reads text to/from the native pasteboard", -> - expect(atom.pasteboard.read()).toEqual ['initial pasteboard content'] + expect(atom.pasteboard.read().text).toBe 'initial pasteboard content' atom.pasteboard.write('next') - expect(atom.pasteboard.read()[0]).toBe 'next' + expect(atom.pasteboard.read().text).toBe 'next' it "returns metadata if the item on the native pasteboard matches the last written item", -> atom.pasteboard.write('next', {meta: 'data'}) - expect(atom.pasteboard.read()).toEqual ['next', {meta: 'data'}] + expect(atom.pasteboard.read().text).toBe 'next' + expect(atom.pasteboard.read().metadata).toEqual {meta: 'data'} diff --git a/src/editor.coffee b/src/editor.coffee index 753754be2..0012f0f35 100644 --- a/src/editor.coffee +++ b/src/editor.coffee @@ -559,7 +559,7 @@ class Editor extends Model # * options: # + A set of options equivalent to {Selection.insertText}. pasteText: (options={}) -> - [text, metadata] = atom.pasteboard.read() + {text, metadata} = atom.pasteboard.read() containsNewlines = text.indexOf('\n') isnt -1 diff --git a/src/pasteboard.coffee b/src/pasteboard.coffee index 2f97333d8..4b019ae78 100644 --- a/src/pasteboard.coffee +++ b/src/pasteboard.coffee @@ -6,6 +6,7 @@ crypto = require 'crypto' # A pasteboard instance is always available under the `atom.pasteboard` global. module.exports = class Pasteboard + metadata: null signatureForMetadata: null # Creates an `md5` hash of some text. @@ -27,10 +28,14 @@ class Pasteboard # Public: Read the text from the clipboard. # - # Returns an {Array}. The first element is the saved text and the second is - # any metadata associated with the text. + # Returns an {Object} with a `text` key and a `metadata` key if it has + # associated metadata. read: -> text = clipboard.readText() - value = [text] - value.push(@metadata) if @signatureForMetadata == @md5(text) - value + #TODO Return object once packages have been updated. + contents = [text] + contents.text = text + if @signatureForMetadata is @md5(text) + contents.push(@metadata) + contents.metadata = @metadata + contents diff --git a/src/selection.coffee b/src/selection.coffee index 915f3fb0b..e1a8d4b03 100644 --- a/src/selection.coffee +++ b/src/selection.coffee @@ -528,8 +528,7 @@ class Selection return if @isEmpty() text = @editor.buffer.getTextInRange(@getBufferRange()) if maintainPasteboard - [currentText, metadata] = atom.pasteboard.read() - text = currentText + '\n' + text + text = atom.pasteboard.read().text + '\n' + text else metadata = { indentBasis: @editor.indentationForBufferRow(@getBufferRange().start.row) } From fc2be08b608a39921084256720a86ccf14a182f2 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 3 Feb 2014 12:21:32 -0800 Subject: [PATCH 02/14] Rename Pasteboard class to Clipboard --- src/atom.coffee | 10 +++++++--- src/{pasteboard.coffee => clipboard.coffee} | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) rename src/{pasteboard.coffee => clipboard.coffee} (91%) diff --git a/src/atom.coffee b/src/atom.coffee index 3cc30c31e..760831b95 100644 --- a/src/atom.coffee +++ b/src/atom.coffee @@ -28,7 +28,7 @@ WindowEventHandler = require './window-event-handler' # * `atom.menu` - A {MenuManager} instance # * `atom.workspaceView` - A {WorkspaceView} instance # * `atom.packages` - A {PackageManager} instance -# * `atom.pasteboard` - A {Pasteboard} instance +# * `atom.clipboard` - A {Clipboard} instance # * `atom.project` - A {Project} instance # * `atom.syntax` - A {Syntax} instance # * `atom.themes` - A {ThemeManager} instance @@ -134,7 +134,7 @@ class Atom extends Model Config = require './config' Keymap = require './keymap' PackageManager = require './package-manager' - Pasteboard = require './pasteboard' + Clipboard = require './clipboard' Syntax = require './syntax' ThemeManager = require './theme-manager' ContextMenuManager = require './context-menu-manager' @@ -148,7 +148,11 @@ class Atom extends Model @themes = new ThemeManager({packageManager: @packages, configDirPath, resourcePath}) @contextMenu = new ContextMenuManager(devMode) @menu = new MenuManager({resourcePath}) - @pasteboard = new Pasteboard() + @clipboard = new Clipboard() + + # TODO Remove once packages have been updated + @pasteboard = @clipboard + @syntax = @deserializers.deserialize(@state.syntax) ? new Syntax() @subscribe @packages, 'activated', => @watchThemes() diff --git a/src/pasteboard.coffee b/src/clipboard.coffee similarity index 91% rename from src/pasteboard.coffee rename to src/clipboard.coffee index 4b019ae78..152edb7c9 100644 --- a/src/pasteboard.coffee +++ b/src/clipboard.coffee @@ -3,9 +3,9 @@ crypto = require 'crypto' # Public: Represents the clipboard used for copying and pasting in Atom. # -# A pasteboard instance is always available under the `atom.pasteboard` global. +# A clipboard instance is always available under the `atom.clipboard` global. module.exports = -class Pasteboard +class Clipboard metadata: null signatureForMetadata: null From b1e99d9927d94b884aa8a12ed0a9371eaa250e04 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 3 Feb 2014 13:10:10 -0800 Subject: [PATCH 03/14] Use atom.clipboard instead of atom.pasteboard --- spec/editor-spec.coffee | 6 +++--- spec/editor-view-spec.coffee | 2 +- spec/pasteboard-spec.coffee | 12 ++++++------ src/editor-view.coffee | 6 +++--- src/editor.coffee | 2 +- src/selection.coffee | 4 ++-- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/spec/editor-spec.coffee b/spec/editor-spec.coffee index 7339c3dda..741ea3b4c 100644 --- a/spec/editor-spec.coffee +++ b/spec/editor-spec.coffee @@ -1885,7 +1885,7 @@ describe "Editor", -> editor.cutToEndOfLine() expect(buffer.lineForRow(2)).toBe ' if (items.length' expect(buffer.lineForRow(3)).toBe ' var pivot = item' - expect(atom.pasteboard.read().text).toBe ' <= 1) return items;\ns.shift(), current, left = [], right = [];' + expect(atom.clipboard.read().text).toBe ' <= 1) return items;\ns.shift(), current, left = [], right = [];' describe "when text is selected", -> it "only cuts the selected text, not to the end of the line", -> @@ -1895,7 +1895,7 @@ describe "Editor", -> expect(buffer.lineForRow(2)).toBe ' if (items.lengthurn items;' expect(buffer.lineForRow(3)).toBe ' var pivot = item' - expect(atom.pasteboard.read().text).toBe ' <= 1) ret\ns.shift(), current, left = [], right = [];' + expect(atom.clipboard.read().text).toBe ' <= 1) ret\ns.shift(), current, left = [], right = [];' describe ".copySelectedText()", -> it "copies selected text onto the clipboard", -> @@ -1906,7 +1906,7 @@ describe "Editor", -> describe ".pasteText()", -> it "pastes text into the buffer", -> - atom.pasteboard.write('first') + atom.clipboard.write('first') editor.pasteText() expect(editor.buffer.lineForRow(0)).toBe "var first = function () {" expect(buffer.lineForRow(1)).toBe " var first = function(items) {" diff --git a/spec/editor-view-spec.coffee b/spec/editor-view-spec.coffee index 329e12e5b..54d435185 100644 --- a/spec/editor-view-spec.coffee +++ b/spec/editor-view-spec.coffee @@ -2517,7 +2517,7 @@ describe "EditorView", -> describe "when editor:copy-path is triggered", -> it "copies the absolute path to the editor view's file to the pasteboard", -> editorView.trigger 'editor:copy-path' - expect(atom.pasteboard.read().text).toBe editor.getPath() + expect(atom.clipboard.read().text).toBe editor.getPath() describe "when editor:move-line-up is triggered", -> describe "when there is no selection", -> diff --git a/spec/pasteboard-spec.coffee b/spec/pasteboard-spec.coffee index f52779a37..5e8dddfde 100644 --- a/spec/pasteboard-spec.coffee +++ b/spec/pasteboard-spec.coffee @@ -1,11 +1,11 @@ describe "Pasteboard", -> describe "write(text, metadata) and read()", -> it "writes and reads text to/from the native pasteboard", -> - expect(atom.pasteboard.read().text).toBe 'initial pasteboard content' - atom.pasteboard.write('next') - expect(atom.pasteboard.read().text).toBe 'next' + expect(atom.clipboard.read().text).toBe 'initial pasteboard content' + atom.clipboard.write('next') + expect(atom.clipboard.read().text).toBe 'next' it "returns metadata if the item on the native pasteboard matches the last written item", -> - atom.pasteboard.write('next', {meta: 'data'}) - expect(atom.pasteboard.read().text).toBe 'next' - expect(atom.pasteboard.read().metadata).toEqual {meta: 'data'} + atom.clipboard.write('next', {meta: 'data'}) + expect(atom.clipboard.read().text).toBe 'next' + expect(atom.clipboard.read().metadata).toEqual {meta: 'data'} diff --git a/src/editor-view.coffee b/src/editor-view.coffee index c3754070b..e29a2cc13 100644 --- a/src/editor-view.coffee +++ b/src/editor-view.coffee @@ -209,7 +209,7 @@ class EditorView extends View 'editor:toggle-line-comments': => @toggleLineCommentsInSelection() 'editor:log-cursor-scope': => @logCursorScope() 'editor:checkout-head-revision': => @checkoutHead() - 'editor:copy-path': => @copyPathToPasteboard() + 'editor:copy-path': => @copyPathToClipboard() 'editor:move-line-up': => @editor.moveLineUp() 'editor:move-line-down': => @editor.moveLineDown() 'editor:duplicate-line': => @editor.duplicateLine() @@ -1411,9 +1411,9 @@ class EditorView extends View @highlightedLine = null # Copies the current file path to the native clipboard. - copyPathToPasteboard: -> + copyPathToClipboard: -> path = @editor.getPath() - atom.pasteboard.write(path) if path? + atom.clipboard.write(path) if path? ### Internal ### diff --git a/src/editor.coffee b/src/editor.coffee index 0012f0f35..bc422b154 100644 --- a/src/editor.coffee +++ b/src/editor.coffee @@ -559,7 +559,7 @@ class Editor extends Model # * options: # + A set of options equivalent to {Selection.insertText}. pasteText: (options={}) -> - {text, metadata} = atom.pasteboard.read() + {text, metadata} = atom.clipboard.read() containsNewlines = text.indexOf('\n') isnt -1 diff --git a/src/selection.coffee b/src/selection.coffee index e1a8d4b03..7847e33f9 100644 --- a/src/selection.coffee +++ b/src/selection.coffee @@ -528,11 +528,11 @@ class Selection return if @isEmpty() text = @editor.buffer.getTextInRange(@getBufferRange()) if maintainPasteboard - text = atom.pasteboard.read().text + '\n' + text + text = atom.clipboard.read().text + '\n' + text else metadata = { indentBasis: @editor.indentationForBufferRow(@getBufferRange().start.row) } - atom.pasteboard.write(text, metadata) + atom.clipboard.write(text, metadata) # Public: Creates a fold containing the current selection. fold: -> From 569ab416b84bb78808f81d1d7ec0bbb826127fa7 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 3 Feb 2014 13:12:33 -0800 Subject: [PATCH 04/14] Replace pasteboard references with clipboard --- spec/editor-spec.coffee | 4 ++-- spec/editor-view-spec.coffee | 2 +- spec/pasteboard-spec.coffee | 8 ++++---- spec/spec-helper.coffee | 6 +++--- src/editor.coffee | 18 +++++++++--------- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/spec/editor-spec.coffee b/spec/editor-spec.coffee index 741ea3b4c..38a29f6fb 100644 --- a/spec/editor-spec.coffee +++ b/spec/editor-spec.coffee @@ -1856,12 +1856,12 @@ describe "Editor", -> expect(editor.getCursorBufferPosition()).toEqual [0, 2] expect(editor.getCursorScreenPosition()).toEqual [0, editor.getTabLength() * 2] - describe "pasteboard operations", -> + describe "clipboard operations", -> beforeEach -> editor.setSelectedBufferRanges([[[0, 4], [0, 13]], [[1, 6], [1, 10]]]) describe ".cutSelectedText()", -> - it "removes the selected text from the buffer and places it on the pasteboard", -> + it "removes the selected text from the buffer and places it on the clipboard", -> editor.cutSelectedText() expect(buffer.lineForRow(0)).toBe "var = function () {" expect(buffer.lineForRow(1)).toBe " var = function(items) {" diff --git a/spec/editor-view-spec.coffee b/spec/editor-view-spec.coffee index 54d435185..b84867374 100644 --- a/spec/editor-view-spec.coffee +++ b/spec/editor-view-spec.coffee @@ -2515,7 +2515,7 @@ describe "EditorView", -> expect(edited).toBe false describe "when editor:copy-path is triggered", -> - it "copies the absolute path to the editor view's file to the pasteboard", -> + it "copies the absolute path to the editor view's file to the clipboard", -> editorView.trigger 'editor:copy-path' expect(atom.clipboard.read().text).toBe editor.getPath() diff --git a/spec/pasteboard-spec.coffee b/spec/pasteboard-spec.coffee index 5e8dddfde..eaf4c7eb1 100644 --- a/spec/pasteboard-spec.coffee +++ b/spec/pasteboard-spec.coffee @@ -1,11 +1,11 @@ -describe "Pasteboard", -> +describe "Clipboard", -> describe "write(text, metadata) and read()", -> - it "writes and reads text to/from the native pasteboard", -> - expect(atom.clipboard.read().text).toBe 'initial pasteboard content' + it "writes and reads text to/from the native clipboard", -> + expect(atom.clipboard.read().text).toBe 'initial clipboard content' atom.clipboard.write('next') expect(atom.clipboard.read().text).toBe 'next' - it "returns metadata if the item on the native pasteboard matches the last written item", -> + it "returns metadata if the item on the native clipboard matches the last written item", -> atom.clipboard.write('next', {meta: 'data'}) expect(atom.clipboard.read().text).toBe 'next' expect(atom.clipboard.read().metadata).toEqual {meta: 'data'} diff --git a/spec/spec-helper.coffee b/spec/spec-helper.coffee index 8e939d03d..c93dcf4fd 100644 --- a/spec/spec-helper.coffee +++ b/spec/spec-helper.coffee @@ -95,9 +95,9 @@ beforeEach -> TokenizedBuffer.prototype.chunkSize = Infinity spyOn(TokenizedBuffer.prototype, "tokenizeInBackground").andCallFake -> @tokenizeNextChunk() - pasteboardContent = 'initial pasteboard content' - spyOn(clipboard, 'writeText').andCallFake (text) -> pasteboardContent = text - spyOn(clipboard, 'readText').andCallFake -> pasteboardContent + clipboardContent = 'initial clipboard content' + spyOn(clipboard, 'writeText').andCallFake (text) -> clipboardContent = text + spyOn(clipboard, 'readText').andCallFake -> clipboardContent addCustomMatchers(this) diff --git a/src/editor.coffee b/src/editor.coffee index bc422b154..c1cfa1114 100644 --- a/src/editor.coffee +++ b/src/editor.coffee @@ -535,24 +535,24 @@ class Editor extends Model # Public: Copies and removes all characters from cursor to the end of the # line. cutToEndOfLine: -> - maintainPasteboard = false + maintainClipboard = false @mutateSelectedText (selection) -> - selection.cutToEndOfLine(maintainPasteboard) - maintainPasteboard = true + selection.cutToEndOfLine(maintainClipboard) + maintainClipboard = true # Public: Cuts the selected text. cutSelectedText: -> - maintainPasteboard = false + maintainClipboard = false @mutateSelectedText (selection) -> - selection.cut(maintainPasteboard) - maintainPasteboard = true + selection.cut(maintainClipboard) + maintainClipboard = true # Public: Copies the selected text. copySelectedText: -> - maintainPasteboard = false + maintainClipboard = false for selection in @getSelections() - selection.copy(maintainPasteboard) - maintainPasteboard = true + selection.copy(maintainClipboard) + maintainClipboard = true # Public: Pastes the text in the clipboard. # From 55ca32f7b3ebb545315272d79766fb95e42bde11 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 3 Feb 2014 13:12:56 -0800 Subject: [PATCH 05/14] Rename pasteboard-spec to clipboard-spec --- spec/{pasteboard-spec.coffee => clipboard-spec.coffee} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename spec/{pasteboard-spec.coffee => clipboard-spec.coffee} (100%) diff --git a/spec/pasteboard-spec.coffee b/spec/clipboard-spec.coffee similarity index 100% rename from spec/pasteboard-spec.coffee rename to spec/clipboard-spec.coffee From 70a7514f9e01ca599a471cb8d688037abe553480 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 3 Feb 2014 13:20:24 -0800 Subject: [PATCH 06/14] Add Clipboard::readWithMetadata This includes the associated metadata and Clipboard::read now returns a String. --- spec/clipboard-spec.coffee | 9 +++++---- spec/editor-spec.coffee | 4 ++-- spec/editor-view-spec.coffee | 2 +- src/clipboard.coffee | 31 +++++++++++++++++++------------ src/editor.coffee | 2 +- 5 files changed, 28 insertions(+), 20 deletions(-) diff --git a/spec/clipboard-spec.coffee b/spec/clipboard-spec.coffee index eaf4c7eb1..0553f0eae 100644 --- a/spec/clipboard-spec.coffee +++ b/spec/clipboard-spec.coffee @@ -1,11 +1,12 @@ describe "Clipboard", -> describe "write(text, metadata) and read()", -> it "writes and reads text to/from the native clipboard", -> - expect(atom.clipboard.read().text).toBe 'initial clipboard content' + expect(atom.clipboard.read()).toBe 'initial clipboard content' atom.clipboard.write('next') - expect(atom.clipboard.read().text).toBe 'next' + expect(atom.clipboard.read()).toBe 'next' it "returns metadata if the item on the native clipboard matches the last written item", -> atom.clipboard.write('next', {meta: 'data'}) - expect(atom.clipboard.read().text).toBe 'next' - expect(atom.clipboard.read().metadata).toEqual {meta: 'data'} + expect(atom.clipboard.read()).toBe 'next' + expect(atom.clipboard.readWithMetadata().text).toBe 'next' + expect(atom.clipboard.readWithMetadata().metadata).toEqual {meta: 'data'} diff --git a/spec/editor-spec.coffee b/spec/editor-spec.coffee index 38a29f6fb..8d5e05d9a 100644 --- a/spec/editor-spec.coffee +++ b/spec/editor-spec.coffee @@ -1885,7 +1885,7 @@ describe "Editor", -> editor.cutToEndOfLine() expect(buffer.lineForRow(2)).toBe ' if (items.length' expect(buffer.lineForRow(3)).toBe ' var pivot = item' - expect(atom.clipboard.read().text).toBe ' <= 1) return items;\ns.shift(), current, left = [], right = [];' + expect(atom.clipboard.read()).toBe ' <= 1) return items;\ns.shift(), current, left = [], right = [];' describe "when text is selected", -> it "only cuts the selected text, not to the end of the line", -> @@ -1895,7 +1895,7 @@ describe "Editor", -> expect(buffer.lineForRow(2)).toBe ' if (items.lengthurn items;' expect(buffer.lineForRow(3)).toBe ' var pivot = item' - expect(atom.clipboard.read().text).toBe ' <= 1) ret\ns.shift(), current, left = [], right = [];' + expect(atom.clipboard.read()).toBe ' <= 1) ret\ns.shift(), current, left = [], right = [];' describe ".copySelectedText()", -> it "copies selected text onto the clipboard", -> diff --git a/spec/editor-view-spec.coffee b/spec/editor-view-spec.coffee index b84867374..b63079d11 100644 --- a/spec/editor-view-spec.coffee +++ b/spec/editor-view-spec.coffee @@ -2517,7 +2517,7 @@ describe "EditorView", -> describe "when editor:copy-path is triggered", -> it "copies the absolute path to the editor view's file to the clipboard", -> editorView.trigger 'editor:copy-path' - expect(atom.clipboard.read().text).toBe editor.getPath() + expect(atom.clipboard.read()).toBe editor.getPath() describe "when editor:move-line-up is triggered", -> describe "when there is no selection", -> diff --git a/src/clipboard.coffee b/src/clipboard.coffee index 152edb7c9..00725b5e7 100644 --- a/src/clipboard.coffee +++ b/src/clipboard.coffee @@ -11,16 +11,19 @@ class Clipboard # Creates an `md5` hash of some text. # - # text - A {String} to encrypt. + # * text: A {String} to hash. # - # Returns an encrypted {String}. + # Returns a hashed {String}. md5: (text) -> crypto.createHash('md5').update(text, 'utf8').digest('hex') # Public: Write the given text to the clipboard. # - # text - A {String} to store. - # metadata - An {Object} of additional info to associate with the text. + # The metadata associated with the text is available by calling + # {.readWithMetadata}. + # + # * text: A {String} to store. + # * metadata: An {Object} of additional info to associate with the text. write: (text, metadata) -> @signatureForMetadata = @md5(text) @metadata = metadata @@ -28,14 +31,18 @@ class Clipboard # Public: Read the text from the clipboard. # + # Returns a {String}. + read: -> + clipboard.readText() + + # Public: Read the text from the clipboard and return both the text and the + # associated metadata. + # # Returns an {Object} with a `text` key and a `metadata` key if it has # associated metadata. - read: -> - text = clipboard.readText() - #TODO Return object once packages have been updated. - contents = [text] - contents.text = text + readWithMetadata: -> + text = @read() if @signatureForMetadata is @md5(text) - contents.push(@metadata) - contents.metadata = @metadata - contents + {text, @metadata} + else + {text} diff --git a/src/editor.coffee b/src/editor.coffee index c1cfa1114..904c8dfa4 100644 --- a/src/editor.coffee +++ b/src/editor.coffee @@ -559,7 +559,7 @@ class Editor extends Model # * options: # + A set of options equivalent to {Selection.insertText}. pasteText: (options={}) -> - {text, metadata} = atom.clipboard.read() + {text, metadata} = atom.clipboard.readWithMetadata() containsNewlines = text.indexOf('\n') isnt -1 From 66530eb69a83788bfb16ba679846ddea88f8e152 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 3 Feb 2014 13:28:09 -0800 Subject: [PATCH 07/14] Rename remaining pasteboard occurences --- spec/editor-spec.coffee | 2 +- src/selection.coffee | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/spec/editor-spec.coffee b/spec/editor-spec.coffee index 8d5e05d9a..31649ab44 100644 --- a/spec/editor-spec.coffee +++ b/spec/editor-spec.coffee @@ -1860,7 +1860,7 @@ describe "Editor", -> beforeEach -> editor.setSelectedBufferRanges([[[0, 4], [0, 13]], [[1, 6], [1, 10]]]) - describe ".cutSelectedText()", -> + fdescribe ".cutSelectedText()", -> it "removes the selected text from the buffer and places it on the clipboard", -> editor.cutSelectedText() expect(buffer.lineForRow(0)).toBe "var = function () {" diff --git a/src/selection.coffee b/src/selection.coffee index 7847e33f9..7df6730b4 100644 --- a/src/selection.coffee +++ b/src/selection.coffee @@ -506,28 +506,28 @@ class Selection # Public: Cuts the selection until the end of the line. # - # * maintainPasteboard: + # * maintainClipboard: # ? - cutToEndOfLine: (maintainPasteboard) -> + cutToEndOfLine: (maintainClipboard) -> @selectToEndOfLine() if @isEmpty() - @cut(maintainPasteboard) + @cut(maintainClipboard) - # Public: Copies the selection to the pasteboard and then deletes it. + # Public: Copies the selection to the clipboard and then deletes it. # - # * maintainPasteboard: + # * maintainClipboard: # ? - cut: (maintainPasteboard=false) -> - @copy(maintainPasteboard) + cut: (maintainClipboard=false) -> + @copy(maintainClipboard) @delete() - # Public: Copies the current selection to the pasteboard. + # Public: Copies the current selection to the clipboard. # - # * maintainPasteboard: + # * maintainClipboard: # ? - copy: (maintainPasteboard=false) -> + copy: (maintainClipboard=false) -> return if @isEmpty() text = @editor.buffer.getTextInRange(@getBufferRange()) - if maintainPasteboard + if maintainClipboard text = atom.clipboard.read().text + '\n' + text else metadata = { indentBasis: @editor.indentationForBufferRow(@getBufferRange().start.row) } From fbdb5b59eaa77c9bab4f768a19a7938ddf0e7b61 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 3 Feb 2014 13:29:20 -0800 Subject: [PATCH 08/14] Remove pasteboard shim --- src/atom.coffee | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/atom.coffee b/src/atom.coffee index 760831b95..fb9488452 100644 --- a/src/atom.coffee +++ b/src/atom.coffee @@ -150,9 +150,6 @@ class Atom extends Model @menu = new MenuManager({resourcePath}) @clipboard = new Clipboard() - # TODO Remove once packages have been updated - @pasteboard = @clipboard - @syntax = @deserializers.deserialize(@state.syntax) ? new Syntax() @subscribe @packages, 'activated', => @watchThemes() From 84e69db268382d1dd64fbab5a725a424be1b4206 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 3 Feb 2014 13:31:52 -0800 Subject: [PATCH 09/14] Upgrade to to-the-hubs@0.19.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 94a73828d..1f3ed195e 100644 --- a/package.json +++ b/package.json @@ -98,7 +98,7 @@ "tabs": "0.18.0", "terminal": "0.27.0", "timecop": "0.13.0", - "to-the-hubs": "0.18.0", + "to-the-hubs": "0.19.0", "tree-view": "0.66.0", "update-package-dependencies": "0.2.0", "visual-bell": "0.6.0", From f0c200f23330a0a1abb93c456e94c61a01d8c233 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 3 Feb 2014 13:32:07 -0800 Subject: [PATCH 10/14] Upgrade to gists@0.16.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1f3ed195e..b1d151ce2 100644 --- a/package.json +++ b/package.json @@ -77,7 +77,7 @@ "feedback": "0.22.0", "find-and-replace": "0.81.0", "fuzzy-finder": "0.32.0", - "gists": "0.15.0", + "gists": "0.16.0", "git-diff": "0.23.0", "github-sign-in": "0.18.0", "go-to-line": "0.16.0", From ca6521b71177a05969e7680faa1026b487f895df Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 3 Feb 2014 13:34:28 -0800 Subject: [PATCH 11/14] Upgrade to settings-view@0.65.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b1d151ce2..5f41749ca 100644 --- a/package.json +++ b/package.json @@ -89,7 +89,7 @@ "metrics": "0.24.0", "package-generator": "0.25.0", "release-notes": "0.17.0", - "settings-view": "0.64.0", + "settings-view": "0.65.0", "snippets": "0.24.0", "spell-check": "0.21.0", "status-bar": "0.32.0", From 02f0c49d0e673df8d51f730e7997cc3456f1063e Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 3 Feb 2014 13:36:12 -0800 Subject: [PATCH 12/14] Unfocus spec --- spec/editor-spec.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/editor-spec.coffee b/spec/editor-spec.coffee index 31649ab44..8d5e05d9a 100644 --- a/spec/editor-spec.coffee +++ b/spec/editor-spec.coffee @@ -1860,7 +1860,7 @@ describe "Editor", -> beforeEach -> editor.setSelectedBufferRanges([[[0, 4], [0, 13]], [[1, 6], [1, 10]]]) - fdescribe ".cutSelectedText()", -> + describe ".cutSelectedText()", -> it "removes the selected text from the buffer and places it on the clipboard", -> editor.cutSelectedText() expect(buffer.lineForRow(0)).toBe "var = function () {" From 0e0ae17cd3935847c3928fd4ff07a7116cca2b0a Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 3 Feb 2014 13:39:54 -0800 Subject: [PATCH 13/14] Upgrade to tree-view@0.67.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5f41749ca..b11f3f1ed 100644 --- a/package.json +++ b/package.json @@ -99,7 +99,7 @@ "terminal": "0.27.0", "timecop": "0.13.0", "to-the-hubs": "0.19.0", - "tree-view": "0.66.0", + "tree-view": "0.67.0", "update-package-dependencies": "0.2.0", "visual-bell": "0.6.0", "welcome": "0.4.0", From a04f77b4001c7009d8e8411d2782fc9015c22aba Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 3 Feb 2014 13:50:40 -0800 Subject: [PATCH 14/14] Update atom.clipboard.read() call for new return value --- src/selection.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/selection.coffee b/src/selection.coffee index 7df6730b4..7aceb8a79 100644 --- a/src/selection.coffee +++ b/src/selection.coffee @@ -528,7 +528,7 @@ class Selection return if @isEmpty() text = @editor.buffer.getTextInRange(@getBufferRange()) if maintainClipboard - text = atom.clipboard.read().text + '\n' + text + text = "#{atom.clipboard.read()}\n#{text}" else metadata = { indentBasis: @editor.indentationForBufferRow(@getBufferRange().start.row) }